[asterisk-commits] pabelanger: testsuite/asterisk/trunk r1501 - in /asterisk/trunk: ./ configs/ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 12 15:46:12 CDT 2011


Author: pabelanger
Date: Thu May 12 15:46:07 2011
New Revision: 1501

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=1501
Log:
Revert TestCase merge.

Work still needs to be done to confirm it will not break existing tests.

Added:
    asterisk/trunk/tests/udptl/configs/ast1/manager.conf
      - copied unchanged from r1479, asterisk/trunk/tests/udptl/configs/ast1/manager.conf
    asterisk/trunk/tests/udptl/configs/ast2/manager.conf
      - copied unchanged from r1479, asterisk/trunk/tests/udptl/configs/ast2/manager.conf
Removed:
    asterisk/trunk/configs/manager.conf
    asterisk/trunk/configs/manager.general.conf.inc
    asterisk/trunk/lib/python/asterisk/TestCase.py
    asterisk/trunk/tests/udptl/configs/ast1/manager.general.conf.inc
    asterisk/trunk/tests/udptl/configs/ast2/manager.general.conf.inc
Modified:
    asterisk/trunk/configs/asterisk.options.conf.inc
    asterisk/trunk/lib/python/asterisk/__init__.py
    asterisk/trunk/lib/python/asterisk/asterisk.py
    asterisk/trunk/runtests.py
    asterisk/trunk/tests/agi/exit_status/userA/agi-bin/badinterpreter.agi   (props changed)
    asterisk/trunk/tests/agi/exit_status/userA/agi-bin/badinterpreter2.agi   (props changed)
    asterisk/trunk/tests/agi/exit_status/userA/agi-bin/badinterpreter3.agi   (props changed)
    asterisk/trunk/tests/agi/exit_status/userA/agi-bin/donothing.agi   (props changed)
    asterisk/trunk/tests/agi/exit_status/userA/agi-bin/executing.agi   (props changed)
    asterisk/trunk/tests/agi/exit_status/userA/agi-bin/waiting.agi   (props changed)
    asterisk/trunk/tests/manager/login/run-test
    asterisk/trunk/tests/udptl/run-test

Modified: asterisk/trunk/configs/asterisk.options.conf.inc
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/configs/asterisk.options.conf.inc?view=diff&rev=1501&r1=1500&r2=1501
==============================================================================
--- asterisk/trunk/configs/asterisk.options.conf.inc (original)
+++ asterisk/trunk/configs/asterisk.options.conf.inc Thu May 12 15:46:07 2011
@@ -4,4 +4,3 @@
 verbose = 15
 nocolor = yes
 dumpcore = yes
-execincludes = yes

Modified: asterisk/trunk/lib/python/asterisk/__init__.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/__init__.py?view=diff&rev=1501&r1=1500&r2=1501
==============================================================================
--- asterisk/trunk/lib/python/asterisk/__init__.py (original)
+++ asterisk/trunk/lib/python/asterisk/__init__.py Thu May 12 15:46:07 2011
@@ -1,0 +1,1 @@
+__all__ = [ "asterisk", "config", "version", "cdr", "utils" ]

Modified: asterisk/trunk/lib/python/asterisk/asterisk.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/asterisk.py?view=diff&rev=1501&r1=1500&r2=1501
==============================================================================
--- asterisk/trunk/lib/python/asterisk/asterisk.py (original)
+++ asterisk/trunk/lib/python/asterisk/asterisk.py Thu May 12 15:46:07 2011
@@ -43,25 +43,24 @@
     asterisk.conf.
     """
 
-    def __init__(self, base=None, ast_conf_options=None, host="127.0.0.1"):
+    def __init__(self, base=None, ast_conf_options=None):
         """Construct an Asterisk instance.
 
         Keyword Arguments:
         base -- This is the root of the files associated with this instance of
