[asterisk-commits] espiceland: testsuite/asterisk/trunk r517 - in /asterisk/trunk/tests: ./ fast...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 20 14:59:27 CDT 2010


Author: espiceland
Date: Tue Jul 20 14:59:23 2010
New Revision: 517

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=517
Log:
Two tests for FastAGI which test ability to connect and behavior of channelStatus() and answer().

Added:
    asterisk/trunk/tests/fastagi/
    asterisk/trunk/tests/fastagi/channel-status/
    asterisk/trunk/tests/fastagi/channel-status/run-test   (with props)
    asterisk/trunk/tests/fastagi/channel-status/test-config.yaml   (with props)
    asterisk/trunk/tests/fastagi/configs/
    asterisk/trunk/tests/fastagi/configs/extensions.conf   (with props)
    asterisk/trunk/tests/fastagi/configs/logger.conf   (with props)
    asterisk/trunk/tests/fastagi/configs/manager.conf   (with props)
    asterisk/trunk/tests/fastagi/connect/
    asterisk/trunk/tests/fastagi/connect/run-test   (with props)
    asterisk/trunk/tests/fastagi/connect/test-config.yaml   (with props)
Modified:
    asterisk/trunk/tests/tests.yaml

Added: asterisk/trunk/tests/fastagi/channel-status/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/channel-status/run-test?view=auto&rev=517
==============================================================================
--- asterisk/trunk/tests/fastagi/channel-status/run-test (added)
+++ asterisk/trunk/tests/fastagi/channel-status/run-test Tue Jul 20 14:59:23 2010
@@ -1,0 +1,150 @@
+#!/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 = {}
+        self.timeout = 45
+        self.test = 4
+
+        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_answer_failure(self, reason):
+        print 'Could not answer the call:', reason.getTraceback()
+
+    def on_failure(self, reason):
+        print 'Could not run deferred for', self.test, '::', reason.getTraceback()
+
+    def on_answer(self, status):
+        self.do_test(self.agi)
+
+    def get_deferred(self, agi):
+        return agi.channelStatus(agi.variables['agi_channel'])
+        
+    def finish_test(self, status):
+        print "status is", status
+        self.passed[status] = (self.test == status)
+        if self.test == 4:
+            print "Answering call"
+            self.test = 6
+            self.agi.answer().addCallback(self.on_answer).addErrback(self.on_answer_failure)
+        elif self.test == 6:
+            self.result_changed()
+
+    # This gets invoked by the dialplan when A answers call 
+    # Disconnect agi and set test result values
+
+    def do_test(self, agi):
+        self.agi = agi
+        if self.test == 4:
+            print "Connection established. Testing for channel status code 4."
+        elif self.test == 6:
+            print "Testing for channel status code 6."
+        
+        return self.get_deferred(agi).addCallback(self.finish_test).addErrback(self.on_failure)
+
+
+
+	# Read test results and dialplan globals
+    def read_result(self):
+        self.agi.finish()
+        if self.passed[4] is True and self.passed[6] is True:
+            print "PASS - FastAGI channelStatus() 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."
+            if self.passed[4] is not True: print "Test 4 failed (ringing)."
+            if self.passed[6] is not True: print "Test 6 failed (up)."
+
+        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")
+
+        # Set blocking=False so that we can test channel status before call is answered.
+        print "Originating call to begin test."
+        if self.ast_version < AsteriskVersion("1.6.2"):
+            self.asterisk.cli_exec("originate Local/c_exten at agitest extension echo at agitest",blocking=False)
+        else:
+            self.asterisk.cli_exec("channel originate Local/c_exten at agitest extension echo at agitest", blocking=False)
+
+
+    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[6] is not None:
+            reactor.callLater(2, self.read_result)
+
+    def run(self):
+        self.start_asterisk()
+
+        # Make a call 
+        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[4] is not True or agi_test.passed[6] is not True:
+        return 1
+
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(run() or 0)

Propchange: asterisk/trunk/tests/fastagi/channel-status/run-test
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/fastagi/channel-status/run-test
------------------------------------------------------------------------------
    svn:executable = *

Propchange: asterisk/trunk/tests/fastagi/channel-status/run-test
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/fastagi/channel-status/run-test
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/fastagi/channel-status/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/channel-status/test-config.yaml?view=auto&rev=517
==============================================================================
--- asterisk/trunk/tests/fastagi/channel-status/test-config.yaml (added)
+++ asterisk/trunk/tests/fastagi/channel-status/test-config.yaml Tue Jul 20 14:59:23 2010
@@ -1,0 +1,12 @@
+testinfo:
+    summary:     'Test FastAGI channelStatus() function.'
+    description: |
+        "Test FastAGI channelStatus() function.  Note: This test also relies on FastAGI's answer() function, so this test can be considered a test for both functions."
+
+
+properties:
+    minversion: '1.4'
+    dependencies:
+        - app : 'python'
+        - app : 'twisted'
+        - app : 'starpy'

