diff options
author | Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com> | 2018-03-14 11:46:53 +0000 |
---|---|---|
committer | Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com> | 2018-03-14 11:58:38 +0000 |
commit | d07a9a7d18baa7dafbf12d2da9c554aa1718933f (patch) | |
tree | 250632577b3a8409897f807168f2b1c2ff998b6c | |
parent | 4b8b674b65830a24230faed71e8d9a1048139c89 (diff) |
Fix retrieving "options" section in "scenario"
In [1] a new method to rename the "scenario" host names was implemented.
This method parses all sections with host names and applies the
"qualified" name.
Some malformed test cases define the "options" section without content.
This causes that [2] retrieves "None" value instead of an empty
dictionary. This possibility must be handled in the new method.
[1]I44da30dac562c1a4166e084645ae91c17798651d
[2]https://github.com/opnfv/yardstick/blob/4b8b674b65830a24230faed71e8d9a1048139c89/yardstick/benchmark/core/task.py#L630
JIRA: YARDSTICK-1073
Change-Id: I8864b428734ead8c5aa39de5091d3a2a691be060
Signed-off-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
-rw-r--r-- | yardstick/benchmark/core/task.py | 6 | ||||
-rw-r--r-- | yardstick/tests/unit/benchmark/core/test_task.py | 28 |
2 files changed, 32 insertions, 2 deletions
diff --git a/yardstick/benchmark/core/task.py b/yardstick/benchmark/core/task.py index e7acde696..4272a6db9 100644 --- a/yardstick/benchmark/core/task.py +++ b/yardstick/benchmark/core/task.py @@ -344,7 +344,8 @@ class Task(object): # pragma: no cover # TODO support get multi hosts/vms info context_cfg = {} - server_name = scenario_cfg.get('options', {}).get('server_name', {}) + options = scenario_cfg.get('options') or {} + server_name = options.get('server_name') or {} def config_context_target(cfg): target = cfg['target'] @@ -627,7 +628,8 @@ class TaskParser(object): # pragma: no cover scenario['host'] = qualified_name(scenario['host']) if 'target' in scenario: scenario['target'] = qualified_name(scenario['target']) - server_name = scenario.get('options', {}).get('server_name', {}) + options = scenario.get('options') or {} + server_name = options.get('server_name') or {} if 'host' in server_name: server_name['host'] = qualified_name(server_name['host']) if 'target' in server_name: diff --git a/yardstick/tests/unit/benchmark/core/test_task.py b/yardstick/tests/unit/benchmark/core/test_task.py index 1ce30eacb..9e8e4e9f7 100644 --- a/yardstick/tests/unit/benchmark/core/test_task.py +++ b/yardstick/tests/unit/benchmark/core/test_task.py @@ -421,6 +421,34 @@ key2: self.parser._change_node_names(scenario, [my_context]) self.assertEqual(scenario, expected_scenario) + def test__change_node_names_options_empty(self): + ctx_attrs = { + 'name': 'demo', + 'task_id': '1234567890' + } + + my_context = dummy.DummyContext() + my_context.init(ctx_attrs) + scenario = copy.deepcopy(self.scenario) + scenario['options'] = None + + self.parser._change_node_names(scenario, [my_context]) + self.assertIsNone(scenario['options']) + + def test__change_node_names_options_server_name_empty(self): + ctx_attrs = { + 'name': 'demo', + 'task_id': '1234567890' + } + + my_context = dummy.DummyContext() + my_context.init(ctx_attrs) + scenario = copy.deepcopy(self.scenario) + scenario['options']['server_name'] = None + + self.parser._change_node_names(scenario, [my_context]) + self.assertIsNone(scenario['options']['server_name']) + def test__parse_tasks(self): task_obj = task.Task() _uuid = uuid.uuid4() |