[Asterisk-code-review] asterisk.py: Add replaceable parameters to config files (testsuite[master])
George Joseph
asteriskteam at digium.com
Mon Dec 4 16:28:54 CST 2017
George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/7442
Change subject: asterisk.py: Add replaceable parameters to config files
......................................................................
asterisk.py: Add replaceable parameters to config files
Referencing special files like keys and certificates in config
files is a problem because the location of those files will be
different for each invocation of a test and for each instance
of asterisk in that test. The sip tls tests worked around this
by creating "helper" files and custom python but this isn't very
scalable.
* The Asterisk.install_config function has been modified to look
for replaceable parameters in the format "<<directory>>" in config
files and replace them with the actual path for this asterisk
instance. "directory" would be the key in the asterisk.conf
[directories] section. The replacement would be the path value
prepended with the asterisk instance's base directory for this
test.
For instance, in mytest/configs/ast1/pjsip.conf
priv_key_file = <<astetcdir>>/privkey1.pem
might become
priv_key_file = /tmp/asterisk-testsuite/\
ad41368488ddbac785d54e5689db3b8e/run_5/ast1/etc/asterisk/privkey1.pem
You could then include the privkey1.pem file in the test's configs
directory with the config file it's referenced from.
Change-Id: I805e6016d56e3531996a863e9dcf93b2dc75ad1c
---
M README.txt
M lib/python/asterisk/asterisk.py
2 files changed, 20 insertions(+), 2 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/42/7442/1
diff --git a/README.txt b/README.txt
index 0f7d48c..2135791 100644
--- a/README.txt
+++ b/README.txt
@@ -288,7 +288,15 @@
file for your test and the global Asterisk logger.conf will automatically
include it. The filename convention is <asterisk module>.<category>.conf.inc.
Again, settings in 'asterisk.options.conf.inc' would be included in
-asterisk.conf [options] category.
+asterisk.conf [options] category. Config files may contain replaceable
+parameters that map to the entries in the [directories] section of the
+asterisk.conf file. Use the "<<directory>>" syntax to have the token
+replaced with the actual value of that entry. For instance:
+
+priv_key_file = <<astetcdir>>/privkey1.pem
+might become
+priv_key_file = /tmp/asterisk-testsuite/ad41368488ddbac785d54e5689db3b8e/run_5/ast1/etc/asterisk/privkey1.pem
+
b) Preconditions
diff --git a/lib/python/asterisk/asterisk.py b/lib/python/asterisk/asterisk.py
index 1c2da02..10ee683 100755
--- a/lib/python/asterisk/asterisk.py
+++ b/lib/python/asterisk/asterisk.py
@@ -16,6 +16,7 @@
import time
import shutil
import logging
+import fileinput
import test_suite_utils
@@ -262,7 +263,6 @@
LOGGER.warning("Asterisk %s stop deferred already called" %
self._host)
self.exited = True
-
class Asterisk(object):
"""An instance of Asterisk.
@@ -678,6 +678,15 @@
return os.path.join(self.base + self.directories[astdirkey], *paths)
+# Quick little function for doing search and replace in a file used below.
+ def _file_replace_string(self, file):
+ for line in fileinput.input(file, inplace=1):
+ if "<<" in line:
+ for key in self.directories.keys():
+ line = line.replace("<<%s>>" % key,
+ "%s%s" % (self.base, self.directories[key]))
+ sys.stdout.write(line)
+
def install_configs(self, cfg_path, deps=None):
"""Installs all files located in the configuration directory for this
instance of Asterisk.
@@ -778,6 +787,7 @@
os.remove(target_path)
try:
shutil.copyfile(cfg_path, target_path)
+ self._file_replace_string(target_path);
except shutil.Error:
LOGGER.warn("'%s' and '%s' are the same file" %
(cfg_path, target_path))
--
To view, visit https://gerrit.asterisk.org/7442
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I805e6016d56e3531996a863e9dcf93b2dc75ad1c
Gerrit-Change-Number: 7442
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171204/7a33e722/attachment.html>
More information about the asterisk-code-review
mailing list