<p>pespin <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18662">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">testenv: Support test overlaying a directory to look for templates<br><br>This way tests which require a very specific config file can override<br>specific template files used by object classes.<br><br>Change-Id: I65d1b1e826d2d430ee83810d998b98d0ccaa07cd<br>---<br>M selftest/suite_test/suite_test.ok<br>M selftest/suite_test/suite_test.ok.ign<br>M selftest/suite_test/suite_test.py<br>A selftest/suite_test/suitedirB/suiteC/mytemplatedir/.gitignore<br>A selftest/suite_test/suitedirB/suiteC/suite.conf<br>A selftest/suite_test/suitedirB/suiteC/test_template_overlay.py<br>M src/osmo_gsm_tester/core/template.py<br>M src/osmo_gsm_tester/obj/stp_osmo.py<br>M src/osmo_gsm_tester/testenv.py<br>9 files changed, 181 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/selftest/suite_test/suite_test.ok b/selftest/suite_test/suite_test.ok</span><br><span>index fee07d0..a7c6422 100644</span><br><span>--- a/selftest/suite_test/suite_test.ok</span><br><span>+++ b/selftest/suite_test/suite_test.ok</span><br><span>@@ -619,5 +619,109 @@</span><br><span>     skip: test_fail.py</span><br><span>     skip: test_fail_raise.py</span><br><span>     pass: test_suite_params.py (N.N sec)</span><br><span style="color: hsl(120, 100%, 40%);">+- test with template overlay</span><br><span style="color: hsl(120, 100%, 40%);">+cnf suiteC: DBG: reading suite.conf  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+---------------------------------------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+trial suiteC</span><br><span style="color: hsl(120, 100%, 40%);">+---------------------------------------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+tst suiteC: reserving resources in [PATH]/selftest/suite_test/test_work/state_dir ...  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst suiteC: DBG: {combining='resources'}  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst {combining_scenarios='resources'}: DBG: {definition_conf={ip_address=[{'addr': '10.42.42.2'}]}}  [suiteC↪{combining_scenarios='resources'}]  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst suiteC: DBG: {combining='modifiers'}  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst {combining_scenarios='modifiers'}: DBG: {definition_conf={}}  [suiteC↪{combining_scenarios='modifiers'}]  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst suiteC: Reserving 1 x ip_address (candidates: 3)  [resource.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst suiteC: DBG: Picked - _hash: fd103b22c7cf2480d609150e06f4bbd92ac78d8c</span><br><span style="color: hsl(120, 100%, 40%);">+  addr: 10.42.42.2</span><br><span style="color: hsl(120, 100%, 40%);">+  [resource.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+----------------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+trial suiteC test_template_overlay.py</span><br><span style="color: hsl(120, 100%, 40%);">+----------------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_template_overlay.py:[LINENR]: - Testing: expect to fail on invalid templates overlay dir  [suiteC↪test_template_overlay.py:[LINENR]]  [test_template_overlay.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_template_overlay.py:[LINENR]: sucess: setting non-existing templates dir raised RuntimeError  [suiteC↪test_template_overlay.py:[LINENR]]  [test_template_overlay.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_template_overlay.py:[LINENR]:   [suiteC↪test_template_overlay.py:[LINENR]]  [test_template_overlay.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+--- ReservedResources: DBG: requesting use of ip_address {specifics={}}  [resource.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst suiteC: Using 1 x ip_address (candidates: 1)  [resource.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst suiteC: DBG: Picked - _hash: fd103b22c7cf2480d609150e06f4bbd92ac78d8c</span><br><span style="color: hsl(120, 100%, 40%);">+  _reserved_by: suiteC-[ID_NUM]-[ID_NUM]</span><br><span style="color: hsl(120, 100%, 40%);">+  addr: 10.42.42.2</span><br><span style="color: hsl(120, 100%, 40%);">+  [resource.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+--- ReservedResources: DBG: {available=1}  [resource.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+--- ReservedResources: DBG: {using={_hash='fd103b22c7cf2480d609150e06f4bbd92ac78d8c', _reserved_by='suiteC-[ID_NUM]-[ID_NUM]', addr='10.42.42.2'}}  [resource.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_template_overlay.py:[LINENR]: - Testing: original template  [suiteC↪test_template_overlay.py:[LINENR]]  [test_template_overlay.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+run osmo-stp_10.42.42.2: DBG: {config_file='test_trial_tmp/test_run_6/suiteC/test_template_overlay.py/osmo-stp_10.42.42.2/osmo-stp.cfg'}  [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2]  [stp_osmo.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst suiteC: DBG: {combining='config'}  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst {combining_scenarios='config'}: DBG: {definition_conf={}}  [suiteC↪{combining_scenarios='config'}]  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+run osmo-stp_10.42.42.2: DBG: STP CONFIG:</span><br><span style="color: hsl(120, 100%, 40%);">+{'stp': {'ip_address': {'_hash': 'fd103b22c7cf2480d609150e06f4bbd92ac78d8c',</span><br><span style="color: hsl(120, 100%, 40%);">+                        '_reserved_by': 'suiteC-[ID_NUM]-[ID_NUM]',</span><br><span style="color: hsl(120, 100%, 40%);">+                        '_used': True,</span><br><span style="color: hsl(120, 100%, 40%);">+                        'addr': '10.42.42.2'}}}  [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2]  [stp_osmo.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+cnf Templates: DBG: rendering osmo-stp.cfg.tmpl  [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪Templates]  [template.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+run osmo-stp_10.42.42.2: DBG: ! Configuration rendered by osmo-gsm-tester</span><br><span style="color: hsl(120, 100%, 40%);">+log stderr</span><br><span style="color: hsl(120, 100%, 40%);">+ logging filter all 1</span><br><span style="color: hsl(120, 100%, 40%);">+ logging color 1</span><br><span style="color: hsl(120, 100%, 40%);">+ logging print category 1</span><br><span style="color: hsl(120, 100%, 40%);">+ logging print extended-timestamp 1</span><br><span style="color: hsl(120, 100%, 40%);">+ logging level set-all debug</span><br><span style="color: hsl(120, 100%, 40%);">+line vty</span><br><span style="color: hsl(120, 100%, 40%);">+ no login</span><br><span style="color: hsl(120, 100%, 40%);">+ bind 10.42.42.2</span><br><span style="color: hsl(120, 100%, 40%);">+!ctrl</span><br><span style="color: hsl(120, 100%, 40%);">+! bind 10.42.42.2</span><br><span style="color: hsl(120, 100%, 40%);">+cs7 instance 0</span><br><span style="color: hsl(120, 100%, 40%);">+ xua rkm routing-key-allocation dynamic-permitted</span><br><span style="color: hsl(120, 100%, 40%);">+ listen m3ua 2905</span><br><span style="color: hsl(120, 100%, 40%);">+  accept-asp-connections dynamic-permitted</span><br><span style="color: hsl(120, 100%, 40%);">+  local-ip 10.42.42.2</span><br><span style="color: hsl(120, 100%, 40%);">+  [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2]  [stp_osmo.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_template_overlay.py:[LINENR]: - Testing:overlay template  [suiteC↪test_template_overlay.py:[LINENR]]  [test_template_overlay.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_template_overlay.py:[LINENR]: - After creating the new template, still old template is used  [suiteC↪test_template_overlay.py:[LINENR]]  [test_template_overlay.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+run osmo-stp_10.42.42.2: DBG: {config_file='test_trial_tmp/test_run_6/suiteC/test_template_overlay.py/osmo-stp_10.42.42_2.2/osmo-stp.cfg'}  [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2]  [stp_osmo.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+run osmo-stp_10.42.42.2: DBG: STP CONFIG:</span><br><span style="color: hsl(120, 100%, 40%);">+{'stp': {'ip_address': {'_hash': 'fd103b22c7cf2480d609150e06f4bbd92ac78d8c',</span><br><span style="color: hsl(120, 100%, 40%);">+                        '_reserved_by': 'suiteC-[ID_NUM]-[ID_NUM]',</span><br><span style="color: hsl(120, 100%, 40%);">+                        '_used': True,</span><br><span style="color: hsl(120, 100%, 40%);">+                        'addr': '10.42.42.2'}}}  [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2]  [stp_osmo.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+cnf Templates: DBG: rendering osmo-stp.cfg.tmpl  [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪Templates]  [template.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+run osmo-stp_10.42.42.2: DBG: ! Configuration rendered by osmo-gsm-tester</span><br><span style="color: hsl(120, 100%, 40%);">+log stderr</span><br><span style="color: hsl(120, 100%, 40%);">+ logging filter all 1</span><br><span style="color: hsl(120, 100%, 40%);">+ logging color 1</span><br><span style="color: hsl(120, 100%, 40%);">+ logging print category 1</span><br><span style="color: hsl(120, 100%, 40%);">+ logging print extended-timestamp 1</span><br><span style="color: hsl(120, 100%, 40%);">+ logging level set-all debug</span><br><span style="color: hsl(120, 100%, 40%);">+line vty</span><br><span style="color: hsl(120, 100%, 40%);">+ no login</span><br><span style="color: hsl(120, 100%, 40%);">+ bind 10.42.42.2</span><br><span style="color: hsl(120, 100%, 40%);">+!ctrl</span><br><span style="color: hsl(120, 100%, 40%);">+! bind 10.42.42.2</span><br><span style="color: hsl(120, 100%, 40%);">+cs7 instance 0</span><br><span style="color: hsl(120, 100%, 40%);">+ xua rkm routing-key-allocation dynamic-permitted</span><br><span style="color: hsl(120, 100%, 40%);">+ listen m3ua 2905</span><br><span style="color: hsl(120, 100%, 40%);">+  accept-asp-connections dynamic-permitted</span><br><span style="color: hsl(120, 100%, 40%);">+  local-ip 10.42.42.2</span><br><span style="color: hsl(120, 100%, 40%);">+  [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2]  [stp_osmo.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_template_overlay.py:[LINENR]: - New template is used after re-generating cache with set_overlay_template_dir:  [suiteC↪test_template_overlay.py:[LINENR]]  [test_template_overlay.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+run osmo-stp_10.42.42.2: DBG: {config_file='test_trial_tmp/test_run_6/suiteC/test_template_overlay.py/osmo-stp_10.42.42_3.2/osmo-stp.cfg'}  [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2]  [stp_osmo.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+run osmo-stp_10.42.42.2: DBG: STP CONFIG:</span><br><span style="color: hsl(120, 100%, 40%);">+{'stp': {'ip_address': {'_hash': 'fd103b22c7cf2480d609150e06f4bbd92ac78d8c',</span><br><span style="color: hsl(120, 100%, 40%);">+                        '_reserved_by': 'suiteC-[ID_NUM]-[ID_NUM]',</span><br><span style="color: hsl(120, 100%, 40%);">+                        '_used': True,</span><br><span style="color: hsl(120, 100%, 40%);">+                        'addr': '10.42.42.2'}}}  [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2]  [stp_osmo.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+cnf Templates: DBG: rendering osmo-stp.cfg.tmpl  [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪Templates]  [template.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+run osmo-stp_10.42.42.2: DBG: ! Overlay Config file genreated by test</span><br><span style="color: hsl(120, 100%, 40%);">+line vty</span><br><span style="color: hsl(120, 100%, 40%);">+ no login</span><br><span style="color: hsl(120, 100%, 40%);">+ bind 10.42.42.2</span><br><span style="color: hsl(120, 100%, 40%);">+          [suiteC↪test_template_overlay.py:[LINENR]↪test_template_overlay.py↪osmo-stp_10.42.42.2]  [stp_osmo.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_template_overlay.py:[LINENR] Test passed (N.N sec)  [suiteC↪test_template_overlay.py]  [test.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+---------------------------------------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+trial suiteC PASS</span><br><span style="color: hsl(120, 100%, 40%);">+---------------------------------------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+PASS: suiteC (pass: 1)</span><br><span style="color: hsl(120, 100%, 40%);">+    pass: test_template_overlay.py (N.N sec)</span><br><span> </span><br><span> - graceful exit.</span><br><span>diff --git a/selftest/suite_test/suite_test.ok.ign b/selftest/suite_test/suite_test.ok.ign</span><br><span>index 9bd168f..460da92 100644</span><br><span>--- a/selftest/suite_test/suite_test.ok.ign</span><br><span>+++ b/selftest/suite_test/suite_test.ok.ign</span><br><span>@@ -3,3 +3,4 @@</span><br><span> \([0-9.]+ sec\) (N.N sec)</span><br><span> {combining_scenarios='resources', scenario='foo'}:.*       {combining_scenarios='resources', scenario='foo'}: [RESOURCE_DICT]</span><br><span> test_suite-[0-9]*-[0-9]*  test_suite-[ID_NUM]-[ID_NUM]</span><br><span style="color: hsl(120, 100%, 40%);">+suiteC-[0-9]*-[0-9]*      suiteC-[ID_NUM]-[ID_NUM]</span><br><span>diff --git a/selftest/suite_test/suite_test.py b/selftest/suite_test/suite_test.py</span><br><span>index 4b32439..260b9c4 100755</span><br><span>--- a/selftest/suite_test/suite_test.py</span><br><span>+++ b/selftest/suite_test/suite_test.py</span><br><span>@@ -105,6 +105,13 @@</span><br><span> results = s.run_tests('test_suite_params.py')</span><br><span> print(report.suite_to_text(s))</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+print('- test with template overlay')</span><br><span style="color: hsl(120, 100%, 40%);">+trial = FakeTrial()</span><br><span style="color: hsl(120, 100%, 40%);">+s_def = suite.load('suiteC')</span><br><span style="color: hsl(120, 100%, 40%);">+s = suite.SuiteRun(trial, 'suiteC', s_def)</span><br><span style="color: hsl(120, 100%, 40%);">+results = s.run_tests('test_template_overlay.py')</span><br><span style="color: hsl(120, 100%, 40%);">+print(report.suite_to_text(s))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> print('\n- graceful exit.')</span><br><span> #deleting generated tmp trial dir:</span><br><span> shutil.rmtree(example_trial_dir, ignore_errors=True)</span><br><span>diff --git a/selftest/suite_test/suitedirB/suiteC/mytemplatedir/.gitignore b/selftest/suite_test/suitedirB/suiteC/mytemplatedir/.gitignore</span><br><span>new file mode 100644</span><br><span>index 0000000..1e2640b</span><br><span>--- /dev/null</span><br><span>+++ b/selftest/suite_test/suitedirB/suiteC/mytemplatedir/.gitignore</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+# For 'test_template_overlay.py', it's fine having this directory completely</span><br><span style="color: hsl(120, 100%, 40%);">+# empy. However, we need a file in this directory so it can be stored in git.</span><br><span style="color: hsl(120, 100%, 40%);">+# Ignore everything in this directory</span><br><span style="color: hsl(120, 100%, 40%);">+*</span><br><span style="color: hsl(120, 100%, 40%);">+# Except this file</span><br><span style="color: hsl(120, 100%, 40%);">+!.gitignore</span><br><span>diff --git a/selftest/suite_test/suitedirB/suiteC/suite.conf b/selftest/suite_test/suitedirB/suiteC/suite.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..44be3fc</span><br><span>--- /dev/null</span><br><span>+++ b/selftest/suite_test/suitedirB/suiteC/suite.conf</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+resources:</span><br><span style="color: hsl(120, 100%, 40%);">+  ip_address:</span><br><span style="color: hsl(120, 100%, 40%);">+  - addr: 10.42.42.2 # stp</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+defaults:</span><br><span style="color: hsl(120, 100%, 40%);">+  timeout: 60s</span><br><span>diff --git a/selftest/suite_test/suitedirB/suiteC/test_template_overlay.py b/selftest/suite_test/suitedirB/suiteC/test_template_overlay.py</span><br><span>new file mode 100644</span><br><span>index 0000000..2dd9378</span><br><span>--- /dev/null</span><br><span>+++ b/selftest/suite_test/suitedirB/suiteC/test_template_overlay.py</span><br><span>@@ -0,0 +1,44 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/env python3</span><br><span style="color: hsl(120, 100%, 40%);">+from osmo_gsm_tester.testenv import *</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+import os</span><br><span style="color: hsl(120, 100%, 40%);">+import sys</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+print('- Testing: expect to fail on invalid templates overlay dir')</span><br><span style="color: hsl(120, 100%, 40%);">+try:</span><br><span style="color: hsl(120, 100%, 40%);">+    #stp.configure()</span><br><span style="color: hsl(120, 100%, 40%);">+    tenv.set_overlay_template_dir(os.path.join(os.path.dirname(__file__), 'nonexistent-templatedir'))</span><br><span style="color: hsl(120, 100%, 40%);">+    sys.stderr.write('Error: setting non-existing templates dir should raise RuntimeError\n')</span><br><span style="color: hsl(120, 100%, 40%);">+    assert(False)</span><br><span style="color: hsl(120, 100%, 40%);">+except RuntimeError:</span><br><span style="color: hsl(120, 100%, 40%);">+    print('sucess: setting non-existing templates dir raised RuntimeError\n')</span><br><span style="color: hsl(120, 100%, 40%);">+    pass</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+mytemplatedir = os.path.join(os.path.dirname(__file__), 'mytemplatedir')</span><br><span style="color: hsl(120, 100%, 40%);">+tenv.set_overlay_template_dir(mytemplatedir)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+stp = tenv.stp()</span><br><span style="color: hsl(120, 100%, 40%);">+print('- Testing: original template')</span><br><span style="color: hsl(120, 100%, 40%);">+stp.configure()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+print('- Testing:overlay template')</span><br><span style="color: hsl(120, 100%, 40%);">+mytemplatefile = os.path.join(mytemplatedir, 'osmo-stp.cfg.tmpl')</span><br><span style="color: hsl(120, 100%, 40%);">+try:</span><br><span style="color: hsl(120, 100%, 40%);">+    with open(mytemplatefile, 'w') as f:</span><br><span style="color: hsl(120, 100%, 40%);">+        r = """! Overlay Config file genreated by test</span><br><span style="color: hsl(120, 100%, 40%);">+line vty</span><br><span style="color: hsl(120, 100%, 40%);">+ no login</span><br><span style="color: hsl(120, 100%, 40%);">+ bind ${stp.ip_address.addr}</span><br><span style="color: hsl(120, 100%, 40%);">+        """</span><br><span style="color: hsl(120, 100%, 40%);">+        f.write(r)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # After creating the new template, it won\'t be used until</span><br><span style="color: hsl(120, 100%, 40%);">+    # set_overlay_template_dir() is called again because the templates are</span><br><span style="color: hsl(120, 100%, 40%);">+    # somehow cached by mako.</span><br><span style="color: hsl(120, 100%, 40%);">+    print('- After creating the new template, still old template is used' )</span><br><span style="color: hsl(120, 100%, 40%);">+    stp.configure()</span><br><span style="color: hsl(120, 100%, 40%);">+    print('- New template is used after re-generating cache with set_overlay_template_dir:')</span><br><span style="color: hsl(120, 100%, 40%);">+    tenv.set_overlay_template_dir(mytemplatedir)</span><br><span style="color: hsl(120, 100%, 40%);">+    stp.configure()</span><br><span style="color: hsl(120, 100%, 40%);">+finally:</span><br><span style="color: hsl(120, 100%, 40%);">+    os.remove(mytemplatefile)</span><br><span>diff --git a/src/osmo_gsm_tester/core/template.py b/src/osmo_gsm_tester/core/template.py</span><br><span>index 82985ef..8178c13 100644</span><br><span>--- a/src/osmo_gsm_tester/core/template.py</span><br><span>+++ b/src/osmo_gsm_tester/core/template.py</span><br><span>@@ -31,6 +31,8 @@</span><br><span>     return os.path.join(os.path.dirname(os.path.dirname(__file__)), 'templates')</span><br><span> </span><br><span> def set_templates_dir(*templates_dirs):</span><br><span style="color: hsl(120, 100%, 40%);">+    '''Set a lit of directories to look for templates. It must be called</span><br><span style="color: hsl(120, 100%, 40%);">+       everytime a template file is updated.'''</span><br><span>     global _lookup</span><br><span>     global _logger</span><br><span>     if not templates_dirs:</span><br><span>diff --git a/src/osmo_gsm_tester/obj/stp_osmo.py b/src/osmo_gsm_tester/obj/stp_osmo.py</span><br><span>index 1382016..83a2f75 100644</span><br><span>--- a/src/osmo_gsm_tester/obj/stp_osmo.py</span><br><span>+++ b/src/osmo_gsm_tester/obj/stp_osmo.py</span><br><span>@@ -35,7 +35,6 @@</span><br><span> </span><br><span>     def start(self):</span><br><span>         self.log('Starting osmo-stp')</span><br><span style="color: hsl(0, 100%, 40%);">-        self.run_dir = util.Dir(self.testenv.test().get_run_dir().new_dir(self.name()))</span><br><span>         self.configure()</span><br><span> </span><br><span>         inst = util.Dir(os.path.abspath(self.testenv.suite().trial().get_inst('osmo-stp')))</span><br><span>@@ -61,6 +60,7 @@</span><br><span>         self.process.launch()</span><br><span> </span><br><span>     def configure(self):</span><br><span style="color: hsl(120, 100%, 40%);">+        self.run_dir = util.Dir(self.testenv.test().get_run_dir().new_dir(self.name()))</span><br><span>         self.config_file = self.run_dir.new_file('osmo-stp.cfg')</span><br><span>         self.dbg(config_file=self.config_file)</span><br><span> </span><br><span>diff --git a/src/osmo_gsm_tester/testenv.py b/src/osmo_gsm_tester/testenv.py</span><br><span>index f3ac02e..7ca854b 100644</span><br><span>--- a/src/osmo_gsm_tester/testenv.py</span><br><span>+++ b/src/osmo_gsm_tester/testenv.py</span><br><span>@@ -24,6 +24,7 @@</span><br><span> import sys</span><br><span> </span><br><span> from .core import process</span><br><span style="color: hsl(120, 100%, 40%);">+from .core import template</span><br><span> from .core import log as log_module</span><br><span> from .core import process as process_module</span><br><span> from .core import resource</span><br><span>@@ -139,6 +140,7 @@</span><br><span>         self.suite_run.reserved_resources.put_all()</span><br><span>         MainLoop.unregister_poll_func(self.poll)</span><br><span>         self.test_import_modules_cleanup()</span><br><span style="color: hsl(120, 100%, 40%);">+        self.set_overlay_template_dir(None)</span><br><span> </span><br><span>     def config_suite_specific(self):</span><br><span>         return self.suite_run.config_suite_specific()</span><br><span>@@ -146,6 +148,14 @@</span><br><span>     def config_test_specific(self):</span><br><span>         return self.suite_run.config_suite_specific().get(self._test.module_name(), {})</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+    def set_overlay_template_dir(self, template_dir=None):</span><br><span style="color: hsl(120, 100%, 40%);">+        '''Overlay a directory on top of default one when looking for</span><br><span style="color: hsl(120, 100%, 40%);">+           directories. It must be called everytime a template file is updated.'''</span><br><span style="color: hsl(120, 100%, 40%);">+        if template_dir is None:</span><br><span style="color: hsl(120, 100%, 40%);">+            template.set_templates_dir(template.default_templates_dir())</span><br><span style="color: hsl(120, 100%, 40%);">+        else:</span><br><span style="color: hsl(120, 100%, 40%);">+            template.set_templates_dir(template_dir, template.default_templates_dir())</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>     def prompt(self, *msgs, **msg_details):</span><br><span>         'ask for user interaction. Do not use in tests that should run automatically!'</span><br><span>         if msg_details:</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18662">change 18662</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.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.osmocom.org/c/osmo-gsm-tester/+/18662"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-gsm-tester </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I65d1b1e826d2d430ee83810d998b98d0ccaa07cd </div>
<div style="display:none"> Gerrit-Change-Number: 18662 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>