-        Asterisk.  By default, the base is "/tmp/asterisk-testsuite" directory.
-        Given a base, it will be appended to the default base directory.
-
-        Example Usage:
-        self.asterisk = Asterisk(base="manager/login")
+        Asterisk.  By default, the base is "tmp/" within the current working
+        directory.  Given a base, a unique directory name will be generated to
+        hold all files.
+
+        Example Usage:
+        self.asterisk = Asterisk(base=os.path.join(os.getcwd(),
+                                                   "tests/ami-login/tmp"))
         """
         self.directories = {}
         self.ast_version = AsteriskVersion()
 
-        self.base = "/tmp/asterisk-testsuite"
         self.astetcdir = "/etc/asterisk"
         self.ast_binary = utils.which("asterisk") or "/usr/sbin/asterisk"
-        self.host = host
-        self.valgrind = False
 
         # Find the system installed asterisk.conf
         ast_confs = [
@@ -77,8 +76,10 @@
             print "No asterisk.conf found on the system!"
             return
 
-        if base is not None:
-            self.base = "%s/%s" % (self.base, base)
+        # Choose an install base
+        self.base = base
+        if self.base is None:
+            self.base = "%s/tmp" % os.getcwd()
         i = 1
         while True:
             if not os.path.isdir("%s/ast%d" % (self.base, i)):
@@ -114,8 +115,6 @@
             "-f", "-g", "-q", "-m", "-n",
             "-C", "%s" % os.path.join(self.astetcdir, "asterisk.conf")
         ]
-        if self.valgrind:
-            cmd.insert(0, "valgrind")
         try:
             self.process = subprocess.Popen(cmd)
         except OSError:

Modified: asterisk/trunk/runtests.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/runtests.py?view=diff&rev=1501&r1=1500&r2=1501
==============================================================================
--- asterisk/trunk/runtests.py (original)
+++ asterisk/trunk/runtests.py Thu May 12 15:46:07 2011
@@ -109,7 +109,7 @@
             "res_fax_spandsp.so",
             "res_fax_digium.so",
         ]
-        ast = Asterisk()
+        ast = Asterisk(base="/tmp/asterisk-testsuite/runtests")
 
         if "astmoddir" not in ast.directories:
             return False
@@ -121,13 +121,12 @@
 
 
 class TestConfig:
-    def __init__(self, test_name, ast_version, options):
+    def __init__(self, test_name, ast_version):
         self.can_run = True
         self.did_run = False
         self.time = 0.0
         self.test_name = test_name
         self.ast_version = ast_version
-        self.options = options
         self.skip = None
         self.config = None
         self.summary = None
@@ -146,11 +145,8 @@
         start_time = time.time()
         cmd = [
             "%s/run-test" % self.test_name,
-            "-v", str(self.ast_version),
-            "-n", str(self.test_name)
+            "-v", str(self.ast_version)
         ]
-        if self.options.valgrind:
-            cmd.append("--valgrind")
         if os.path.exists(cmd[0]) and os.access(cmd[0], os.X_OK):
             print "Running %s ..." % cmd
             try:
@@ -285,7 +281,7 @@
             for val in t:
                 path = "%s/%s" % (test_dir, t[val])
                 if val == "test":
-                    tests.append(TestConfig(path, ast_version, self.options))
+                    tests.append(TestConfig(path, ast_version))
                 elif val == "dir":
                     tests += self._parse_test_yaml(path, ast_version)
 
@@ -405,9 +401,6 @@
     parser.add_option("-t", "--test",
             dest="test",
             help="Run a single specified test instead of all tests.")
-    parser.add_option("--valgrind", action="store_true",
-            dest="valgrind", default=False,
-            help="Run Asterisk under valgrind.")
     (options, args) = parser.parse_args(argv)
 
     # Check to see if this has been executed within a sub directory of an

Propchange: asterisk/trunk/tests/agi/exit_status/userA/agi-bin/badinterpreter.agi
            ('svn:mergeinfo' removed)

Propchange: asterisk/trunk/tests/agi/exit_status/userA/agi-bin/badinterpreter2.agi
            ('svn:mergeinfo' removed)

Propchange: asterisk/trunk/tests/agi/exit_status/userA/agi-bin/badinterpreter3.agi
            ('svn:mergeinfo' removed)

Propchange: asterisk/trunk/tests/agi/exit_status/userA/agi-bin/donothing.agi
            ('svn:mergeinfo' removed)

Propchange: asterisk/trunk/tests/agi/exit_status/userA/agi-bin/executing.agi
            ('svn:mergeinfo' removed)

Propchange: asterisk/trunk/tests/agi/exit_status/userA/agi-bin/waiting.agi
            ('svn:mergeinfo' removed)

Modified: asterisk/trunk/tests/manager/login/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/manager/login/run-test?view=diff&rev=1501&r1=1500&r2=1501
==============================================================================
--- asterisk/trunk/tests/manager/login/run-test (original)
+++ asterisk/trunk/tests/manager/login/run-test Thu May 12 15:46:07 2011
@@ -8,35 +8,77 @@
 '''
 
 import sys
-from twisted.internet import reactor
+import os
+import shutil
+import time
+from twisted.application import service, internet
+from twisted.internet import reactor, defer
+from starpy import manager
 
 sys.path.append("lib/python")
 from asterisk.asterisk import Asterisk
-from asterisk.TestCase import TestCase
 
-class AMILoginTest(TestCase):
-    def __init__(self, argv):
-        TestCase.__init__(self, argv)
-        self.create_asterisk()
+workingdir = "/tmp/asterisk-testsuite/manager/login"
+testdir = "tests/manager/login"
 
-    def ami_logoff(self, ami):
+
+class AMILoginTest:
+    def __init__(self):
+        self.passed = False
+        self.last_step = ""
+        self.ami = None
+
+        reactor.callWhenRunning(self.run)
+
+        print "Creating Asterisk instance ..."
+        self.ast1 = Asterisk(base=workingdir)
+        self.ast1.install_configs("%s/configs/ast1" % (testdir))
+
+    def stop_reactor(self):
+        print "Stopping Reactor ..."
+        if reactor.running:
+            reactor.stop()
+
+    def start_asterisk(self):
+        self.log_last_step("Starting Asterisk")
+        self.ast1.start()
+
+    def stop_asterisk(self):
+        self.ast1.stop()
+
+    def log_last_step(self, step):
+        print step
+        self.last_step = step
+
+    def on_error(self, ami):
+        print "ERROR, Last Step: %s" % self.last_step
+        self.stop_reactor()
+
+    def on_logoff(self, ami):
+        self.log_last_step("Logoff Successful")
         self.passed = True
         self.stop_reactor()
 
-    def ami_connect(self, ami):
-        TestCase.ami_connect(self, ami)
-        self.ami[0].logoff().addCallbacks(self.ami_logoff, self.ami_login_error)
+    def on_connect(self, ami):
+        self.log_last_step("Connected to the AMI")
+        self.ami = ami
+        self.ami.logoff().addCallbacks(self.on_logoff, self.on_error)
+        self.log_last_step("Logging off")
 
     def run(self):
-        TestCase.run(self)
-        self.create_ami_factory(1, "user", "mysecret")
+        self.start_asterisk()
 
-def main(argv=None):
-    if argv is None:
-        argv = sys.argv
+        # A timeout in case things hang and fail
+        reactor.callLater(20, self.stop_reactor)
 
-    test = AMILoginTest(argv)
-    test.start_asterisk()
+        self.log_last_step("Logging in to the AMI")
+        self.ami_factory = manager.AMIFactory("user", "mysecret")
+        self.ami_factory.login('127.0.0.1', 5038).addCallbacks(self.on_connect,
+                                                               self.on_error)
+
+
+def main():
+    test = AMILoginTest()
     reactor.run()
     test.stop_asterisk()
     if test.passed:

Modified: asterisk/trunk/tests/udptl/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/udptl/run-test?view=diff&rev=1501&r1=1500&r2=1501
==============================================================================
--- asterisk/trunk/tests/udptl/run-test (original)
+++ asterisk/trunk/tests/udptl/run-test Thu May 12 15:46:07 2011
@@ -7,31 +7,60 @@
 the GNU General Public License Version 2.
 '''
 import sys
-from twisted.internet import reactor
+import os
+import signal
+import subprocess
+from optparse import OptionParser
+from twisted.application import service, internet
+from twisted.internet import reactor, defer
 from starpy import manager
 
 sys.path.append("lib/python")
 from asterisk.asterisk import Asterisk
 from asterisk.version import AsteriskVersion
-from asterisk.TestCase import TestCase
 
-class UdptlTest(TestCase):
+workingdir = "/tmp/asterisk-testsuite/udptl"
+testdir = "tests/udptl"
+
+class UdptlTest:
     def __init__(self, argv):
-        self.reactor_timeout = 60
+        self.last_step = ""
+        self.passed = False
 
-        TestCase.__init__(self, argv)
-        self.create_asterisk(2)
+        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)
 
-    def ami_connect(self, ami):
-        TestCase.ami_connect(self, ami)
-        if ami.id == 0:
-            self.ami[0].originate(channel = "SIP/666 at receiver",
-                    application = "SendFax",
-                    data = "tests/udptl/1page.tif")
-        elif ami.id == 1:
-            self.ami[1].registerEvent("UserEvent", self.check_recv_fax_result)
+        reactor.callWhenRunning(self.run)
+
+        self.ast1 = Asterisk(base=workingdir)
+        self.ast1.install_configs("%s/configs/ast1" % (testdir))
+
+        self.ast2 = Asterisk(base=workingdir)
+        self.ast2.install_configs("%s/configs/ast2" % (testdir))
+
+    def start_asterisk(self):
+        self.log_last_step("Starting Asterisk")
+        self.ast1.start()
+        self.ast1.cli_exec("fax set debug on")
+        self.ast2.start()
+        self.ast2.cli_exec("fax set debug on")
+
+    def stop_asterisk(self):
+        self.ast1.stop()
+        self.ast2.stop()
+
+    def ami_on_connect1(self, ami):
+        self.log_last_step("Connected to AMI 1")
+        self.ami1 = ami
+        self.ami1.originate(channel = "SIP/666 at receiver",
+                            application = "SendFax",
+                            data = "tests/udptl/1page.tif")
 
     def check_recv_fax_result(self, ami, event):
+        self.log_last_step("Checking Userevent")
         if event.get("userevent").lower() != "recvstatus":
             return
         self.stop_reactor()
@@ -45,12 +74,34 @@
             self.passed = False
             print "UDPTL test failed!"
 
+    def ami_on_connect2(self, ami):
+        self.log_last_step("Connected to AMI 2")
+        self.ami2 = ami
+        self.ami2.registerEvent("UserEvent", self.check_recv_fax_result)
+
+    def ami_login_error(self, ami):
+        self.log_last_step("AMI login failed")
+        reactor.callLater(1, self.stop_reactor)
+
     def ami_login(self):
-        self.create_ami_factory(2, "user", "mysecret")
+        self.log_last_step("Logging in to the AMI")
+        self.ami_factory1 = manager.AMIFactory("user", "mysecret")
+        self.ami_factory2 = manager.AMIFactory("user", "mysecret")
+        self.ami_factory1.login('127.0.0.1', 5038).addCallbacks(self.ami_on_connect1, self.ami_login_error)
+        self.ami_factory2.login('127.0.0.1', 5039).addCallbacks(self.ami_on_connect2, self.ami_login_error)
+
+    def log_last_step(self, step):
+        print step
+        self.lastStep = step
+
+    def stop_reactor(self):
+        print "Stopping reactor"
+        if reactor.running:
+            reactor.stop()
 
     def run(self):
-        TestCase.run(self)
         self.ami_login()
+        self.shutdowncall = reactor.callLater(60, self.stop_reactor)
 
 
 def main(argv=None):
@@ -68,5 +119,3 @@
 
 if __name__ == "__main__":
     sys.exit(main() or 0)
-
-# vim:sw=4:ts=4:expandtab:textwidth=79




More information about the asterisk-commits mailing list