Skip to content

Commit

Permalink
squash:add normalize_kickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
skycastlelily committed Nov 12, 2024
1 parent 4622974 commit e01d3c7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tmt/steps/provision/mrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ class BeakerGuestData(tmt.steps.provision.GuestSshData):
metavar='KEY=VALUE',
help='Optional Beaker kickstart to use when provisioning the guest.',
multiple=True,
normalize=tmt.utils.normalize_string_dict)
normalize=tmt.utils.normalize_kickstart)

beaker_job_owner: Optional[str] = field(
default=None,
Expand Down
32 changes: 31 additions & 1 deletion tmt/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5589,7 +5589,7 @@ def normalize_adjust(
def normalize_string_dict(
key_address: str,
raw_value: Any,
logger: tmt.log.Logger) -> dict[str, Any]:
logger: tmt.log.Logger) -> dict[str, str]:
"""
Normalize a key/value dictionary.
Expand All @@ -5609,6 +5609,36 @@ def normalize_string_dict(
:param value: input value from key source.
"""

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)):
normalized = {}

for datum in cast(list[str], raw_value):
try:
key, value = datum.split('=', 1)

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

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

return normalized

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


def normalize_kickstart(
key_address: str,
raw_value: Any,
logger: tmt.log.Logger) -> dict[str, Any]:
"""Normalize content of kickstart file."""

if isinstance(raw_value, dict):
return {
str(key).strip(): (value if isinstance(value, (list, dict, tuple))
Expand Down

0 comments on commit e01d3c7

Please sign in to comment.