[asterisk-commits] mmichelson: branch mmichelson/bridge-tests r3296 - in /asterisk/team/mmichels...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 3 17:59:30 CDT 2012


Author: mmichelson
Date: Tue Jul  3 17:59:28 2012
New Revision: 3296

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3296
Log:
Tighten up the AMIEvent module some more.

Things to do still:

* Make sure callback types function properly
* Add event count logic to the module
* Update test object so that modules are unable to overwrite
  the "passed" value directly. Instead, they must call a helper
  method so that modules cannot undo the failure result another
  module may have already set.


Modified:
    asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py
    asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/configs/ast1/extensions.conf
    asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/test-config.yaml

Modified: asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py?view=diff&rev=3296&r1=3295&r2=3296
==============================================================================
--- asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py (original)
+++ asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py Tue Jul  3 17:59:28 2012
@@ -10,10 +10,8 @@
 
 class AMIEventInstance(object):
     def __init__(self, instance_config, test_object):
-        print(instance_config)
-        print(instance_config['conditions'])
         self.match_conditions = instance_config['conditions']['match']
-        self.nonmatch_conditions = instance_config['conditions'].get('nomatch', [])
+        self.nonmatch_conditions = instance_config['conditions'].get('nomatch', {})
         if 'start' in instance_config:
             self.passed = True if instance_config['start'] == 'pass' else False
         else:
@@ -23,14 +21,14 @@
 
         if 'Event' not in self.match_conditions:
             logger.error("No event specified to match on. Aborting test")
-            raise
+            raise Exception
 
         test_object.register_ami_observer(self.ami_connect)
+        test_object.register_stop_observer(self.__check_result)
 
     def ami_connect(self, ami):
         if str(ami.id) in self.ids:
-            logger.debug("Registering event %s on ami instance %d" %
-                    self.match_conditions['Event'], ami.id)
+            logger.debug("Registering event %s" % self.match_conditions['Event'])
             ami.registerEvent(self.match_conditions['Event'], self.__event_callback)
 
     def event_callback(self, ami, event):
@@ -41,51 +39,62 @@
         """Check event conditions to see if subclasses should
         be called into"""
 
-        for k,v in self.match_conditions:
-            logger.debug("Checking if %s (event) matches condition %s"
-                    % event.get(k), v)
-            if not re.match(v, event.get(k)):
-                logger.debug("No match")
+        for k,v in self.match_conditions.items():
+            if not re.match(v, event.get(k.lower())):
+                logger.debug("Condition %s:%s does not match %s:%s in event" %
+                        (k, v, k, event.get(k.lower())))
                 return
             else:
-                logger.debug("Match")
+                logger.debug("Condition %s:%s matches %s:%s in event" %
+                        (k, v, k, event.get(k.lower())))
 
-        for k,v in self.nonmatch_conditions:
-            logger.debug("Checking if %s (event) does not match condition %s"
-                    % event.get(k), v)
-            if re.match(v, event.get(k)):
-                logger.debug("Match")
+        for k,v in self.nonmatch_conditions.items():
+            if re.match(v, event.get(k.lower())):
+                logger.debug("Condition %s:%s matches %s:%s in event" %
+                        (k, v, k, event.get(k.lower())))
                 return
             else:
-                logger.debug("No match")
+                logger.debug("Condition %s:%s does not match %s:%s in event" %
+                        (k, v, k, event.get(k.lower())))
 
         #Conditions have matched up as expected
         #so leave it to the individual types to determine
         #how to proceed
 
-        self.event_callback(ami, event)
+        return self.event_callback(ami, event)
+
+    def __check_result(self, callback_param):
+        '''This will check against event counts and the like and then
+        call into overridden veresions'''
+        pass
 
 class AMIHeaderMatchInstance(AMIEventInstance):
     def __init__(self, instance_config, test_object):
         super(AMIHeaderMatchInstance, self).__init__(instance_config, test_object)
         logger.debug("Initializing an AMIHeaderMatchInstance")
