[asterisk-commits] Do not use local Asterisk settings for remote execution. (testsuite[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 3 06:18:34 CST 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: Do not use local Asterisk settings for remote execution.
......................................................................


Do not use local Asterisk settings for remote execution.

When attempting to run tests against a remote Asterisk, there can come
issues since the testsuite has some assumptions that the target Asterisk
system is local. Specifically, the Asterisk version, the Asterisk build
options, and the Asterisk modules are all assumed to be gathered from
the system where the testsuite is running.

For the build options and the modules, this change makes it so that we
just always assume the desired build options and modules are present.

What's more interesting is the Asterisk version. runtests.py contains a
-v option that allows for you to manually specify the version. This
change expands that option a bit to make it so that whenever the
AsteriskVersion() is queried, the version passed into runtests.py is
returned. This means that when running against a remote Asterisk, you
MUST specify the -v option in order to tell the testsuite what the
remote Asterisk version is. This will allow for tests to accurately
determine how/if to run.

Change-Id: I1cefd6f3b1ec0a9edb58dec008ddb3461e0949b8
---
M lib/python/asterisk/test_conditions.py
M lib/python/asterisk/test_config.py
M lib/python/asterisk/test_runner.py
M lib/python/asterisk/version.py
M runtests.py
M test-config.yaml
6 files changed, 49 insertions(+), 10 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/lib/python/asterisk/test_conditions.py b/lib/python/asterisk/test_conditions.py
index 1bff550..dbf36a7 100644
--- a/lib/python/asterisk/test_conditions.py
+++ b/lib/python/asterisk/test_conditions.py
@@ -246,7 +246,12 @@
     condition check
     """
 
-    build_options = AsteriskBuildOptions()
+    try:
+        build_options = AsteriskBuildOptions()
+    except:
+        # If no build options were found, we're running against a remote
+        # Asterisk.
+        build_options = None
 
     def __init__(self, test_config):
         """Initialize a new test condition
@@ -278,6 +283,11 @@
         True if all conditions are met
         False if a condition was not met.
         """
+        if not TestCondition.build_options:
+            # We assume that remote Asterisks have been set up with proper build
+            # options.
+            return True
+
         ret_val = True
         for option in self.my_build_options:
             build_option, expected_value = option
diff --git a/lib/python/asterisk/test_config.py b/lib/python/asterisk/test_config.py
index c0abe48..eb0a03d 100644
--- a/lib/python/asterisk/test_config.py
+++ b/lib/python/asterisk/test_config.py
@@ -141,11 +141,19 @@
             if not found:
                 print "Unknown custom dependency - '%s'" % self.name
         elif "asterisk" in dep:
-            self.name = dep["asterisk"]
-            self.met = self._find_asterisk_module(self.name)
+            if self.ast:
+                self.name = dep["asterisk"]
+                self.met = self._find_asterisk_module(self.name)
+            else:
+                # Remote Asterisk instance. Assume dependency is met
+                self.met = True
         elif "buildoption" in dep:
-            self.name = dep["buildoption"]
-            self.met = self._find_build_flag(self.name)
+            if self.ast:
+                self.name = dep["buildoption"]
+                self.met = self._find_build_flag(self.name)
+            else:
+                # Remote Asterisk instance. Assume dependency is met
+                self.met = True
         elif "pcap" in dep:
             self.name = "pcap"
             from test_case import PCAP_AVAILABLE
diff --git a/lib/python/asterisk/test_runner.py b/lib/python/asterisk/test_runner.py
index 640ccd3..b06b03c 100755
--- a/lib/python/asterisk/test_runner.py
+++ b/lib/python/asterisk/test_runner.py
@@ -305,6 +305,13 @@
         return 1
     ast_version = args[2]
 
+    try:
+        AsteriskVersion()
+    except OSError:
+        # If there is no Asterisk version on the local system, then we need to
+        # set the version to the one that was passed into the application.
+        AsteriskVersion(default=ast_version)
+
     LOGGER.info("Starting test run for %s" % test_directory)
     test_config = load_test_config(test_directory)
     if test_config is None:
diff --git a/lib/python/asterisk/version.py b/lib/python/asterisk/version.py
index 7cbb9ef..5c25032 100644
--- a/lib/python/asterisk/version.py
+++ b/lib/python/asterisk/version.py
@@ -97,6 +97,7 @@
     # This should be the last thing called.
     return (parent_branch, True)
 
+DEFAULT_VERSION = None
 
 class AsteriskVersion(object):
     """An Asterisk Version.
@@ -127,15 +128,26 @@
 
     supported_modifiers = ['rc', 'beta']
 
-    def __init__(self, version=None):
+    def __init__(self, version=None, default=None):
         """Construct an Asterisk Version parser.
 
         Keyword Arguments:
         version -- The Asterisk version string to parse.
+        default -- Set a default version value. Whenever the initializer is
+                   called without the version keyword argument, then this
+                   default version will get returned instead. This setting
+                   persists beyond the lifetime of this object.
         """
+        global DEFAULT_VERSION
+
+        if default:
+            DEFAULT_VERSION = default
 
         if not version:
-            version = AsteriskVersion.get_version_from_binary()
+            if DEFAULT_VERSION:
+                version = DEFAULT_VERSION
+            else:
+                version = AsteriskVersion.get_version_from_binary()
 
         self.raw_version = version
         self.branch = False
diff --git a/runtests.py b/runtests.py
index 0ecbd2d..6c79476 100755
--- a/runtests.py
+++ b/runtests.py
@@ -769,12 +769,10 @@
     signal.signal(signal.SIGUSR1, handle_usr1)
     signal.signal(signal.SIGTERM, handle_term)
 
-    ast_version = AsteriskVersion(options.version)
+    ast_version = AsteriskVersion(default=options.version)
 
     if options.list_tests or options.list_tags:
         test_suite = TestSuite(ast_version, options)
-
-        print "Asterisk Version: %s\n" % str(ast_version)
 
         if options.list_tests:
             test_suite.list_tests()
diff --git a/test-config.yaml b/test-config.yaml
index eb34483..9bcfeb7 100644
--- a/test-config.yaml
+++ b/test-config.yaml
@@ -103,6 +103,10 @@
 # This is useful when you want to use the Test Suite to test Asterisk, but
 # where Asterisk has a particular complex configuration and is part of a
 # larger integrated system.
+#
+# Because of checks for the running Asterisk version, when running against
+# a remote instance of Asterisk, you must specify the version with the -v
+# option to runtests.py
 config-remote:
     asterisk-instances:
         -

-- 
To view, visit https://gerrit.asterisk.org/2124
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1cefd6f3b1ec0a9edb58dec008ddb3461e0949b8
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>



More information about the asterisk-commits mailing list