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

Translate Or constraint properly for mrack #3327

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions tests/unit/test_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,18 @@ def test_parse_maximal_constraint() -> None:
print(textwrap.dedent(hw_spec_out))

assert tmt.utils.dict_to_yaml(hw.constraint.to_spec()) == textwrap.dedent(hw_spec_out).lstrip()

def test_parse_or_constraint() -> None:
hw_spec_out = """
or:
- hostname: == dummy1.redhat.com
- hostname: == dummy2.redhat.com
"""
or_hardware_requirements = """
or:
- hostname: dummy1.redhat.com
- hostname: dummy2.redhat.com
"""
hw = parse_hw(or_hardware_requirements)
assert tmt.utils.dict_to_yaml(
hw.constraint.to_spec()) == textwrap.dedent(hw_spec_out).lstrip()
11 changes: 5 additions & 6 deletions tmt/steps/provision/mrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,11 @@ def _translate_tmt_hw(self, hw: tmt.hardware.Hardware) -> dict[str, Any]:
""" Return hw requirements from given hw dictionary """

assert hw.constraint

transformed = MrackHWAndGroup(
children=[
constraint_to_beaker_filter(constraint, logger)
for constraint in hw.constraint.variant()
])
# Beaker,unlike instance-type-based infrastructures like AWS, does
# have the actual filtering, and can express `or` and `and`
# groups. And our `constraint_to_beaker_filter()` does that,
# even for groups nested deeper in the tree.
transformed = constraint_to_beaker_filter(hw.constraint, logger)

logger.debug('Transformed hardware', tmt.utils.dict_to_yaml(transformed.to_mrack()))

Expand Down