[asterisk-commits] kmoore: testsuite/asterisk/trunk r4958 - in /asterisk/trunk: lib/python/aster...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 16 11:23:04 CDT 2014
Author: kmoore
Date: Wed Apr 16 11:22:47 2014
New Revision: 4958
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4958
Log:
Testsuite: Add config driven call file framework
This adds a pluggable module for testing call file capabilities and
adds a test that exercises basic call file support via pbx_spool.
(closes issue ASTERISK-23217)
Review: https://reviewboard.asterisk.org/r/3313/
Reported by: Matt Jordan
Added:
asterisk/trunk/sample-yaml/callfiles-config.yaml.sample (with props)
asterisk/trunk/tests/pbx/create_call_files/
asterisk/trunk/tests/pbx/create_call_files/configs/
asterisk/trunk/tests/pbx/create_call_files/configs/ast1/
asterisk/trunk/tests/pbx/create_call_files/configs/ast1/extensions.conf (with props)
asterisk/trunk/tests/pbx/create_call_files/test-config.yaml (with props)
Modified:
asterisk/trunk/lib/python/asterisk/pluggable_modules.py
asterisk/trunk/tests/pbx/tests.yaml
Modified: asterisk/trunk/lib/python/asterisk/pluggable_modules.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/pluggable_modules.py?view=diff&rev=4958&r1=4957&r2=4958
==============================================================================
--- asterisk/trunk/lib/python/asterisk/pluggable_modules.py (original)
+++ asterisk/trunk/lib/python/asterisk/pluggable_modules.py Wed Apr 16 11:22:47 2014
@@ -7,9 +7,10 @@
This program is free software, distributed under the terms of
the GNU General Public License Version 2.
"""
-
+import os
import sys
import logging
+import shutil
sys.path.append("lib/python")
from ami import AMIEventInstance
@@ -263,3 +264,66 @@
return (ami, event)
+class CallFiles(object):
+ """ This class allows call files to be created from a YAML configuration"""
+ def __init__(self, instance_config, test_object):
+ """Constructor"""
+ super(CallFiles, self).__init__()
+ self.test_object = test_object
+ self.call_file_instances = instance_config
+
+ if self.call_file_instances:
+ self.test_object.register_ami_observer(self.ami_connect)
+ else:
+ LOGGER.error("No configuration was specified for call files")
+ self.test_failed()
+
+ def test_failed(self):
+ """Checks to see whether or not the call files were
+ correctly specified """
+ self.test_object.set_passed(False)
+ self.test_object.stop_reactor()
+
+ def write_call_file(self, call_file_num, call_file):
+ """Write out the specified call file
+
+ Keyword Parameters:
+ call_file_num Which call file in the test we're writing out
+ call_file A dictionary containing the call file
+ information, derived from the YAML
+ """
+ params = call_file.get('call-file-params')
+ if not params:
+ LOGGER.error("No call file parameters specified")
+ self.test_failed()
+ return
+
+ self.locale = ("%s%s/tmp/test%d.call" %
+ (self.test_object.ast[int(call_file['id'])].base,
+ self.test_object.ast[int(call_file['id'])].directories
+ ["astspooldir"], call_file_num))
+
+ with open(self.locale, 'w') as outfile:
+ for key, value in params.items():
+ outfile.write("%s: %s\n" % (key, value))
+ LOGGER.debug("Wrote call file to %s" % self.locale)
+ self.move_file(call_file_num, call_file)
+
+ def ami_connect(self, ami):
+ """Handler for AMI connection """
+ for index, call_file in enumerate(self.call_file_instances):
+ if ami.id == int(call_file.get('id')):
+ self.write_call_file(index, call_file)
+
+ def move_file(self, call_file_num, call_file):
+ """Moves call files to astspooldir directory to be run """
+ src_file = self.locale
+ dst_file = ("%s%s/outgoing/test%s.call" %
+ (self.test_object.ast[int(call_file['id'])].base,
+ self.test_object.ast[int(call_file['id'])].directories
+ ["astspooldir"], call_file_num))
+
+ LOGGER.info("Moving file %s to %s" % (src_file, dst_file))
+
+ shutil.move(src_file, dst_file)
+ os.utime(dst_file, None)
Added: asterisk/trunk/sample-yaml/callfiles-config.yaml.sample
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/sample-yaml/callfiles-config.yaml.sample?view=auto&rev=4958
==============================================================================
--- asterisk/trunk/sample-yaml/callfiles-config.yaml.sample (added)
+++ asterisk/trunk/sample-yaml/callfiles-config.yaml.sample Wed Apr 16 11:22:47 2014
@@ -1,0 +1,38 @@
+# Configuration sample for the pluggable module Call Files. For an extensive
+# example check out the test-config in the /tests/pbx/create_call_files folder
+# of the testsuite.
+
+test-modules:
+ test-object:
+ config-section: test-object-config
+ typename: 'test_case.TestCaseModule'
+ modules:
+ -
+ config-section: call-files-config
+ typename: 'pluggable_modules.CallFiles'
+
+call-files-config:
+ # The ID of the AMI instance in which you want to Create and Execute
+ # the Call File.
+ id: '0'
+
+ # Whether to ignore failure of the originate.
+ ignore-originate-failure: 'no'
+
+ # Set parameters for the call files
+ call-file-params:
+ -
+ # The channel to execute the call file.
+ Channel: 'Local/s at default'
+
+ # The application to start once the channel is answered.
+ Application: 'Echo'
+
+ # The data to provide to the application.
+ Data: ''
+
+ # Aternatively, a context, extension, and priority can be set to override
+ # the application setting
+ Context: 'default'
+ Extension: '1234'
+ Priority: '1'
Propchange: asterisk/trunk/sample-yaml/callfiles-config.yaml.sample
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/sample-yaml/callfiles-config.yaml.sample
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/sample-yaml/callfiles-config.yaml.sample
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/pbx/create_call_files/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/pbx/create_call_files/configs/ast1/extensions.conf?view=auto&rev=4958
==============================================================================
--- asterisk/trunk/tests/pbx/create_call_files/configs/ast1/extensions.conf (added)
+++ asterisk/trunk/tests/pbx/create_call_files/configs/ast1/extensions.conf Wed Apr 16 11:22:47 2014
@@ -1,0 +1,16 @@
+[tests]
+
+exten => app1,1,Answer()
+ same => n,Echo()
+ same => n,Hangup()
+
+exten => app2,1,Answer()
+ same => n,Echo()
+ same => n,Hangup()
+
+[TestSet]
+
+exten => success,1,Answer()
+ same => n,UserEvent(CallResult, result: success)
+ same => n,Hangup()
+
Propchange: asterisk/trunk/tests/pbx/create_call_files/configs/ast1/extensions.conf
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/pbx/create_call_files/configs/ast1/extensions.conf
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/pbx/create_call_files/configs/ast1/extensions.conf
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/pbx/create_call_files/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/pbx/create_call_files/test-config.yaml?view=auto&rev=4958
==============================================================================
--- asterisk/trunk/tests/pbx/create_call_files/test-config.yaml (added)
+++ asterisk/trunk/tests/pbx/create_call_files/test-config.yaml Wed Apr 16 11:22:47 2014
@@ -1,0 +1,69 @@
+testinfo:
+ summary: 'Testing the pluggable module Call Files for Creation and Execution'
+ description: |
+ 'This configuration runs a single instance of Asterisk to create
+ a call file, then move that call file into the astspooldir to be
+ executed. App2 will answer the call and playback a file. App1 will
+ answer their call and also playback a file. Both user will emit
+ userevents in order to indicate that the two calls were in fact
+ successful'
+
+test-modules:
+ test-object:
+ config-section: test-object-config
+ typename: 'test_case.TestCaseModule'
+ modules:
+ -
+ config-section: call-files-config
+ typename: 'pluggable_modules.CallFiles'
+ -
+ config-section: ami-config
+ typename: 'ami.AMIEventModule'
+ -
+ config-section: hangup-monitor
+ typename: 'pluggable_modules.HangupMonitor'
+
+test-object-config:
+ asterisk-instances: 1
+ connect-ami: True
+
+call-files-config:
+ -
+ ignore-originate-failure: 'no'
+ id: '0'
+ call-file-params:
+ Channel: 'Local/app2 at tests'
+ Context: 'TestSet'
+ Extension: 'success'
+ Priority: 1
+ -
+ ignore-originate-failure: 'no'
+ id: '0'
+ call-file-params:
+ Channel: 'Local/app1 at tests'
+ Application: 'UserEvent'
+ Data: 'CallResult, result: success'
+
+ami-config:
+ -
+ type: 'headermatch'
+ id: '0'
+ conditions:
+ match:
+ Event: 'UserEvent'
+ UserEvent: 'CallResult'
+ requirements:
+ match:
+ result: 'success'
+ count: 2
+
+hangup-monitor:
+ ids: [ '0', ]
+
+properties:
+ minversion: '1.8.0.0'
+ dependencies:
+ - python : 'twisted'
+ - python : 'starpy'
+ - asterisk : 'app_userevent'
+ - asterisk : 'pbx_spool'
Propchange: asterisk/trunk/tests/pbx/create_call_files/test-config.yaml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/pbx/create_call_files/test-config.yaml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/pbx/create_call_files/test-config.yaml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: asterisk/trunk/tests/pbx/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/pbx/tests.yaml?view=diff&rev=4958&r1=4957&r2=4958
==============================================================================
--- asterisk/trunk/tests/pbx/tests.yaml (original)
+++ asterisk/trunk/tests/pbx/tests.yaml Wed Apr 16 11:22:47 2014
@@ -1,5 +1,6 @@
# Enter tests here in the order they should be considered for execution:
tests:
+ - test: 'create_call_files'
- test: 'ast_db'
- test: 'dialplan'
- test: 'call-files'
More information about the asterisk-commits
mailing list