[asterisk-commits] espiceland: testsuite/asterisk/trunk r539 - /asterisk/trunk/tests/fastagi/han...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jul 21 15:28:25 CDT 2010
Author: espiceland
Date: Wed Jul 21 15:28:22 2010
New Revision: 539
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=539
Log:
Test fastagi.hangup().
Added:
asterisk/trunk/tests/fastagi/hangup/
asterisk/trunk/tests/fastagi/hangup/run-test (with props)
asterisk/trunk/tests/fastagi/hangup/test-config.yaml (with props)
Added: asterisk/trunk/tests/fastagi/hangup/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/hangup/run-test?view=auto&rev=539
==============================================================================
--- asterisk/trunk/tests/fastagi/hangup/run-test (added)
+++ asterisk/trunk/tests/fastagi/hangup/run-test Wed Jul 21 15:28:22 2010
@@ -1,0 +1,141 @@
+#!/usr/bin/python
+'''
+Copyright (C) 2010, Digium, Inc.
+Erin Spiceland <espiceland at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import sys
+import os
+import math
+from optparse import OptionParser
+from twisted.application import service, internet
+from twisted.internet import reactor
+from starpy import fastagi
+
+sys.path.append("lib/python")
+from asterisk.asterisk import Asterisk
+from asterisk.version import AsteriskVersion
+
+class FastAGIChannelStatusTest:
+ def __init__(self, argv):
+ self.passed = False
+ self.timeout = 45
+ self.test = 1
+
+ parser = OptionParser()
+ parser.add_option("-v", "--version", dest="ast_version",
+ help="Asterisk version string")
+ (options, args) = parser.parse_args(argv)
+ self.ast_version = AsteriskVersion(options.ast_version)
+
+ # Listen for results from dialplan
+ self.agi_factory = fastagi.FastAGIFactory(self.do_test)
+ reactor.listenTCP(4573, self.agi_factory, self.timeout, '127.0.0.1')
+ reactor.callWhenRunning(self.run)
+
+ print self.ast_version
+ self.asterisk = Asterisk(base=os.path.join(os.getcwd(), "/tmp/asterisk-testsuite/fastagi"))
+ self.asterisk.install_config("tests/fastagi/configs/extensions.conf")
+ self.asterisk.install_config("tests/fastagi/configs/manager.conf")
+ self.asterisk.install_config("tests/fastagi/configs/logger.conf")
+
+ def on_hangup_failure(self, reason):
+ print 'Could not hangup:', reason.getTraceback()
+
+ def on_failure(self, reason):
+ print "Channel is not active. Hangup succeeded."
+ self.passed = True
+ self.result_changed()
+
+ def on_hangup(self, status):
+ self.test = 2
+ self.do_test(self.agi)
+
+
+ def finish_test(self, status):
+ print "Channel is still up! Status is", status
+ self.passed = False
+ self.result_changed()
+
+ # This gets invoked by the dialplan when the call is answered
+ # Hangup via fastagi and test channel status
+ def do_test(self, agi):
+ self.agi = agi
+ if self.test == 1:
+ print "Connection established."
+ return agi.hangup().addCallback(self.on_hangup).addErrback(self.on_hangup_failure)
+ elif self.test == 2:
+ print "Testing for closed channel."
+ # We expect this call to fail, as channelStatus() cannot query a dead channel
+ return agi.channelStatus(agi.variables['agi_channel']).addCallback(self.finish_test).addErrback(self.on_failure)
+
+
+
+ # Read test results and dialplan globals
+ def read_result(self):
+ self.agi.finish()
+ if self.passed is True:
+ print "PASS - FastAGI hangup() works as expected."
+ else:
+ self.asterisk.cli_exec("core show channels")
+
+ if self.ast_version < AsteriskVersion("1.6.1"):
+ self.asterisk.cli_exec("core show globals")
+ else:
+ self.asterisk.cli_exec("dialplan show globals")
+
+ print "FAIL - View result of 'core show globals' in log for more detailed failure results."
+
+ self.stop_asterisk()
+
+ if reactor.running:
+ print "Stopping Reactor ..."
+ reactor.stop()
+
+
+ def launch_test(self):
+ self.asterisk.cli_exec("core set verbose 10")
+ self.asterisk.cli_exec("agi set debug on")
+
+ print "Originating call to begin test."
+ if self.ast_version < AsteriskVersion("1.6.2"):
+ self.asterisk.cli_exec("originate Local/b_exten at agitest extension echo at agitest")
+ else:
+ self.asterisk.cli_exec("channel originate Local/b_exten at agitest extension echo at agitest")
+
+
+ def start_asterisk(self):
+ print "Starting Asterisk"
+ self.asterisk.start()
+
+ def stop_asterisk(self):
+ print "Stopping Asterisk"
+ self.asterisk.stop()
+
+
+ # Read result before timeout
+ def result_changed(self):
+ if self.passed is True:
+ reactor.callLater(2, self.read_result)
+
+ def run(self):
+ self.start_asterisk()
+ reactor.callLater(2, self.launch_test)
+ reactor.callLater(self.timeout, self.read_result)
+
+def run(argv=None):
+ if argv is None:
+ argv = sys.argv
+
+ agi_test = FastAGIChannelStatusTest(argv)
+ reactor.run()
+ if agi_test.passed is not True:
+ return 1
+
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(run() or 0)
Propchange: asterisk/trunk/tests/fastagi/hangup/run-test
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/fastagi/hangup/run-test
------------------------------------------------------------------------------
svn:executable = *
Propchange: asterisk/trunk/tests/fastagi/hangup/run-test
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/fastagi/hangup/run-test
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/fastagi/hangup/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/hangup/test-config.yaml?view=auto&rev=539
==============================================================================
--- asterisk/trunk/tests/fastagi/hangup/test-config.yaml (added)
+++ asterisk/trunk/tests/fastagi/hangup/test-config.yaml Wed Jul 21 15:28:22 2010
@@ -1,0 +1,14 @@
+testinfo:
+ summary: 'Test FastAGI hangup() function.'
+ description: |
+ 'Test FastAGI hangup() function. Note: this test requires that
+ channelStatus() throw an error when it is asked to check the status
+ of a dead channel.'
+
+
+properties:
+ minversion: '1.4'
+ dependencies:
+ - app : 'python'
+ - app : 'twisted'
+ - app : 'starpy'
Propchange: asterisk/trunk/tests/fastagi/hangup/test-config.yaml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/fastagi/hangup/test-config.yaml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/fastagi/hangup/test-config.yaml
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list