[asterisk-commits] kmoore: testsuite/asterisk/trunk r3606 - in /asterisk/trunk: lib/python/aster...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 17 15:30:35 CST 2013


Author: kmoore
Date: Thu Jan 17 15:30:31 2013
New Revision: 3606

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3606
Log:
Add AMI event triggering of originations

This adds the ability to trigger originations from any AMI event using
YAML configuration as an extension of the Originator pluggable module.
As a part of this enhancement, AMIPrivateCallbackInstance was added
which can be used to hook AMI events with an arbitrary callback if a
YAML definition of the event is already available in the format used
by AMIEventModule.

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

Modified:
    asterisk/trunk/lib/python/asterisk/PluggableModules.py
    asterisk/trunk/sample-yaml/originator-config.yaml.sample

Modified: asterisk/trunk/lib/python/asterisk/PluggableModules.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/PluggableModules.py?view=diff&rev=3606&r1=3605&r2=3606
==============================================================================
--- asterisk/trunk/lib/python/asterisk/PluggableModules.py (original)
+++ asterisk/trunk/lib/python/asterisk/PluggableModules.py Thu Jan 17 15:30:31 2013
@@ -11,6 +11,7 @@
 import logging
 
 sys.path.append("lib/python")
+from ami import AMIEventInstance
 
 LOGGER = logging.getLogger(__name__)
 
@@ -22,6 +23,7 @@
         test_object.register_scenario_started_observer(self.scenario_started)
         self.test_object = test_object
         self.current_destination = 0
+        self.ami_callback = None
         self.config = {
             'channel': 'Local/s at default',
             'application': 'Echo',
@@ -31,7 +33,8 @@
             'priority': '',
             'ignore-originate-failure': 'no',
             'trigger': 'scenario_start',
-            'id': '0'
+            'id': '0',
+            'event': None
         }
 
         # process config
@@ -40,6 +43,18 @@
         for k in module_config.keys():
             if k in self.config:
                 self.config[k] = module_config[k]
+
+        # create event callback if necessary
+        if self.config['trigger'] == 'event':
+            if not self.config['event']:
+                LOGGER.error("Event specifier for trigger type 'event' is missing")
+                raise Exception
+
+            # set id to the AMI id for the origination if it is unset
+            if 'id' not in self.config['event']:
+                self.config['event']['id'] = self.config['id']
+
+            self.ami_callback = AMIPrivateCallbackInstance(self.config['event'], test_object, self.originate_callback)
         return
 
     def ami_connect(self, ami):
@@ -59,6 +74,12 @@
             self.test_object.set_passed(False)
         return None
 
+    def originate_callback(self, ami, event):
+        '''Handle event callbacks.'''
+        LOGGER.info('Got event callback')
+        self.originate_call()
+        return True
+
     def originate_call(self):
         '''Handle origination of the call based on the options provided in the configuration.'''
         LOGGER.info("Originating call")
@@ -77,3 +98,22 @@
         if self.config['trigger'] == 'scenario_start':
             self.originate_call()
         return result
+
+class AMIPrivateCallbackInstance(AMIEventInstance):
+    '''
+    Subclass of AMIEventInstance that operates by calling a user-defined
+    callback function. The callback function returns the current disposition
+    of the test (i.e. whether the test is currently passing or failing).
+    '''
+    def __init__(self, instance_config, test_object, callback):
+        super(AMIPrivateCallbackInstance, self).__init__(instance_config, test_object)
+        self.callback = callback
+        if 'start' in instance_config:
+            self.passed = True if instance_config['start'] == 'pass' else False
+
+    def event_callback(self, ami, event):
+        self.passed = self.callback(ami, event)
+
+    def check_result(self, callback_param):
+        self.test_object.set_passed(self.passed)
+        return callback_param

Modified: asterisk/trunk/sample-yaml/originator-config.yaml.sample
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/sample-yaml/originator-config.yaml.sample?view=diff&rev=3606&r1=3605&r2=3606
==============================================================================
--- asterisk/trunk/sample-yaml/originator-config.yaml.sample (original)
+++ asterisk/trunk/sample-yaml/originator-config.yaml.sample Thu Jan 17 15:30:31 2013
@@ -21,6 +21,13 @@
     # Whether to ignore failure of the origination. (default: 'no')
     ignore-originate-failure: 'no'
 
-    # This determines what triggers the origination.  The available options are 'scenario_start' (default) and 'ami_connect'.
+    # This determines what triggers the origination.  The available options are 'scenario_start' (default), 'ami_connect', and 'event'.
     trigger: 'scenario_start'
 
+    # if 'event' is specified as the trigger, an event definition needs to be specified.
+    # This is similar to the event definition used for the callback variant of the AMIEventModule.
+    event:
+        id: '0'
+        conditions:
+            match:
+                Event: TestEvent




More information about the asterisk-commits mailing list