[asterisk-commits] mjordan: branch mjordan/test_conditions r2261 - in /asterisk/team/mjordan/tes...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 15 08:12:04 CDT 2011


Author: mjordan
Date: Thu Sep 15 08:12:02 2011
New Revision: 2261

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=2261
Log:
Updates to prep SipDialogTestCondition for inclusion in trunk

Added:
    asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/SipDialogTestCondition.py   (with props)
Modified:
    asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/LockTestCondition.py
    asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/TestConditions.py
    asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/TestConfig.py
    asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/ThreadTestCondition.py
    asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/authenticate_nominal/test-config.yaml
    asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/check_voicemail_new_user/test-config.yaml
    asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/func_vmcount/test-config.yaml
    asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/leave_voicemail_nominal/test-config.yaml

Modified: asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/LockTestCondition.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/LockTestCondition.py?view=diff&rev=2261&r1=2260&r2=2261
==============================================================================
--- asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/LockTestCondition.py (original)
+++ asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/LockTestCondition.py Thu Sep 15 08:12:02 2011
@@ -145,8 +145,8 @@
     is never a good thing.
     """
 
-    def __init__(self):
-        super(LockTestCondition, self).__init__("LockTestCondition")
+    def __init__(self, test_config):
+        super(LockTestCondition, self).__init__(test_config)
         self.locks = []
 
         """ core show locks is dependent on DEBUG_THREADS """
@@ -265,17 +265,26 @@
         lockLines += "=======================================================================\n"
         return lockLines
 
+class TestConfig(object):
+    def __init__(self):
+        """ Values here don't matter much - we just need to have something """
+        self.classTypeName = "asterisk.LockTestCondition.LockTestCondition"
+        self.passExpected = True
+        self.type = "Post"
+        self.relatedCondition = ""
+        self.config = {}
+
 class LockTestConditionUnitTest(unittest.TestCase):
     def test_evaluate_failed(self):
         ast = AstMockObjectFailure()
-        obj = LockTestCondition()
+        obj = LockTestCondition(TestConfig())
         obj.register_asterisk_instance(ast)
         obj.evaluate()
         self.assertEqual(obj.getStatus(), 'Failed')
 
     def test_evaluate_pass(self):
         ast = AstMockObjectPassed()
-        obj = LockTestCondition()
+        obj = LockTestCondition(TestConfig())
         obj.register_asterisk_instance(ast)
         obj.evaluate()
         self.assertEqual(obj.getStatus(), 'Passed')
@@ -283,7 +292,7 @@
     def test_evaluate_multiple(self):
         ast1 = AstMockObjectPassed()
         ast2 = AstMockObjectFailure()
-        obj = LockTestCondition()
+        obj = LockTestCondition(TestConfig())
         obj.register_asterisk_instance(ast1)
         obj.register_asterisk_instance(ast2)
         obj.evaluate()

