[asterisk-commits] mmichelson: branch mmichelson/bridge-tests r3293 - /asterisk/team/mmichelson/...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jul 3 15:28:50 CDT 2012
Author: mmichelson
Date: Tue Jul 3 15:28:46 2012
New Revision: 3293
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3293
Log:
Some major and minor fixes.
In short, I'm not that good with Python
Modified:
asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py
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=3293&r1=3292&r2=3293
==============================================================================
--- asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py (original)
+++ asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py Tue Jul 3 15:28:46 2012
@@ -8,14 +8,20 @@
logger = logging.getLogger(__name__)
-class AMIEventInstance:
+class AMIEventInstance(object):
def __init__(self, instance_config, test_object):
- self.match_conditions = dict(instance_config['conditions']['match'])
- self.nonmatch_conditions = dict(instance_config['conditions']['nomatch'])
- self.passed = True if instance_config['start'] == 'pass' else False
- self.ids = instance_config['id'].split(',')
+ print(instance_config)
+ print(instance_config['conditions'])
+ self.match_conditions = instance_config['conditions']['match']
+ self.nonmatch_conditions = instance_config['conditions'].get('nomatch', [])
+ if 'start' in instance_config:
+ self.passed = True if instance_config['start'] == 'pass' else False
+ else:
+ self.passed = True
- if 'Event' not in self.matches:
+ self.ids = instance_config['id'].split(',') if 'id' in instance_config else ['0']
+
+ if 'Event' not in self.match_conditions:
logger.error("No event specified to match on. Aborting test")
raise
@@ -23,6 +29,8 @@
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)
ami.registerEvent(self.match_conditions['Event'], self.__event_callback)
def event_callback(self, ami, event):
@@ -34,12 +42,22 @@
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")
return
+ else:
+ logger.debug("Match")
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")
return
+ else:
+ logger.debug("No match")
#Conditions have matched up as expected
#so leave it to the individual types to determine
@@ -49,23 +67,29 @@
class AMIHeaderMatchInstance(AMIEventInstance):
def __init__(self, instance_config, test_object):
- super(instance_config)
+ 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.nonmatch_requirements = dict(instance_config['requirements']['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.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
class AMICallbackInstance(AMIEventInstance):
def __init__(self, instance_config, test_object):
- super(instance_config, test_object)
+ super(AMICallbackInstance, self).__init__(instance_config, test_object)
self.callback_module = instance_config['callback_module']
self.callback_method = instance_config['callback_method']
self.module = None
@@ -77,16 +101,20 @@
if not self.module:
raise
self.module.load_module(self.callback_module)
- #XXX Now what? Just call the method? getattr?
- self.callback_method(ami, event)
+ #XXX Now what? Just call the method? getattr?
+ self.callback_method(ami, event)
class AMIEventInstanceFactory:
- def create_instance(instance_config):
+ @staticmethod
+ def create_instance(instance_config, test_object):
+ print(instance_config)
instance_type = instance_config['type']
if instance_type == "headermatch":
- return AMIHeaderMatchInstance(instance_config)
- elif instance_type = "callback:":
- return AMICallbackInstance(instance_config)
+ logger.debug("instance type is 'headermatch'")
+ return AMIHeaderMatchInstance(instance_config, test_object)
+ elif instance_type == "callback:":
+ logger.debug("instance type is 'callback'")
+ return AMICallbackInstance(instance_config, test_object)
else:
logger.error("Invalid type %s specified for AMI event instance" %
instance_type)
@@ -94,10 +122,12 @@
class AMIEvent(object):
def __init__(self, module_config, test_object):
+ logger.debug("Initializing AMIEvent module")
self.test_object = test_object
self.ami_instances = []
for instance in module_config:
- self.ami_instances.append(AMIEventInstanceFactory.create_instance(instance)
+ self.ami_instances.append(AMIEventInstanceFactory.create_instance(instance['instance'],
+ test_object))
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 asterisk-commits
mailing list