Skip to content

Commit

Permalink
Add support for kickstart to mrack plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
skycastlelily committed Aug 29, 2024
1 parent db6604b commit 569a5b1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 29 deletions.
3 changes: 3 additions & 0 deletions tmt/schemas/provision/beaker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ properties:
hardware:
$ref: "/schemas/provision/hardware#/definitions/hardware"

kickstart:
$ref: "/schemas/provision/kickstart#/definitions/kickstart"

role:
$ref: "/schemas/common#/definitions/role"

Expand Down
29 changes: 1 addition & 28 deletions tmt/steps/provision/artemis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from tmt.utils import (
ProvisionError,
UpdatableMessage,
_normalize_user_data,
dict_to_yaml,
field,
retry_session,
Expand Down Expand Up @@ -86,34 +87,6 @@
DEFAULT_RETRY_BACKOFF_FACTOR = 1


def _normalize_user_data(
key_address: str,
raw_value: Any,
logger: tmt.log.Logger) -> dict[str, str]:
if isinstance(raw_value, dict):
return {
str(key).strip(): str(value).strip() for key, value in raw_value.items()
}

if isinstance(raw_value, (list, tuple)):
user_data = {}

for datum in raw_value:
try:
key, value = datum.split('=', 1)

except ValueError as exc:
raise tmt.utils.NormalizationError(
key_address, datum, 'a KEY=VALUE string') from exc

user_data[key.strip()] = value.strip()

return user_data

raise tmt.utils.NormalizationError(
key_address, value, 'a dictionary or a list of KEY=VALUE strings')


def _normalize_log_type(
key_address: str,
raw_value: Any,
Expand Down
19 changes: 18 additions & 1 deletion tmt/steps/provision/mrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
import tmt.steps
import tmt.steps.provision
import tmt.utils
from tmt.utils import Command, ProvisionError, ShellScript, UpdatableMessage, field
from tmt.utils import (
Command,
ProvisionError,
ShellScript,
UpdatableMessage,
_normalize_user_data,
field,
)

mrack: Any
providers: Any
Expand Down Expand Up @@ -678,6 +685,7 @@ def create_host_requirement(self, host: dict[str, Any]) -> dict[str, Any]:
hardware = cast(Optional[tmt.hardware.Hardware], host.get('hardware'))
if hardware and hardware.constraint:
host.update({"beaker": self._translate_tmt_hw(hardware)})
host["beaker"]["ks_append"] = host.get('kickstart')
req: dict[str, Any] = super().create_host_requirement(host)
whiteboard = host.get("whiteboard", host.get("tmt_name", req.get("whiteboard")))
req.update({"whiteboard": whiteboard})
Expand Down Expand Up @@ -754,6 +762,13 @@ class BeakerGuestData(tmt.steps.provision.GuestSshData):
{DEFAULT_API_SESSION_REFRESH} seconds by default.
""",
normalize=tmt.utils.normalize_int)
kickstart: dict[str, str] = field(
default_factory=dict,
option='--kickstart',
metavar='KEY=VALUE',
help='Optional Beaker kickstart to use when provisioning the guest.',
multiple=True,
normalize=_normalize_user_data)


@dataclasses.dataclass
Expand Down Expand Up @@ -879,6 +894,7 @@ class GuestBeaker(tmt.steps.provision.GuestSsh):
arch: str
image: str = "fedora-latest"
hardware: Optional[tmt.hardware.Hardware] = None
kickstart: dict[str, str]

# Provided in Beaker response
job_id: Optional[str]
Expand Down Expand Up @@ -952,6 +968,7 @@ def _create(self, tmt_name: str) -> None:
'name': f'{self.image}-{self.arch}',
'os': self.image,
'group': 'linux',
'kickstart': self.kickstart,
}

if self.whiteboard is not None:
Expand Down
28 changes: 28 additions & 0 deletions tmt/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,34 @@
from tmt._compat.typing import Self, TypeAlias


def _normalize_user_data(
key_address: str,
raw_value: Any,
logger: tmt.log.Logger) -> dict[str, str]:
if isinstance(raw_value, dict):
return {
str(key).strip(): str(value).strip() for key, value in raw_value.items()
}

if isinstance(raw_value, (list, tuple)):
user_data = {}

for datum in raw_value:
try:
key, value = datum.split('=', 1)

except ValueError as exc:
raise tmt.utils.NormalizationError(
key_address, datum, 'a KEY=VALUE string') from exc

user_data[key.strip()] = value.strip()

return user_data

raise tmt.utils.NormalizationError(
key_address, value, 'a dictionary or a list of KEY=VALUE strings')


def configure_optional_constant(default: Optional[int], envvar: str) -> Optional[int]:
"""
Deduce the actual value of a global constant which may be left unset.
Expand Down

0 comments on commit 569a5b1

Please sign in to comment.