[asterisk-commits] jbigelow: testsuite/asterisk/trunk r3778 - in /asterisk/trunk: ./ lib/python/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue May 14 16:10:36 CDT 2013


Author: jbigelow
Date: Tue May 14 16:10:33 2013
New Revision: 3778

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3778
Log:
Allow pluggable modules to be executed against particular Asterisk versions

This allows pluggable modules to have their configuration section execute
against particular version(s) of Asterisk. Also added a sample
test-config.yaml file that describes most of the settings available.

(issue ASTERISK-21450)
(closes issue ASTERISK-21450)

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


Added:
    asterisk/trunk/sample-yaml/test-config.yaml.sample   (with props)
Modified:
    asterisk/trunk/lib/python/asterisk/TestRunner.py
    asterisk/trunk/runtests.py

Modified: asterisk/trunk/lib/python/asterisk/TestRunner.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/TestRunner.py?view=diff&rev=3778&r1=3777&r2=3778
==============================================================================
--- asterisk/trunk/lib/python/asterisk/TestRunner.py (original)
+++ asterisk/trunk/lib/python/asterisk/TestRunner.py Tue May 14 16:10:33 2013
@@ -81,13 +81,14 @@
 
 sys.path_hooks.append(TestModuleFinder)
 
-def load_test_modules(test_config, test_object, test_path):
+def load_test_modules(test_config, test_object, test_path, ast_version):
     ''' Load optional modules for a test
 
     Parameters:
     test_config The test configuration object
     test_object The test object that the modules will attach to
     test_path The path to the test
+    ast_version A string containing the Asterisk version
     '''
 
     if not test_object:
@@ -100,18 +101,44 @@
         return
 
     for module_spec in test_config['test-modules']['modules']:
-        # If there's a specific portion of the config for this module, use it
-        if ('config-section' in module_spec
-            and module_spec['config-section'] in test_config):
-            module_config = test_config[module_spec['config-section']]
+        if check_module_version(module_spec, ast_version):
+            # If there's a specific portion of the config for this module, use it
+            if ('config-section' in module_spec
+                and module_spec['config-section'] in test_config):
+                module_config = test_config[module_spec['config-section']]
+            else:
+                module_config = test_config
+
+            module_type = load_and_parse_module(module_spec['typename'])
+            # Modules take in two parameters: the module configuration object,
+            # and the test object that they attach to
+            module_type(module_config, test_object)
         else:
