[asterisk-commits] mjordan: testsuite/asterisk/trunk r4228 - in /asterisk/trunk: lib/python/aste...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 27 09:15:40 CDT 2013


Author: mjordan
Date: Fri Sep 27 09:15:34 2013
New Revision: 4228

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4228
Log:
Convert IAX2 basic call test to use pluggable modules; updates for Asterisk 12

This patch does two things to the IAX2 basic call test:
(1) It updates the test to use the various pluggable modules. This removes the
    run-test file that previously provided the test, and instead builds the
    test using its test-config configuration file.
(2) It updates the test to run correctly under Asterisk 12.

A few other modifications were made to the pluggable modules to better support
tests like the IAX2 basic call test. This includes:

* It updates CDR parsing/checking to handle checking CDR entries across
  multiple instances of Asterisk. This is backwards compatible with existing
  CDR checking.
* It adds a new pluggable module that will automagically end a test once the
  last channel has hung up. This is useful when using the 'bare bones' test
  object TestCase.TestCaseModule, which doesn't by itself provide a mechanism
  for ending a test.

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

(closes issue ASTERISK-22219)
Reported by: Matt Jordan


Removed:
    asterisk/trunk/tests/channels/iax2/basic-call/run-test
Modified:
    asterisk/trunk/lib/python/asterisk/PluggableModules.py
    asterisk/trunk/lib/python/asterisk/cdr.py
    asterisk/trunk/tests/channels/iax2/basic-call/configs/ast1/extensions.conf
    asterisk/trunk/tests/channels/iax2/basic-call/test-config.yaml

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=4228&r1=4227&r2=4228
==============================================================================
--- asterisk/trunk/lib/python/asterisk/PluggableModules.py (original)
+++ asterisk/trunk/lib/python/asterisk/PluggableModules.py Fri Sep 27 09:15:34 2013
@@ -183,3 +183,40 @@
             LOGGER.info('Hanging up channel %s' % obj['channel'])
             ami.hangup(obj['channel']).addErrback(__hangup_ignore)
             self.channels.remove(obj)
+
+
+class HangupMonitor(object):
+    ''' A class that monitors for new channels and hungup channels. When all
+    channels it has monitored for have hung up, it ends the test.
+
+    Essentially, as long as there are new channels it will keep the test
+    going; however, once channels start hanging up it will kill the test
+    on the last hung up channel.
+    '''
+
+    def __init__(self, instance_config, test_object):
+        ''' Constructor for pluggable modules '''
+        super(HangupMonitor, self).__init__()
+        self.__dict__.update(instance_config)
+        self.test_object = test_object
+        self.test_object.register_ami_observer(self.__ami_connect)
+        self.channels = []
+
+    def __ami_connect(self, ami):
+        ''' AMI connect handler '''
+        if str(ami.id) in self.ids:
+            ami.registerEvent('Newchannel', self.__new_channel_handler)
+            ami.registerEvent('Hangup', self.__hangup_handler)
+
+    def __new_channel_handler(self, ami, event):
+        ''' Handler for the Newchannel event '''
+        LOGGER.debug('Tracking channel %s' % event['channel'])
+        self.channels.append(event['channel'])
+
+    def __hangup_handler(self, ami, event):
+        ''' Handler for the Hangup event '''
+        LOGGER.debug('Channel %s hungup' % event['channel'])
+        self.channels.remove(event['channel'])
+        if len(self.channels) == 0:
+            LOGGER.info('All channels have hungup; stopping test')
+            self.test_object.stop_reactor()

Modified: asterisk/trunk/lib/python/asterisk/cdr.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/cdr.py?view=diff&rev=4228&r1=4227&r2=4228
==============================================================================
--- asterisk/trunk/lib/python/asterisk/cdr.py (original)
+++ asterisk/trunk/lib/python/asterisk/cdr.py Fri Sep 27 09:15:34 2013
@@ -39,8 +39,11 @@
         self.cdr_records = {}
         for record in module_config:
             file_name = record['file']
