From 87f2fe003a92919682c8ab9b2ed6cb904a204469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Prchl=C3=ADk?= Date: Mon, 17 Jun 2024 15:04:03 +0200 Subject: [PATCH] Fix normalization of `hardware` key/option (#3015) A bug was introduced in the patching adding multiple disks to testcloud plugin, and the test was missing. --- tests/unit/test_hardware.py | 14 ++++++++++++++ tmt/steps/provision/__init__.py | 7 ++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/unit/test_hardware.py b/tests/unit/test_hardware.py index 79ba7b37a8..f1a254ecf3 100644 --- a/tests/unit/test_hardware.py +++ b/tests/unit/test_hardware.py @@ -89,6 +89,20 @@ def test_constraint_components_pattern(value: str, expected: tuple[Any, Any]) -> assert match.groups() == expected +def test_normalize_hardware(root_logger) -> None: + # All major classes of requirements: + spec = ( + # Simple name.child_name=value + 'cpu.processors=1', + # The same but with cpu.flags which have special handling + 'cpu.flag!=avc', + # name[peer_index].child_name=value + 'disk[1].size=1' + ) + + tmt.steps.provision.normalize_hardware('', spec, root_logger) + + @pytest.mark.parametrize( ('spec', 'expected_exc', 'expected_message'), [ diff --git a/tmt/steps/provision/__init__.py b/tmt/steps/provision/__init__.py index f54c63acaa..c9473de7a7 100644 --- a/tmt/steps/provision/__init__.py +++ b/tmt/steps/provision/__init__.py @@ -531,7 +531,7 @@ def normalize_hardware( elif components.name == 'cpu' and components.child_name == 'flag': if components.name not in merged: - merged[components.name] = [] + merged[components.name] = {} if 'flag' not in merged['cpu']: merged['cpu']['flag'] = [] @@ -540,15 +540,12 @@ def normalize_hardware( elif components.child_name: if components.name not in merged: - merged[components.name] = [] + merged[components.name] = {} merged[components.name][components.child_name] = \ f'{components.operator} {components.value}' else: - if components.name not in merged: - merged[components.name] = [] - merged[components.name] = f'{components.operator} {components.value}' # Very crude, we will need something better to handle `and` and