pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18798 )


Change subject: Refactor test specific config parsing & generation
......................................................................

Refactor test specific config parsing & generation

The dictionary is generated once during test creation at suite startup.

Change-Id: I4de511d64ccf65d2ec6eec45dcf28529b74c5d26
---
M selftest/suite_test/suite_test.ok
M src/osmo_gsm_tester/core/suite.py
M src/osmo_gsm_tester/core/test.py
M src/osmo_gsm_tester/testenv.py
4 files changed, 24 insertions(+), 8 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester 
refs/changes/98/18798/1

diff --git a/selftest/suite_test/suite_test.ok 
b/selftest/suite_test/suite_test.ok
index 3264fe2..c7c76d7 100644
--- a/selftest/suite_test/suite_test.ok
+++ b/selftest/suite_test/suite_test.ok
@@ -27,6 +27,8 @@
   - times: '2'

 - run hello world test
+tst test_suite: DBG: {combining='config'}
+tst {combining_scenarios='config'}: DBG: {definition_conf={}}  
[test_suite↪{combining_scenarios='config'}]

 ---------------------------------------------------------------------
 trial test_suite
@@ -179,6 +181,9 @@
     FAIL: test_fail_raise.py (N.N sec) ExpectedFail: This failure is expected
     skip: test_suite_params.py
 - test with half empty scenario
+tst test_suite: DBG: {combining='config'}  [suite.py:[LINENR]]
+tst {combining_scenarios='config'}: DBG: {definition_conf={}}  
[test_suite↪{combining_scenarios='config'}]  [suite.py:[LINENR]]
+tst {combining_scenarios='config', scenario='foo'}: DBG: {conf={}, 
scenario='foo'}  [test_suite↪{combining_scenarios='config', scenario='foo'}]  
[suite.py:[LINENR]]

 ---------------------------------------------------------------------
 trial test_suite
@@ -265,6 +270,9 @@
     skip: test_fail_raise.py
     skip: test_suite_params.py
 - test with scenario
+tst test_suite: DBG: {combining='config'}  [suite.py:[LINENR]]
+tst {combining_scenarios='config'}: DBG: {definition_conf={}}  
[test_suite↪{combining_scenarios='config'}]  [suite.py:[LINENR]]
+tst {combining_scenarios='config', scenario='foo'}: DBG: {conf={}, 
scenario='foo'}  [test_suite↪{combining_scenarios='config', scenario='foo'}]  
[suite.py:[LINENR]]

 ---------------------------------------------------------------------
 trial test_suite
@@ -351,6 +359,9 @@
     skip: test_fail_raise.py
     skip: test_suite_params.py
 - test with scenario and modifiers
+tst test_suite: DBG: {combining='config'}  [suite.py:[LINENR]]
+tst {combining_scenarios='config'}: DBG: {definition_conf={}}  
[test_suite↪{combining_scenarios='config'}]  [suite.py:[LINENR]]
+tst {combining_scenarios='config', scenario='foo'}: DBG: {conf={}, 
scenario='foo'}  [test_suite↪{combining_scenarios='config', scenario='foo'}]  
[suite.py:[LINENR]]
 tst test_suite: reserving resources in 
[PATH]/selftest/suite_test/test_work/state_dir ...  [suite.py:[LINENR]]
 tst test_suite: DBG: {combining='resources'}  [suite.py:[LINENR]]
 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]]
@@ -483,6 +494,9 @@
     skip: test_fail_raise.py
     skip: test_suite_params.py
 - test with suite-specific config
+tst test_suite: DBG: {combining='config'}  [suite.py:[LINENR]]
+tst {combining_scenarios='config'}: DBG: {definition_conf={}}  
[test_suite↪{combining_scenarios='config'}]  [suite.py:[LINENR]]
+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]]
 tst test_suite: reserving resources in 
[PATH]/selftest/suite_test/test_work/state_dir ...  [suite.py:[LINENR]]
 tst test_suite: DBG: {combining='resources'}  [suite.py:[LINENR]]
 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]]
@@ -598,9 +612,6 @@
 trial test_suite test_suite_params.py
 ----------------------------------------------
 tst test_suite_params.py:[LINENR]: starting test  
[test_suite↪test_suite_params.py:[LINENR]]  [test_suite_params.py:[LINENR]]
-tst test_suite: DBG: {combining='config'}  [suite.py:[LINENR]]
-tst {combining_scenarios='config'}: DBG: {definition_conf={}}  
[test_suite↪{combining_scenarios='config'}]  [suite.py:[LINENR]]
-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]]
 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]]
 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]]
 tst test_suite_params.py:[LINENR]:                        
