[svn-commits] russell: testsuite/asterisk/trunk r162 - in /asterisk/trunk: lib/python/aster...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Mar 31 02:23:12 CDT 2010


Author: russell
Date: Wed Mar 31 02:23:07 2010
New Revision: 162

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=162
Log:
Extend lib/python, add 2 new tests.

In lib/python, add the ability to create multiple running instances of Asterisk
from within a python script.  This was inspired by the same feature provided by
asttest for tests written in lua.

Add the 'ami-login' test.  This uses Asterisk() from lib/python/ to create an
instance of Asterisk and ensure that it can log in to the AMI interface
successfully.

Add the 'iax-call-basic' test.  This creates 2 Asterisk() instances and originates
an IAX2 call between them.  Both ends connect to a FastAGI server implemented by
the test script to verify that the call was set up.

Added:
    asterisk/trunk/lib/python/asterisk/asterisk.py   (with props)
    asterisk/trunk/tests/ami-login/   (with props)
    asterisk/trunk/tests/ami-login/configs/
    asterisk/trunk/tests/ami-login/configs/logger.conf   (with props)
    asterisk/trunk/tests/ami-login/configs/manager.conf   (with props)
    asterisk/trunk/tests/ami-login/run-test   (with props)
    asterisk/trunk/tests/ami-login/test-config.yaml   (with props)
    asterisk/trunk/tests/iax-call-basic/   (with props)
    asterisk/trunk/tests/iax-call-basic/configs/
    asterisk/trunk/tests/iax-call-basic/configs/extensions.conf   (with props)
    asterisk/trunk/tests/iax-call-basic/configs/iax.conf   (with props)
    asterisk/trunk/tests/iax-call-basic/configs/logger.conf   (with props)
    asterisk/trunk/tests/iax-call-basic/configs/manager.conf   (with props)
    asterisk/trunk/tests/iax-call-basic/configs2/
    asterisk/trunk/tests/iax-call-basic/configs2/extensions.conf   (with props)
    asterisk/trunk/tests/iax-call-basic/configs2/iax.conf   (with props)
    asterisk/trunk/tests/iax-call-basic/configs2/logger.conf   (with props)
    asterisk/trunk/tests/iax-call-basic/configs2/manager.conf   (with props)
    asterisk/trunk/tests/iax-call-basic/run-test   (with props)
    asterisk/trunk/tests/iax-call-basic/test-config.yaml   (with props)
Modified:
    asterisk/trunk/tests/tests.yaml

