Skip to content

Commit

Permalink
Define Beaker pool HW requirement (teemtee#3058)
Browse files Browse the repository at this point in the history
Related to teemtee#2346
  • Loading branch information
happz authored and The-Mule committed Oct 14, 2024
1 parent 3ea7987 commit 75a9ad1
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
24 changes: 24 additions & 0 deletions spec/hardware/beaker.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
summary: |
Select or provision a guest with Beaker-specific parameters.

description: |
.. code-block::

beaker:
# String, name of the Beaker pool to use for provisioning.
pool: "some-pool"


.. note::

The requirements are consumed by Beaker-aware ``provision``
plugins only, and cannot be enforced in any other
infrastructure.

.. versionadded:: 1.35

example:
- |
# Select any system, as long as it is not from the given Beaker pool
beaker:
pool: "!= very-rare-machines"
1 change: 1 addition & 0 deletions tests/unit/provision/mrack/test_hw.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_maximal_constraint(root_logger: Logger) -> None:

assert result.to_mrack() == {
'and': [
{'or': []},
{'or': []},
{
'and': [
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def test_normalize_invalid_hardware(


FULL_HARDWARE_REQUIREMENTS = """
beaker:
pool: "!= foo.*"
boot:
method: bios
compatible:
Expand Down Expand Up @@ -242,6 +244,7 @@ def test_normalize_invalid_hardware(
def test_parse_maximal_constraint() -> None:
hw_spec_out = """
and:
- beaker.pool: '!= foo.*'
- boot.method: contains bios
- and:
- compatible.distro: contains rhel-7
Expand Down
19 changes: 19 additions & 0 deletions tmt/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,22 @@ def _parse_location(spec: Spec) -> BaseConstraint:
return group


@ungroupify
def _parse_beaker(spec: Spec) -> BaseConstraint:
"""
Parse constraints related to the ``beaker`` HW requirement.
:param spec: raw constraint block specification.
:returns: block representation as :py:class:`BaseConstraint` or one of its subclasses.
"""

group = And()

group.constraints += _parse_text_constraints(spec, 'beaker', ('pool',))

return group


@ungroupify
def _parse_generic_spec(spec: Spec) -> BaseConstraint:
"""
Expand All @@ -1367,6 +1383,9 @@ def _parse_generic_spec(spec: Spec) -> BaseConstraint:
spec['arch'])
]

if 'beaker' in spec:
group.constraints += [_parse_beaker(spec['beaker'])]

if 'boot' in spec:
group.constraints += [_parse_boot(spec['boot'])]

Expand Down
13 changes: 13 additions & 0 deletions tmt/schemas/provision/hardware.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ definitions:
# arch:
# type: string

# HW requirements: single `beaker` item
beaker:
type: object

properties:
pool:
type: string

additionalProperties: false

# enforce at least one property
minProperties: 1

# HW requirements: `boot` block
boot:
type: object
Expand Down

0 comments on commit 75a9ad1

Please sign in to comment.