From 938d8bc767ee77845c70fa8db6b3bce4dd0b8b47 Mon Sep 17 00:00:00 2001 From: skycastlelily Date: Fri, 15 Nov 2024 17:17:20 +0800 Subject: [PATCH] Support `cpu.frequency` hardware requirement for ``mrack`` (#3297) --- docs/releases.rst | 5 +++-- spec/hardware/cpu.fmf | 6 +++--- tests/unit/provision/mrack/test_hw.py | 9 ++++++++- tmt/hardware.py | 2 +- tmt/steps/provision/mrack.py | 13 +++++++++++++ 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/docs/releases.rst b/docs/releases.rst index 57cc57ca02..e5b5075d88 100644 --- a/docs/releases.rst +++ b/docs/releases.rst @@ -10,8 +10,9 @@ tmt-1.39.0 The :ref:`/plugins/provision/beaker` provision plugin gains support for :ref:`system.model-name`, -:ref:`system.vendor-name` and -:ref:`cpu.family` hardware requirements. +:ref:`system.vendor-name`, +:ref:`cpu.family` and +:ref:`cpu.frequency` hardware requirements. The ``tmt lint`` command now reports a failure if empty environment files are found. diff --git a/spec/hardware/cpu.fmf b/spec/hardware/cpu.fmf index 046234779b..dc00d78595 100644 --- a/spec/hardware/cpu.fmf +++ b/spec/hardware/cpu.fmf @@ -70,7 +70,7 @@ description: | are also useful resources. .. versionchanged:: 1.39 - ``beaker`` plugins supports ``family`` + ``beaker`` plugins supports ``family`` and ``frequency`` .. versionchanged:: 1.38 ``beaker`` plugins supports ``stepping`` @@ -125,8 +125,8 @@ example: link: - implemented-by: /tmt/steps/provision/artemis.py - note: "``cpu.vendor``, ``cpu.vendor-name`` and ``cpu.hyper-threading`` not implemented yet" + note: "``cpu.vendor``, ``cpu.vendor-name``, ``cpu.frequency`` and ``cpu.hyper-threading`` not implemented yet" - implemented-by: /tmt/steps/provision/mrack.py - note: "``cpu.flag``, ``cpu.processors``, ``cpu.model``, ``cpu.cores``, ``cpu.model-name``, ``cpu.hyper-threading``, ``cpu.stepping``, ``cpu.family`` and ``cpu.vendor-name`` only" + note: "``cpu.sockets``, ``cpu.threads``, ``cpu.cores-per-socket``, ``cpu.threads-per-core``, ``cpu.family-name``, ``cpu.vendor`` not implemented yet" - implemented-by: /tmt/steps/provision/testcloud.py note: "``cpu.processors`` only" diff --git a/tests/unit/provision/mrack/test_hw.py b/tests/unit/provision/mrack/test_hw.py index 2ce6b5dea3..2ade60d5e9 100644 --- a/tests/unit/provision/mrack/test_hw.py +++ b/tests/unit/provision/mrack/test_hw.py @@ -115,7 +115,14 @@ def test_maximal_constraint(root_logger: Logger) -> None: }, }, }, - {'or': []}, + { + 'cpu': { + 'speed': { + '_op': '>=', + '_value': '2300.0', + }, + }, + }, {'or': []}, { 'not': diff --git a/tmt/hardware.py b/tmt/hardware.py index 8446950b74..837efa7f92 100644 --- a/tmt/hardware.py +++ b/tmt/hardware.py @@ -737,7 +737,7 @@ def _cast_int(raw_value: Any) -> int: ) -class NumberConstraint(Constraint[float]): +class NumberConstraint(Constraint['Quantity']): """ A constraint representing a float number """ @classmethod diff --git a/tmt/steps/provision/mrack.py b/tmt/steps/provision/mrack.py index 967c1d069d..fffe4e1557 100644 --- a/tmt/steps/provision/mrack.py +++ b/tmt/steps/provision/mrack.py @@ -309,6 +309,18 @@ def _transform_cpu_model_name( children=[MrackHWBinOp('model_name', beaker_operator, actual_value)]) +def _transform_cpu_frequency( + constraint: tmt.hardware.NumberConstraint, + logger: tmt.log.Logger) -> MrackBaseHWElement: + beaker_operator, actual_value, _ = operator_to_beaker_op( + constraint.operator, + str(float(constraint.value.to('MHz').magnitude))) + + return MrackHWGroup( + 'cpu', + children=[MrackHWBinOp('speed', beaker_operator, actual_value)]) + + def _transform_cpu_stepping( constraint: tmt.hardware.IntegerConstraint, logger: tmt.log.Logger) -> MrackBaseHWElement: @@ -633,6 +645,7 @@ def _transform_system_vendor_name( 'cpu.cores': _transform_cpu_cores, # type: ignore[dict-item] 'cpu.family': _transform_cpu_family, # type: ignore[dict-item] 'cpu.flag': _transform_cpu_flag, # type: ignore[dict-item] + 'cpu.frequency': _transform_cpu_frequency, # type: ignore[dict-item] 'cpu.hyper_threading': _transform_cpu_hyper_threading, # type: ignore[dict-item] 'cpu.model': _transform_cpu_model, # type: ignore[dict-item] 'cpu.model_name': _transform_cpu_model_name, # type: ignore[dict-item]