Change in osmo-gsm-tester[master]: Split Scenario class to its own file

2020-05-11 Thread pespin
pespin has posted comments on this change. ( 
https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18200 )

Change subject: Split Scenario class to its own file
..


Patch Set 1: Code-Review+2


--
To view, visit https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18200
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: Ia029de7ecda4c8dc3d0b4c412e4c9c0a65cf0185
Gerrit-Change-Number: 18200
Gerrit-PatchSet: 1
Gerrit-Owner: pespin 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Comment-Date: Mon, 11 May 2020 15:04:42 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in osmo-gsm-tester[master]: Split Scenario class to its own file

2020-05-11 Thread pespin
pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18200 )

Change subject: Split Scenario class to its own file
..

Split Scenario class to its own file

Change-Id: Ia029de7ecda4c8dc3d0b4c412e4c9c0a65cf0185
---
M selftest/suite_test/suite_test.py
M src/osmo_gsm_tester/core/config.py
A src/osmo_gsm_tester/core/scenario.py
M src/osmo_gsm_tester/core/suite.py
4 files changed, 148 insertions(+), 112 deletions(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, approved



diff --git a/selftest/suite_test/suite_test.py 
b/selftest/suite_test/suite_test.py
index fc5f9df..a096027 100755
--- a/selftest/suite_test/suite_test.py
+++ b/selftest/suite_test/suite_test.py
@@ -3,7 +3,11 @@
 import sys
 import _prep
 import shutil
-from osmo_gsm_tester.core import log, config, util, report
+from osmo_gsm_tester.core import log
+from osmo_gsm_tester.core import config
+from osmo_gsm_tester.core import util
+from osmo_gsm_tester.core import report
+from osmo_gsm_tester.core import scenario
 from osmo_gsm_tester.core import suite
 from osmo_gsm_tester.core.schema import generate_schemas, get_all_schema

@@ -66,26 +70,26 @@

 print('- test with half empty scenario')
 trial = FakeTrial()
-scenario = config.Scenario('foo', 'bar')
-scenario['resources'] = { 'bts': [{'type': 'osmo-bts-trx'}] }
-s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
+sc = scenario.Scenario('foo', 'bar')
+sc['resources'] = { 'bts': [{'type': 'osmo-bts-trx'}] }
+s = suite.SuiteRun(trial, 'test_suite', s_def, [sc])
 results = s.run_tests('hello_world.py')
 print(report.suite_to_text(s))

 print('- test with scenario')
 trial = FakeTrial()
-scenario = config.Scenario('foo', 'bar')
-scenario['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 
'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 
'sysmo'}] }
-s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
+sc = scenario.Scenario('foo', 'bar')
+sc['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 
'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 
'sysmo'}] }
+s = suite.SuiteRun(trial, 'test_suite', s_def, [sc])
 results = s.run_tests('hello_world.py')
 print(report.suite_to_text(s))

 print('- test with scenario and modifiers')
 trial = FakeTrial()
-scenario = config.Scenario('foo', 'bar')
-scenario['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 
'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 
'sysmo'}] }
-scenario['modifiers'] = { 'bts': [{ 'times': '2', 'trx_list': 
[{'nominal_power': '20'}, {'nominal_power': '20'}]}, {'type': 'sysmo'}] }
-s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
+sc = scenario.Scenario('foo', 'bar')
+sc['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 
'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 
'sysmo'}] }
+sc['modifiers'] = { 'bts': [{ 'times': '2', 'trx_list': [{'nominal_power': 
'20'}, {'nominal_power': '20'}]}, {'type': 'sysmo'}] }
+s = suite.SuiteRun(trial, 'test_suite', s_def, [sc])
 s.reserve_resources()
 print(repr(s.reserved_resources))
 results = s.run_tests('hello_world.py')
@@ -93,9 +97,9 @@

 print('- test with suite-specific config')
 trial = FakeTrial()
