[Asterisk-code-review] RFC: Add runtime option that allows automatic realtime execu... (testsuite[master])

Mark Michelson asteriskteam at digium.com
Fri Dec 11 17:24:08 CST 2015


Mark Michelson has uploaded a new change for review.

  https://gerrit.asterisk.org/1803

Change subject: RFC: Add runtime option that allows automatic realtime execution.
......................................................................

RFC: Add runtime option that allows automatic realtime execution.

This adds a command line option to runtests.py that allows for tests to
be run in realtime mode if possible. This makes it so that any tests
that use configuration files that are registered realtime converters
will automatically be run using a realtime database instead.

This change has the "RFC" designation on it because, for one, it's based
on another RFC commit. Second, this feels a bit on the "hackish" side,
so it's up for debate about whether this can be done better.

As it stands, this change has been tested by running tests like:

./runtests.py -r -t tests/channels/pjsip/ami/show_endpoints

and has proven that they get run using realtime rather than the static
pjsip.conf configuration file.

Change-Id: Ieec1b1cfa48cadab108c4ab65122ce36ab697e4e
---
M lib/python/asterisk/test_case.py
M lib/python/asterisk/test_config.py
M lib/python/asterisk/test_runner.py
M runtests.py
M test-config.yaml
5 files changed, 82 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/03/1803/1

diff --git a/lib/python/asterisk/test_case.py b/lib/python/asterisk/test_case.py
index ea24e0c..985ab4a 100644
--- a/lib/python/asterisk/test_case.py
+++ b/lib/python/asterisk/test_case.py
@@ -228,7 +228,8 @@
         count  The number of Asterisk instances to create, if no remote
                Asterisk instances have been specified
         """
-        if self.global_config.config:
+        if (self.global_config.config and
+            self.global_config.config.get('asterisk-instances')):
             asterisks = self.global_config.config.get('asterisk-instances')
         else:
             asterisks = [{'num': i + 1, 'host': '127.0.0.%d' % (i + 1)}
diff --git a/lib/python/asterisk/test_config.py b/lib/python/asterisk/test_config.py
index c0abe48..85a9cf3 100644
--- a/lib/python/asterisk/test_config.py
+++ b/lib/python/asterisk/test_config.py
@@ -291,6 +291,7 @@
         self.test_configuration = None
         self.condition_definitions = []
         self.global_test_config = global_test_config
+        self.realtime_config = {}
 
         try:
             self._parse_config()
@@ -379,6 +380,14 @@
         for feature in self.features:
             self.feature_check[feature] = False
 
+    def _process_realtime(self):
+        """Process realtime configuration block"""
+
+        if not self.config:
+            return
+
+        self.realtime_config = self.config.get('realtime-config', {})
+
     def _parse_config(self):
         """Parse the test-config YAML file."""
 
@@ -394,6 +403,7 @@
         self._process_global_settings()
         self._process_testinfo()
         self._process_properties()
+        self._process_realtime()
 
     def get_conditions(self):
         """
diff --git a/lib/python/asterisk/test_runner.py b/lib/python/asterisk/test_runner.py
index 640ccd3..54e96da 100755
--- a/lib/python/asterisk/test_runner.py
+++ b/lib/python/asterisk/test_runner.py
@@ -93,13 +93,14 @@
 sys.path_hooks.append(TestModuleFinder)
 
 
-def load_test_modules(test_config, test_object, ast_version):
+def load_test_modules(test_config, test_object, ast_version, realtime):
     """Load the pluggable modules for a test
 
     Keyword Arguments:
     test_config The test configuration object
     test_object The test object that the modules will attach to
     ast_version A string containing the Asterisk version
+    realtime Boolean that indicates if test is to be run in realtime mode
     """
 
     if not test_object:
@@ -129,6 +130,15 @@
             LOGGER.debug("Skipping the loading of test module %s due to it's "
                          "minversion and/or maxversion not being met." %
                          module_spec['typename'])
