[svn-commits] russell: testsuite/asterisk/trunk r1056 - in /asterisk/trunk: lib/python/aste...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Dec 3 15:52:37 CST 2010


Author: russell
Date: Fri Dec  3 15:52:32 2010
New Revision: 1056

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=1056
Log:
Add a SIPpTest class to lib/python/asterisk, add sip/options test.

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

Added:
    asterisk/trunk/lib/python/asterisk/sipp.py   (with props)
    asterisk/trunk/tests/sip/options/
    asterisk/trunk/tests/sip/options/configs/
    asterisk/trunk/tests/sip/options/configs/ast1/
    asterisk/trunk/tests/sip/options/configs/ast1/extensions.conf   (with props)
    asterisk/trunk/tests/sip/options/run-test   (with props)
    asterisk/trunk/tests/sip/options/sipp/
    asterisk/trunk/tests/sip/options/sipp/options.xml   (with props)
    asterisk/trunk/tests/sip/options/sipp/options2.xml   (with props)
    asterisk/trunk/tests/sip/options/test-config.yaml   (with props)
Modified:
    asterisk/trunk/tests/sip/tests.yaml
    asterisk/trunk/tests/tests.yaml

Added: asterisk/trunk/lib/python/asterisk/sipp.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/sipp.py?view=auto&rev=1056
==============================================================================
--- asterisk/trunk/lib/python/asterisk/sipp.py (added)
+++ asterisk/trunk/lib/python/asterisk/sipp.py Fri Dec  3 15:52:32 2010
@@ -1,0 +1,124 @@
+""" SIPp based tests.
+
+This module provides a class that implements a test of a single Asterisk
+instance using 1 or more SIPp scenarios.
+
+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 subprocess
+
+from asterisk import Asterisk
+
+
+class SIPpTest:
+    """
+    A SIPp based test for the Asterisk testsuite.
+
+    This is a common implementation of a test that uses 1 or more SIPp
+    scenarios.  The result code of each SIPp instance is used to determine
+    whether or not the test passed.
+
+    This class currently uses a single Asterisk instance and runs all of the
+    scenarios against it.  If any configuration needs to be provided to this
+    Asterisk instance, it is expected to be in the configs/ast1/ direcotry
+    under the test_dir provided to the constructor.  This directory was
+    chosen based on the convention that has been established in the testsuite
+    for the location of configuration for a test.
+    """
+
+    def __init__(self, working_dir, test_dir, scenarios):
+        """
+
+        Arguments:
+
+        working_dir - A path to the working directory to use for the temporary
+            Asterisk instance.  This is typically a path to somewhere in /tmp.
+
+        test_dir - The path to the directory containing the run-test file.
+
+        scenarios - A list of SIPp scenarios.  This class expects these
+            to exist in the sipp directory under test_dir.  The list must be
+            constructed as a list of dictionaries.  Each dictionary must have
+            the key 'scenario' with the value being the filename of the SIPp
+            scenario.  Any other key-value pairs are treated as arguments
+            to SIPp.  For example, specity '-timeout' : '60s' to set the
+            timeout option to SIPp to 60 seconds.  If a parameter specified
+            is also one specified by default, the value provided will be used.
+            The default SIPp parameters include:
+                -p <port>    - Unless otherwise specified, the port number will
+                               be 5060 + <scenario list index, starting at 1>.
+                               So, the first SIPp sceario will use port 5061.
+                -m 1         - Stop the test after 1 'call' is processed.
+                -i 127.0.0.1 - Use this as the local IP address for the Contact
+                               headers, Via headers, etc.
+                -timeout 20s - Set a global test timeout of 20 seconds.
+        """
+        self.working_dir = working_dir
+        self.test_dir = test_dir
+        self.scenarios = scenarios
+        self.sipp = []
+        self.stdout = []
+        self.stderr = []
+        self.result = []
+
+        self.ast1 = Asterisk(base=self.working_dir)
+        self.ast1.install_configs('%s/configs/ast1' % self.test_dir)
+
+    def __run_sipp(self, scenario, default_port):
+        sipp_args = [
+                'sipp', '127.0.0.1',
+                '-sf', '%s/sipp/%s' % (self.test_dir, scenario['scenario'])
+        ]
+        default_args = {
+            '-p' : default_port,
+            '-m' : '1',
+            '-i' : '127.0.0.1',
+            '-timeout' : '20s'
+        }
+
+        # Override and extend defaults
+        default_args.update(scenario)
+        del default_args['scenario']
+
+        for (key, val) in default_args.items():
+            sipp_args.extend([ key, val ])
+
+        return subprocess.Popen(sipp_args,
+                                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+    def run(self):
+        """
+        Run the test.
+
+        Returns 0 for success, 1 for failure.
+        """
+        self.ast1.start()
+
+        for s in self.scenarios:
+            default_port = 5060 + len(self.sipp) + 1
+            self.sipp.append(self.__run_sipp(s, str(default_port)))
+
+        passed = True
+        for i in range(len(self.sipp)):
+            (out, err) = self.sipp[i].communicate()
+            self.stdout.append(out)
+            self.stderr.append(err)
+            self.result.append(self.sipp[i].wait())
+            print "SIPp scenario #%d %s" % (i, "FAILED" if self.result[i] else
+                                               "Passed")
+            if self.result[i]:
+                passed = False
+                print self.stdout[i]
+                print self.stderr[i]
+
+        self.ast1.stop()
+
+        return 0 if passed else 1
+

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

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

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

Added: asterisk/trunk/tests/sip/options/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/sip/options/configs/ast1/extensions.conf?view=auto&rev=1056
==============================================================================
--- asterisk/trunk/tests/sip/options/configs/ast1/extensions.conf (added)
+++ asterisk/trunk/tests/sip/options/configs/ast1/extensions.conf Fri Dec  3 15:52:32 2010
@@ -1,0 +1,8 @@
+[default]
+
+; This extension just needs to exist so Asterisk will respond to the OPTIONS
+; request for 1234 with a 200 OK.
+exten => 1234,1,NoOp()
+
+; Note that no 5555 extension exists, so Asterisk should respond to that OPTIONS
+; request with a 404 Not Found.

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

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

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

Added: asterisk/trunk/tests/sip/options/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/sip/options/run-test?view=auto&rev=1056
==============================================================================
--- asterisk/trunk/tests/sip/options/run-test (added)
+++ asterisk/trunk/tests/sip/options/run-test Fri Dec  3 15:52:32 2010
@@ -1,0 +1,41 @@
+#!/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
+
+sys.path.append("lib/python")
+from asterisk.sipp import SIPpTest
+
+WORKING_DIR = "/tmp/asterisk-testsuite/sip/options"
+TEST_DIR = os.path.dirname(os.path.realpath(__file__))
+
+SIPP_SCENARIOS = [
+    {
+        'scenario' : 'options.xml'
+    },
+    {
+        'scenario' : 'options2.xml'
+    }
+]
+
+
+def main(argv=None):
+    if argv is None:
+        argv = sys.argv
+
+    test = SIPpTest(WORKING_DIR, TEST_DIR, SIPP_SCENARIOS)
+    return test.run()
+
+
+if __name__ == "__main__":
+    sys.exit(main())
+
+
+# vim:sw=4:ts=4:expandtab:textwidth=79

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

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

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

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

Added: asterisk/trunk/tests/sip/options/sipp/options.xml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/sip/options/sipp/options.xml?view=auto&rev=1056
==============================================================================
--- asterisk/trunk/tests/sip/options/sipp/options.xml (added)
+++ asterisk/trunk/tests/sip/options/sipp/options.xml Fri Dec  3 15:52:32 2010
@@ -1,0 +1,22 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="UAC OPTIONS">
+  <send retrans="500"> <![CDATA[
+      OPTIONS sip:1234@[remote_ip]:[remote_port] SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]
+      To: Asterisk <sip:1234@[remote_ip]:[remote_port]>
+      Call-ID: [call_id]
+      CSeq: 1 OPTIONS
+      Contact: sip:sipp@[local_ip]:[local_port]
+      Max-Forwards: 70
+      Subject: Asterisk Testsuite
+      Content-Length: [len]
+
+    ]]>
+  </send>
+
+  <recv response="200">
+  </recv>
+</scenario>

Propchange: asterisk/trunk/tests/sip/options/sipp/options.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/sip/options/sipp/options.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/sip/options/sipp/options.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/sip/options/sipp/options2.xml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/sip/options/sipp/options2.xml?view=auto&rev=1056
==============================================================================
--- asterisk/trunk/tests/sip/options/sipp/options2.xml (added)
+++ asterisk/trunk/tests/sip/options/sipp/options2.xml Fri Dec  3 15:52:32 2010
@@ -1,0 +1,22 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="UAC OPTIONS">
+  <send retrans="500"> <![CDATA[
+      OPTIONS sip:5555@[remote_ip]:[remote_port] SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]
+      To: Asterisk <sip:5555@[remote_ip]:[remote_port]>
+      Call-ID: [call_id]
+      CSeq: 1 OPTIONS
+      Contact: sip:sipp@[local_ip]:[local_port]
+      Max-Forwards: 70
+      Subject: Asterisk Testsuite
+      Content-Length: [len]
+
+    ]]>
+  </send>
+
+  <recv response="404">
+  </recv>
+</scenario>

Propchange: asterisk/trunk/tests/sip/options/sipp/options2.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/sip/options/sipp/options2.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/sip/options/sipp/options2.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/sip/options/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/sip/options/test-config.yaml?view=auto&rev=1056
==============================================================================
--- asterisk/trunk/tests/sip/options/test-config.yaml (added)
+++ asterisk/trunk/tests/sip/options/test-config.yaml Fri Dec  3 15:52:32 2010
@@ -1,0 +1,10 @@
+testinfo:
+    summary:     'Test SIP OPTIONS handling'
+    description: |
+        'Run two SIPp scnearios that send an OPTIONS request.  In one instance,
+         we expect a 200 response, and in the other we expect a 404 response.'
+
+properties:
+    minversion: '1.4'
+    dependencies:
+        - app : 'sipp'

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

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

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

Modified: asterisk/trunk/tests/sip/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/sip/tests.yaml?view=diff&rev=1056&r1=1055&r2=1056
==============================================================================
--- asterisk/trunk/tests/sip/tests.yaml (original)
+++ asterisk/trunk/tests/sip/tests.yaml Fri Dec  3 15:52:32 2010
@@ -1,3 +1,5 @@
 # Enter tests here in the order they should be considered for execution:
 tests:
-    - test: 'handle_response_refer'
+    # Temporarily disabled until random failures are debugged.
+    #- test: 'handle_response_refer'
+    - test: 'options'

Modified: asterisk/trunk/tests/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/tests.yaml?view=diff&rev=1056&r1=1055&r2=1056
==============================================================================
--- asterisk/trunk/tests/tests.yaml (original)
+++ asterisk/trunk/tests/tests.yaml Fri Dec  3 15:52:32 2010
@@ -21,7 +21,7 @@
     # Temporarily disabled while failures are debugged
     #- test: 'sip_register'
     # Temporarily disabled while failures are debugged
-    #- dir: 'sip'
+    - dir: 'sip'
     - test: 'udptl'
     - test: 'udptl_v6'
     # Temporarily disabled while failures are debugged




More information about the svn-commits mailing list