[Asterisk-code-review] testsuite: add the ability to test number of pjsip channels (testsuite[master])

Torrey Searle asteriskteam at digium.com
Wed Apr 18 03:43:28 CDT 2018


Torrey Searle has uploaded this change for review. ( https://gerrit.asterisk.org/8808


Change subject: testsuite: add the ability to test number of pjsip channels
......................................................................

testsuite: add the ability to test number of pjsip channels

ported sip_channel_test_condition to work with pjsip

Change-Id: I48a54fe0cbec8fdcc0934d5a330eac2724bc2f4f
---
A lib/python/asterisk/pjsip_channel_test_condition.py
M test-config.yaml
2 files changed, 70 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/08/8808/1

diff --git a/lib/python/asterisk/pjsip_channel_test_condition.py b/lib/python/asterisk/pjsip_channel_test_condition.py
new file mode 100644
index 0000000..2956bef
--- /dev/null
+++ b/lib/python/asterisk/pjsip_channel_test_condition.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2018, Digium, Inc.
+Torrey Searle  <tsearle at gmail.com>
+Nitesh Bansal <nitesh.bansal at gmail.com>
+Matt Jordan <mjordan at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+"""
+
+from twisted.internet import defer
+from test_conditions import TestCondition
+
+
+class PJSipChannelTestCondition(TestCondition):
+    """Test condition that checks for the existence of PJSIP channels.
+
+    If channels are detected and the number of active channels is greater than
+    the configured amount, an error is raised.
+
+    By default, the number of allowed active channels is 0.
+    """
+
+    def __init__(self, test_config):
+        """Constructor"""
+        super(PJSipChannelTestCondition, self).__init__(test_config)
+
+        self.allowed_channels = 0
+        if ('allowedchannels' in test_config.config):
+            self.allowed_channels = test_config.config['allowedchannels']
+
+    def evaluate(self, related_test_condition = None):
+        """Evaluate the test condition"""
+
+        def __channel_callback(result):
+            """Callback for the CLI command"""
+
+            channel_tokens = result.output.strip().split('\n')
+            active_channels = 0
+            for token in channel_tokens:
+                if 'Objects found: ' in token:
+                    active_channels = int(token[token.find(":")+1:].strip())
+            if active_channels > self.allowed_channels:
+                super(PJSipChannelTestCondition, self).fail_check(
+                    ("Detected number of active PJSIP channels %d is greater "
+                     "than the allowed %d on Asterisk %s" %
+                     (active_channels, self.allowed_channels, result.host)))
+            return result
+
+        def __raise_finished(finished_deferred):
+            """Let things know when we're done"""
+            finished_deferred.callback(self)
+            return finished_deferred
+
+        finished_deferred = defer.Deferred()
+        # Set to pass and let a failure override
+        super(PJSipChannelTestCondition, self).pass_check()
+
+        exec_list = [ast.cli_exec('pjsip show channels').addCallback(
+            __channel_callback) for ast in self.ast]
+        defer.DeferredList(exec_list).addCallback(__raise_finished,
+                                                  finished_deferred)
+        return finished_deferred
diff --git a/test-config.yaml b/test-config.yaml
index 2e03fb3..6ea1339 100644
--- a/test-config.yaml
+++ b/test-config.yaml
@@ -52,6 +52,12 @@
                 post:
                     typename: 'sip_channel_test_condition.SipChannelTestCondition'
             -
+                name: 'pjsip-channels'
+                pre:
+                    typename: 'pjsip_channel_test_condition.PJSipChannelTestCondition'
+                post:
+                    typename: 'pjsip_channel_test_condition.PJSipChannelTestCondition'
+            -
                 name: 'memory'
                 pre:
                     typename: 'memory_test_condition.MemoryPreTestCondition'

-- 
To view, visit https://gerrit.asterisk.org/8808
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I48a54fe0cbec8fdcc0934d5a330eac2724bc2f4f
Gerrit-Change-Number: 8808
Gerrit-PatchSet: 1
Gerrit-Owner: Torrey Searle <tsearle at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180418/9ddeab7f/attachment.html>


More information about the asterisk-code-review mailing list