<p>pespin has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18798">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Refactor test specific config parsing & generation<br><br>The dictionary is generated once during test creation at suite startup.<br><br>Change-Id: I4de511d64ccf65d2ec6eec45dcf28529b74c5d26<br>---<br>M selftest/suite_test/suite_test.ok<br>M src/osmo_gsm_tester/core/suite.py<br>M src/osmo_gsm_tester/core/test.py<br>M src/osmo_gsm_tester/testenv.py<br>4 files changed, 24 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/98/18798/1</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 3264fe2..c7c76d7 100644</span><br><span>--- a/selftest/suite_test/suite_test.ok</span><br><span>+++ b/selftest/suite_test/suite_test.ok</span><br><span>@@ -27,6 +27,8 @@</span><br><span>   - times: '2'</span><br><span> </span><br><span> - run hello world test</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_suite: DBG: {combining='config'}</span><br><span style="color: hsl(120, 100%, 40%);">+tst {combining_scenarios='config'}: DBG: {definition_conf={}}  [test_suite↪{combining_scenarios='config'}]</span><br><span> </span><br><span> ---------------------------------------------------------------------</span><br><span> trial test_suite</span><br><span>@@ -179,6 +181,9 @@</span><br><span>     FAIL: test_fail_raise.py (N.N sec) ExpectedFail: This failure is expected</span><br><span>     skip: test_suite_params.py</span><br><span> - test with half empty scenario</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_suite: DBG: {combining='config'}  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst {combining_scenarios='config'}: DBG: {definition_conf={}}  [test_suite↪{combining_scenarios='config'}]  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst {combining_scenarios='config', scenario='foo'}: DBG: {conf={}, scenario='foo'}  [test_suite↪{combining_scenarios='config', scenario='foo'}]  [suite.py:[LINENR]]</span><br><span> </span><br><span> ---------------------------------------------------------------------</span><br><span> trial test_suite</span><br><span>@@ -265,6 +270,9 @@</span><br><span>     skip: test_fail_raise.py</span><br><span>     skip: test_suite_params.py</span><br><span> - test with scenario</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_suite: DBG: {combining='config'}  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst {combining_scenarios='config'}: DBG: {definition_conf={}}  [test_suite↪{combining_scenarios='config'}]  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst {combining_scenarios='config', scenario='foo'}: DBG: {conf={}, scenario='foo'}  [test_suite↪{combining_scenarios='config', scenario='foo'}]  [suite.py:[LINENR]]</span><br><span> </span><br><span> ---------------------------------------------------------------------</span><br><span> trial test_suite</span><br><span>@@ -351,6 +359,9 @@</span><br><span>     skip: test_fail_raise.py</span><br><span>     skip: test_suite_params.py</span><br><span> - test with scenario and modifiers</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_suite: DBG: {combining='config'}  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst {combining_scenarios='config'}: DBG: {definition_conf={}}  [test_suite↪{combining_scenarios='config'}]  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst {combining_scenarios='config', scenario='foo'}: DBG: {conf={}, scenario='foo'}  [test_suite↪{combining_scenarios='config', scenario='foo'}]  [suite.py:[LINENR]]</span><br><span> tst test_suite: reserving resources in [PATH]/selftest/suite_test/test_work/state_dir ...  [suite.py:[LINENR]]</span><br><span> tst test_suite: DBG: {combining='resources'}  [suite.py:[LINENR]]</span><br><span> tst {combining_scenarios='resources'}: DBG: {definition_conf={bts=[{'label': 'sysmoCell 5000'}, {'label': 'sysmoCell 5000'}, {'type': 'sysmo'}], ip_address=[{}], modem=[{}, {}]}}  [test_suite↪{combining_scenarios='resources'}]  [suite.py:[LINENR]]</span><br><span>@@ -483,6 +494,9 @@</span><br><span>     skip: test_fail_raise.py</span><br><span>     skip: test_suite_params.py</span><br><span> - test with suite-specific config</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_suite: DBG: {combining='config'}  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst {combining_scenarios='config'}: DBG: {definition_conf={}}  [test_suite↪{combining_scenarios='config'}]  [suite.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst {combining_scenarios='config', scenario='foo'}: DBG: {conf={suite={test_suite={some_suite_global_param='heyho', test_suite_params={one_bool_parameter='true', second_list_parameter=['23', '45']}}}}, scenario='foo'}  [test_suite↪{combining_scenarios='config', scenario='foo'}]  [suite.py:[LINENR]]</span><br><span> tst test_suite: reserving resources in [PATH]/selftest/suite_test/test_work/state_dir ...  [suite.py:[LINENR]]</span><br><span> tst test_suite: DBG: {combining='resources'}  [suite.py:[LINENR]]</span><br><span> tst {combining_scenarios='resources'}: DBG: {definition_conf={bts=[{'label': 'sysmoCell 5000'}, {'label': 'sysmoCell 5000'}, {'type': 'sysmo'}], ip_address=[{}], modem=[{}, {}]}}  [test_suite↪{combining_scenarios='resources'}]  [suite.py:[LINENR]]</span><br><span>@@ -598,9 +612,6 @@</span><br><span> trial test_suite test_suite_params.py</span><br><span> ----------------------------------------------</span><br><span> tst test_suite_params.py:[LINENR]: starting test  [test_suite↪test_suite_params.py:[LINENR]]  [test_suite_params.py:[LINENR]]</span><br><span style="color: hsl(0, 100%, 40%);">-tst test_suite: DBG: {combining='config'}  [suite.py:[LINENR]]</span><br><span style="color: hsl(0, 100%, 40%);">-tst {combining_scenarios='config'}: DBG: {definition_conf={}}  [test_suite↪{combining_scenarios='config'}]  [suite.py:[LINENR]]</span><br><span style="color: hsl(0, 100%, 40%);">-tst {combining_scenarios='config', scenario='foo'}: DBG: {conf={suite={test_suite={some_suite_global_param='heyho', test_suite_params={one_bool_parameter='true', second_list_parameter=['23', '45']}}}}, scenario='foo'}  [test_suite↪{combining_scenarios='config', scenario='foo'}]  [suite.py:[LINENR]]</span><br><span> tst test_suite_params.py:[LINENR]: SPECIFIC SUITE CONFIG: {'some_suite_global_param': 'heyho',  [test_suite↪test_suite_params.py:[LINENR]]  [test_suite_params.py:[LINENR]]</span><br><span> tst test_suite_params.py:[LINENR]:  'test_suite_params': {'one_bool_parameter': 'true',  [test_suite↪test_suite_params.py:[LINENR]]  [test_suite_params.py:[LINENR]]</span><br><span> tst test_suite_params.py:[LINENR]:                        'second_list_parameter': ['23', '45']}}  [test_suite↪test_suite_params.py:[LINENR]]  [test_suite_params.py:[LINENR]]</span><br><span>@@ -619,6 +630,8 @@</span><br><span>     pass: test_suite_params.py (N.N sec)</span><br><span> - test with template overlay</span><br><span> cnf suiteC: DBG: reading suite.conf  [suite.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> </span><br><span> ---------------------------------------------------------------------</span><br><span> trial suiteC</span><br><span>@@ -651,8 +664,6 @@</span><br><span> --- ReservedResources: DBG: {using={_hash='fd103b22c7cf2480d609150e06f4bbd92ac78d8c', _reserved_by='suiteC-[ID_NUM]-[ID_NUM]', addr='10.42.42.2'}}  [resource.py:[LINENR]]</span><br><span> tst test_template_overlay.py:[LINENR]: - Testing: original template  [suiteC↪test_template_overlay.py:[LINENR]]  [test_template_overlay.py:[LINENR]]</span><br><span> 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(0, 100%, 40%);">-tst suiteC: DBG: {combining='config'}  [suite.py:[LINENR]]</span><br><span style="color: hsl(0, 100%, 40%);">-tst {combining_scenarios='config'}: DBG: {definition_conf={}}  [suiteC↪{combining_scenarios='config'}]  [suite.py:[LINENR]]</span><br><span> run osmo-stp_10.42.42.2: DBG: STP CONFIG:</span><br><span> {'stp': {'ip_address': {'_hash': 'fd103b22c7cf2480d609150e06f4bbd92ac78d8c',</span><br><span>                         '_reserved_by': 'suiteC-[ID_NUM]-[ID_NUM]',</span><br><span>diff --git a/src/osmo_gsm_tester/core/suite.py b/src/osmo_gsm_tester/core/suite.py</span><br><span>index c55c5e9..9b9062d 100644</span><br><span>--- a/src/osmo_gsm_tester/core/suite.py</span><br><span>+++ b/src/osmo_gsm_tester/core/suite.py</span><br><span>@@ -98,7 +98,8 @@</span><br><span>     def load_tests(self):</span><br><span>         self.tests = []</span><br><span>         for test_basename in self.definition.test_basenames:</span><br><span style="color: hsl(0, 100%, 40%);">-            self.tests.append(test.Test(self, test_basename))</span><br><span style="color: hsl(120, 100%, 40%);">+            test_specific_config = self.config_suite_specific().get(test_basename.rstrip('.py'), {})</span><br><span style="color: hsl(120, 100%, 40%);">+            self.tests.append(test.Test(self, test_basename, test_specific_config))</span><br><span> </span><br><span>     def mark_start(self):</span><br><span>         self.start_timestamp = time.time()</span><br><span>diff --git a/src/osmo_gsm_tester/core/test.py b/src/osmo_gsm_tester/core/test.py</span><br><span>index 7347229..45dfd41 100644</span><br><span>--- a/src/osmo_gsm_tester/core/test.py</span><br><span>+++ b/src/osmo_gsm_tester/core/test.py</span><br><span>@@ -35,11 +35,12 @@</span><br><span>     PASS = 'pass'</span><br><span>     FAIL = 'FAIL'</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    def __init__(self, suite_run, test_basename):</span><br><span style="color: hsl(120, 100%, 40%);">+    def __init__(self, suite_run, test_basename, test_specific_config):</span><br><span>         self.basename = test_basename</span><br><span>         super().__init__(log.C_TST, self.basename)</span><br><span>         self._run_dir = None</span><br><span>         self.suite_run = suite_run</span><br><span style="color: hsl(120, 100%, 40%);">+        self._config_test_specific = test_specific_config</span><br><span>         self.path = os.path.join(self.suite_run.definition.suite_dir, self.basename)</span><br><span>         self.status = Test.UNKNOWN</span><br><span>         self.start_timestamp = 0</span><br><span>@@ -134,6 +135,9 @@</span><br><span>         self.status = Test.SKIP</span><br><span>         self.duration = 0</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+    def config_test_specific(self):</span><br><span style="color: hsl(120, 100%, 40%);">+        return self._config_test_specific</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>     def set_report_stdout(self, text):</span><br><span>         'Overwrite stdout text stored in report from inside a test'</span><br><span>         self._report_stdout = text</span><br><span>diff --git a/src/osmo_gsm_tester/testenv.py b/src/osmo_gsm_tester/testenv.py</span><br><span>index d6c18ee..11199c2 100644</span><br><span>--- a/src/osmo_gsm_tester/testenv.py</span><br><span>+++ b/src/osmo_gsm_tester/testenv.py</span><br><span>@@ -146,7 +146,7 @@</span><br><span>         return self.suite_run.config_suite_specific()</span><br><span> </span><br><span>     def config_test_specific(self):</span><br><span style="color: hsl(0, 100%, 40%);">-        return self.suite_run.config_suite_specific().get(self._test.module_name(), {})</span><br><span style="color: hsl(120, 100%, 40%);">+        return self._test.config_test_specific()</span><br><span> </span><br><span>     def set_overlay_template_dir(self, template_dir=None):</span><br><span>         '''Overlay a directory on top of default one when looking for</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18798">change 18798</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/+/18798"/><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: I4de511d64ccf65d2ec6eec45dcf28529b74c5d26 </div>
<div style="display:none"> Gerrit-Change-Number: 18798 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>