Skip to content

Commit

Permalink
fix: Translate host_requires properly
Browse files Browse the repository at this point in the history
  • Loading branch information
skycastlelily committed Jan 9, 2025
1 parent bf24bc0 commit c44726b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
39 changes: 39 additions & 0 deletions docs/guides/beaker_hostRequires.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,42 @@ And the result would be following XML:
</and>
<system_type value="Machine"/>
</hostRequires>
Here is an example of Beaker provisioning using hostRequires without and/or:

.. code:: yaml
domains:
- hosts:
#########
# Provisioning c9s
#########
- group: client
name: bkr-c9s-latest.eagle.test
os: c9s
provider: beaker
beaker: # use some beaker specific requirements
hostRequires:
cpu_count:
_value: 1
_op: "="
name: eagle.test
type: linux
This requirement is then translated to XML for the Beaker job, along with other specifics:

.. code:: xml
<distroRequires>
<and>
<distro_name op="like" value="CentOS-Stream-9%"/>
<distro_variant op="=" value="BaseOS"/> // from provisioning config
<distro_arch op="=" value="x86_64"/> // default
<distro_tag op="=" value="RC-0.1"/> // from provisioning config
</and>
</distroRequires>
<hostRequires> // translated `hostRequires` key
<cpu_count value="1" op="="/> // translated `cpu_count`, `_value` and `_op` keys
<system_type value="Machine"/>
</hostRequires>
9 changes: 8 additions & 1 deletion src/mrack/providers/beaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,21 @@ def _req_to_bkr_job(self, req): # pylint: disable=too-many-locals
recipe.addDistroRequires(arch_node)

host_requires = specs.get("hostRequires")
if host_requires: # suppose to be dict like {"or": [dict()], "and": [dict()]}
if host_requires:
for operand, operand_value in host_requires.items():
if operand.startswith("_"):
recipe.node.getElementsByTagName("hostRequires")[0].setAttribute(
operand[1:],
operand_value,
)
continue
if operand not in ["and", "or"]:
req_node = xml_doc().createElement(operand)
req_node = add_dict_to_node(req_node, operand_value)
recipe.node.getElementsByTagName("hostRequires")[0].appendChild(
req_node
)
continue
# known operands are ["and", "or"]
req_node = xml_doc().createElement(operand)
for dct in operand_value:
Expand Down

0 comments on commit c44726b

Please sign in to comment.