[asterisk-commits] mjordan: testsuite/asterisk/trunk r3736 - in /asterisk/trunk: ./ lib/python/a...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed May 1 11:13:07 CDT 2013
Author: mjordan
Date: Wed May 1 11:13:04 2013
New Revision: 3736
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3736
Log:
Add sip-channels test condition
This patch adds the ability to check for the presence of SIP channels prior to
and after test execution using the pre-/post-condition checking API. If a
SIP channel is detected, the test is failed.
(closes issue ASTERISK-20502)
Reported by: Nitesh Bansal
patches:
SipChannelTestCondition.py uploaded by Nitesh Bansal (License 6418)
test-config.yaml uploaded by Nitesh Bansal (License 6418)
Added:
asterisk/trunk/lib/python/asterisk/SipChannelTestCondition.py (with props)
Modified:
asterisk/trunk/test-config.yaml
Added: asterisk/trunk/lib/python/asterisk/SipChannelTestCondition.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/SipChannelTestCondition.py?view=auto&rev=3736
==============================================================================
--- asterisk/trunk/lib/python/asterisk/SipChannelTestCondition.py (added)
+++ asterisk/trunk/lib/python/asterisk/SipChannelTestCondition.py Wed May 1 11:13:04 2013
@@ -1,0 +1,60 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2013, Digium, Inc.
+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.
+'''
+
+import logging
+import logging.config
+import unittest
+
+from twisted.internet import defer
+from TestConditions import TestCondition
+
+logger = logging.getLogger(__name__)
+
+class SipChannelTestCondition(TestCondition):
+ """
+ Test condition that checks for the existance of SIP 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):
+ super(SipChannelTestCondition, 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):
+ def __channel_callback(result):
+ channel_tokens = result.output.strip().split('\n')
+ active_channels = 0
+ for token in channel_tokens:
+ if 'active SIP channel' in token:
+ active_channel_tokens = token.partition(' ')
+ active_channels = int(active_channel_tokens[0].strip())
+ if active_channels > self.allowed_channels:
+ super(SipChannelTestCondition, self).failCheck(
+ 'Detected number of active SIP channels %d is greater than the allowed %d on Asterisk %s'
+ % (active_channels, self.allowed_channels, result.host))
+ return result
+
+ def __raise_finished(result):
+ self.__finished_deferred.callback(self)
+ return result
+
+ self.__finished_deferred = defer.Deferred()
+ # Set to pass and let a failure override
+ super(SipChannelTestCondition, self).passCheck()
+
+ defer.DeferredList([ast.cli_exec('sip show channels').addCallback(__channel_callback) for ast in self.ast]
+ ).addCallback(__raise_finished)
+ return self.__finished_deferred
Propchange: asterisk/trunk/lib/python/asterisk/SipChannelTestCondition.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/lib/python/asterisk/SipChannelTestCondition.py
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/lib/python/asterisk/SipChannelTestCondition.py
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: asterisk/trunk/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/test-config.yaml?view=diff&rev=3736&r1=3735&r2=3736
==============================================================================
--- asterisk/trunk/test-config.yaml (original)
+++ asterisk/trunk/test-config.yaml Wed May 1 11:13:04 2013
@@ -45,6 +45,12 @@
typename: 'asterisk.ChannelTestCondition.ChannelTestCondition'
post:
typename: 'asterisk.ChannelTestCondition.ChannelTestCondition'
+ -
+ name: 'sip-channels'
+ pre:
+ typename: 'asterisk.SipChannelTestCondition.SipChannelTestCondition'
+ post:
+ typename: 'asterisk.SipChannelTestCondition.SipChannelTestCondition'
# Exclude all long-running tests (greater than one minute)
config-fast:
@@ -89,6 +95,7 @@
- name: 'locks'
- name: 'file-descriptors'
- name: 'channels'
+ - name: 'sip-channels'
config-specific-version:
properties:
More information about the asterisk-commits
mailing list