<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7442">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">asterisk.py:  Add replaceable parameters to config files<br><br>Referencing special files like keys and certificates in config<br>files is a problem because the location of those files will be<br>different for each invocation of a test and for each instance<br>of asterisk in that test.  The sip tls tests worked around this<br>by creating "helper" files and custom python but this isn't very<br>scalable.<br><br>* The Asterisk.install_config function has been modified to look<br>  for replaceable parameters in the format "<<directory>>" in config<br>  files and replace them with the actual path for this asterisk<br>  instance.  "directory" would be the key in the asterisk.conf<br>  [directories] section.  The replacement would be the path value<br>  prepended with the asterisk instance's base directory for this<br>  test.<br><br>For instance, in mytest/configs/ast1/pjsip.conf<br>priv_key_file = <<astetcdir>>/privkey1.pem<br>might become<br>priv_key_file = /tmp/asterisk-testsuite/\<br>     ad41368488ddbac785d54e5689db3b8e/run_5/ast1/etc/asterisk/privkey1.pem<br><br>You could then include the privkey1.pem file in the test's configs<br>directory with the config file it's referenced from.<br><br>Change-Id: I805e6016d56e3531996a863e9dcf93b2dc75ad1c<br>---<br>M README.txt<br>M lib/python/asterisk/asterisk.py<br>2 files changed, 20 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/42/7442/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/README.txt b/README.txt<br>index 0f7d48c..2135791 100644<br>--- a/README.txt<br>+++ b/README.txt<br>@@ -288,7 +288,15 @@<br> file for your test and the global Asterisk logger.conf will automatically<br> include it. The filename convention is <asterisk module>.<category>.conf.inc.<br> Again, settings in 'asterisk.options.conf.inc' would be included in<br>-asterisk.conf [options] category.<br>+asterisk.conf [options] category.  Config files may contain replaceable<br>+parameters that map to the entries in the [directories] section of the<br>+asterisk.conf file.  Use the "<<directory>>" syntax to have the token<br>+replaced with the actual value of that entry.  For instance:<br>+<br>+priv_key_file = <<astetcdir>>/privkey1.pem<br>+might become<br>+priv_key_file = /tmp/asterisk-testsuite/ad41368488ddbac785d54e5689db3b8e/run_5/ast1/etc/asterisk/privkey1.pem<br>+<br> <br> b) Preconditions<br> <br>diff --git a/lib/python/asterisk/asterisk.py b/lib/python/asterisk/asterisk.py<br>index 1c2da02..10ee683 100755<br>--- a/lib/python/asterisk/asterisk.py<br>+++ b/lib/python/asterisk/asterisk.py<br>@@ -16,6 +16,7 @@<br> import time<br> import shutil<br> import logging<br>+import fileinput<br> <br> import test_suite_utils<br> <br>@@ -262,7 +263,6 @@<br>             LOGGER.warning("Asterisk %s stop deferred already called" %<br>                            self._host)<br>         self.exited = True<br>-<br> <br> class Asterisk(object):<br>     """An instance of Asterisk.<br>@@ -678,6 +678,15 @@<br> <br>         return os.path.join(self.base + self.directories[astdirkey], *paths)<br> <br>+# Quick little function for doing search and replace in a file used below.<br>+    def _file_replace_string(self, file):<br>+        for line in fileinput.input(file, inplace=1):<br>+            if "<<" in line:<br>+                for key in self.directories.keys():<br>+                    line = line.replace("<<%s>>" % key,<br>+                                    "%s%s" % (self.base, self.directories[key]))<br>+            sys.stdout.write(line)<br>+<br>     def install_configs(self, cfg_path, deps=None):<br>         """Installs all files located in the configuration directory for this<br>         instance of Asterisk.<br>@@ -778,6 +787,7 @@<br>             os.remove(target_path)<br>         try:<br>             shutil.copyfile(cfg_path, target_path)<br>+            self._file_replace_string(target_path);<br>         except shutil.Error:<br>             LOGGER.warn("'%s' and '%s' are the same file" %<br>                         (cfg_path, target_path))<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7442">change 7442</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/7442"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: testsuite </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I805e6016d56e3531996a863e9dcf93b2dc75ad1c </div>
<div style="display:none"> Gerrit-Change-Number: 7442 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>