Added: asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/SipDialogTestCondition.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/SipDialogTestCondition.py?view=auto&rev=2261
==============================================================================
--- asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/SipDialogTestCondition.py (added)
+++ asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/SipDialogTestCondition.py Thu Sep 15 08:12:02 2011
@@ -1,0 +1,475 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2011, Digium, Inc.
+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 time
+import unittest
+
+from TestConditions import TestCondition
+from starpy import manager
+
+logger = logging.getLogger(__name__)
+
+class SipDialogTestCondition(TestCondition):
+    """
+    This class is a base class for the pre- and post-test condition
+    classes that check for the existance of SIP dialogs in Asterisk.  It provides common
+    functionality for parsing out the results of the 'sip show objects' and
+    'sip show history' Asterisk commands
+    """
+
+    def __init__(self, test_config):
+        super(SipDialogTestCondition, self).__init__(test_config)
+
+    def __get_dialog_names(self, objects):
+        inObjects = False
+        objectList = objects.split('\n')
+        dialogNames = []
+        for o in objectList:
+            if "Dialog objects" in o:
+                inObjects = True
+            if "name:" in o and inObjects:
+                dialogNames.append(o[o.find(":")+1:].strip())
+        return dialogNames
+
+    def get_sip_dialogs(self, ast):
+        dialogNames = []
+        dialogsHistory = {}
+        objects = ast.cli_exec("sip show objects", True)
+        dialogNames = self.__get_dialog_names(objects)
+
+        for dn in dialogNames:
+            logger.debug("Retrieving history for SIP dialog %s" % dn)
+            rawHistory = ast.cli_exec("sip show history %s" % dn, True)
+            dialogsHistory[dn] = rawHistory.split('\n')
+
+        return dialogsHistory
+
+class SipDialogPreTestCondition(SipDialogTestCondition):
+    """
+    Check the pre-test conditions for SIP dialogs.  This test simply
+    checks that there are no SIP dialogs present before test execution.
+    """
+
+    def __init__(self, test_config):
+        super(SipDialogPreTestCondition, self).__init__(test_config)
+
+    def evaluate(self, related_test_condition = None):
+        for ast in self.ast:
+            ast.cli_exec("sip set history on")
+            dialogsHistory = super(SipDialogPreTestCondition, self).get_sip_dialogs(ast)
+
+            if len(dialogsHistory) > 0:
+                """ If any dialogs are present before test execution, something funny is going on """
+                super(SipDialogPreTestCondition, self).failCheck(
+                    "%d dialogs were detected in Asterisk %s before test execution" % (len(dialogsHistory), ast.host))
+            else:
+                super(SipDialogPreTestCondition, self).passCheck()
+
+
+class SipDialogPostTestCondition(SipDialogTestCondition):
+    """
+    Check the post-test conditions for SIP dialogs.  This test looks for
+    any SIP dialogs still in existence.  If it does not detect any, the test
+    passes.  If it does detect dialogs, it checks to make sure that the dialogs
+    have been hungup and are scheduled for destruction.  If those two conditions
+    are met, the test passes; otherwise it fails.
+
+    Note: as a future enhancement, implement an AMI command that will force
+    garbage collection on the SIP dialogs.  We can then also check that the scheduler
+    properly collects SIP dialogs as part of this test.
+    """
+
+    def __init__(self, test_config):
+        super(SipDialogPostTestCondition, self).__init__(test_config)
+
+        self.sipHistorySequence = []
+        if 'sipHistoryRequirements' in test_config.config:
+            self.sipHistorySequence = test_config.config['sipHistoryRequirements']
+
+    def evaluate(self, related_test_condition = None):
+
+        for ast in self.ast:
+            sipHistoryRequirements = {}
+            dialogsHistory = super(SipDialogPostTestCondition, self).get_sip_dialogs(ast)
+
+            """ Set up the history statements to look for in each dialog history """
+            for dialogName in dialogsHistory.keys():
+                sipHistoryCheck = {}
+                for h in self.sipHistorySequence:
+                    sipHistoryCheck[h] = False
+                sipHistoryRequirements[dialogName] = sipHistoryCheck
+
+            """ Assume we pass the check.  This will be overriden if any history check fails """
+            super(SipDialogPostTestCondition, self).passCheck()
+            if (len(dialogsHistory) > 0):
+                for dialog, history in dialogsHistory.items():
+                    scheduled = False
+                    for h in history:
+                        if "SchedDestroy" in h:
+                            scheduled = True
+                        for req in sipHistoryRequirements[dialog].keys():
+                            if req in h:
+                                sipHistoryRequirements[dialog][req] = True
+
+                    if not scheduled:
+                        super(SipDialogPostTestCondition, self).failCheck(
+                            "Dialog %s in Asterisk instance %s not scheduled for destruction" % (dialog, ast.host))
+                    for req in sipHistoryRequirements[dialog].keys():
+                        if sipHistoryRequirements[dialog][req] == False:
+                            super(SipDialogPostTestCondition, self).failCheck(
+                                "Dialog %s in Asterisk instance %s did not have required step in history: %s" % (dialog, ast.host, req))
+
+class TestConfig(object):
+    def __init__(self):
+        """ Values here don't matter much - we just need to have something """
+        self.classTypeName = "asterisk.SipDialogTestCondition.SipDialogPostTestCondition"
+        self.passExpected = True
+        self.type = "Post"
+        self.relatedCondition = ""
+        self.config = {}
+
+class TestConfigWithHistory(TestConfig):
+    def __init__(self):
+        super(TestConfigWithHistory, self).__init__()
+        """ Values here don't matter much - we just need to have something """
+        tempList = []
+        self.config['sipHistoryRequirements'] = tempList
+        self.config['sipHistoryRequirements'].append('Hangup') 
+        self.config['sipHistoryRequirements'].append('NewChan')
+
+class AstMockObjectPostTestNoDestructionFail(object):
+    def __init__(self):
+        self.host = "127.0.0.6"
+
+    def cli_exec(self, command, sync = True):
+        retString = ""
+        if command == "sip show objects":
+            retString = "-= Peer objects: 4 static, 0 realtime, 0 autocreate =-\n\n"
+            retString += "name: audio\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7002\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7001\ntype: peer\nobjflags: 0\nrefcount: 1\n\n"
+            retString += "name: zoiper_01\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "-= Peer objects by IP =-\n\n"
+            retString += "name: zoiper_01\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: audio\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7002\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "-= Registry objects: 0 =-\n\n"
+            retString += "-= Dialog objects:\n\n"
+            retString += "name: 2ec048aa4ed1239664f6408f0c5044c4 at 127.0.0.2:5060\n"
+            retString += "type: dialog\n"
+            retString += "objflags: 0\n"
+            retString += "refcount: 2\n\n"
+            retString += "name: 2ec048aa4ed1239664f6408f0c5044c5 at 127.0.0.2:5060\n"
+            retString += "type: dialog\n"
+            retString += "objflags: 0\n"
+            retString += "refcount: 2\n\n"
+        elif command == "sip show history 2ec048aa4ed1239664f6408f0c5044c4 at 127.0.0.2:5060":
+            retString = "* SIP Call\n"
+            retString += "1. NewChan         Channel SIP/ast1-00000002 - from 2ec048aa4ed1239664f6408f0c5044\n"
+            retString += "2. TxReqRel        INVITE / 102 INVITE - INVITE\n"
+            retString += "3. Rx              SIP/2.0 / 102 INVITE / 100 Trying\n"
+            retString += "4. Rx              SIP/2.0 / 102 INVITE / 200 OK\n"
+            retString += "5. TxReq           ACK / 102 ACK - ACK\n"
+            retString += "6. Rx              BYE / 102 BYE / sip:ast2 at 127.0.0.2:5060\n"
+            retString += "7. RTCPaudio       Quality:ssrc=28249381;themssrc=485141946;lp=0;rxjitter=0.000029\n"
+            retString += "8. RTCPaudioJitter Quality:minrxjitter=0.000000;maxrxjitter=0.000000;avgrxjitter=0\n"
+            retString += "9. RTCPaudioLoss   Quality:minrxlost=0.000000;maxrxlost=0.000000;avgrxlost=0.00000\n"
+            retString += "10. RTCPaudioRTT    Quality:minrtt=0.000000;maxrtt=0.000000;avgrtt=0.000000;stdevrt\n"
+            retString += "11. SchedDestroy    32000 ms\n"
+            retString += "12. TxResp          SIP/2.0 / 102 BYE - 200 OK\n"
+            retString += "13. Hangup          Cause Normal Clearing\n"
+        elif command == "sip show history 2ec048aa4ed1239664f6408f0c5044c5 at 127.0.0.2:5060":
+            retString = "* SIP Call\n"
+            retString += "1. NewChan         Channel SIP/ast1-00000002 - from 2ec048aa4ed1239664f6408f0c5044\n"
+            retString += "2. TxReqRel        INVITE / 102 INVITE - INVITE\n"
+            retString += "3. Rx              SIP/2.0 / 102 INVITE / 100 Trying\n"
+            retString += "4. Rx              SIP/2.0 / 102 INVITE / 200 OK\n"
+            retString += "5. TxReq           ACK / 102 ACK - ACK\n"
+            retString += "6. Rx              BYE / 102 BYE / sip:ast2 at 127.0.0.2:5060\n"
+            retString += "7. RTCPaudio       Quality:ssrc=28249381;themssrc=485141946;lp=0;rxjitter=0.000029\n"
+            retString += "8. RTCPaudioJitter Quality:minrxjitter=0.000000;maxrxjitter=0.000000;avgrxjitter=0\n"
+            retString += "9. RTCPaudioLoss   Quality:minrxlost=0.000000;maxrxlost=0.000000;avgrxlost=0.00000\n"
+            retString += "10. RTCPaudioRTT    Quality:minrtt=0.000000;maxrtt=0.000000;avgrtt=0.000000;stdevrt\n"
+            retString += "11. TxResp          SIP/2.0 / 102 BYE - 200 OK\n"
+            retString += "12. Hangup          Cause Normal Clearing\n"
+        return retString
+
+class AstMockObjectPostTestNoHangupFail(object):
+    def __init__(self):
+        self.host = "127.0.0.5"
+
+    def cli_exec(self, command, sync = True):
+        retString = ""
+        if command == "sip show objects":
+            retString = "-= Peer objects: 4 static, 0 realtime, 0 autocreate =-\n\n"
+            retString += "name: audio\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7002\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7001\ntype: peer\nobjflags: 0\nrefcount: 1\n\n"
+            retString += "name: zoiper_01\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "-= Peer objects by IP =-\n\n"
+            retString += "name: zoiper_01\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: audio\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7002\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "-= Registry objects: 0 =-\n\n"
+            retString += "-= Dialog objects:\n\n"
+            retString += "name: 2ec048aa4ed1239664f6408f0c5044c4 at 127.0.0.2:5060\n"
+            retString += "type: dialog\n"
+            retString += "objflags: 0\n"
+            retString += "refcount: 2\n\n"
+            retString += "name: 2ec048aa4ed1239664f6408f0c5044c5 at 127.0.0.2:5060\n"
+            retString += "type: dialog\n"
+            retString += "objflags: 0\n"
+            retString += "refcount: 2\n\n"
+        elif command == "sip show history 2ec048aa4ed1239664f6408f0c5044c4 at 127.0.0.2:5060":
+            retString = "* SIP Call\n"
+            retString += "1. NewChan         Channel SIP/ast1-00000002 - from 2ec048aa4ed1239664f6408f0c5044\n"
+            retString += "2. TxReqRel        INVITE / 102 INVITE - INVITE\n"
+            retString += "3. Rx              SIP/2.0 / 102 INVITE / 100 Trying\n"
+            retString += "4. Rx              SIP/2.0 / 102 INVITE / 200 OK\n"
+            retString += "5. TxReq           ACK / 102 ACK - ACK\n"
+            retString += "6. Rx              BYE / 102 BYE / sip:ast2 at 127.0.0.2:5060\n"
+            retString += "7. RTCPaudio       Quality:ssrc=28249381;themssrc=485141946;lp=0;rxjitter=0.000029\n"
+            retString += "8. RTCPaudioJitter Quality:minrxjitter=0.000000;maxrxjitter=0.000000;avgrxjitter=0\n"
+            retString += "9. RTCPaudioLoss   Quality:minrxlost=0.000000;maxrxlost=0.000000;avgrxlost=0.00000\n"
+            retString += "10. RTCPaudioRTT    Quality:minrtt=0.000000;maxrtt=0.000000;avgrtt=0.000000;stdevrt\n"
+            retString += "11. SchedDestroy    32000 ms\n"
+            retString += "12. TxResp          SIP/2.0 / 102 BYE - 200 OK\n"
+        elif command == "sip show history 2ec048aa4ed1239664f6408f0c5044c5 at 127.0.0.2:5060":
+            retString = "* SIP Call\n"
+            retString += "1. NewChan         Channel SIP/ast1-00000002 - from 2ec048aa4ed1239664f6408f0c5044\n"
+            retString += "2. TxReqRel        INVITE / 102 INVITE - INVITE\n"
+            retString += "3. Rx              SIP/2.0 / 102 INVITE / 100 Trying\n"
+            retString += "4. Rx              SIP/2.0 / 102 INVITE / 200 OK\n"
+            retString += "5. TxReq           ACK / 102 ACK - ACK\n"
+            retString += "6. Rx              BYE / 102 BYE / sip:ast2 at 127.0.0.2:5060\n"
+            retString += "7. RTCPaudio       Quality:ssrc=28249381;themssrc=485141946;lp=0;rxjitter=0.000029\n"
+            retString += "8. RTCPaudioJitter Quality:minrxjitter=0.000000;maxrxjitter=0.000000;avgrxjitter=0\n"
+            retString += "9. RTCPaudioLoss   Quality:minrxlost=0.000000;maxrxlost=0.000000;avgrxlost=0.00000\n"
+            retString += "10. RTCPaudioRTT    Quality:minrtt=0.000000;maxrtt=0.000000;avgrtt=0.000000;stdevrt\n"
+            retString += "11. SchedDestroy    32000 ms\n"
+            retString += "12. TxResp          SIP/2.0 / 102 BYE - 200 OK\n"
+            retString += "13. Hangup          Cause Normal Clearing\n"
+        return retString
+
+class AstMockObjectPostTestNoDialogsPass(object):
+    def __init__(self):
+        self.host = "127.0.0.4"
+
+    def cli_exec(self, command, sync = True):
+        retString = ""
+        if command == "sip show objects":
+            retString = "-= Peer objects: 4 static, 0 realtime, 0 autocreate =-\n\n"
+            retString += "name: audio\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7002\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7001\ntype: peer\nobjflags: 0\nrefcount: 1\n\n"
+            retString += "name: zoiper_01\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "-= Peer objects by IP =-\n\n"
+            retString += "name: zoiper_01\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: audio\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7002\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "-= Registry objects: 0 =-\n\n"
+            retString += "-= Dialog objects:\n\n"
+
+        return retString
+
+class AstMockObjectPostTestPass(object):
+    def __init__(self):
+        self.host = "127.0.0.3"
+
+    def cli_exec(self, command, sync = True):
+        retString = ""
+        if command == "sip show objects":
+            retString = "-= Peer objects: 4 static, 0 realtime, 0 autocreate =-\n\n"
+            retString += "name: audio\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7002\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7001\ntype: peer\nobjflags: 0\nrefcount: 1\n\n"
+            retString += "name: zoiper_01\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "-= Peer objects by IP =-\n\n"
+            retString += "name: zoiper_01\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: audio\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7002\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "-= Registry objects: 0 =-\n\n"
+            retString += "-= Dialog objects:\n\n"
+            retString += "name: 2ec048aa4ed1239664f6408f0c5044c4 at 127.0.0.2:5060\n"
+            retString += "type: dialog\n"
+            retString += "objflags: 0\n"
+            retString += "refcount: 2\n\n"
+            retString += "name: 2ec048aa4ed1239664f6408f0c5044c5 at 127.0.0.2:5060\n"
+            retString += "type: dialog\n"
+            retString += "objflags: 0\n"
+            retString += "refcount: 2\n\n"
+        elif command == "sip show history 2ec048aa4ed1239664f6408f0c5044c4 at 127.0.0.2:5060":
+            retString = "* SIP Call\n"
+            retString += "1. NewChan         Channel SIP/ast1-00000002 - from 2ec048aa4ed1239664f6408f0c5044\n"
+            retString += "2. TxReqRel        INVITE / 102 INVITE - INVITE\n"
+            retString += "3. Rx              SIP/2.0 / 102 INVITE / 100 Trying\n"
+            retString += "4. Rx              SIP/2.0 / 102 INVITE / 200 OK\n"
+            retString += "5. TxReq           ACK / 102 ACK - ACK\n"
+            retString += "6. Rx              BYE / 102 BYE / sip:ast2 at 127.0.0.2:5060\n"
+            retString += "7. RTCPaudio       Quality:ssrc=28249381;themssrc=485141946;lp=0;rxjitter=0.000029\n"
+            retString += "8. RTCPaudioJitter Quality:minrxjitter=0.000000;maxrxjitter=0.000000;avgrxjitter=0\n"
+            retString += "9. RTCPaudioLoss   Quality:minrxlost=0.000000;maxrxlost=0.000000;avgrxlost=0.00000\n"
+            retString += "10. RTCPaudioRTT    Quality:minrtt=0.000000;maxrtt=0.000000;avgrtt=0.000000;stdevrt\n"
+            retString += "11. SchedDestroy    32000 ms\n"
+            retString += "12. TxResp          SIP/2.0 / 102 BYE - 200 OK\n"
+            retString += "13. Hangup          Cause Normal Clearing\n"
+        elif command == "sip show history 2ec048aa4ed1239664f6408f0c5044c5 at 127.0.0.2:5060":
+            retString = "* SIP Call\n"
+            retString += "1. NewChan         Channel SIP/ast1-00000002 - from 2ec048aa4ed1239664f6408f0c5044\n"
+            retString += "2. TxReqRel        INVITE / 102 INVITE - INVITE\n"
+            retString += "3. Rx              SIP/2.0 / 102 INVITE / 100 Trying\n"
+            retString += "4. Rx              SIP/2.0 / 102 INVITE / 200 OK\n"
+            retString += "5. TxReq           ACK / 102 ACK - ACK\n"
+            retString += "6. Rx              BYE / 102 BYE / sip:ast2 at 127.0.0.2:5060\n"
+            retString += "7. RTCPaudio       Quality:ssrc=28249381;themssrc=485141946;lp=0;rxjitter=0.000029\n"
+            retString += "8. RTCPaudioJitter Quality:minrxjitter=0.000000;maxrxjitter=0.000000;avgrxjitter=0\n"
+            retString += "9. RTCPaudioLoss   Quality:minrxlost=0.000000;maxrxlost=0.000000;avgrxlost=0.00000\n"
+            retString += "10. RTCPaudioRTT    Quality:minrtt=0.000000;maxrtt=0.000000;avgrtt=0.000000;stdevrt\n"
+            retString += "11. SchedDestroy    32000 ms\n"
+            retString += "12. TxResp          SIP/2.0 / 102 BYE - 200 OK\n"
+            retString += "13. Hangup          Cause Normal Clearing\n"
+        return retString
+
+class AstMockObjectPreTestFail(object):
+    def __init__(self):
+        self.host = "127.0.0.2"
+
+    def cli_exec(self, command, sync = True):
+        retString = ""
+        if command == "sip show objects":
+            retString = "-= Peer objects: 4 static, 0 realtime, 0 autocreate =-\n\n"
+            retString += "name: audio\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7002\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7001\ntype: peer\nobjflags: 0\nrefcount: 1\n\n"
+            retString += "name: zoiper_01\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "-= Peer objects by IP =-\n\n"
+            retString += "name: zoiper_01\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: audio\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7002\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "-= Registry objects: 0 =-\n\n"
+            retString += "-= Dialog objects:\n\n"
+            retString += "name: 2ec048aa4ed1239664f6408f0c5044c4 at 127.0.0.2:5060\n"
+            retString += "type: dialog\n"
+            retString += "objflags: 0\n"
+            retString += "refcount: 2\n\n"
+        elif command == "sip show history 2ec048aa4ed1239664f6408f0c5044c4 at 127.0.0.2:5060":
+            retString = "* SIP Call\n"
+            retString += "1. NewChan         Channel SIP/ast1-00000002 - from 2ec048aa4ed1239664f6408f0c5044\n"
+            retString += "2. TxReqRel        INVITE / 102 INVITE - INVITE\n"
+            retString += "3. Rx              SIP/2.0 / 102 INVITE / 100 Trying\n"
+            retString += "4. Rx              SIP/2.0 / 102 INVITE / 200 OK\n"
+            retString += "5. TxReq           ACK / 102 ACK - ACK\n"
+            retString += "6. Rx              BYE / 102 BYE / sip:ast2 at 127.0.0.2:5060\n"
+            retString += "7. RTCPaudio       Quality:ssrc=28249381;themssrc=485141946;lp=0;rxjitter=0.000029\n"
+            retString += "8. RTCPaudioJitter Quality:minrxjitter=0.000000;maxrxjitter=0.000000;avgrxjitter=0\n"
+            retString += "9. RTCPaudioLoss   Quality:minrxlost=0.000000;maxrxlost=0.000000;avgrxlost=0.00000\n"
+            retString += "10. RTCPaudioRTT    Quality:minrtt=0.000000;maxrtt=0.000000;avgrtt=0.000000;stdevrt\n"
+            retString += "11. SchedDestroy    32000 ms\n"
+            retString += "12. TxResp          SIP/2.0 / 102 BYE - 200 OK\n"
+            retString += "13. Hangup          Cause Normal Clearing\n"
+        return retString
+
+class AstMockObjectPreTestPass(object):
+    def __init__(self):
+        self.host = "127.0.0.1"
+
+    def cli_exec(self, command, sync = True):
+        retString = ""
+        if command == "sip show objects":
+            retString = "-= Peer objects: 4 static, 0 realtime, 0 autocreate =-\n\n"
+            retString += "name: audio\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7002\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7001\ntype: peer\nobjflags: 0\nrefcount: 1\n\n"
+            retString += "name: zoiper_01\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "-= Peer objects by IP =-\n\n"
+            retString += "name: zoiper_01\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: audio\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "name: 7002\ntype: peer\nobjflags: 0\nrefcount: 3\n\n"
+            retString += "-= Registry objects: 0 =-\n\n"
+            retString += "-= Dialog objects:\n"
+        elif command == "sip show history":
+            return "\n"
+        return retString
+
+
+class SipDialogTestConditionUnitTest(unittest.TestCase):
+    def test_pre_test_pass(self):
+        ast = AstMockObjectPreTestPass()
+        obj = SipDialogPreTestCondition(TestConfig())
+        obj.register_asterisk_instance(ast)
+        obj.evaluate()
+        self.assertEqual(obj.getStatus(), 'Passed')
+
+    def test_pre_test_fail(self):
+        ast = AstMockObjectPreTestFail()
+        obj = SipDialogPreTestCondition(TestConfig())
+        obj.register_asterisk_instance(ast)
+        obj.evaluate()
+        self.assertEqual(obj.getStatus(), 'Failed')
+
+    def test_pre_test_fail_multi_asterisk(self):
+        ast1 = AstMockObjectPreTestFail()
+        ast2 = AstMockObjectPreTestPass()
+        obj = SipDialogPreTestCondition(TestConfig())
+        obj.register_asterisk_instance(ast1)
+        obj.register_asterisk_instance(ast2)
+        obj.evaluate()
+        self.assertEqual(obj.getStatus(), 'Failed')
+
+    def test_post_test_pass(self):
+        ast = AstMockObjectPostTestPass()
+        obj = SipDialogPostTestCondition(TestConfigWithHistory())
+        obj.register_asterisk_instance(ast)
+        obj.evaluate()
+        self.assertEqual(obj.getStatus(), 'Passed')
+
+    def test_post_test_no_dialog_pass(self):
+        ast = AstMockObjectPostTestNoDialogsPass()
+        obj = SipDialogPostTestCondition(TestConfig())
+        obj.register_asterisk_instance(ast)
+        obj.evaluate()
+        self.assertEqual(obj.getStatus(), 'Passed')
+
+    def test_post_test_no_hangup_fail(self):
+        ast = AstMockObjectPostTestNoHangupFail()
+        logger.debug("Running post_test_no_hangup_fail")
+        obj = SipDialogPostTestCondition(TestConfigWithHistory())
+        obj.register_asterisk_instance(ast)
+        obj.evaluate()
+        self.assertEqual(obj.getStatus(), 'Failed')
+
+    def test_post_test_no_destruction_fail(self):
+        ast = AstMockObjectPostTestNoDestructionFail()
+        obj = SipDialogPostTestCondition(TestConfigWithHistory())
+        obj.register_asterisk_instance(ast)
+        obj.evaluate()
+        self.assertEqual(obj.getStatus(), 'Failed')
+
+    def test_post_test_multi_asterisk_fail(self):
+        ast1 = AstMockObjectPostTestNoHangupFail()
+        ast2 = AstMockObjectPostTestNoDestructionFail()
+        ast3 = AstMockObjectPostTestNoDialogsPass()
+        ast4 = AstMockObjectPostTestPass()
+        obj = SipDialogPostTestCondition(TestConfigWithHistory())
+        obj.register_asterisk_instance(ast1)
+        obj.register_asterisk_instance(ast2)
+        obj.register_asterisk_instance(ast3)
+        obj.register_asterisk_instance(ast4)
+        obj.evaluate()
+        self.assertEqual(obj.getStatus(), 'Failed')
+
+def main():
+    logging.basicConfig(level=logging.DEBUG)
+    unittest.main()
+
+
+if __name__ == "__main__":
+    main()

