[asterisk-commits] mmichelson: branch mmichelson/bridge-tests r3298 - in /asterisk/team/mmichels...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Jul 6 09:18:08 CDT 2012
Author: mmichelson
Date: Fri Jul 6 09:18:04 2012
New Revision: 3298
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3298
Log:
Put finishing touches on AMI module.
* Added method to TestCase to update the pass/fail value.
Modules that previously directly set the value now call this
function.
* Updated starting pass/fail logic for AMI module. For headermatch
types, it makes no sense to be able to set the starting value, because
if "fail" is chosen, the test will never pass. Instead, the 'start'
option only applies to callback types.
* Updated final start/pass logic for callback types.
* Switched from throwing exceptions to updating pass/fail
values.
Modified:
asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/TestCase.py
asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/TestRunner.py
asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py
asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/cdr.py
asterisk/team/mmichelson/bridge-tests/tests/cdr/ForkCdrModule.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/TestCase.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/TestCase.py?view=diff&rev=3298&r1=3297&r2=3298
==============================================================================
--- asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/TestCase.py (original)
+++ asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/TestCase.py Fri Jul 6 09:18:04 2012
@@ -468,3 +468,11 @@
callback The deferred callback function to be called when AMI connects
'''
self._ami_callbacks.append(callback)
+
+ def set_passed(self, value):
+ '''Accumulate pass/fail value. If a test module has already
+ claimed that the test has failed, then this method will ignore
+ any further attempts to change the pass/fail status.'''
+ if not self.passed:
+ return
+ self.passed = value
Modified: asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/TestRunner.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/TestRunner.py?view=diff&rev=3298&r1=3297&r2=3298
==============================================================================
--- asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/TestRunner.py (original)
+++ asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/TestRunner.py Fri Jul 6 09:18:04 2012
@@ -99,6 +99,10 @@
# Not an error - just no optional modules specified
return
+ # Assume that support for loading from the test path may be needed.
+ TestModuleFinder.supported_paths.append(test_path)
+ sys.path.append(test_path)
+
for module_spec in test_config['test-modules']['modules']:
# If there's a specific portion of the config for this module, use it
if ('config-section' in module_spec
@@ -107,20 +111,15 @@
else:
module_config = test_config
- if ('load-from-test' in module_spec and module_spec['load-from-test']):
- TestModuleFinder.supported_paths.append(test_path)
- sys.path.append(test_path)
-
if ('load-from-path' in module_spec):
TestModuleFinder.supported_paths.append(
module_spec['load-from-path'])
sys.path.append(module_spec['load-from-path'])
- if 'typename' in module_spec:
- module_type = load_and_parse_module(module_spec['typename'])
- # Modules take in two parameters: the module configuration object,
- # and the test object that they attach to
- module_type(module_config, test_object)
+ module_type = load_and_parse_module(module_spec['typename'])
+ # Modules take in two parameters: the module configuration object,
+ # and the test object that they attach to
+ module_type(module_config, test_object)
def load_and_parse_module(type_name):
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=3298&r1=3297&r2=3298
==============================================================================
--- asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py (original)
+++ asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py Fri Jul 6 09:18:04 2012
@@ -10,14 +10,31 @@
class AMIEventInstance(object):
def __init__(self, instance_config, test_object):
+ self.test_object = test_object
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
+ self.ids = instance_config['id'].split(',') if 'id' in instance_config else ['0']
+ self.passed = True
+
+ if 'count' in instance_config:
+ count = instance_config['count']
+ if count[0] == '<':
+ # Need at most this many events
+ self.count_min = 0
+ self.count_max = int(count[1:])
+ elif count[0] == '>':
+ # Need at least this many events
+ self.count_min = int(count[1:])
+ self.count_max = float("inf")
+ else:
+ # Need exactly this many events
+ self.count_min = int(count)
+ self.count_max = int(count)
else:
- self.passed = True
-
- self.ids = instance_config['id'].split(',') if 'id' in instance_config else ['0']
+ self.count_min = 0
+ self.count_max = float("inf")
+
+ self.event_count = 0
if 'Event' not in self.match_conditions:
logger.error("No event specified to match on. Aborting test")
@@ -41,21 +58,23 @@
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" %
+ logger.debug("Condition %s: %s does not match %s: %s in event" %
(k, v, k, event.get(k.lower())))
return
else:
- logger.debug("Condition %s:%s matches %s:%s in event" %
+ logger.debug("Condition %s: %s matches %s: %s in event" %
(k, v, k, event.get(k.lower())))
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" %
+ logger.debug("Condition %s: %s matches %s: %s in event" %
(k, v, k, event.get(k.lower())))
return
else:
- logger.debug("Condition %s:%s does not match %s:%s in event" %
- (k, v, k, event.get(k.lower())))
+ logger.debug("Condition %s: %s does not match %s: %s in event" %
+ (k, v, k, event.get(k.lower())))
+
+ self.event_count += 1
#Conditions have matched up as expected
#so leave it to the individual types to determine
@@ -63,49 +82,70 @@
return self.event_callback(ami, event)
+ def check_result(self, callback_param):
+ '''Virtual method to be overridden by subclasses'''
+
def __check_result(self, callback_param):
'''This will check against event counts and the like and then
call into overridden veresions'''
- pass
+ if (self.event_count > self.count_max
+ or self.event_count < self.count_min):
+ logger.warning("Event occurred %d times, which is out of the"
+ " allowable range" % self.event_count)
+ self.test_object.set_passed(False)
+ return callback_param
+ return self.check_result(callback_param)
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 = instance_config['requirements'].get('match', {})
- self.nonmatch_requirements = instance_config['requirements'].get('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.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" %
+ logger.warning("Requirement %s: %s does not match %s: %s in event" %
+ (k, v, k, event.get(k.lower())))
+ self.passed = False
+ 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.items():
if re.match(v, event.get(k.lower(), '')):
- logger.debug("Requirement %s:%s matches %s:%s in event" %
+ logger.warning("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" %
+ self.passed = False
+ else:
+ logger.debug("Requirement %s: %s does not match %s: %s in event" %
(k, v, k, event.get(k.lower(), '')))
return (ami, event)
+
+ def check_result(self, callback_param):
+ self.test_object.set_passed(self.passed)
+ return callback_param
class AMICallbackInstance(AMIEventInstance):
def __init__(self, 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']
+ if 'start' in instance_config:
+ self.passed = True if instance_config['start'] == 'pass' else False
def event_callback(self, ami, event):
callback_module = __import__(self.callback_module)
method = getattr(callback_module, self.callback_method)
- return method(ami, event)
+ self.passed = method(ami, event)
+
+ def check_result(self, callback_param):
+ self.test_object.set_passed(self.passed)
+ return callback_param
class AMIEventInstanceFactory:
@staticmethod
Modified: asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/cdr.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/cdr.py?view=diff&rev=3298&r1=3297&r2=3298
==============================================================================
--- asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/cdr.py (original)
+++ asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/cdr.py Fri Jul 6 09:18:04 2012
@@ -91,7 +91,7 @@
LOGGER.error("%s.csv - CDR results did not meet expectations. Test Failed." % key)
expectations_met = False
- self.test_object.passed = expectations_met
+ self.test_object.set_passed(expectations_met)
class AsteriskCSVCDRLine(astcsv.AsteriskCSVLine):
Modified: asterisk/team/mmichelson/bridge-tests/tests/cdr/ForkCdrModule.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/bridge-tests/tests/cdr/ForkCdrModule.py?view=diff&rev=3298&r1=3297&r2=3298
==============================================================================
--- asterisk/team/mmichelson/bridge-tests/tests/cdr/ForkCdrModule.py (original)
+++ asterisk/team/mmichelson/bridge-tests/tests/cdr/ForkCdrModule.py Fri Jul 6 09:18:04 2012
@@ -39,7 +39,7 @@
if int(cdr1[0].duration) < int(cdr1[1].duration):
logger.error("Fail: Original CDR duration shorter than forked")
- self.test_object.passed = False
+ self.test_object.set_passed(False)
return
@@ -76,7 +76,7 @@
logger.Error("EPIC FAILURE: CDR record %s is missing one or " \
"more key fields. This should never be able to " \
"happen." % cdritem)
- self.test_object.passed = False
+ self.test_object.set_passed(False)
return
# The dialplan is set up so that these two CDRs should each last at
@@ -85,7 +85,7 @@
if ((int(cdr1[0].duration) <= 1) or (int(cdr1[1].duration) <= 1)):
logger.error("FAILURE: One or both CDRs only lasted a second or " \
"less (expected more)")
- self.test_object.passed = False
+ self.test_object.set_passed(False)
return
end = time.strptime(cdr1[0].end, "%Y-%m-%d %H:%M:%S")
@@ -98,6 +98,6 @@
"one second or less.\n")
logger.error("Actual times: end cdr1 = %s begin cdr2 = %s" %
(cdr1[0].end, cdr1[1].start))
- self.test_object.passed = False
+ self.test_object.set_passed(False)
return
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=3298&r1=3297&r2=3298
==============================================================================
--- 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 Fri Jul 6 09:18:04 2012
@@ -9,5 +9,5 @@
exten => 1,n,Set(CDR(accountcode)=cdrtest_local)
exten => 1,n,Set(CDR(userfield)=bazinga)
exten => 1,n,UserEvent(eggs, Style: scrambled)
-exten => 1,n,UserEvent(bacon, Style: crispy)
+;exten => 1,n,UserEvent(bacon, Style: crispy)
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=3298&r1=3297&r2=3298
==============================================================================
--- 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 Fri Jul 6 09:18:04 2012
@@ -9,13 +9,11 @@
typename: 'SimpleTestCase.SimpleTestCase'
modules:
-
- config-section: 'cdr-config'
- typename: 'cdr.CDRModule'
- -
config-section: 'ami-config'
typename: 'ami.AMIEvent'
-
- load-from-test: 'True'
+ config-section: 'cdr-config'
+ typename: 'cdr.CDRModule'
test-object-config:
spawn-after-hangup: True
@@ -45,7 +43,7 @@
-
id: '0'
type: 'headermatch'
- start: 'pass'
+ count: '1'
conditions:
match:
Event: 'UserEvent'
More information about the asterisk-commits
mailing list