[asterisk-commits] dvossel: testsuite/asterisk/trunk r304 - in /asterisk/trunk/tests/directed_pi...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 20 12:55:12 CDT 2010


Author: dvossel
Date: Thu May 20 12:55:09 2010
New Revision: 304

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=304
Log:
Addition of a PickupChan() dialplan app test

Review: https://reviewboard.asterisk.org/r/660/

Added:
    asterisk/trunk/tests/directed_pickup/
    asterisk/trunk/tests/directed_pickup/configs/
    asterisk/trunk/tests/directed_pickup/configs/extensions.conf   (with props)
    asterisk/trunk/tests/directed_pickup/configs/iax.conf   (with props)
    asterisk/trunk/tests/directed_pickup/run-test   (with props)
    asterisk/trunk/tests/directed_pickup/test-config.yaml   (with props)

Added: asterisk/trunk/tests/directed_pickup/configs/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/directed_pickup/configs/extensions.conf?view=auto&rev=304
==============================================================================
--- asterisk/trunk/tests/directed_pickup/configs/extensions.conf (added)
+++ asterisk/trunk/tests/directed_pickup/configs/extensions.conf Thu May 20 12:55:09 2010
@@ -1,0 +1,44 @@
+[general]
+
+[globals]
+
+[pickuptest]
+
+exten => h,1,GoToIf($[${RINGING_EXTEN}=1]?is_ringing:bye)
+
+; this is the ringing channel, see if it got picked up correctly or not.
+exten => h,n(is_ringing),GoToIf($[${RINGING_EXTEN_PASS}=1]?is_ringing_passed:is_ringing_failed)
+
+exten => h,n(is_ringing_failed),AGI(agi://127.0.0.1:4574) ;Tell the test script pickup failed
+exten => h,n,GoTo(pickuptest,h,bye) ; finish
+
+exten => h,n(is_ringing_passed),AGI(agi://127.0.0.1:4573) ;Tell the test script pickup passed
+exten => h,n(bye),NoOp(Bye ${CHANNEL})
+
+
+exten => 1001,1,Dial(IAX2/iax_pickup_b at 127.0.0.1/ringing_exten)
+
+;test 1 with no options
+exten => 1002,1,PickupChan(IAX2/iax_pickup_b)
+exten => 1002,n,Wait(1)
+exten => 1002,n,Hangup()
+
+;test 2 with 'p' option
+exten => 1003,1,PickupChan(IAX2/iax_pickup,p)
+exten => 1003,n,Wait(1)
+exten => 1003,n,Hangup()
+
+; this exten Answers and waits for the other side to answer
+exten => waiting_exten,1,Answer()
+exten => waiting_exten,n,Wait(10)
+
+; this exten never answers and expects another channel to pick it up during its wait period
+exten => ringing_exten,1,Set(RINGING_EXTEN=1)
+exten => ringing_exten,n,Set(RINGING_EXTEN_PASS=1)
+exten => ringing_exten,n,Wait(10)
+exten => ringing_exten,n,NoOp(This should not get called)
+
+; this exten should be hungup on before reaching this
+exten => ringing_exten,n,Set(RINGING_EXTEN_PASS=0)
+exten => ringing_exten,n,Hangup()
+

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

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

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

Added: asterisk/trunk/tests/directed_pickup/configs/iax.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/directed_pickup/configs/iax.conf?view=auto&rev=304
==============================================================================
--- asterisk/trunk/tests/directed_pickup/configs/iax.conf (added)
+++ asterisk/trunk/tests/directed_pickup/configs/iax.conf Thu May 20 12:55:09 2010
@@ -1,0 +1,12 @@
+[general]
+disallow=all
+allow=ulaw
+jitterbuffer=no
+forcejitterbuffer=no
+
+[iax_pickup_b]
+type=friend
+host=127.0.0.1
+context=pickuptest
+requirecalltoken=no
+

Propchange: asterisk/trunk/tests/directed_pickup/configs/iax.conf
------------------------------------------------------------------------------
    svn:eol-style = native

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

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

Added: asterisk/trunk/tests/directed_pickup/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/directed_pickup/run-test?view=auto&rev=304
==============================================================================
--- asterisk/trunk/tests/directed_pickup/run-test (added)
+++ asterisk/trunk/tests/directed_pickup/run-test Thu May 20 12:55:09 2010
@@ -1,0 +1,178 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2010, Digium, Inc.
+David Vossel <dvossel 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 time
+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
+
+NOT_RUN = 0
+PASS = 1
+FAIL = 2
+SKIP = 4
+class PickupTest:
+    def __init__(self, argv):
+
+        # Test timeout in seconds
+        self.test_to = 15
+        self.last_step = ""
+        self.test1_res = NOT_RUN
+        self.test2_res = NOT_RUN
+        self.passed = FAIL
+
+        # get version info
+        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)
+
+        # FastAGI, listen for results from dialplan
+        # PASS on port 4573
+        # FAIL on port 4574
+        self.agi_pass = fastagi.FastAGIFactory(self.report_test_passed)
+        self.agi_fail = fastagi.FastAGIFactory(self.report_test_failed)
+        reactor.listenTCP(4573, self.agi_pass, self.test_to, '127.0.0.1')
+        reactor.listenTCP(4574, self.agi_fail, self.test_to, '127.0.0.1')
+
+        reactor.callWhenRunning(self.run)
+
+        print self.ast_version
+        self.asterisk1 = Asterisk(base=os.path.join(os.getcwd(), "/tmp/asterisk-testsuite/directed_pickup"))
+        self.asterisk1.install_config("tests/directed_pickup/configs/extensions.conf")
+        self.asterisk1.install_config("tests/directed_pickup/configs/iax.conf")
+
+    def shut_down(self):
+        self.log_last_step("Reading results")
+        self.asterisk1.cli_exec("core show channels")# if channels are still up for some reason, we want to know that as well
+
+        self.stop_asterisk()
+
+        if reactor.running:
+            print "Stopping Reactor ..."
+            reactor.stop()
+
+        if self.test1_res != FAIL and self.test2_res != FAIL:
+            self.passed = True
+            print "Tests Passed"
+        else:
+            if self.test1_res != PASS:
+                print "Test 1 failed, Test 2 did not run"
+            else:
+                print "Test 1 Passed, Test 2 failed"
+            print "Tests Failed"
+
+    # Close out the agi
+    def handle_agi_result(self, agi):
+        sequence = fastagi.InSequence()
+        sequence.append(agi.finish)
+        return sequence()
+
+    # set the result, schedule next step
+    def handle_result(self, result):
+        self.asterisk1.cli_exec("console hangup")
+
+        if self.test1_res == NOT_RUN:
+            self.log_last_step("Pickup Test 1 results came in.")
+            self.test1_res = result
+        elif self.test2_res == NOT_RUN:
+            self.log_last_step("Pickup Test 2 results came in.")
+            self.test2_res = result
+
+        if self.test1_res == FAIL or self.test2_res == FAIL:
+            # schedule early shutdown, a test failed
+            reactor.callLater(2, self.shut_down)
+        elif self.test1_res != NOT_RUN and self.test2_res != NOT_RUN:
+            # schedule early shutdown, all tests ran
+            reactor.callLater(2, self.shut_down)
+        elif self.test2_res == NOT_RUN:
+            # schedule test2 if test1 passed
+            reactor.callLater(2, self.launch_test2)
+
+    # This gets invoked by the dialplan when pickup test passes
+    def report_test_passed(self, agi):
+        self.handle_result(PASS)
+        return self.handle_agi_result(agi)
+
+    # This gets invoked by the dialplan when pickup test fails
+    def report_test_failed(self, agi):
+        self.handle_result(FAIL)
+        return self.handle_agi_result(agi)
+
+    def test1_pickup(self):
+        self.asterisk1.cli_exec("core show channels")
+        self.log_last_step("Issuing the pickup")
+        self.asterisk1.cli_exec("console dial 1002 at pickuptest")
+
+    def launch_test1(self):
+        self.log_last_step("Starting Test 1")
+        self.asterisk1.cli_exec("core set verbose 10")
+        if self.ast_version < AsteriskVersion("1.6.2"):
+            self.asterisk1.cli_exec("originate IAX2/iax_pickup_b at 127.0.0.1/waiting_exten extension 1001 at pickuptest")
+        else:
+            self.asterisk1.cli_exec("channel originate IAX2/iax_pickup_b at 127.0.0.1/waiting_exten extension 1001 at pickuptest")
+        reactor.callLater(2, self.test1_pickup)
+
+    def test2_pickup(self):
+        self.asterisk1.cli_exec("core show channels")
+        self.log_last_step("Issuing the pickup")
+        self.asterisk1.cli_exec("console dial 1003 at pickuptest")
+
+    def launch_test2(self):
+        self.log_last_step("Starting Test 2")
+        if self.ast_version < AsteriskVersion("1.8"):
+            # this part requires version 1.8 or greater.
+            self.test2 = SKIP
+            reactor.callLater(2, self.shut_down)
+        else:
+            self.asterisk1.cli_exec("core set verbose 10")
+            self.asterisk1.cli_exec("channel originate IAX2/iax_pickup_b at 127.0.0.1/waiting_exten extension 1001 at pickuptest")
+            reactor.callLater(2, self.test2_pickup)
+
+    def start_asterisk(self):
+        self.log_last_step("Starting Asterisk")
+        self.asterisk1.start()
+
+    def stop_asterisk(self):
+        self.asterisk1.stop()
+
+    def log_last_step(self, step):
+        print step
+        self.last_step = step
+
+    def run(self):
+        self.start_asterisk()
+
+        # call test1 extension now
+        reactor.callLater(1, self.launch_test1)
+
+        # stop and read results after timeout
+        reactor.callLater(self.test_to, self.shut_down)
+
+def main(argv=None):
+    if argv is None:
+        argv = sys.argv
+
+    pickup_test = PickupTest(argv)
+    reactor.run()
+    pickup_test.stop_asterisk()
+    if pickup_test.passed != PASS:
+        return 1
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main() or 0)
+

Propchange: asterisk/trunk/tests/directed_pickup/run-test
------------------------------------------------------------------------------
    svn:eol-style = native

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

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

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

Added: asterisk/trunk/tests/directed_pickup/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/directed_pickup/test-config.yaml?view=auto&rev=304
==============================================================================
--- asterisk/trunk/tests/directed_pickup/test-config.yaml (added)
+++ asterisk/trunk/tests/directed_pickup/test-config.yaml Thu May 20 12:55:09 2010
@@ -1,0 +1,10 @@
+testinfo:
+    summary:     'Test PickupChan'
+    description: |
+        'This test verifies functionality of the PickupChan app and its options'
+
+properties:
+    minversion: '1.6.0'
+    dependencies:
+        - python : 'twisted'
+        - python : 'starpy'

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

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

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




More information about the asterisk-commits mailing list