Skip to content
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
11 changes: 9 additions & 2 deletions src/pushsource/_impl/model/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
from .base import PushItem
from .. import compat_attr as attr
from attr import asdict
from .conv import datestr, instance_of_str, instance_of, optional_str, optional, in_
from .conv import (
convert_maybe,
datestr,
instance_of_str,
instance_of,
optional_str,
optional,
)


class BootMode(enum.Enum):
Expand Down Expand Up @@ -113,7 +120,7 @@ class VMIPushItem(PushItem):
description = attr.ib(type=str, default=None, validator=instance_of_str)
"""A brief human-readable description of the image."""

boot_mode = attr.ib(type=BootMode, default=None, validator=optional(in_(BootMode)))
boot_mode = attr.ib(type=BootMode, default=None, converter=convert_maybe(BootMode))
"""Boot mode supported by the image (if known): uefi, legacy, or hybrid (uefi + legacy)."""

cloud_info = attr.ib(
Expand Down
38 changes: 37 additions & 1 deletion tests/model/test_vmi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from pytest import raises

from pushsource import VMIRelease, VMIPushItem
from pushsource import BootMode, VMIRelease, VMIPushItem


def test_invalidate_datestr():
Expand Down Expand Up @@ -42,3 +43,38 @@ def test_marketplace_title():
name="myname",
)
assert pi.marketplace_title == ""


@pytest.mark.parametrize("boot_mode", [None, "hybrid", "uefi", "legacy"])
def test_bootmode_converter_success(boot_mode):
"""Ensure the BootMode converter works when valid data is given."""

release = VMIRelease(
product="myprod", arch="x86_64", version="7.0", respin=1, date="20240101"
)

pi = VMIPushItem(
description="mydescription", name="myname", release=release, boot_mode=boot_mode
)

if boot_mode:
assert pi.boot_mode == BootMode(boot_mode)
else:
assert not pi.boot_mode


@pytest.mark.parametrize("boot_mode", ["foo", "bar", 12])
def test_bootmode_converter_invalid(boot_mode):
"""Ensure the BootMode converter fails on invalid data."""

release = VMIRelease(
product="myprod", arch="x86_64", version="7.0", respin=1, date="20240101"
)

with raises(ValueError):
VMIPushItem(
description="mydescription",
name="myname",
release=release,
boot_mode=boot_mode,
)