Propchange: asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/SipDialogTestCondition.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/SipDialogTestCondition.py
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/SipDialogTestCondition.py
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/TestConditions.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/TestConditions.py?view=diff&rev=2261&r1=2260&r2=2261
==============================================================================
--- asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/TestConditions.py (original)
+++ asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/TestConditions.py Thu Sep 15 08:12:02 2011
@@ -157,19 +157,19 @@
 
     __buildOptions = AsteriskBuildOptions()
 
-    def __init__(self, name):
+    def __init__(self, test_config):
         """
         Initialize a new test condition
 
         Keyword arguments:
-        name -- The name of the condition that is being checked
+        test_config - the test configuration object that defines this Test Condition
         """
         self.failureReasons = []
-        self.__name = name
+        self.__name = test_config.classTypeName
         self.__testStatus = TestStatuses.Inconclusive
         self.ast = []
         self.build_options = []
-        self.pass_expected = True
+        self.pass_expected = test_config.passExpected
 
     def __str__(self):
         """

Modified: asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/TestConfig.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/TestConfig.py?view=diff&rev=2261&r1=2260&r2=2261
==============================================================================
--- asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/TestConfig.py (original)
+++ asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/TestConfig.py Thu Sep 15 08:12:02 2011
@@ -52,6 +52,8 @@
             self.type = config['type'].upper().strip()
         if 'relatedCondition' in config:
             self.relatedCondition = config['relatedCondition'].strip()
+        """ Let non-standard configuration items be obtained from the config object """
+        self.config = config
 
     def get_type(self):
         """
