[asterisk-commits] kmoore: testsuite/asterisk/trunk r4466 - in /asterisk/trunk: lib/python/aster...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Dec 16 08:04:32 CST 2013
Author: kmoore
Date: Mon Dec 16 08:04:25 2013
New Revision: 4466
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4466
Log:
Testsuite: Check CEL Extra fields in an order-agnostic way
This adds new functionality to the AMI-based CEL event module to allow
checking the CEL Extra field in a way that doesn't depend on arbitrary
ordering and thus prevents tests checking this data from bouncing.
(closes issue ASTERISK-22885)
Review: https://reviewboard.asterisk.org/r/3071/
Modified:
asterisk/trunk/lib/python/asterisk/ami.py
asterisk/trunk/sample-yaml/ami-config.yaml.sample
asterisk/trunk/tests/bridge/transfer_failure/test-config.yaml
Modified: asterisk/trunk/lib/python/asterisk/ami.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/ami.py?view=diff&rev=4466&r1=4465&r2=4466
==============================================================================
--- asterisk/trunk/lib/python/asterisk/ami.py (original)
+++ asterisk/trunk/lib/python/asterisk/ami.py Mon Dec 16 08:04:25 2013
@@ -4,6 +4,7 @@
import sys
import logging
import re
+import json
logger = logging.getLogger(__name__)
@@ -280,6 +281,8 @@
self.requirements = {}
for key, value in requirements['match'].items():
lower_key = key.lower()
+ if lower_key == "extra":
+ value = dict((k.lower(), v) for k,v in value.iteritems())
self.requirements[lower_key] = value
self.orderings = requirements.get('partialorder') or []
self.named_id = requirements.get('id')
@@ -291,7 +294,21 @@
item = self.requirements.get(key)
if item is None:
continue
- if re.match(item, value) is None:
+
+ # test 'Extra' fields against the JSON blob
+ if key == "extra":
+ if not len(value):
+ continue
+ extra_obj = json.loads(value)
+ for extra_key, extra_value in extra_obj.items():
+ extra_item = item.get(extra_key.lower())
+ if extra_item is None:
+ continue
+ if re.search(extra_item, str(extra_value)) is None:
+ logger.debug('Skipping %s - %s does not equal %s for extra-subfield %s' %
+ (event['eventname'], extra_item, str(extra_value), extra_key))
+ return False
+ elif re.search(item, value) is None:
logger.debug('Skipping %s - %s does not equal %s for field %s' %
(event['eventname'], item, value, key))
return False
Modified: asterisk/trunk/sample-yaml/ami-config.yaml.sample
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/sample-yaml/ami-config.yaml.sample?view=diff&rev=4466&r1=4465&r2=4466
==============================================================================
--- asterisk/trunk/sample-yaml/ami-config.yaml.sample (original)
+++ asterisk/trunk/sample-yaml/ami-config.yaml.sample Mon Dec 16 08:04:25 2013
@@ -194,6 +194,14 @@
match:
EventName: 'HANGUP'
Channel: 'SIP/alice-.*'
+ # Extra is a special case that is relevant for hangups
+ # and other events that provide additional data in the
+ # CEL Extra field as a JSON blob. Individual fields can
+ # be matched using regex or ignored via omission.
+ Extra:
+ HangupCause: '16'
+ HangupSource: '.*/bob-.*'
+ DialStatus: 'ANSWER'
-
# The same as the previous requirement but with a slightly
# different partialorder.
Modified: asterisk/trunk/tests/bridge/transfer_failure/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/bridge/transfer_failure/test-config.yaml?view=diff&rev=4466&r1=4465&r2=4466
==============================================================================
--- asterisk/trunk/tests/bridge/transfer_failure/test-config.yaml (original)
+++ asterisk/trunk/tests/bridge/transfer_failure/test-config.yaml Mon Dec 16 08:04:25 2013
@@ -612,7 +612,10 @@
CallerIDdnid: 'alice_blind'
Exten: 'alice_blind'
Context: 'default'
- Extra: '.*16.*ANSWER.*/alice-.*'
+ Extra:
+ hangupcause: '16'
+ dialstatus: 'ANSWER'
+ hangupsource: '.*/alice-.*'
-
match:
EventName: 'CHAN_END'
@@ -685,7 +688,10 @@
CallerIDdnid: 'alice_attended'
Exten: 'alice_attended'
Context: 'default'
- Extra: '.*16.*ANSWER.*/alice-.*'
+ Extra:
+ hangupcause: '16'
+ dialstatus: 'ANSWER'
+ hangupsource: '.*/alice-.*'
-
match:
EventName: 'CHAN_END'
@@ -758,7 +764,9 @@
CallerIDdnid: 'bob_blind'
Exten: 'bob_blind'
Context: 'default'
- Extra: '.*16.*ANSWER.*'
+ Extra:
+ hangupcause: '16'
+ dialstatus: 'ANSWER'
-
match:
EventName: 'CHAN_END'
@@ -831,7 +839,9 @@
CallerIDdnid: 'bob_attended'
Exten: 'bob_attended'
Context: 'default'
- Extra: '.*16.*ANSWER.*'
+ Extra:
+ hangupcause: '16'
+ dialstatus: 'ANSWER'
-
match:
EventName: 'CHAN_END'
@@ -880,7 +890,9 @@
CallerIDnum: '4321'
Application: 'AppDial'
AppData: '\(Outgoing Line\)'
- Extra: '.*16.*/alice-.*'
+ Extra:
+ hangupcause: '16'
+ hangupsource: '.*/alice-.*'
-
match:
EventName: 'CHAN_END'
@@ -923,7 +935,9 @@
CallerIDnum: '4321'
Application: 'AppDial'
AppData: '\(Outgoing Line\)'
- Extra: '.*16.*/alice-.*'
+ Extra:
+ hangupcause: '16'
+ hangupsource: '.*/alice-.*'
-
match:
EventName: 'CHAN_END'
@@ -966,7 +980,8 @@
CallerIDnum: '4321'
Application: 'AppDial'
AppData: '\(Outgoing Line\)'
- Extra: '.*16.*'
+ Extra:
+ hangupcause: '16'
-
match:
EventName: 'CHAN_END'
@@ -1009,7 +1024,8 @@
CallerIDnum: '4321'
Application: 'AppDial'
AppData: '\(Outgoing Line\)'
- Extra: '.*16.*'
+ Extra:
+ hangupcause: '16'
-
match:
EventName: 'CHAN_END'
More information about the asterisk-commits
mailing list