-scenario = config.Scenario('foo', 'bar')
-scenario['config'] = {'suite': {s.name(): { 'some_suite_global_param': 
'heyho', 'test_suite_params': {'one_bool_parameter': 'true', 
'second_list_parameter': ['23', '45']
-s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
+sc = scenario.Scenario('foo', 'bar')
+sc['config'] = {'suite': {s.name(): { 'some_suite_global_param': 'heyho', 
'test_suite_params': {'one_bool_parameter': 'true', 'second_list_parameter': 
['23', '45']
+s = suite.SuiteRun(trial, 'test_suite', s_def, [sc])
 s.reserve_resources()
 print(repr(s.reserved_resources))
 results = s.run_tests('test_suite_params.py')
diff --git a/src/osmo_gsm_tester/core/config.py 
b/src/osmo_gsm_tester/core/config.py
index 98d422f..88e522d 100644
--- a/src/osmo_gsm_tester/core/config.py
+++ b/src/osmo_gsm_tester/core/config.py
@@ -165,6 +165,13 @@
 with open(path, 'w') as f:
 f.write(tostr(config))

+def fromstr(config_str, validation_schema=None):
+config = yaml.safe_load(config_str)
+config = _standardize(config)
+if validation_schema is not None:
+schema.validate(config, validation_schema)
+return config
+
 def tostr(config):
 return _tostr(_standardize(config))

@@ -188,99 +195,6 @@
 defaults = read_config_file(DEFAULTS_CONF, if_missing_return={})
 return defaults.get(for_kind, {})

-class Scenario(log.Origin, dict):
-def __init__(self, name, path, param_list=[]):
-super().__init__(log.C_TST, name)
-self.path = path
-self.param_list = param_list
-
-@classmethod
-def count_cont_char_backward(cls, str, 

Change in osmo-gsm-tester[master]: Split Scenario class to its own file

2020-05-11 Thread pespin
pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18200 )


Change subject: Split Scenario class to its own file
..

Split Scenario class to its own file

Change-Id: Ia029de7ecda4c8dc3d0b4c412e4c9c0a65cf0185
---
M selftest/suite_test/suite_test.py
M src/osmo_gsm_tester/core/config.py
A src/osmo_gsm_tester/core/scenario.py
M src/osmo_gsm_tester/core/suite.py
4 files changed, 148 insertions(+), 112 deletions(-)



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

diff --git a/selftest/suite_test/suite_test.py 
b/selftest/suite_test/suite_test.py
index fc5f9df..a096027 100755
--- a/selftest/suite_test/suite_test.py
+++ b/selftest/suite_test/suite_test.py
@@ -3,7 +3,11 @@
 import sys
 import _prep
 import shutil
-from osmo_gsm_tester.core import log, config, util, report
+from osmo_gsm_tester.core import log
+from osmo_gsm_tester.core import config
+from osmo_gsm_tester.core import util
+from osmo_gsm_tester.core import report
+from osmo_gsm_tester.core import scenario
 from osmo_gsm_tester.core import suite
 from osmo_gsm_tester.core.schema import generate_schemas, get_all_schema

@@ -66,26 +70,26 @@

 print('- test with half empty scenario')
 trial = FakeTrial()
-scenario = config.Scenario('foo', 'bar')
-scenario['resources'] = { 'bts': [{'type': 'osmo-bts-trx'}] }
-s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
+sc = scenario.Scenario('foo', 'bar')
+sc['resources'] = { 'bts': [{'type': 'osmo-bts-trx'}] }
+s = suite.SuiteRun(trial, 'test_suite', s_def, [sc])
 results = s.run_tests('hello_world.py')
 print(report.suite_to_text(s))

 print('- test with scenario')
 trial = FakeTrial()
-scenario = config.Scenario('foo', 'bar')
-scenario['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 
'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 
'sysmo'}] }
-s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
+sc = scenario.Scenario('foo', 'bar')
+sc['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 
'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 
'sysmo'}] }
+s = suite.SuiteRun(trial, 'test_suite', s_def, [sc])
 results = s.run_tests('hello_world.py')
 print(report.suite_to_text(s))

 print('- test with scenario and modifiers')
 trial = FakeTrial()
-scenario = config.Scenario('foo', 'bar')
-scenario['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 
'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 
'sysmo'}] }
-scenario['modifiers'] = { 'bts': [{ 'times': '2', 'trx_list': 
[{'nominal_power': '20'}, {'nominal_power': '20'}]}, {'type': 'sysmo'}] }
-s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
+sc = scenario.Scenario('foo', 'bar')
+sc['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 
'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 
'sysmo'}] }
+sc['modifiers'] = { 'bts': [{ 'times': '2', 'trx_list': [{'nominal_power': 
'20'}, {'nominal_power': '20'}]}, {'type': 'sysmo'}] }
+s = suite.SuiteRun(trial, 'test_suite', s_def, [sc])
 s.reserve_resources()
 print(repr(s.reserved_resources))
 results = s.run_tests('hello_world.py')
@@ -93,9 +97,9 @@

 print('- test with suite-specific config')
 trial = FakeTrial()
-scenario = config.Scenario('foo', 'bar')
-scenario['config'] = {'suite': {s.name(): { 'some_suite_global_param': 
'heyho', 'test_suite_params': {'one_bool_parameter': 'true', 
'second_list_parameter': ['23', '45']
-s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
+sc = scenario.Scenario('foo', 'bar')
+sc['config'] = {'suite': {s.name(): { 'some_suite_global_param': 'heyho', 
'test_suite_params': {'one_bool_parameter': 'true', 'second_list_parameter': 
['23', '45']
+s = suite.SuiteRun(trial, 'test_suite', s_def, [sc])
 s.reserve_resources()
 print(repr(s.reserved_resources))
 results = s.run_tests('test_suite_params.py')
diff --git a/src/osmo_gsm_tester/core/config.py 
b/src/osmo_gsm_tester/core/config.py
index 98d422f..88e522d 100644
--- a/src/osmo_gsm_tester/core/config.py
+++ b/src/osmo_gsm_tester/core/config.py
@@ -165,6 +165,13 @@
 with open(path, 'w') as f:
 f.write(tostr(config))

+def fromstr(config_str, validation_schema=None):
+config = yaml.safe_load(config_str)
+config = _standardize(config)
+if validation_schema is not None:
+schema.validate(config, validation_schema)
+return config
+
 def tostr(config):
 return _tostr(_standardize(config))

@@ -188,99 +195,6 @@
 defaults = read_config_file(DEFAULTS_CONF, if_missing_return={})
 return defaults.get(for_kind, {})

-class Scenario(log.Origin, dict):
-def __init__(self, name, path, param_list=[]):
-super().__init__(log.C_TST, name)
-self.path = path
-self.param_list = param_list
-
-@classmethod
-def