Added: asterisk/trunk/lib/python/asterisk/asterisk.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/asterisk.py?view=auto&rev=162
==============================================================================
--- asterisk/trunk/lib/python/asterisk/asterisk.py (added)
+++ asterisk/trunk/lib/python/asterisk/asterisk.py Wed Mar 31 02:23:07 2010
@@ -1,0 +1,230 @@
+#!/usr/bin/env python
+""" Asterisk Instances in Python.
+
+This module provides an interface for creating instances of Asterisk
+from within python code.
+
+Copyright (C) 2010, Digium, Inc.
+Russell Bryant <russell 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
+import shutil
+import subprocess
+
+from config import ConfigFile
+
+
+class Asterisk:
+    """An instance of Asterisk.
+
+    This class assumes that Asterisk has been installed on the system.  The
+    installed version of Asterisk will be mirrored for this dynamically created
+    instance.
+
+    Instantiate an Asterisk object to create an instance of Asterisk from
+    within python code.  Multiple instances of Asterisk are allowed.  However,
+    custom configuration will need to be provided to prevent some modules from
+    conflicting with each other.  For example, modules that listen for network
+    connections will need to be configured to use different ports on each
+    instance of Asterisk.
+    """
+
+    def __init__(self, base=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/" 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"))
+        """
+        # Find the system installed asterisk.conf
+        ast_confs = [
+                "/etc/asterisk/asterisk.conf",
+                "/usr/local/etc/asterisk/asterisk.conf"
+        ]
+        ast_conf = None
+        for c in ast_confs:
+            if os.path.exists(c):
+                ast_conf = ConfigFile(c)
+                break
+        if ast_conf is None:
+            print "No asterisk.conf found on the system!"
+            return
+
+        # 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)):
+                self.base = "%s/ast%d" % (self.base, i)
+                break
+            i += 1
+        os.makedirs(self.base)
+
+        # Mirror system install directory structure
+        dir_cat = None
+        for c in ast_conf.categories:
+            if c.name == "directories":
+                dir_cat = c
+        if dir_cat is None:
+            print "Unable to discover dir layout from asterisk.conf"
+            return
+        self.__gen_ast_conf(ast_conf, dir_cat)
+        for (var, val) in dir_cat.options:
+            self.__mirror_dir(var, val)
+
+    def start(self):
+        """Start this instance of Asterisk.
+
+        This function starts up this instance of Asterisk.
+
+        Example Usage:
+        asterisk.start()
+        """
+        cmd = [
+            "asterisk",
+            "-f", "-g", "-q", "-m",
+            "-C", "%s" % os.path.join(self.astetcdir, "asterisk.conf")
+        ]
+        self.process = subprocess.Popen(cmd)
+        time.sleep(5.0)
+        # XXX
+        # We need a _much_ better way to determine if Asterisk
+        # is actually up and running and fully initialized
+
+    def stop(self):
+        """Stop this instance of Asterisk.
+
+        This function is used to stop this instance of Asterisk.
+
+        Example Usage:
+        asterisk.stop()
+        """
+        self.process.terminate()
+        time.sleep(5.0)
+        try:
+            if not self.process.poll():
+                self.process.kill()
+        except OSError:
+            pass
+        (self.stdout, self.stderr) = self.process.communicate()
+        return self.process.returncode
+
+    def install_config(self, cfg_path):
+        """Install a custom configuration file for this instance of Asterisk.
+
+        By default, the configuration used will be whatever is found in the
+        system install of Asterisk.  However, custom configuration files to be
+        used only by this instance can be provided via this API call.
+
+        Keyword Arguments:
+        cfg_path -- This argument must be the path to the configuration file
+        to be installed into the directory tree for this instance of Asterisk.
+
+        Example Usage:
+        asterisk.install_config("tests/my-cool-test/configs/manager.conf")
+        """
+        if not os.path.exists(cfg_path):
+            print "Config file '%s' does not exist" % cfg_path
+            return
+        if not self.astetcdir:
+            print "Don't know where to put local config!"
+            return
+        target_path = os.path.join(self.astetcdir, os.path.basename(cfg_path))
+        if os.path.exists(target_path):
+            os.remove(target_path)
+        try:
+            shutil.copyfile(cfg_path, target_path)
+        except shutil.Error:
+            print "'%s' and '%s' are the same file" % (cfg_path, target_path)
+        except IOError:
+            print "The destination is not writable '%s'" % target_path
+
+    def cli_exec(self, cli_cmd):
+        """Execute a CLI command on this instance of Asterisk.
+
+        Keyword Arguments:
+        cli_cmd -- The command to execute.
+
+        Example Usage:
+        asterisk.cli_exec("core set verbose 10")
+        """
+        cmd = [
+            "asterisk",
+            "-C", "%s" % os.path.join(self.astetcdir, "asterisk.conf"),
+            "-rx", "%s" % cli_cmd
+        ]
+        print "Executing %s ..." % cmd
+        process = subprocess.Popen(cmd)
+        process.wait()
+
+    def __gen_ast_conf(self, ast_conf, dir_cat):
+        self.astetcdir = None
+        for (var, val) in dir_cat.options:
+            if var == "astetcdir":
+                self.astetcdir = "%s%s" % (self.base, val)
+                os.makedirs(self.astetcdir)
+
+        if self.astetcdir is None:
+            print "Could not determine astetcdir"
+            return
+
+        local_ast_conf_path = os.path.join(self.astetcdir, "asterisk.conf")
+
+        try:
+            f = open(local_ast_conf_path, "w")
+        except IOError:
+            print "Failed to open %s" % local_ast_conf_path
+            return
+        except:
+            print "Unexpected error: %s" % sys.exc_info()[0]
+            return
+
+        for c in ast_conf.categories:
+            f.write("[%s]\n\n" % c.name)
+            if c.name == "directories":
+                for (var, val) in c.options:
+                    f.write("%s = %s%s\n" % (var, self.base, val))
+            else:
+                for (var, val) in c.options:
+                    f.write("%s = %s\n" % (var, val))
+            f.write("\n")
+
+        f.close()
+
+    def __mirror_dir(self, ast_dir_name, ast_dir_path):
+        self.__makedirs(ast_dir_path)
+        dirs_only = [ "astrundir", "astlogdir", "astspooldir" ]
+        if ast_dir_name in dirs_only:
+            return
+        blacklist = [ "astdb" ]
+        for dirname, dirnames, filenames in os.walk(ast_dir_path):
+            for filename in filenames:
+                target = "%s/%s" % (self.base, os.path.join(ast_dir_path,
+                                    dirname, filename))
+                if os.path.exists(target) or filename in blacklist:
+                    continue
+                os.symlink(os.path.join(ast_dir_path, dirname, filename),
+                           target)
+
+    def __makedirs(self, ast_dir_path):
+        target_dir = "%s%s" % (self.base, ast_dir_path)
+        if not os.path.exists(target_dir):
+            os.makedirs(target_dir)
+        for dirname, dirnames, filenames in os.walk(ast_dir_path):
+            for d in dirnames:
+                self.__makedirs(os.path.join(target_dir, dirname, d))
+