@@ -75,9 +77,7 @@
             m = __import__(module)
             for comp in parts[1:]:
                 m = getattr(m, comp)
-            obj = m()
-            if not self.passExpected:
-                obj.pass_expected = False
+            obj = m(self)
             return obj
         return None
 

Modified: asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/ThreadTestCondition.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/ThreadTestCondition.py?view=diff&rev=2261&r1=2260&r2=2261
==============================================================================
--- asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/ThreadTestCondition.py (original)
+++ asterisk/team/mjordan/test_conditions/trunk/lib/python/asterisk/ThreadTestCondition.py Thu Sep 15 08:12:02 2011
@@ -10,6 +10,7 @@
 import logging
 import logging.config
 from TestConditions import TestCondition
+from version import AsteriskVersion
 
 logger = logging.getLogger(__name__)
 
@@ -21,8 +22,11 @@
     command
     """
 
-    def __init__(self, name):
-        super(ThreadTestCondition, self).__init__(name)
+    __ast_version = AsteriskVersion()
+    __ast_version_10 = AsteriskVersion("10")
+
+    def __init__(self, test_config):
+        super(ThreadTestCondition, self).__init__(test_config)
 
         """
         astThreads is a list of tuples, where the first entry is the host IP of the
@@ -30,6 +34,10 @@
         thread name
         """
         self.astThreads = []
+
+        self.ignoredThreads = []
+        if 'ignoredThreads' in test_config.config:
+            self.ignoredThreads = test_config.config['ignoredThreads']
 
         """ Core show threads is not available if LOW_MEMORY is turned on """
         self.add_build_option("LOW_MEMORY", "0")
@@ -46,10 +54,15 @@
             if not 'threads listed' in line and not 'Asterisk ending' in line:
                 """ get the name and thread ID - strip off the cli_exec / pthread ID """
                 initialPartition = line.partition(' ')
-                initialPartition = initialPartition[2].partition(' ')
+                """
+                In v10 and greater, the result of core show threads introduces the Asterisk thread ID
+                immediately after the pthread ID.  Use that if its available.
+                """
+                if (ThreadTestCondition.__ast_version >= ThreadTestCondition.__ast_version_10):
+                    initialPartition = initialPartition[2].partition(' ')
                 threadId = initialPartition[0]
                 threadName = initialPartition[2].partition(' ')[0]
-                if threadId != "" and threadName != "":
+                if threadId != "" and threadName != "" and threadName not in self.ignoredThreads:
                     logger.debug("Tracking thread %s[%s]" % (threadName, threadId))
                     thread_list.append((threadId, threadName))
 
@@ -64,8 +77,8 @@
     in the system prior to test execution.
     """
 
