From a75f85a058db6d0b256c4b3137c4144ce20bd73f Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Fri, 12 Jun 2020 17:13:26 +0200 Subject: Refactor test specific config parsing & generation The dictionary is generated once during test creation at suite startup. Change-Id: I4de511d64ccf65d2ec6eec45dcf28529b74c5d26 --- selftest/suite_test/suite_test.ok | 21 ++++++++++++++++----- src/osmo_gsm_tester/core/suite.py | 3 ++- src/osmo_gsm_tester/core/test.py | 6 +++++- src/osmo_gsm_tester/testenv.py | 2 +- 4 files changed, 24 insertions(+), 8 deletions(-) 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 @@ resources: - 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_suite (fail: 1, skip: 6) 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 @@ PASS: test_suite (pass: 1, skip: 6) 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 @@ PASS: test_suite (pass: 1, skip: 6) 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 @@ PASS: test_suite (pass: 1, skip: 6) 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 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 (pass: 1, skip: 6) 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 @@ tst suiteC: DBG: Picked - _hash: fd103b22c7cf2480d609150e06f4bbd92ac78d8c --- 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 @@ class SuiteRun(log.Origin): 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 @@ class Test(log.Origin): 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 @@ class Test(log.Origin): 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 @@ class TestEnv(log_module.Origin): 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 -- cgit v1.2.3