Propchange: asterisk/trunk/lib/python/asterisk/asterisk.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/lib/python/asterisk/asterisk.py
------------------------------------------------------------------------------
    svn:executable = *

Propchange: asterisk/trunk/lib/python/asterisk/asterisk.py
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/lib/python/asterisk/asterisk.py
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Propchange: asterisk/trunk/tests/ami-login/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Mar 31 02:23:07 2010
@@ -1,0 +1,1 @@
+tmp

Added: asterisk/trunk/tests/ami-login/configs/logger.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/ami-login/configs/logger.conf?view=auto&rev=162
==============================================================================
--- asterisk/trunk/tests/ami-login/configs/logger.conf (added)
+++ asterisk/trunk/tests/ami-login/configs/logger.conf Wed Mar 31 02:23:07 2010
@@ -1,0 +1,7 @@
+[general]
+
+[logfiles]
+
+console =>
+messages => notice,warning,error
+full => notice,warning,error,debug,verbose

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

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

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

Added: asterisk/trunk/tests/ami-login/configs/manager.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/ami-login/configs/manager.conf?view=auto&rev=162
==============================================================================
--- asterisk/trunk/tests/ami-login/configs/manager.conf (added)
+++ asterisk/trunk/tests/ami-login/configs/manager.conf Wed Mar 31 02:23:07 2010
@@ -1,0 +1,10 @@
+[general]
+enabled = yes
+port = 5038
+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/ami-login/configs/manager.conf
------------------------------------------------------------------------------
    svn:eol-style = native

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

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

Added: asterisk/trunk/tests/ami-login/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/ami-login/run-test?view=auto&rev=162
==============================================================================
--- asterisk/trunk/tests/ami-login/run-test (added)
+++ asterisk/trunk/tests/ami-login/run-test Wed Mar 31 02:23:07 2010
@@ -1,0 +1,82 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2010, Digium, Inc.
+Russell Bryant <russell 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 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
+
+
+class AMILoginTest:
+    def __init__(self):
+        self.passed = False
+
+        reactor.callWhenRunning(self.run)
+
+        print "Creating Asterisk instance ..."
+        self.asterisk = Asterisk(base=os.path.join(os.getcwd(),
+                                                   "tests/ami-login/tmp"))
+        self.asterisk.install_config("tests/ami-login/configs/manager.conf")
+        self.asterisk.install_config("tests/ami-login/configs/logger.conf")
+
+    def start_asterisk(self):
+        print "Starting Asterisk ..."
+        self.asterisk.start()
+
+    def stop_asterisk(self):
+        print "Stopping Asterisk ..."
+        self.asterisk.stop()
+
+    def on_logoff(self, ami):
+        print "Logoff successful."
+        self.passed = True
+        reactor.stop()
+
+    def on_logoff_error(self):
+        print "Logoff failed."
+        reactor.stop()
+        self.stop_asterisk()
+
+    def on_connect(self, ami):
+        print "Connected.  Now logging off ..."
+        ami.logoff().addCallbacks(self.on_logoff, self.on_logoff_error)
+
+    def on_connect_error(self, ami):
+        print "FAILED TO CONNECT AND LOGIN TO AMI"
+        reactor.stop()
+        self.stop_asterisk()
+
+    def run(self):
+        self.start_asterisk()
+
+        print "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_connect_error)
+
+def main():
+    test = AMILoginTest()
+    reactor.run()
+    test.stop_asterisk()
+    if test.passed:
+        return 0
+    return 1
+
+
+if __name__ == "__main__":
+    sys.exit(main() or 0)
+
+
+# vim:sw=4:ts=4:expandtab:textwidth=79

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

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

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

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

