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

fix: Translate host_requires properly #305

Merged
merged 1 commit into from
Jan 9, 2025
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
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
Loading