Propchange: asterisk/trunk/tests/fastagi/channel-status/test-config.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/fastagi/channel-status/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/fastagi/channel-status/test-config.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/fastagi/configs/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/configs/extensions.conf?view=auto&rev=517
==============================================================================
--- asterisk/trunk/tests/fastagi/configs/extensions.conf (added)
+++ asterisk/trunk/tests/fastagi/configs/extensions.conf Tue Jul 20 14:59:23 2010
@@ -1,0 +1,23 @@
+[general]
+
+[globals]
+DEBUG=FAIL - nothing done
+
+[agitest]
+exten => echo,1,Answer()
+exten => echo,n,Echo()
+
+exten => b_exten,1,Answer()
+exten => b_exten,n,Set(GLOBAL(DEBUG)=FAIL-before agi)
+exten => b_exten,n,AGI(agi://127.0.0.1:4573)
+exten => b_exten,n,Set(GLOBAL(DEBUG)=${AGISTATUS})
+exten => b_exten,n,Wait(5)
+exten => b_exten,n,HangUp()
+
+;exten => c_exten,1,Answer()
+exten => c_exten,1,Set(GLOBAL(DEBUG)=FAIL-before agi)
+exten => c_exten,n,AGI(agi://127.0.0.1:4573)
+exten => c_exten,n,Set(GLOBAL(DEBUG)=${AGISTATUS})
+exten => c_exten,n,Wait(15)
+exten => c_exten,n,HangUp()
+

Propchange: asterisk/trunk/tests/fastagi/configs/extensions.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/fastagi/configs/extensions.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/fastagi/configs/extensions.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/fastagi/configs/logger.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/configs/logger.conf?view=auto&rev=517
==============================================================================
--- asterisk/trunk/tests/fastagi/configs/logger.conf (added)
+++ asterisk/trunk/tests/fastagi/configs/logger.conf Tue Jul 20 14:59:23 2010
@@ -1,0 +1,105 @@
+;
+; Logging Configuration
+;
+; In this file, you configure logging to files or to
+; the syslog system.
+;
+; "logger reload" at the CLI will reload configuration
+; of the logging system.
+
+[general]
+;
+; Customize the display of debug message time stamps
+; this example is the ISO 8601 date format (yyyy-mm-dd HH:MM:SS)
+;
+; see strftime(3) Linux manual for format specifiers.  Note that there is also
+; a fractional second parameter which may be used in this field.  Use %1q
+; for tenths, %2q for hundredths, etc.
+;
+;dateformat=%F %T       ; ISO 8601 date format
+;dateformat=%F %T.%3q   ; with milliseconds
+;
+; This appends the hostname to the name of the log files.
+;appendhostname = yes
+;
+; This determines whether or not we log queue events to a file
+; (defaults to yes).
+;queue_log = no
+;
+; Set the queue_log filename
+; (defaults to queue_log)
+;queue_log_name = queue_log
+;
+; Log rotation strategy:
+; sequential:  Rename archived logs in order, such that the newest
+;              has the highest sequence number [default].
+; rotate:  Rotate all the old files, such that the oldest has the
+;          highest sequence number [this is the expected behavior
+;          for Unix administrators].
+; timestamp:  Rename the logfiles using a timestamp instead of a
+;             sequence number when "logger rotate" is executed.
+;rotatestrategy = rotate
+;
+; Run a system command after rotating the files.  This is mainly
+; useful for rotatestrategy=rotate. The example allows the last
+; two archive files to remain uncompressed, but after that point,
+; they are compressed on disk.
+;
+; exec_after_rotate=gzip -9 ${filename}.2
+;
+;
+; For each file, specify what to log.
+;
+; For console logging, you set options at start of
+; Asterisk with -v for verbose and -d for debug
+; See 'asterisk -h' for more information.
+;
+; Directory for log files is configures in asterisk.conf
+; option astlogdir
+;
+[logfiles]
+;
+; Format is "filename" and then "levels" of debugging to be included:
+;    debug
+;    notice
+;    warning
+;    error
+;    verbose
+;    dtmf
+;
+; Special filename "console" represents the system console
+;
+; Filenames can either be relative to the standard Asterisk log directory
+; (see 'astlogdir' in asterisk.conf), or absolute paths that begin with
+; '/'.
+;
+; Special level name "*" means all levels, even dynamic levels registered
+; by modules after the logger has been initialized (this means that loading
+; and unloading modules that create/remove dynamic logger levels will result
+; in these levels being included on filenames that have a level name of "*",
+; without any need to perform a 'logger reload' or similar operation). Note
+; that there is no value in specifying both "*" and specific level names for
+; a filename; the "*" level means all levels, and the remaining level names
+; will be ignored.
+;
+; We highly recommend that you DO NOT turn on debug mode if you are simply
+; running a production system.  Debug mode turns on a LOT of extra messages,
+; most of which you are unlikely to understand without an understanding of
+; the underlying code.  Do NOT report debug messages as code issues, unless
+; you have a specific issue that you are attempting to debug.  They are
+; messages for just that -- debugging -- and do not rise to the level of
+; something that merit your attention as an Asterisk administrator.  Debug
+; messages are also very verbose and can and do fill up logfiles quickly;
+; this is another reason not to have debug mode on a production system unless
+; you are in the process of debugging a specific issue.
+;
+;debug => debug
+console => notice,warning,error
+;console => notice,warning,error,debug
+messages => notice,warning,error
+full => notice,warning,error,debug,verbose
+
+;syslog keyword : This special keyword logs to syslog facility
+;
+;syslog.local0 => notice,warning,error
+;

Propchange: asterisk/trunk/tests/fastagi/configs/logger.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/fastagi/configs/logger.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/fastagi/configs/logger.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/fastagi/configs/manager.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/configs/manager.conf?view=auto&rev=517
==============================================================================
--- asterisk/trunk/tests/fastagi/configs/manager.conf (added)
+++ asterisk/trunk/tests/fastagi/configs/manager.conf Tue Jul 20 14:59:23 2010
@@ -1,0 +1,10 @@
+[general]
+enabled = yes
+port = 5039
+bindaddr = 127.0.0.1
+
+[user]
+secret = mysecret
+read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
+write = system,call,agent,user,config,command,reporting,originate
+

Propchange: asterisk/trunk/tests/fastagi/configs/manager.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/fastagi/configs/manager.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/fastagi/configs/manager.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/fastagi/connect/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/connect/run-test?view=auto&rev=517
==============================================================================
--- asterisk/trunk/tests/fastagi/connect/run-test (added)
+++ asterisk/trunk/tests/fastagi/connect/run-test Tue Jul 20 14:59:23 2010
@@ -1,0 +1,129 @@
+#!/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 FastAGIConnectTest:
+    def __init__(self, argv):
+        self.passed = False
+        self.timeout = 45
+
+        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")
+
+    def on_failure(self, reason):
+        print 'Could not run sequence to close connection: ', reason.getTraceback()
+
+    def get_deferred(self, agi):
+        sequence = fastagi.InSequence()
+        sequence.append(agi.finish)
+        return sequence()
+        
+
+    def finish_test(self, agi):
+        self.passed = True
+        self.result_changed()
+        
+    # This gets invoked by the dialplan when the call is answered
+    # Disconnect agi and set test result values
+    def do_test(self, agi):
+        print "Connection established."
+        return self.get_deferred(agi).addCallback(self.finish_test).addErrback(self.on_failure)
+
+
+
+
+	# Read test results and dialplan globals
+    def read_result(self):
+
+        if self.passed is True:
+            print "PASS - FastAGI connection 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 - FastAGI Connection test failed. 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")
+
+        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()
+
+        # Make a call 
+        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 = FastAGIConnectTest(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/connect/run-test
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/fastagi/connect/run-test
------------------------------------------------------------------------------
    svn:executable = *

Propchange: asterisk/trunk/tests/fastagi/connect/run-test
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/fastagi/connect/run-test
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/fastagi/connect/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/connect/test-config.yaml?view=auto&rev=517
==============================================================================
--- asterisk/trunk/tests/fastagi/connect/test-config.yaml (added)
+++ asterisk/trunk/tests/fastagi/connect/test-config.yaml Tue Jul 20 14:59:23 2010
@@ -1,0 +1,12 @@
+testinfo:
+    summary:     'Test FastAGI connection.'
+    description: |
+        'Test FastAGI connection.'
+
+
+properties:
+    minversion: '1.4'
+    dependencies:
+        - app : 'python'
+        - app : 'twisted'
+        - app : 'starpy'

Propchange: asterisk/trunk/tests/fastagi/connect/test-config.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/fastagi/connect/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/fastagi/connect/test-config.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: asterisk/trunk/tests/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/tests.yaml?view=diff&rev=517&r1=516&r2=517
==============================================================================
--- asterisk/trunk/tests/tests.yaml (original)
+++ asterisk/trunk/tests/tests.yaml Tue Jul 20 14:59:23 2010
@@ -32,3 +32,5 @@
     - test: 'queues/macro_gosub_test'
     - test: 'queues/ringinuse_and_pause'
     - test: 'queues/wrapup_time'
+    - test: 'fastagi/connect'
+    - test: 'fastagi/channel-status'




More information about the asterisk-commits mailing list