+
+    if realtime:
+        # Realtime conversion pluggable module needs to be loaded. Its
+        # configuration is found in the global test-config.yaml file, in the
+        # "realtime-config" section.
+        realtime_config = test_object.global_config.realtime_config
+        realtime_class = 'realtime_converter.RealtimeConverter'
+        module_type = load_and_parse_module(realtime_class)
+        module_type(realtime_config, test_object)
 
 
 def check_module_version(module_spec, ast_version):
@@ -305,6 +315,11 @@
         return 1
     ast_version = args[2]
 
+    if (len(args) >= 4):
+        realtime = True
+    else:
+        realtime = False
+
     LOGGER.info("Starting test run for %s" % test_directory)
     test_config = load_test_config(test_directory)
     if test_config is None:
@@ -317,7 +332,7 @@
         return 1
 
     # Load other modules that may be specified
-    load_test_modules(test_config, test_object, ast_version)
+    load_test_modules(test_config, test_object, ast_version, realtime)
 
     # Kick off the twisted reactor
     reactor.run()
diff --git a/runtests.py b/runtests.py
index 0ecbd2d..e2a2edf 100755
--- a/runtests.py
+++ b/runtests.py
@@ -93,9 +93,11 @@
         if not os.path.exists(cmd[0]):
             cmd = ["./lib/python/asterisk/test_runner.py",
                    "%s" % self.test_name]
+            cmd.append(str(self.ast_version).rstrip())
+            if self.options.realtime:
+                cmd.append('realtime')
         if os.path.exists(cmd[0]) and os.access(cmd[0], os.X_OK):
             self.stdout_print("Running %s ..." % cmd)
-            cmd.append(str(self.ast_version).rstrip())
             p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                  stderr=subprocess.STDOUT)
             self.pid = p.pid
@@ -735,6 +737,9 @@
     parser.add_option("-L", "--list-tags", action="store_true",
                       dest="list_tags", default=False,
                       help="List available tags")
+    parser.add_option("-r", "--realtime", action="store_true",
+                      dest="realtime", default=False,
+                      help="Run tests in realtime mode")
     parser.add_option("-s", "--syslog", action="store_true",
                       dest="syslog", default=False,
                       help="Log test start/stop to syslog")
diff --git a/test-config.yaml b/test-config.yaml
index eb34483..1f00658 100644
--- a/test-config.yaml
+++ b/test-config.yaml
@@ -143,3 +143,50 @@
         # branch not based on Asterisk trunk.
         forced-version: 1.8.0.0
 
+# This section demonstrates how to integrate automatic realtime testing into
+# the testsuite. If realtime-config is specified, then Asterisk will replace known
+# configuration file data with realtime equivalents when running tests.
+#
+# The tests assume that the realtime engine being used by Asterisk is ODBC since that
+# is the only realtime backend that has core support.
+config-realtime:
+    realtime-config:
+        # The DBMS being used for the test. This is passed as a URL type to
+        # sqlalchemy. For information on what types of technology can be specified
+        # here, see http://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls
+        #
+        # Default: postgresql
+        engine: 'postgresql'
+        # User that should access the database. This is used both by sqlalchemy when
+        # populating the database and by Asterisk when reading configuration from the
+        # database
+        #
+        # Default: asterisk
+        username: 'asterisk'
+        # Password that corresponds to the user accessing the database. This is used
+        # both by sqlalchemy when populating the database and by Asterisk when reading
+        # configuration from the database
+        #
+        # Default: asterisk
+        password: 'asterisk'
+        # Hostname or IP address where the database can be reached. This is used by
+        # sqlalchemy when populating the database.
+        #
+        # Default: localhost
+        host: 'localhost'
+        # Port where the database can be reached. This is used by sqlalchemy when
+        # populating the database.
+        #
+        # Default: 5432
+        port: '5432'
+        # The name of the database where the configuration tables can be found. This is
+        # used by sqlalchemy when populating the database.
+        #
+        # Default: asterisk
+        db: 'asterisk'
+        # The name of the ODBC DSN for Asterisk to use when connecting to the database. This
+        # DSN references an odbc.ini file that tells the database, host, and port for Asterisk
+        # to use when connecting to the database.
+        #
+        # Default: asterisk
+        dsn: 'asterisk'

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieec1b1cfa48cadab108c4ab65122ce36ab697e4e
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-code-review mailing list