-            if file_name not in self.cdr_records:
-                self.cdr_records[file_name] = []
+            ast_id = record.get('id') or 0
+            if ast_id not in self.cdr_records:
+                self.cdr_records[ast_id] = {}
+            if file_name not in self.cdr_records[ast_id]:
+                self.cdr_records[ast_id][file_name] = []
             for csv_line in record['lines']:
                 # Set the record to the default fields, then update with what
                 # was passed in to us
@@ -48,7 +51,8 @@
                 if csv_line is not None:
                     dict_record.update(csv_line)
 
-                self.cdr_records[file_name].append(AsteriskCSVCDRLine(**dict_record))
+                self.cdr_records[ast_id][file_name].append(
+                    AsteriskCSVCDRLine(**dict_record))
 
         # Hook ourselves onto the test object
         test_object.register_stop_observer(self._check_cdr_records)
@@ -64,7 +68,8 @@
         try:
             self.match_cdrs()
         except:
-            LOGGER.error("Exception while checking CDRs: %s" % sys.exc_info()[0])
+            LOGGER.error("Exception while checking CDRs: %s" %
+                         sys.exc_info()[0])
         return callback_param
 
 
@@ -74,17 +79,22 @@
         matching.
         '''
         expectations_met = True
-        for key in self.cdr_records:
-            cdr_expect = AsteriskCSVCDR(records=self.cdr_records[key])
-            cdr_file = AsteriskCSVCDR(fn="%s/%s/cdr-csv/%s.csv" %
-                (self.test_object.ast[0].base,
-                 self.test_object.ast[0].directories['astlogdir'],
-                 key))
-            if cdr_expect.match(cdr_file):
-                LOGGER.debug("%s.csv - CDR results met expectations" % key)
-            else:
-                LOGGER.error("%s.csv - CDR results did not meet expectations.  Test Failed." % key)
-                expectations_met = False
+        for ast_id in self.cdr_records:
+            ast_instance = self.test_object.ast[ast_id]
+            for file_name in self.cdr_records[ast_id]:
+                records = self.cdr_records[ast_id][file_name]
+                cdr_expect = AsteriskCSVCDR(records=records)
+                cdr_file = AsteriskCSVCDR(fn="%s/%s/cdr-csv/%s.csv" %
+                    (ast_instance.base,
+                     ast_instance.directories['astlogdir'],
+                     file_name))
+                if cdr_expect.match(cdr_file):
+                    LOGGER.debug("%s.csv: CDR results met expectations" %
+                                 file_name)
+                else:
+                    LOGGER.error("%s.csv: actual did not match expected." %
+                                 file_name)
+                    expectations_met = False
 
         self.test_object.set_passed(expectations_met)
 

Modified: asterisk/trunk/tests/channels/iax2/basic-call/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/iax2/basic-call/configs/ast1/extensions.conf?view=diff&rev=4228&r1=4227&r2=4228
==============================================================================
--- asterisk/trunk/tests/channels/iax2/basic-call/configs/ast1/extensions.conf (original)
+++ asterisk/trunk/tests/channels/iax2/basic-call/configs/ast1/extensions.conf Fri Sep 27 09:15:34 2013
@@ -5,5 +5,4 @@
 [iaxtest]
 
 exten => 1000,1,Answer()
-exten => 1000,n,Wait(1)
-exten => 1000,n,Hangup()
+exten => 1000,n,Echo()

Modified: asterisk/trunk/tests/channels/iax2/basic-call/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/iax2/basic-call/test-config.yaml?view=diff&rev=4228&r1=4227&r2=4228
==============================================================================
--- asterisk/trunk/tests/channels/iax2/basic-call/test-config.yaml (original)
+++ asterisk/trunk/tests/channels/iax2/basic-call/test-config.yaml Fri Sep 27 09:15:34 2013
@@ -2,7 +2,9 @@
     summary:     'Test a basic IAX2 call'
     description: |
         'This test initiates an IAX2 call between 2 instances of Asterisk.
-        Both ends connect to a FastAGI server implemented in the test script.'
+        The test only verifies that an IAX2 call is actually instantiated
+        between the two Asterisk instances and that proper records are
+        generated.'
 
 properties:
     minversion: '1.8.0.0'
@@ -12,3 +14,154 @@
         - asterisk : 'cdr_csv'
     tags:
         - iax2
+
+test-modules:
+    test-object:
+        config-section: test-object-config
+        typename: 'TestCase.TestCaseModule'
+    modules:
+        -
+            config-section: originator
+            typename: 'PluggableModules.Originator'
+        -
+            config-section: ami-config
+            typename: 'ami.AMIEventModule'
+        -
+            config-section: hangup-monitor
+            typename: 'PluggableModules.HangupMonitor'
+        -
+            config-section: cdr-config
+            typename: 'cdr.CDRModule'
+        -
+            minversion: '12.0.0'
+            config-section: 'cel-config'
+            typename: 'ami.AMIEventModule'
+
+
+test-object-config:
+    asterisk-instances: 2
+    connect-ami: True
+
+originator:
+    trigger: 'ami_connect'
+    id: '0'
+    channel: 'IAX2/guest at 127.0.0.1:4569/1000'
+    context: 'iaxtest'
+    exten: '1000'
+    priority: '1'
+    async: 'True'
+
+ami-config:
+    -
+        id: '0'
+        type: 'headermatch'
+        count: '1'
+        conditions:
+            match:
+                Event: 'Newchannel'
+        requirements:
+            match:
+                Channel: 'IAX2/127.0.0.1:4569-.*'
+    -
+        id: '1'
+        type: 'headermatch'
+        count: '1'
+        conditions:
+            match:
+                Event: 'Newchannel'
+        requirements:
+            match:
+                Channel: 'IAX2/127.0.0.1:4570-.*'
+    -
+        id: '0'
+        type: 'headermatch'
+        count: '1'
+        conditions:
+            match:
+                Event: 'Hangup'
+        requirements:
+            match:
+                Channel: 'IAX2/127.0.0.1:4569-.*'
+    -
+        id: '1'
+        type: 'headermatch'
+        count: '1'
+        conditions:
+            match:
+                Event: 'Hangup'
+        requirements:
+            match:
+                Channel: 'IAX2/127.0.0.1:4570-.*'
+
+hangup-monitor:
+    ids: '0'
+
+cdr-config:
+    -
+        id: 0
+        file: 'Master'
+        lines:
+            -
+                destination: '1000'
+                dcontext: 'iaxtest'
+                channel: 'IAX2/127.0.0.1:4569-.*'
+                lastapp: 'Echo'
+                disposition: 'ANSWERED'
+                amaflags: 'DOCUMENTATION'
+    -
+        id: 1
+        file: 'Master'
+        lines:
+            -
+                destination: '1000'
+                dcontext: 'iaxtest'
+                channel: 'IAX2/127.0.0.1:4570-.*'
+                lastapp: 'Hangup'
+                disposition: 'ANSWERED'
+                amaflags: 'DOCUMENTATION'
+
+cel-config:
+    -
+        id: '0'
+        type: 'cel'
+        conditions:
+            match:
+                Channel: 'IAX2/127.0.0.1:4569-.*'
+        requirements:
+            -
+                match:
+                    EventName: CHAN_START
+            -
+                match:
+                    EventName: ANSWER
+            -
+                match:
+                    EventName: HANGUP
+            -
+                match:
+                    EventName: CHAN_END
+            -
+                match:
+                    EventName: LINKEDID_END
+    -
+        id: '1'
+        type: 'cel'
+        conditions:
+            match:
+                Channel: 'IAX2/127.0.0.1:4570-.*'
+        requirements:
+            -
+                match:
+                    EventName: CHAN_START
+            -
+                match:
+                    EventName: ANSWER
+            -
+                match:
+                    EventName: HANGUP
+            -
+                match:
+                    EventName: CHAN_END
+            -
+                match:
+                    EventName: LINKEDID_END




More information about the asterisk-commits mailing list