<p>Torrey Searle has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8808">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">testsuite: add the ability to test number of pjsip channels<br><br>ported sip_channel_test_condition to work with pjsip<br><br>Change-Id: I48a54fe0cbec8fdcc0934d5a330eac2724bc2f4f<br>---<br>A lib/python/asterisk/pjsip_channel_test_condition.py<br>M test-config.yaml<br>2 files changed, 70 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/08/8808/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/lib/python/asterisk/pjsip_channel_test_condition.py b/lib/python/asterisk/pjsip_channel_test_condition.py<br>new file mode 100644<br>index 0000000..2956bef<br>--- /dev/null<br>+++ b/lib/python/asterisk/pjsip_channel_test_condition.py<br>@@ -0,0 +1,64 @@<br>+#!/usr/bin/env python<br>+'''<br>+Copyright (C) 2018, Digium, Inc.<br>+Torrey Searle <tsearle@gmail.com><br>+Nitesh Bansal <nitesh.bansal@gmail.com><br>+Matt Jordan <mjordan@digium.com><br>+<br>+This program is free software, distributed under the terms of<br>+the GNU General Public License Version 2.<br>+"""<br>+<br>+from twisted.internet import defer<br>+from test_conditions import TestCondition<br>+<br>+<br>+class PJSipChannelTestCondition(TestCondition):<br>+ """Test condition that checks for the existence of PJSIP channels.<br>+<br>+ If channels are detected and the number of active channels is greater than<br>+ the configured amount, an error is raised.<br>+<br>+ By default, the number of allowed active channels is 0.<br>+ """<br>+<br>+ def __init__(self, test_config):<br>+ """Constructor"""<br>+ super(PJSipChannelTestCondition, self).__init__(test_config)<br>+<br>+ self.allowed_channels = 0<br>+ if ('allowedchannels' in test_config.config):<br>+ self.allowed_channels = test_config.config['allowedchannels']<br>+<br>+ def evaluate(self, related_test_condition = None):<br>+ """Evaluate the test condition"""<br>+<br>+ def __channel_callback(result):<br>+ """Callback for the CLI command"""<br>+<br>+ channel_tokens = result.output.strip().split('\n')<br>+ active_channels = 0<br>+ for token in channel_tokens:<br>+ if 'Objects found: ' in token:<br>+ active_channels = int(token[token.find(":")+1:].strip())<br>+ if active_channels > self.allowed_channels:<br>+ super(PJSipChannelTestCondition, self).fail_check(<br>+ ("Detected number of active PJSIP channels %d is greater "<br>+ "than the allowed %d on Asterisk %s" %<br>+ (active_channels, self.allowed_channels, result.host)))<br>+ return result<br>+<br>+ def __raise_finished(finished_deferred):<br>+ """Let things know when we're done"""<br>+ finished_deferred.callback(self)<br>+ return finished_deferred<br>+<br>+ finished_deferred = defer.Deferred()<br>+ # Set to pass and let a failure override<br>+ super(PJSipChannelTestCondition, self).pass_check()<br>+<br>+ exec_list = [ast.cli_exec('pjsip show channels').addCallback(<br>+ __channel_callback) for ast in self.ast]<br>+ defer.DeferredList(exec_list).addCallback(__raise_finished,<br>+ finished_deferred)<br>+ return finished_deferred<br>diff --git a/test-config.yaml b/test-config.yaml<br>index 2e03fb3..6ea1339 100644<br>--- a/test-config.yaml<br>+++ b/test-config.yaml<br>@@ -52,6 +52,12 @@<br> post:<br> typename: 'sip_channel_test_condition.SipChannelTestCondition'<br> -<br>+ name: 'pjsip-channels'<br>+ pre:<br>+ typename: 'pjsip_channel_test_condition.PJSipChannelTestCondition'<br>+ post:<br>+ typename: 'pjsip_channel_test_condition.PJSipChannelTestCondition'<br>+ -<br> name: 'memory'<br> pre:<br> typename: 'memory_test_condition.MemoryPreTestCondition'<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8808">change 8808</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8808"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: testsuite </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I48a54fe0cbec8fdcc0934d5a330eac2724bc2f4f </div>
<div style="display:none"> Gerrit-Change-Number: 8808 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Torrey Searle <tsearle@gmail.com> </div>