From 7def3ebf768a8183a4d889a8ad75cc97b42b28fa Mon Sep 17 00:00:00 2001 From: skycastlelily Date: Tue, 29 Oct 2024 23:13:30 +0800 Subject: [PATCH] Support `system.model-name` hardware requirement for `mrack` (#3280) --- docs/releases.rst | 8 ++++++++ spec/hardware/system.fmf | 10 +++++++++- tests/unit/provision/mrack/test_hw.py | 25 ++++++++++++++++++++++++- tmt/steps/provision/mrack.py | 18 ++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/docs/releases.rst b/docs/releases.rst index 8f28b6979a..1a8b74e828 100644 --- a/docs/releases.rst +++ b/docs/releases.rst @@ -5,6 +5,14 @@ ====================== +tmt-1.39.0 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The :ref:`/plugins/provision/beaker` provision plugin gains +support for :ref:`system.model-name` +hardware requirement. + + tmt-1.38.0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/spec/hardware/system.fmf b/spec/hardware/system.fmf index 15b123a9ea..06f9b2e045 100644 --- a/spec/hardware/system.fmf +++ b/spec/hardware/system.fmf @@ -20,12 +20,20 @@ description: | # Integer or string, required number of NUMA nodes. numa-nodes: 2|">= 2" + .. versionchanged:: 1.38 + ``beaker`` plugins supports ``model-name`` + example: - | # Select any system by a given vendor system: vendor-name: "~ HPE" + - | + # Select any system by a given model name + system: + model-name: "~ PowerEdge R750" + - | # Select any HPE system with enough NUMA nodes. system: @@ -34,4 +42,4 @@ example: link: - implemented-by: /tmt/steps/provision/mrack.py - note: "``system.numa-nodes`` only" + note: "``system.numa-nodes`` and ``system.model-name`` only" diff --git a/tests/unit/provision/mrack/test_hw.py b/tests/unit/provision/mrack/test_hw.py index 323ffdcd7b..20e79ba7c4 100644 --- a/tests/unit/provision/mrack/test_hw.py +++ b/tests/unit/provision/mrack/test_hw.py @@ -292,7 +292,14 @@ def test_maximal_constraint(root_logger: Logger) -> None: }, }, }, - {'or': []}, + { + 'system': { + 'model': { + '_op': 'like', + '_value': 'PowerEdge R750', + }, + }, + }, ] }, { @@ -886,3 +893,19 @@ def test_system_numa_nodes(root_logger: Logger) -> None: } } } + + +def test_system_model_name(root_logger: Logger) -> None: + result = _CONSTRAINT_TRANSFORMERS['system.model_name']( + _parse_system({'model-name': '!~ PowerEdge R750.*'}), root_logger) + + assert result.to_mrack() == { + 'not': { + 'system': { + 'model': { + '_op': 'like', + '_value': 'PowerEdge R750%' + } + } + } + } diff --git a/tmt/steps/provision/mrack.py b/tmt/steps/provision/mrack.py index f1cc51c6cb..82bd57ab8b 100644 --- a/tmt/steps/provision/mrack.py +++ b/tmt/steps/provision/mrack.py @@ -579,6 +579,23 @@ def _transform_system_numa_nodes( children=[MrackHWBinOp('numanodes', beaker_operator, actual_value)]) +def _transform_system_model_name( + constraint: tmt.hardware.TextConstraint, + logger: tmt.log.Logger) -> MrackBaseHWElement: + beaker_operator, actual_value, negate = operator_to_beaker_op( + constraint.operator, + str(constraint.value)) + + if negate: + return MrackHWNotGroup(children=[ + MrackHWGroup('system', + children=[MrackHWBinOp('model', beaker_operator, actual_value)]) + ]) + + return MrackHWGroup('system', + children=[MrackHWBinOp('model', beaker_operator, actual_value)]) + + ConstraintTransformer = Callable[[ tmt.hardware.Constraint[Any], tmt.log.Logger], MrackBaseHWElement] @@ -608,6 +625,7 @@ def _transform_system_numa_nodes( 'zcrypt.adapter': _transform_zcrypt_adapter, # type: ignore[dict-item] 'zcrypt.mode': _transform_zcrypt_mode, # type: ignore[dict-item] 'system.numa_nodes': _transform_system_numa_nodes, # type: ignore[dict-item] + 'system.model_name': _transform_system_model_name, # type: ignore[dict-item] 'iommu.is_supported': _transform_iommu_is_supported, # type: ignore[dict-item] }