'second_list_parameter': ['23', '45']}}  
[test_suite↪test_suite_params.py:[LINENR]]  [test_suite_params.py:[LINENR]]
@@ -619,6 +630,8 @@
     pass: test_suite_params.py (N.N sec)
 - test with template overlay
 cnf suiteC: DBG: reading suite.conf  [suite.py:[LINENR]]
+tst suiteC: DBG: {combining='config'}  [suite.py:[LINENR]]
+tst {combining_scenarios='config'}: DBG: {definition_conf={}}  
[suiteC↪{combining_scenarios='config'}]  [suite.py:[LINENR]]

 ---------------------------------------------------------------------
 trial suiteC
@@ -651,8 +664,6 @@
 --- ReservedResources: DBG: 
{using={_hash='fd103b22c7cf2480d609150e06f4bbd92ac78d8c', 
_reserved_by='suiteC-[ID_NUM]-[ID_NUM]', addr='10.42.42.2'}}  
[resource.py:[LINENR]]
 tst test_template_overlay.py:[LINENR]: - Testing: original template  
[suiteC↪test_template_overlay.py:[LINENR]]  [test_template_overlay.py:[LINENR]]
 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]]
-tst suiteC: DBG: {combining='config'}  [suite.py:[LINENR]]
-tst {combining_scenarios='config'}: DBG: {definition_conf={}}  
[suiteC↪{combining_scenarios='config'}]  [suite.py:[LINENR]]
 run osmo-stp_10.42.42.2: DBG: STP CONFIG:
 {'stp': {'ip_address': {'_hash': 'fd103b22c7cf2480d609150e06f4bbd92ac78d8c',
                         '_reserved_by': 'suiteC-[ID_NUM]-[ID_NUM]',
diff --git a/src/osmo_gsm_tester/core/suite.py 
b/src/osmo_gsm_tester/core/suite.py
index c55c5e9..9b9062d 100644
--- a/src/osmo_gsm_tester/core/suite.py
+++ b/src/osmo_gsm_tester/core/suite.py
@@ -98,7 +98,8 @@
     def load_tests(self):
         self.tests = []
         for test_basename in self.definition.test_basenames:
-            self.tests.append(test.Test(self, test_basename))
+            test_specific_config = 
self.config_suite_specific().get(test_basename.rstrip('.py'), {})
+            self.tests.append(test.Test(self, test_basename, 
test_specific_config))

     def mark_start(self):
         self.start_timestamp = time.time()
diff --git a/src/osmo_gsm_tester/core/test.py b/src/osmo_gsm_tester/core/test.py
index 7347229..45dfd41 100644
--- a/src/osmo_gsm_tester/core/test.py
+++ b/src/osmo_gsm_tester/core/test.py
@@ -35,11 +35,12 @@
     PASS = 'pass'
     FAIL = 'FAIL'

-    def __init__(self, suite_run, test_basename):
+    def __init__(self, suite_run, test_basename, test_specific_config):
         self.basename = test_basename
         super().__init__(log.C_TST, self.basename)
         self._run_dir = None
         self.suite_run = suite_run
+        self._config_test_specific = test_specific_config
         self.path = os.path.join(self.suite_run.definition.suite_dir, 
self.basename)
         self.status = Test.UNKNOWN
         self.start_timestamp = 0
@@ -134,6 +135,9 @@
         self.status = Test.SKIP
         self.duration = 0

+    def config_test_specific(self):
+        return self._config_test_specific
+
     def set_report_stdout(self, text):
         'Overwrite stdout text stored in report from inside a test'
         self._report_stdout = text
diff --git a/src/osmo_gsm_tester/testenv.py b/src/osmo_gsm_tester/testenv.py
index d6c18ee..11199c2 100644
--- a/src/osmo_gsm_tester/testenv.py
+++ b/src/osmo_gsm_tester/testenv.py
@@ -146,7 +146,7 @@
         return self.suite_run.config_suite_specific()

     def config_test_specific(self):
-        return 
self.suite_run.config_suite_specific().get(self._test.module_name(), {})
+        return self._test.config_test_specific()

     def set_overlay_template_dir(self, template_dir=None):
         '''Overlay a directory on top of default one when looking for

--
To view, visit https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18798
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Change-Id: I4de511d64ccf65d2ec6eec45dcf28529b74c5d26
Gerrit-Change-Number: 18798
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pes...@sysmocom.de>
Gerrit-MessageType: newchange

Reply via email to