[svn-commits] mjordan: branch mjordan/framework r3284 - in /asterisk/team/mjordan/framework...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Tue Jun 26 17:41:33 CDT 2012
Author: mjordan
Date: Tue Jun 26 17:41:29 2012
New Revision: 3284
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3284
Log:
Make a branch for some of this framework stuff
Added:
asterisk/team/mjordan/framework/ (props changed)
- copied from r3281, asterisk/trunk/
asterisk/team/mjordan/framework/lib/python/asterisk/SimpleTestCase.py
- copied unchanged from r3282, asterisk/trunk/lib/python/asterisk/SimpleTestCase.py
asterisk/team/mjordan/framework/lib/python/asterisk/TestCase.py
- copied unchanged from r3282, asterisk/trunk/lib/python/asterisk/TestCase.py
asterisk/team/mjordan/framework/lib/python/asterisk/TestRunner.py
- copied unchanged from r3282, asterisk/trunk/lib/python/asterisk/TestRunner.py
asterisk/team/mjordan/framework/lib/python/asterisk/cdr.py
- copied unchanged from r3282, asterisk/trunk/lib/python/asterisk/cdr.py
asterisk/team/mjordan/framework/logger.conf
- copied unchanged from r3282, asterisk/trunk/logger.conf
asterisk/team/mjordan/framework/runtests.py
- copied unchanged from r3282, asterisk/trunk/runtests.py
asterisk/team/mjordan/framework/tests/cdr/ForkCdrModule.py
- copied unchanged from r3282, asterisk/trunk/tests/cdr/ForkCdrModule.py
asterisk/team/mjordan/framework/tests/cdr/batch_cdrs/
- copied from r3282, asterisk/trunk/tests/cdr/batch_cdrs/
asterisk/team/mjordan/framework/tests/cdr/cdr_accountcode/test-config.yaml
- copied unchanged from r3282, asterisk/trunk/tests/cdr/cdr_accountcode/test-config.yaml
asterisk/team/mjordan/framework/tests/cdr/cdr_fork_end_time/test-config.yaml
- copied unchanged from r3282, asterisk/trunk/tests/cdr/cdr_fork_end_time/test-config.yaml
asterisk/team/mjordan/framework/tests/cdr/cdr_originate_sip_congestion_log/test-config.yaml
- copied unchanged from r3282, asterisk/trunk/tests/cdr/cdr_originate_sip_congestion_log/test-config.yaml
asterisk/team/mjordan/framework/tests/cdr/cdr_unanswered_yes/test-config.yaml
- copied unchanged from r3282, asterisk/trunk/tests/cdr/cdr_unanswered_yes/test-config.yaml
asterisk/team/mjordan/framework/tests/cdr/cdr_userfield/test-config.yaml
- copied unchanged from r3282, asterisk/trunk/tests/cdr/cdr_userfield/test-config.yaml
asterisk/team/mjordan/framework/tests/cdr/console_dial_sip_answer/test-config.yaml
- copied unchanged from r3282, asterisk/trunk/tests/cdr/console_dial_sip_answer/test-config.yaml
asterisk/team/mjordan/framework/tests/cdr/console_dial_sip_busy/test-config.yaml
- copied unchanged from r3282, asterisk/trunk/tests/cdr/console_dial_sip_busy/test-config.yaml
asterisk/team/mjordan/framework/tests/cdr/console_dial_sip_congestion/test-config.yaml
- copied unchanged from r3282, asterisk/trunk/tests/cdr/console_dial_sip_congestion/test-config.yaml
asterisk/team/mjordan/framework/tests/cdr/console_dial_sip_transfer/test-config.yaml
- copied unchanged from r3282, asterisk/trunk/tests/cdr/console_dial_sip_transfer/test-config.yaml
asterisk/team/mjordan/framework/tests/cdr/console_fork_after_busy_forward/test-config.yaml
- copied unchanged from r3282, asterisk/trunk/tests/cdr/console_fork_after_busy_forward/test-config.yaml
asterisk/team/mjordan/framework/tests/cdr/console_fork_before_dial/test-config.yaml
- copied unchanged from r3282, asterisk/trunk/tests/cdr/console_fork_before_dial/test-config.yaml
asterisk/team/mjordan/framework/tests/cdr/nocdr/test-config.yaml
- copied unchanged from r3282, asterisk/trunk/tests/cdr/nocdr/test-config.yaml
asterisk/team/mjordan/framework/tests/cdr/tests.yaml
- copied unchanged from r3282, asterisk/trunk/tests/cdr/tests.yaml
Removed:
asterisk/team/mjordan/framework/tests/cdr/cdr_accountcode/run-test
asterisk/team/mjordan/framework/tests/cdr/cdr_fork_end_time/run-test
asterisk/team/mjordan/framework/tests/cdr/cdr_originate_sip_congestion_log/run-test
asterisk/team/mjordan/framework/tests/cdr/cdr_unanswered_yes/run-test
asterisk/team/mjordan/framework/tests/cdr/cdr_userfield/run-test
asterisk/team/mjordan/framework/tests/cdr/console_dial_sip_answer/run-test
asterisk/team/mjordan/framework/tests/cdr/console_dial_sip_busy/run-test
asterisk/team/mjordan/framework/tests/cdr/console_dial_sip_congestion/run-test
asterisk/team/mjordan/framework/tests/cdr/console_dial_sip_transfer/run-test
asterisk/team/mjordan/framework/tests/cdr/console_fork_after_busy_forward/run-test
asterisk/team/mjordan/framework/tests/cdr/console_fork_before_dial/run-test
asterisk/team/mjordan/framework/tests/cdr/nocdr/run-test
Modified:
asterisk/team/mjordan/framework/lib/python/asterisk/ami.py
Propchange: asterisk/team/mjordan/framework/
------------------------------------------------------------------------------
reviewboard:url = https://reviewboard.asterisk.org
Propchange: asterisk/team/mjordan/framework/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Jun 26 17:41:29 2012
@@ -1,0 +1,2 @@
+asterisk-test-suite-report.xml
+*.pyc
Propchange: asterisk/team/mjordan/framework/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Jun 26 17:41:29 2012
@@ -1,0 +1,2 @@
+/asterisk/team/group/cdr_test_log_congestion:1823-2951
+/asterisk/trunk:1112
Propchange: asterisk/team/mjordan/framework/
------------------------------------------------------------------------------
svnmerge-integrated = /asterisk/trunk:1-3246
Modified: asterisk/team/mjordan/framework/lib/python/asterisk/ami.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mjordan/framework/lib/python/asterisk/ami.py?view=diff&rev=3284&r1=3281&r2=3284
==============================================================================
--- asterisk/team/mjordan/framework/lib/python/asterisk/ami.py (original)
+++ asterisk/team/mjordan/framework/lib/python/asterisk/ami.py Tue Jun 26 17:41:29 2012
@@ -1,10 +1,151 @@
+#!/usr/bin/env python
+'''Asterisk AMI functionality
+
+This module implements a variety of helper classes that interact with Asterisk
+AMI
+
+Copyright (C) 2012, 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.
+'''
+
from twisted.internet import reactor, protocol
from starpy import manager
import datetime
import sys
+import re
import logging
logger = logging.getLogger(__name__)
+
+class AMIEventModule:
+ ''' A pluggable component that listens for AMI events '''
+
+ def __init__(self, module_config, test_object):
+ ''' Constructor
+
+ Parameters:
+ module_config The yaml loaded configuration for this module
+ test_object A concrete implementation of TestClass
+ '''
+ self._test_object = test_object
+
+ # Build up the events we expect to listen for
+ for asterisk_config in module_config:
+ asterisk_instance = 1
+ expected_events = []
+ if 'asterisk-instance' in asterisk_config:
+ asterisk_instance = asterisk_config['asterisk-instance']
+ for _config in asterisk_instance['expected-events']:
+ sequence_type = 'any-order'
+ if 'sequence-type' in event_config:
+ sequence_type = event_config['sequence-type']
+ for event in event_config['events']:
+ pass_fileds = {}
+ raise_fields = {}
+ pass_type = 'ALL'
+ raise_type = 'ANY'
+ pass_fields = event_config['pass-fields']
+ raise_fields = event_config['raise-fields']
+ pass_type = event_config['pass-type']
+ raise_type = event_config['raise-type']
+ event = AMIEvent(self._test_object.ami[asterisk_instance - 1],
+ event_config['event'],
+ self._handle_event,
+ raise_fields,
+ raise_type,
+ pass_fields,
+ pass_type)
+ expected_events
+
+ def _handle_event(self, ami_event):
+ pass
+
+class AMIEvent:
+ ''' A class that tracks whether or not an AMI event has been received
+ '''
+
+ def __init__(self, ami, event_type, callback, raise_fields={}, raise_match_type='ALL',
+ pass_fields={}, pass_match_type='ANY'):
+ ''' Constructors
+
+ Parameters:
+ ami The AMI instance to register to
+ event_type The type of the event to track
+ callback Called when a match is made. The callback function should
+ receive a single argument, which will be this object.
+ raise_fields A dictionary of fields and values that, if we receive a match on,
+ implies that this event has been received.
+ raise_match_type Specifies whether we have to match on any of the fields, or
+ all of the fields in order to raise the callback. Valid values are ALL,
+ ANY, and ALWAYS (which implies that any event that gets passed the pass
+ fields will be raised).
+ pass_fields A dictionary of fields and values that, if we match on, implies
+ that we should ignore the event
+ pass_match_type Specifies whether we have to match on any of the pass fields to
+ ignore it, or match any of the fields
+ '''
+
+ self.raise_matches = {}
+ self.ami = ami
+ self.event_type = event_type
+ self._callback_fns = []
+ self._callback_fns.append(callback)
+ self._raise_fields = {}
+ for field in raise_fields:
+ self._raise_fields[field] = re.compile(raise_fields[field])
+ self._pass_fields = {}
+ for field in pass_fields:
+ self._pass_fields[field] = re.compile(pass_fields[field])
+ self._raise_match_type = raise_match_type
+ self._pass_match_type = pass_match_type
+ self.ami.registerEvent(self.event_type, self._event_handler)
+
+ def register_callback(self, callback):
+ ''' Register another callback function to be called when a match occurs
+
+ Parameters:
+ callback The function to call
+ '''
+ self._callback_fns.append(callback)
+
+ def _event_handler(self, ami, event):
+ ''' AMI event handler '''
+
+ # Determine if we should pass on this event
+ pass_matches = []
+ for key, value in self._pass_fields.items():
+ if key in event and value.match(event[key]) is not None:
+ pass_matches.append(key)
+ if (self._pass_match_type.upper() == 'ANY' and
+ len(pass_matches) > 0):
+ return
+ elif (self._pass_match_type.upper() == 'ALL' and
+ len(pass_matches) == len(self._pass_fields)):
+ return
+
+ # Determine the matching fields
+ for key, value in self._raise_fields.items():
+ if key in event and value.match(event[key]) is not None:
+ self.raise_matches[key] = True
+ else:
+ self.raise_matches[key] = False
+ matches = len([v for k, v in self.raise_matches.items() if v])
+ if (self._pass_match_type.upper() == 'ANY' and matches > 0):
+ self._raise_callback()
+ elif (self._pass_match_type.upper() == 'ALL' and
+ matches == len(self._raise_fields)):
+ self._raise_callback()
+ elif (self._pass_match_type.upper() == 'ALWAYS'):
+ self._raise_callback()
+
+ def _raise_callback(self):
+ ''' Raise the callbacks '''
+ for callback in self._callback_fns:
+ callback(self)
+
class AMI:
def __init__(self, on_login, on_error, timeout=60, user="mark", secret="mysecret", host="127.0.0.1", port=5038):
More information about the svn-commits
mailing list