From c44726b53c74284e47fdf9a0e1929aa6d352a60f Mon Sep 17 00:00:00 2001 From: lnie Date: Wed, 8 Jan 2025 06:12:07 -0500 Subject: [PATCH] fix: Translate host_requires properly --- docs/guides/beaker_hostRequires.rst | 39 +++++++++++++++++++++++++++++ src/mrack/providers/beaker.py | 9 ++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/docs/guides/beaker_hostRequires.rst b/docs/guides/beaker_hostRequires.rst index 4bb04a55..21c7aec2 100644 --- a/docs/guides/beaker_hostRequires.rst +++ b/docs/guides/beaker_hostRequires.rst @@ -139,3 +139,42 @@ And the result would be following XML: + +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 + + + + + // from provisioning config + // default + // from provisioning config + + + // translated `hostRequires` key + // translated `cpu_count`, `_value` and `_op` keys + + diff --git a/src/mrack/providers/beaker.py b/src/mrack/providers/beaker.py index 0fc6e7c4..c1de721b 100644 --- a/src/mrack/providers/beaker.py +++ b/src/mrack/providers/beaker.py @@ -174,7 +174,7 @@ 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( @@ -182,6 +182,13 @@ def _req_to_bkr_job(self, req): # pylint: disable=too-many-locals 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: