Skip to content

Commit

Permalink
refactor(beaker): move distro_tags and hostRequires to transformer
Browse files Browse the repository at this point in the history
From provider as transformer is the component which should work with
provisioning config.

Also remove the mrack_beaker from specs as it is no longer needed.

Signed-off-by: Petr Vobornik <[email protected]>
  • Loading branch information
pvoborni authored and Tiboris committed Sep 20, 2022
1 parent 64cfa3a commit 7a8bd24
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
11 changes: 3 additions & 8 deletions src/mrack/providers/beaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from bkr.common.hub import HubProxy
from bkr.common.pyconfig import PyConfigParser

from mrack.context import global_context
from mrack.errors import ProvisioningError, ValidationError
from mrack.host import (
STATUS_ACTIVE,
Expand Down Expand Up @@ -155,11 +154,7 @@ def _req_to_bkr_job(self, req): # pylint: disable=too-many-locals
arch_node.setAttribute("value", specs["arch"])
recipe.addDistroRequires(arch_node)

host_requires = global_context.PROV_CONFIG[PROVISIONER_KEY].get(
"hostRequires",
specs.get(f"mrack_{PROVISIONER_KEY}", {}).get("hostRequires", {}),
)

host_requires = specs.get("hostRequires")
if host_requires: # suppose to be dict like {"or": [dict()], "and": [dict()]}
for operand, operand_value in host_requires.items():
if operand.startswith("_"):
Expand All @@ -178,9 +173,9 @@ def _req_to_bkr_job(self, req): # pylint: disable=too-many-locals
)

# Specify the custom xml distro_tag node with values from provisioning config
distro_tags = global_context.PROV_CONFIG["beaker"].get("distro_tags")
distro_tags = specs.get("distro_tags")
if distro_tags:
for tag in distro_tags.get(specs["distro"], []):
for tag in distro_tags:
tag_node = xml_doc().createElement("distro_tag")
tag_node.setAttribute("op", "=")
tag_node.setAttribute("value", tag)
Expand Down
16 changes: 15 additions & 1 deletion src/mrack/transformers/beaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,21 @@ def create_host_requirement(self, host):
),
self._get_pubkeys(host),
),
f"mrack_{CONFIG_KEY}": host.get(CONFIG_KEY, {}),
# TODO: should have similar logic as _get_flavor
"hostRequires": self._find_value(
host.get(CONFIG_KEY, {}),
"hostRequires",
"hostRequires",
host["group"],
default=None,
),
"distro_tags": self._find_value(
host.get(CONFIG_KEY, {}),
"distro_tags",
"distro_tags",
distro,
default=[],
),
}

return specs

0 comments on commit 7a8bd24

Please sign in to comment.