-        self.match_requirements = dict(instance_config['requirements']['match'])
-        self.nonmatch_requirements = dict(instance_config['requirements']['nomatch'])
+        self.match_requirements = instance_config['requirements'].get('match', {})
+        self.nonmatch_requirements = instance_config['requirements'].get('nomatch', {})
 
     def event_callback(self, ami, event):
-        for k,v in self.match_requirements:
-            logger.debug("Checking if %s matches requirement %s"
-                    % event.get(k), v)
-            if not re.match(v, event.get(k)):
-                logger.warning("Required match not met")
-                raise
+        for k,v in self.match_requirements.items():
+            if not re.match(v, event.get(k.lower())):
+                logger.debug("Requirement %s:%s does not match %s:%s in event" %
+                        (k, v, k, event.get(k.lower())))
+                raise Exception
+            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:
-            logger.debug("Checking if %s does not match requirement %s"
-                    % event.get(k), v)
-            if re.match(v, event.get(k)):
-                logger.warning("Required nonmatch not met")
-                raise
+        for k,v in self.nonmatch_requirements.items():
+            if re.match(v, event.get(k.lower(), '')):
+                logger.debug("Requirement %s:%s matches %s:%s in event" %
+                        (k, v, k, event.get(k.lower(), '')))
+                raise Exception
+            else:
+                logger.debug("Requirement %s:%s does not match %s:%s in event" %
+                        (k, v, k, event.get(k.lower(), '')))
+
+        return (ami, event)
 
 class AMICallbackInstance(AMIEventInstance):
     def __init__(self, instance_config, test_object):
@@ -99,15 +108,14 @@
             finder = TestModuleFinder()
             self.module = finder.find_module(self.callback_module)
             if not self.module:
-                raise
+                raise Exception
             self.module.load_module(self.callback_module)
         #XXX Now what? Just call the method? getattr?
-        self.callback_method(ami, event)
+        return self.callback_method(ami, event)
 
 class AMIEventInstanceFactory:
     @staticmethod
     def create_instance(instance_config, test_object):
-        print(instance_config)
         instance_type = instance_config['type']
         if instance_type == "headermatch":
             logger.debug("instance type is 'headermatch'")
@@ -118,7 +126,7 @@
         else:
             logger.error("Invalid type %s specified for AMI event instance" %
                     instance_type)
-            raise
+            raise Exception
 
 class AMIEvent(object):
     def __init__(self, module_config, test_object):

Modified: asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/configs/ast1/extensions.conf?view=diff&rev=3296&r1=3295&r2=3296
==============================================================================
--- asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/configs/ast1/extensions.conf (original)
+++ asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/configs/ast1/extensions.conf Tue Jul  3 17:59:28 2012
@@ -8,4 +8,5 @@
 exten => 1,1,Answer
 exten => 1,n,Set(CDR(accountcode)=cdrtest_local)
 exten => 1,n,Set(CDR(userfield)=bazinga)
+exten => 1,n,UserEvent(eggs)
 exten => 1,n,Hangup

Modified: asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/test-config.yaml?view=diff&rev=3296&r1=3295&r2=3296
==============================================================================
--- asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/test-config.yaml (original)
+++ asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/test-config.yaml Tue Jul  3 17:59:28 2012
@@ -11,6 +11,9 @@
         -
             config-section: 'cdr-config'
             typename: 'cdr.CDRModule'
+        -
+            config-section: 'ami-config'
+            typename: 'ami.AMIEvent'
 
 test-object-config:
     spawn-after-hangup: True
@@ -36,6 +39,23 @@
                 amaflags: 'DOCUMENTATION'
                 userfield: 'bazinga'
 
+ami-config:
+    -
+        instance:
+                id: '0'
+                type: 'headermatch'
+                start: 'pass'
+                conditions:
+                        match:
+                                Event: 'UserEvent'
+                                UserEvent: 'eggs'
+                    
+                requirements:
+                        nomatch:
+                                Style: 'overeasy'
+
+
+
 properties:
     minversion: '1.8.0.0'
     dependencies:




More information about the asterisk-commits mailing list