Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support location.lab-controller hw requirement for mrack #2927

Merged
merged 5 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions spec/hardware/location.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ description: |

example:
- |
# Select a system that is not managed by deprecated lab controllers
# Select a system that is not managed lab-01.foo.bar.com lab controller
location:
lab-controller: "!~ deprecated-lab-.*.foo.bar.com"
lab-controller: "!= lab-01.foo.bar.com"

link:
- implemented-by: /tmt/steps/provision/mrack.py
note: "``==`` and ``!=`` operators only"
34 changes: 32 additions & 2 deletions tests/unit/provision/mrack/test_hw.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
_parse_cpu,
_parse_disk,
_parse_hostname,
_parse_location,
_parse_memory,
_parse_virtualization,
_parse_zcrypt,
Expand Down Expand Up @@ -225,7 +226,12 @@ def test_maximal_constraint(root_logger: Logger) -> None:
'_value': '%.foo.redhat.com'
}
},
{'or': []},
{
'labcontroller': {
'_op': '!=',
'_value': 'lab-1.bar.redhat.com'
}
},
{
'and': [
{'or': []},
Expand Down Expand Up @@ -280,7 +286,8 @@ def test_maximal_constraint(root_logger: Logger) -> None:
}
}
]
}
},

]
}

Expand Down Expand Up @@ -675,3 +682,26 @@ def test_zcrypt_mode(root_logger: Logger) -> None:
}
}
}


def test_location_lab_controller(root_logger: Logger) -> None:

result = _CONSTRAINT_TRANSFORMERS['location.lab_controller'](
_parse_location({"lab-controller": "lab-01.bar.redhat.com"}), root_logger)

assert result.to_mrack() == {
'labcontroller': {
'_op': '==',
'_value': 'lab-01.bar.redhat.com'
}
}

result = _CONSTRAINT_TRANSFORMERS['location.lab_controller'](
_parse_location({"lab-controller": "!= lab-01.bar.redhat.com"}), root_logger)

assert result.to_mrack() == {
'labcontroller': {
'_op': '!=',
'_value': 'lab-01.bar.redhat.com'
}
}
22 changes: 22 additions & 0 deletions tmt/steps/provision/mrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,27 @@ def _transform_zcrypt_mode(
children=[MrackHWKeyValue('ZCRYPT_MODE', beaker_operator, actual_value)])


def _transform_location_lab_controller(
constraint: tmt.hardware.TextConstraint,
logger: tmt.log.Logger) -> MrackBaseHWElement:
if constraint.operator not in [tmt.hardware.Operator.EQ, tmt.hardware.Operator.NEQ]:
raise ProvisionError(
f"Cannot apply hardware requirement '{constraint}', operator not supported.")
beaker_operator, actual_value, negate = operator_to_beaker_op(
constraint.operator,
constraint.value)

if negate:
return MrackHWNotGroup(children=[
MrackHWBinOp('labcontroller', beaker_operator, actual_value)
])

return MrackHWBinOp(
'labcontroller',
beaker_operator,
actual_value)


ConstraintTransformer = Callable[[
tmt.hardware.Constraint[Any], tmt.log.Logger], MrackBaseHWElement]

Expand All @@ -446,6 +467,7 @@ def _transform_zcrypt_mode(
'disk.model_name': _transform_disk_model_name, # type: ignore[dict-item]
'disk.size': _transform_disk_size, # type: ignore[dict-item]
'hostname': _transform_hostname, # type: ignore[dict-item]
'location.lab_controller': _transform_location_lab_controller, # type: ignore[dict-item]
'memory': _transform_memory, # type: ignore[dict-item]
'virtualization.is_virtualized':
_transform_virtualization_is_virtualized, # type: ignore[dict-item]
Expand Down
Loading