-    def __init__(self):
-        super(ThreadPreTestCondition, self).__init__("ThreadPreTestCondition")
+    def __init__(self, test_config):
+        super(ThreadPreTestCondition, self).__init__(test_config)
 
     def evaluate(self, related_test_condition = None):
         for ast in self.ast:
@@ -88,8 +101,8 @@
     failure is flagged.
     """
 
-    def __init__(self):
-        super(ThreadPostTestCondition, self).__init__("ThreadPostTestCondition")
+    def __init__(self, test_config):
+        super(ThreadPostTestCondition, self).__init__(test_config)
 
     def evaluate(self, related_test_condition = None):
 

Modified: asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/authenticate_nominal/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/authenticate_nominal/test-config.yaml?view=diff&rev=2261&r1=2260&r2=2261
==============================================================================
--- asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/authenticate_nominal/test-config.yaml (original)
+++ asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/authenticate_nominal/test-config.yaml Thu Sep 15 08:12:02 2011
@@ -14,7 +14,16 @@
         -
             name: 'asterisk.ThreadTestCondition.ThreadPostTestCondition'
             type: 'Post'
-            relatedCondition: 'ThreadPreTestCondition'
+            relatedCondition: 'asterisk.ThreadTestCondition.ThreadPreTestCondition'
+        -
+            name: 'asterisk.SipDialogTestCondition.SipDialogPreTestCondition'
+            type: 'Pre'
+        -
+            name: 'asterisk.SipDialogTestCondition.SipDialogPostTestCondition'
+            type: 'Post'
+            sipHistoryRequirements:
+                - 'NewChan'
+                - 'Hangup'
         -
             name: 'asterisk.LockTestCondition.LockTestCondition'
             type: 'Pre'

Modified: asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/check_voicemail_new_user/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/check_voicemail_new_user/test-config.yaml?view=diff&rev=2261&r1=2260&r2=2261
==============================================================================
--- asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/check_voicemail_new_user/test-config.yaml (original)
+++ asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/check_voicemail_new_user/test-config.yaml Thu Sep 15 08:12:02 2011
@@ -15,7 +15,16 @@
         -
             name: 'asterisk.ThreadTestCondition.ThreadPostTestCondition'
             type: 'Post'
-            relatedCondition: 'ThreadPreTestCondition'
+            relatedCondition: 'asterisk.ThreadTestCondition.ThreadPreTestCondition'
+        -
+            name: 'asterisk.SipDialogTestCondition.SipDialogPreTestCondition'
+            type: 'Pre'
+        -
+            name: 'asterisk.SipDialogTestCondition.SipDialogPostTestCondition'
+            type: 'Post'
+            sipHistoryRequirements:
+                - 'NewChan'
+                - 'Hangup'
         -
             name: 'asterisk.LockTestCondition.LockTestCondition'
             type: 'Pre'

Modified: asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/func_vmcount/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/func_vmcount/test-config.yaml?view=diff&rev=2261&r1=2260&r2=2261
==============================================================================
--- asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/func_vmcount/test-config.yaml (original)
+++ asterisk/team/mjordan/test_conditions/trunk/tests/apps/voicemail/func_vmcount/test-config.yaml Thu Sep 15 08:12:02 2011
@@ -14,7 +14,7 @@
         -
             name: 'asterisk.ThreadTestCondition.ThreadPostTestCondition'
             type: 'Post'

[... 30 lines stripped ...]



More information about the asterisk-commits mailing list