-            module_config = test_config
-
-        module_type = load_and_parse_module(module_spec['typename'])
-        # Modules take in two parameters: the module configuration object,
-        # and the test object that they attach to
-        module_type(module_config, test_object)
-
+            LOGGER.debug("Skipping the loading of test module %s due to it's " \
+                "minversion and/or maxversion not being met." %
+                module_spec['typename'])
+
+def check_module_version(module_spec, ast_version):
+    ''' Check the module configuration for minversion and maxversion and check
+    if the Asterisk version meets the version(s) if found
+
+    Parameters:
+    module_spec A dictionary of a pluggable module configuration
+    ast_version A string containing the Asterisk version
+
+    Returns:
+    False if minversion or maxversion are found and do not meet the Asterisk
+    version, True otherwise
+    '''
+
+    modminversion = module_spec.get('minversion')
+    modmaxversion = module_spec.get('maxversion')
+    if modminversion is not None and ast_version < modminversion:
+        return False
+    if modmaxversion is not None and ast_version > modmaxversion:
+        return False
+
+    return True
 
 def load_and_parse_module(type_name):
     ''' Take a qualified module/object name, load the module, and return
@@ -265,6 +292,11 @@
         return 1
     test_directory = args[1]
 
+    if (len(args) < 3):
+        LOGGER.error("TestRunner requires the Asterisk version to execute")
+        return 1
+    ast_version = args[2]
+
     LOGGER.info("Starting test run for %s" % test_directory)
     test_config = load_test_config(test_directory)
     if test_config is None:
@@ -277,7 +309,7 @@
         return 1
 
     # Load other modules that may be specified
-    load_test_modules(test_config, test_object, test_directory)
+    load_test_modules(test_config, test_object, test_directory, ast_version)
 
     # Kick off the twisted reactor
     reactor.run()

Modified: asterisk/trunk/runtests.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/runtests.py?view=diff&rev=3778&r1=3777&r2=3778
==============================================================================
--- asterisk/trunk/runtests.py (original)
+++ asterisk/trunk/runtests.py Tue May 14 16:10:33 2013
@@ -59,6 +59,7 @@
             msg = "Running %s ..." % cmd
             print msg
             self.stdout += msg + "\n"
+            cmd.append(str(self.ast_version).rstrip())
             p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                  stderr=subprocess.STDOUT)
             self.pid = p.pid

Added: asterisk/trunk/sample-yaml/test-config.yaml.sample
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/sample-yaml/test-config.yaml.sample?view=auto&rev=3778
==============================================================================
--- asterisk/trunk/sample-yaml/test-config.yaml.sample (added)
+++ asterisk/trunk/sample-yaml/test-config.yaml.sample Tue May 14 16:10:33 2013
@@ -1,0 +1,208 @@
+# This is a sample configuration that describes many of the available settings.
+# Also see the following URL's:
+# https://wiki.asterisk.org/wiki/display/AST/Test+Configuration
+# https://wiki.asterisk.org/wiki/display/AST/Pluggable+Component+Framework
+
+# The testinfo section contains information that describes the purpose of an
+# individual test
+testinfo:
+    # If true, skip execution of this test
+    skip : 'Brief reason for skipping test' # OPTIONAL
+    # A summary of what the test does
+    summary: 'Put a short one liner summary of the test here'
+    # A detailed description of what functionality is covered by the test
+    description: |
+        'Put a more verbose description of the test here.  This may span
+        multiple lines.'
+    # A sequence of key/value pairs specifying issues in an issue tracker related to this test
+    issues: # OPTIONAL
+        # List of issue numbers associated with this test
+        - jira : 'ASTERISK-12345'
+        - jira : 'ASTERISK-10101'
+
+# The properties section contains information about requirements and
+# dependencies for this test.
+properties:
+    # The minimum version of Asterisk necessary to run the test
+    minversion: '1.8.0.0'
+    # The maximum version of Asterisk that this test can exeucte under
+    maxversion: '10.5.1' # OPTIONAL
+    # A sequence of feature specifies that the version of Asterisk under test must support.
+    features: # OPTIONAL
+        # List features the Asterisk version under test must support for this test
+        # to execute.  All features must be satisfied for the test to run.
+        - 'digiumphones'
+        - 'cert'
+    # The Asterisk modules and third party applications/libraries necessary to run the test
+    dependencies: # OPTIONAL
+        # List dependencies that must be met for this test to run. Any of the
+        # keywords listed in this block can occur multiple times.
+        #
+        - buildoption: 'TEST_FRAMEWORK' # OPTIONAL - Asterisk compilation flag
+
+        # Checking for an 'app' dependency behaves like the 'which' command
+        - app: 'bash'
+        - app: 'sipp'
+
+        # A 'python' dependency is a python module.  An attempt will be made to
+        # import a module by this name to determine whether the dependency is
+        # met.
+        - python: 'twisted'
+        - python: 'starpy'
+        - python: 'pjsua'
+        - python: 'yaml'
+
+        # Specifies attributes of SIPp that must be present for this test to execute
+        - sipp:
+            version: 'v3.3'
+
+        # If present, import the yappcap library as a dependency for test execution
+        - 'pcap'
+
+        # A 'module' dependency is an Asterisk module that must be loaded by
+        # Asterisk in order for this test to execute.  If the module is not loaded,
+        # the test will not execute.
+        - module: 'app_dial'
+
+        # 'custom' dependency can be anything.  Checking for this dependency is
+        # done by calling a corresponding method in the Dependency class in
+        # runtests.py.  For example, if the dependency is 'ipv6', then the
+        # depend_ipv6() method is called to determine if the dependency is met.
+        - custom: 'ipv6'
+        - custom: 'fax'
+    # A sequence of tags that categorize the test into groups of similar functionality
+    tags: # OPTIONAL
+        #
+        # List of tags used to select a subset of tests to run.  A test must have all tags to run.
+        #
+        - core # This test is part of the core support level.
+        - voicemail # This test involves voicemail functionality.
+    # The expected result of the test. Setting this to False will cause the test to pass if the test returns failure
+    expectedResult: True # OPTIONAL
+    # Settings that override the runtests script's test-config.yaml pre/post condition test settings
+    testconditions: # OPTIONAL
+        #
+        # List of overrides for pre-test and post-test conditions.  If a condition is
+        # defined for a test, the configuration of that condition in the test overrides
+        # the setting defined in the global test configuration file.
+        #
+        -   # Check for thread usage in Asterisk.  Any threads present in Asterisk after test
+            # execution - and any threads that were detected prior to test execution
+            # that are no longer present - will be flagged as a test error.
+            name: 'threads'
+            #
+            # Disable execution of this condition.  This setting applies to any defined condition.
+            # Any other value but 'False' will result in the condition being executed.
+            enabled: 'False'
+            #
+            # Execute the condition, but expect the condition to fail
+            expectedResult: 'Fail'
+            #
+            # The thread test condition allows for certain detected threads to be
+            # ignored.  This is a list of the thread names, as reported by the CLI
+            # command 'core show threads'
+            ignoredThreads:
+                - 'netconsole'
+                - 'pbx_thread'
+        #
+        -   # Check for SIP dialog usage.  This looks for any SIP dialogs present
+            # in the system before and after a run; if any are present and are not
+            # scheduled for destruction, an error is raised.
+            name: 'sip-dialogs'
+            #
+            # In addition to checking for scheduled destruction, a test can request that
+            # certain entries should appear in the SIP history.  If the entries do not
+            # appear, an error is raised.
+            sipHistoryRequirements:
+                - 'NewChan'
+                - 'Hangup'
+        #
+        -   # Check for held locks in Asterisk after test execution.  A lock is determined to
+            # be in potential error if threads are detected holding mutexes and waiting on
+            # other threads that are also holding mutexes.
+            name: 'locks'
+        #
+        -   # Check for active channels in Asterisk.  If active channels are detected, flag
+            # an error
+            name: 'channels'
+            #
+            # The number of allowed active channels that can exist when the condition is checked.
+            # If the number of channels detected is greater than this value, an error is raised.
+            # By default, this value is 0.
+            allowedchannels: 1
+        #
+        -   # Check for active file descriptors in Asterisk.  File descriptors detected before
+            # test execution are tracked throughout the test; if any additional file descriptors
+            # after test execution are detected, the test condition fails.
+            name: 'file-descriptors'
+
+# Modules to load for tests that use the Test Suite's pluggable framework. If
+# using the Test Suite's pluggable framework, this block is required.
+test-modules:
+    #add-test-to-search-path: 'True'
+    # Defines the primary object that orchestrates test execution
+    test-object:
+        # The keyword in the test-config.yaml file that provides the configuration for the test object
+        config-section: test-object-config
+        # The fully qualified package.module.class to instantiate as the test object
+        # A few that are available:
+        # SimpleTestCase.SimpleTestCase, BridgeTestCase.BridgeTestCase, sipp.SIPpTestCase
+        typename: 'SimpleTestCase.SimpleTestCase'
+    # A sequence that defines optional pluggable modules to inject into the test object
+    modules: # OPTIONAL
+        -
+            # The keyword in the test-config.yaml file that provides the configuration for the module
+            config-section: 'ami-config-1.3'
+            # The fully qualified package.module.class to instantiate as the module.
+            # A few that are available:
+            # ami.AMIEventModule, cdr.CDRModule
+            typename: 'ami.AMIEventModule'
+            # The minimum version of Asterisk necessary to load this module
+            minversion: '1.8.0.0' # OPTIONAL
+            # The maximum version of Asterisk that this module can load under
+            maxversion: '11.0.0' # OPTIONAL
+        -
+            # Similar to above but with different Asterisk version requirements
+            config-section: 'ami-config-1.4'
+            typename: 'ami.AMIEventModule'
+            minversion: '12.0.0'
+
+# The configuration for the test object. The configuration will differ depending on the test object used
+test-object-config:
+    reactor-timeout: 30
+    spawn-after-hangup: True
+    test-iterations:
+        -
+            channel: 'Local/play at default'
+            application: 'Echo'
+
+# The configuration for a pluggable module. See other *-config.yaml.sample files for more details.
+ami-config-1.3:
+    -
+        type: 'headermatch'
+        id: '0'
+        conditions:
+            match:
+                Event: 'Newexten'
+                Channel: 'Local/play at default-00000000;2'
+                Application: 'NoOp'
+        requirements:
+            match:
+                AppData: 'AMI 1.3'
+        count: '1'
+
+# The configuration for a pluggable module. See other *-config.yaml.sample files for more details.
+ami-config-1.4:
+    -
+        type: 'headermatch'
+        id: '0'
+        conditions:
+            match:
+                Event: 'Newexten'
+                Channel: 'Local/play at default-00000000;2'
+                Application: 'Verbose'
+        requirements:
+            match:
+                AppData: 'AMI 1.4'
+        count: '1'
+

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

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

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




More information about the asterisk-commits mailing list