[svn-commits] jrose: testsuite/asterisk/trunk r3341 - in /asterisk/trunk: lib/python/asteri...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jul 19 14:24:44 CDT 2012


Author: jrose
Date: Thu Jul 19 14:24:39 2012
New Revision: 3341

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3341
Log:
AMI Event Module: Add ordered header matching mode

Also fixes a missed inclusion from the ForkCdrModule that made tests
using it end prematurely without indicating failure properly.

Review: https://reviewboard.asterisk.org/r/2056/

Modified:
    asterisk/trunk/lib/python/asterisk/TestCase.py
    asterisk/trunk/lib/python/asterisk/ami.py
    asterisk/trunk/sample-yaml/ami-config.yaml.sample
    asterisk/trunk/tests/cdr/ForkCdrModule.py

Modified: asterisk/trunk/lib/python/asterisk/TestCase.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/TestCase.py?view=diff&rev=3341&r1=3340&r2=3341
==============================================================================
--- asterisk/trunk/lib/python/asterisk/TestCase.py (original)
+++ asterisk/trunk/lib/python/asterisk/TestCase.py Thu Jul 19 14:24:39 2012
@@ -331,6 +331,7 @@
                 except twisted.internet.error.ReactorNotRunning:
                     # Something stopped it between our checks - at least we're stopped
                     pass
+            return result
         if not self._stopping:
             self._stopping = True
             df = self.__stop_asterisk()

Modified: asterisk/trunk/lib/python/asterisk/ami.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/ami.py?view=diff&rev=3341&r1=3340&r2=3341
==============================================================================
--- asterisk/trunk/lib/python/asterisk/ami.py (original)
+++ asterisk/trunk/lib/python/asterisk/ami.py Thu Jul 19 14:24:39 2012
@@ -8,7 +8,7 @@
 logger = logging.getLogger(__name__)
 
 class AMIEventInstance(object):
-    ''' 
+    '''
     Base class for specific instances of AMI event observers
 
     This handles common elements for both headermatch and callback
@@ -149,6 +149,57 @@
         self.test_object.set_passed(self.passed)
         return callback_param
 
+class AMIOrderedHeaderMatchInstance(AMIEventInstance):
+    '''
+    A subclass of AMIEventInstance that operates by matching headers of
+    AMI events to expected values. If a header does not match its expected
+    value, then the test will fail. This differs from AMIHeaderMatchInstance
+    in that the order of specification is used to define an expected order
+    for the events to arrive in which must be matched in order for the test
+    to pass.
+    '''
+    def __init__(self, instance_config, test_object):
+        super(AMIOrderedHeaderMatchInstance, self).__init__(instance_config, test_object)
+        logger.debug("Initializing an AMIOrderedHeaderMatchInstance")
+        self.match_index = 0
+        self.match_requirements = []
+        self.nonmatch_requirements = []
+        for instance in instance_config['requirements']:
+            self.match_requirements.append(
+                    instance.get('match', {}))
+            self.nonmatch_requirements.append(
+                    instance.get('nomatch', {}))
+
+    def event_callback(self, ami, event):
+        if self.match_index >= len(self.match_requirements):
+            logger.debug("Event received and not defined: %s" % event)
+            return
+
+        for k,v in self.match_requirements[self.match_index].items():
+            if not re.match(v, event.get(k.lower())):
+                logger.warning("Requirement %s: %s does not match %s: %s in event" %
+                        (k, v, k, event.get(k.lower())))
+                self.passed = False
+            else:
+                logger.debug("Requirement %s: %s matches %s: %s in event" %
+                        (k, v, k, event.get(k.lower())))
+
+        for k,v in self.nonmatch_requirements[self.match_index].items():
+            if re.match(v, event.get(k.lower(), '')):
+                logger.warning("Requirement %s: %s matches %s: %s in event" %
+                        (k, v, k, event.get(k.lower(), '')))
+                self.passed = False
+            else:
+                logger.debug("Requirement %s: %s does not match %s: %s in event" %
+                        (k, v, k, event.get(k.lower(), '')))
+
+        self.match_index += 1
+        return (ami, event)
+
+    def check_result(self, callback_param):
+        self.test_object.set_passed(self.passed)
+        return callback_param
+
 class AMICallbackInstance(AMIEventInstance):
     '''
     Subclass of AMIEventInstance that operates by calling a user-defined
@@ -178,6 +229,9 @@
         if instance_type == "headermatch":
             logger.debug("instance type is 'headermatch'")
             return AMIHeaderMatchInstance(instance_config, test_object)
+        elif instance_type == "orderedheadermatch":
+            logger.debug("instance type is 'orderedheadermatch'")
+            return AMIOrderedHeaderMatchInstance(instance_config, test_object)
         elif instance_type == "callback":
             logger.debug("instance type is 'callback'")
             return AMICallbackInstance(instance_config, test_object)

Modified: asterisk/trunk/sample-yaml/ami-config.yaml.sample
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/sample-yaml/ami-config.yaml.sample?view=diff&rev=3341&r1=3340&r2=3341
==============================================================================
--- asterisk/trunk/sample-yaml/ami-config.yaml.sample (original)
+++ asterisk/trunk/sample-yaml/ami-config.yaml.sample Thu Jul 19 14:24:39 2012
@@ -47,6 +47,46 @@
         # must occur 3 or more times.
         count: '>3'
     -
+        # The "orderedheadermatch" type indicates that when a condition match is
+        # made, there is a list of ordered requirements. The first time the match
+        # occurs, the first requirement in the list is expected and if it doesn't
+        # match, then the test is failed. If it succeeded, it will expect the
+        # second requirement in the requirements list and it will continue until
+        # either a mismatch occurs and the test fails or the list or requirements
+        # is exhausted.
+        type: 'orderedheadermatch'
+
+        # Conditions are handled exactly the same as for "headermatch" types.
+        conditions:
+            match:
+                Event: 'Bridge'
+                BridgeState: 'Link'
+            nomatch:
+                CallerID1: 'Bob.*'
+
+        # If the parameters in the "conditions" section match, then
+        # the first item in the list in the "requirements" section will be checked.
+        # If any of the requirements should fail, then the test has failed. If they
+        # all succeed, the next time the event is handled the next requirement list
+        # item will be used instead. If a condition matches and the requirements
+        # list is already exhausted, then the event will be allowed without
+        # affecting success or failure of the test.
+        requirements:
+            -
+                match:
+                    uniqueid1: '1234.*'
+                    BridgeType: 'core'
+            -
+                match:
+                    uniqueid1: '5678.*'
+                    BridgeType: 'core'
+
+        # The number of times this event is expected. If just a number is
+        # provided, then the event must happen exactly that number of times.
+        # Normally, this should probably be the number of requirements specified
+        # above.
+        count: '2'
+    -
         # The "callback" type indicates that when event conditions are fulfilled
         # A callback should be called into. This is useful if pass/fail conditions
         # depend on more than just having specific headers match what is expected.

Modified: asterisk/trunk/tests/cdr/ForkCdrModule.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/cdr/ForkCdrModule.py?view=diff&rev=3341&r1=3340&r2=3341
==============================================================================
--- asterisk/trunk/tests/cdr/ForkCdrModule.py (original)
+++ asterisk/trunk/tests/cdr/ForkCdrModule.py Thu Jul 19 14:24:39 2012
@@ -12,6 +12,7 @@
 
 sys.path.append("lib/python")
 from cdr import CDRModule
+from cdr import AsteriskCSVCDR
 
 logger = logging.getLogger(__name__)
 




More information about the svn-commits mailing list