Added: asterisk/trunk/tests/ami-login/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/ami-login/test-config.yaml?view=auto&rev=162
==============================================================================
--- asterisk/trunk/tests/ami-login/test-config.yaml (added)
+++ asterisk/trunk/tests/ami-login/test-config.yaml Wed Mar 31 02:23:07 2010
@@ -1,0 +1,11 @@
+testinfo:
+    summary:     'Test loggin in to the Asterisk Manager Interface'
+    description: |
+        'This test provides a basic AMI sanity check.  It will log in,
+        and log out.'
+
+properties:
+    minversion: '1.4'
+    dependencies:
+        - python : 'twisted'
+        - python : 'starpy'

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

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

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

Propchange: asterisk/trunk/tests/iax-call-basic/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Mar 31 02:23:07 2010
@@ -1,0 +1,1 @@
+tmp

Added: asterisk/trunk/tests/iax-call-basic/configs/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/iax-call-basic/configs/extensions.conf?view=auto&rev=162
==============================================================================
--- asterisk/trunk/tests/iax-call-basic/configs/extensions.conf (added)
+++ asterisk/trunk/tests/iax-call-basic/configs/extensions.conf Wed Mar 31 02:23:07 2010
@@ -1,0 +1,8 @@
+[general]
+
+[globals]
+
+[iaxtest]
+
+exten => 1000,1,Answer()
+exten => 1000,n,AGI(agi://127.0.0.1:4573)

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

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

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

Added: asterisk/trunk/tests/iax-call-basic/configs/iax.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/iax-call-basic/configs/iax.conf?view=auto&rev=162
==============================================================================
--- asterisk/trunk/tests/iax-call-basic/configs/iax.conf (added)
+++ asterisk/trunk/tests/iax-call-basic/configs/iax.conf Wed Mar 31 02:23:07 2010
@@ -1,0 +1,14 @@
+[general]
+
+bindport=4570
+bindaddr=127.0.0.1
+
+disallow=all
+allow=ulaw
+
+jitterbuffer=no
+forcejitterbuffer=no
+
+[guest]
+type=user
+context=iaxtest

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

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

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

Added: asterisk/trunk/tests/iax-call-basic/configs/logger.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/iax-call-basic/configs/logger.conf?view=auto&rev=162
==============================================================================
--- asterisk/trunk/tests/iax-call-basic/configs/logger.conf (added)
+++ asterisk/trunk/tests/iax-call-basic/configs/logger.conf Wed Mar 31 02:23:07 2010
@@ -1,0 +1,8 @@
+[general]
+
+[logfiles]
+
+console =>
+;console => notice,warning,error,debug
+messages => notice,warning,error
+full => notice,warning,error,debug,verbose

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

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

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

Added: asterisk/trunk/tests/iax-call-basic/configs/manager.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/iax-call-basic/configs/manager.conf?view=auto&rev=162
==============================================================================
--- asterisk/trunk/tests/iax-call-basic/configs/manager.conf (added)
+++ asterisk/trunk/tests/iax-call-basic/configs/manager.conf Wed Mar 31 02:23:07 2010
@@ -1,0 +1,10 @@
+[general]
+enabled = yes
+port = 5038
+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/iax-call-basic/configs/manager.conf
------------------------------------------------------------------------------
    svn:eol-style = native

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

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

Added: asterisk/trunk/tests/iax-call-basic/configs2/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/iax-call-basic/configs2/extensions.conf?view=auto&rev=162
==============================================================================
--- asterisk/trunk/tests/iax-call-basic/configs2/extensions.conf (added)
+++ asterisk/trunk/tests/iax-call-basic/configs2/extensions.conf Wed Mar 31 02:23:07 2010
@@ -1,0 +1,8 @@
+[general]
+
+[globals]
+
+[iaxtest]
+
+exten => 1000,1,Answer()
+exten => 1000,n,AGI(agi://127.0.0.1:4573)

Propchange: asterisk/trunk/tests/iax-call-basic/configs2/extensions.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/iax-call-basic/configs2/extensions.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/iax-call-basic/configs2/extensions.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/iax-call-basic/configs2/iax.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/iax-call-basic/configs2/iax.conf?view=auto&rev=162
==============================================================================
--- asterisk/trunk/tests/iax-call-basic/configs2/iax.conf (added)
+++ asterisk/trunk/tests/iax-call-basic/configs2/iax.conf Wed Mar 31 02:23:07 2010
@@ -1,0 +1,11 @@
+[general]
+
+bindport=4569
+bindaddr=127.0.0.1
+
+disallow=all
+allow=ulaw
+
+[guest]
+type=user
+context=iaxtest

Propchange: asterisk/trunk/tests/iax-call-basic/configs2/iax.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/iax-call-basic/configs2/iax.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/iax-call-basic/configs2/iax.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/iax-call-basic/configs2/logger.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/iax-call-basic/configs2/logger.conf?view=auto&rev=162
==============================================================================
--- asterisk/trunk/tests/iax-call-basic/configs2/logger.conf (added)
+++ asterisk/trunk/tests/iax-call-basic/configs2/logger.conf Wed Mar 31 02:23:07 2010
@@ -1,0 +1,8 @@
+[general]
+
+[logfiles]
+
+console =>
+;console => notice,warning,error,debug
+messages => notice,warning,error
+full => notice,warning,error,debug,verbose

Propchange: asterisk/trunk/tests/iax-call-basic/configs2/logger.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/iax-call-basic/configs2/logger.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/iax-call-basic/configs2/logger.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/iax-call-basic/configs2/manager.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/iax-call-basic/configs2/manager.conf?view=auto&rev=162
==============================================================================
--- asterisk/trunk/tests/iax-call-basic/configs2/manager.conf (added)
+++ asterisk/trunk/tests/iax-call-basic/configs2/manager.conf Wed Mar 31 02:23:07 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/iax-call-basic/configs2/manager.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/iax-call-basic/configs2/manager.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/iax-call-basic/configs2/manager.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/iax-call-basic/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/iax-call-basic/run-test?view=auto&rev=162
==============================================================================
--- asterisk/trunk/tests/iax-call-basic/run-test (added)
+++ asterisk/trunk/tests/iax-call-basic/run-test Wed Mar 31 02:23:07 2010
@@ -1,0 +1,104 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2010, Digium, Inc.
+Russell Bryant <russell 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 twisted.application import service, internet
+from twisted.internet import reactor, defer
+from starpy import fastagi
+
+sys.path.append("lib/python")
+from asterisk.asterisk import Asterisk
+
+
+class IAXCallTest:
+    def __init__(self):
+        reactor.callWhenRunning(self.run)
+
+        self.chan1_connected = False
+        self.chan2_connected = False
+        self.f = fastagi.FastAGIFactory(self.fastagi_func)
+        reactor.listenTCP(4573, self.f, 50, '127.0.0.1')
+
+        print "Creating Asterisk instances ..."
+
+        self.asterisk = Asterisk(base=os.path.join(os.getcwd(),
+                                      "tests/iax-call-basic/tmp/"))
+        self.asterisk.install_config("tests/iax-call-basic/configs/manager.conf")
+        self.asterisk.install_config("tests/iax-call-basic/configs/logger.conf")
+        self.asterisk.install_config("tests/iax-call-basic/configs/extensions.conf")
+        self.asterisk.install_config("tests/iax-call-basic/configs/iax.conf")
+
+        self.asterisk2 = Asterisk(base=os.path.join(os.getcwd(),
+                                      "tests/iax-call-basic/tmp/"))
+        self.asterisk2.install_config("tests/iax-call-basic/configs2/manager.conf")
+        self.asterisk2.install_config("tests/iax-call-basic/configs2/logger.conf")
+        self.asterisk2.install_config("tests/iax-call-basic/configs2/extensions.conf")
+        self.asterisk2.install_config("tests/iax-call-basic/configs2/iax.conf")
+
+    def fastagi_func(self, agi):
+        sequence = fastagi.InSequence()
+        def get_channel(c):
+            print "Connection received for %s ..." % c
+            if c.split("-")[0] == "IAX2/127.0.0.1:4569":
+                self.chan1_connected = True
+            elif c.split("-")[0] == "IAX2/127.0.0.1:4570":
+                self.chan2_connected = True
+        agi.getVariable("CHANNEL").addCallback(get_channel)
+        sequence.append(agi.execute, "Wait", "5")
+        sequence.append(agi.hangup)
+        sequence.append(agi.finish)
+
+    def start_asterisk(self):
+        print "Starting Asterisk instances ..."
+        self.asterisk.start()
+        self.asterisk2.start()
+
+    def stop_asterisk(self):
+        print "Stopping Asterisk instances ..."
+        self.asterisk.stop()
+        self.asterisk2.stop()
+
+    def run(self):
+        self.start_asterisk()
+
+        cmds = [
+            "core set verbose 10",
+            "iax2 set debug on"
+        ]
+        for c in cmds:
+            self.asterisk.cli_exec(c)
+            self.asterisk2.cli_exec(c)
+
+        self.asterisk.cli_exec(
+                "originate IAX2/guest at 127.0.0.1:4569/1000 extension 1000 at iaxtest")
+
+
+def stop_reactor():
+    print "Stopping Reactor ..."
+    if reactor.running:
+        reactor.stop()
+
+
+def main():
+    test = IAXCallTest()
+    reactor.callLater(20, stop_reactor)
+    reactor.run()
+    test.stop_asterisk()
+    if test.chan1_connected and test.chan2_connected:
+        return 0
+    return 1
+
+
+if __name__ == "__main__":
+    sys.exit(main() or 0)
+
+
+# vim:sw=4:ts=4:expandtab:textwidth=79

Propchange: asterisk/trunk/tests/iax-call-basic/run-test
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/iax-call-basic/run-test
------------------------------------------------------------------------------
    svn:executable = *

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

Propchange: asterisk/trunk/tests/iax-call-basic/run-test
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/iax-call-basic/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/iax-call-basic/test-config.yaml?view=auto&rev=162
==============================================================================
--- asterisk/trunk/tests/iax-call-basic/test-config.yaml (added)
+++ asterisk/trunk/tests/iax-call-basic/test-config.yaml Wed Mar 31 02:23:07 2010
@@ -1,0 +1,11 @@
+testinfo:
+    summary:     'Test a basic IAX2 call'
+    description: |
+        'This test initiates an IAX2 call between 2 instances of Asterisk.
+        Both ends connect to a FastAGI server implemented in the test script.'
+
+properties:
+    minversion: '1.4'
+    dependencies:
+        - python : 'twisted'
+        - python : 'starpy'

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

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

Propchange: asterisk/trunk/tests/iax-call-basic/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=162&r1=161&r2=162
==============================================================================
--- asterisk/trunk/tests/tests.yaml (original)
+++ asterisk/trunk/tests/tests.yaml Wed Mar 31 02:23:07 2010
@@ -1,5 +1,7 @@
 # Enter tests here in the order they should be considered for execution:
 tests:
     - test: 'example'
+    - test: 'ami-login'
     - test: 'blind-transfer-accountcode'
     - test: 'rfc2833_dtmf_detect'
+    - test: 'iax-call-basic'




More information about the svn-commits mailing list