mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-13 12:16:29 +00:00
Support to exclude machine (#1835)
* Support to exclude machine * add tests
This commit is contained in:
parent
5fdc340e58
commit
adb39ca93f
@ -535,7 +535,9 @@ class AddonModel(CoreSysAttributes, ABC):
|
|||||||
|
|
||||||
# Machine / Hardware
|
# Machine / Hardware
|
||||||
machine = config.get(ATTR_MACHINE)
|
machine = config.get(ATTR_MACHINE)
|
||||||
if machine and self.sys_machine not in machine:
|
if machine and f"!{self.sys_machine}" in machine:
|
||||||
|
return False
|
||||||
|
elif machine and self.sys_machine not in machine:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Home Assistant
|
# Home Assistant
|
||||||
|
@ -120,7 +120,10 @@ V_LIST = "list"
|
|||||||
|
|
||||||
RE_SCHEMA_ELEMENT = re.compile(
|
RE_SCHEMA_ELEMENT = re.compile(
|
||||||
r"^(?:"
|
r"^(?:"
|
||||||
r"|bool|email|url|port"
|
r"|bool"
|
||||||
|
r"|email"
|
||||||
|
r"|url"
|
||||||
|
r"|port"
|
||||||
r"|str(?:\((?P<s_min>\d+)?,(?P<s_max>\d+)?\))?"
|
r"|str(?:\((?P<s_min>\d+)?,(?P<s_max>\d+)?\))?"
|
||||||
r"|password(?:\((?P<p_min>\d+)?,(?P<p_max>\d+)?\))?"
|
r"|password(?:\((?P<p_min>\d+)?,(?P<p_max>\d+)?\))?"
|
||||||
r"|int(?:\((?P<i_min>\d+)?,(?P<i_max>\d+)?\))?"
|
r"|int(?:\((?P<i_min>\d+)?,(?P<i_max>\d+)?\))?"
|
||||||
@ -148,24 +151,25 @@ RE_DOCKER_IMAGE_BUILD = re.compile(
|
|||||||
|
|
||||||
SCHEMA_ELEMENT = vol.Match(RE_SCHEMA_ELEMENT)
|
SCHEMA_ELEMENT = vol.Match(RE_SCHEMA_ELEMENT)
|
||||||
|
|
||||||
|
RE_MACHINE = re.compile(
|
||||||
MACHINE_ALL = [
|
r"^!?(?:"
|
||||||
"intel-nuc",
|
r"|intel-nuc"
|
||||||
"odroid-c2",
|
r"|odroid-c2"
|
||||||
"odroid-n2",
|
r"|odroid-n2"
|
||||||
"odroid-xu",
|
r"|odroid-xu"
|
||||||
"qemuarm-64",
|
r"|qemuarm-64"
|
||||||
"qemuarm",
|
r"|qemuarm"
|
||||||
"qemux86-64",
|
r"|qemux86-64"
|
||||||
"qemux86",
|
r"|qemux86"
|
||||||
"raspberrypi",
|
r"|raspberrypi"
|
||||||
"raspberrypi2",
|
r"|raspberrypi2"
|
||||||
"raspberrypi3-64",
|
r"|raspberrypi3-64"
|
||||||
"raspberrypi3",
|
r"|raspberrypi3"
|
||||||
"raspberrypi4-64",
|
r"|raspberrypi4-64"
|
||||||
"raspberrypi4",
|
r"|raspberrypi4"
|
||||||
"tinker",
|
r"|tinker"
|
||||||
]
|
r")$"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _simple_startup(value) -> str:
|
def _simple_startup(value) -> str:
|
||||||
@ -185,7 +189,7 @@ SCHEMA_ADDON_CONFIG = vol.Schema(
|
|||||||
vol.Required(ATTR_SLUG): vol.Coerce(str),
|
vol.Required(ATTR_SLUG): vol.Coerce(str),
|
||||||
vol.Required(ATTR_DESCRIPTON): vol.Coerce(str),
|
vol.Required(ATTR_DESCRIPTON): vol.Coerce(str),
|
||||||
vol.Required(ATTR_ARCH): [vol.In(ARCH_ALL)],
|
vol.Required(ATTR_ARCH): [vol.In(ARCH_ALL)],
|
||||||
vol.Optional(ATTR_MACHINE): [vol.In(MACHINE_ALL)],
|
vol.Optional(ATTR_MACHINE): vol.All([vol.Match(RE_MACHINE)], vol.Unique()),
|
||||||
vol.Optional(ATTR_URL): vol.Url(),
|
vol.Optional(ATTR_URL): vol.Url(),
|
||||||
vol.Required(ATTR_STARTUP): vol.All(_simple_startup, vol.Coerce(AddonStartup)),
|
vol.Required(ATTR_STARTUP): vol.All(_simple_startup, vol.Coerce(AddonStartup)),
|
||||||
vol.Required(ATTR_BOOT): vol.In([BOOT_AUTO, BOOT_MANUAL]),
|
vol.Required(ATTR_BOOT): vol.In([BOOT_AUTO, BOOT_MANUAL]),
|
||||||
|
@ -70,3 +70,87 @@ def test_valid_basic_build():
|
|||||||
config = load_json_fixture("basic-build-config.json")
|
config = load_json_fixture("basic-build-config.json")
|
||||||
|
|
||||||
vd.SCHEMA_BUILD_CONFIG(config)
|
vd.SCHEMA_BUILD_CONFIG(config)
|
||||||
|
|
||||||
|
|
||||||
|
def test_valid_machine():
|
||||||
|
"""Validate valid machine config."""
|
||||||
|
config = load_json_fixture("basic-addon-config.json")
|
||||||
|
|
||||||
|
config["machine"] = [
|
||||||
|
"intel-nuc",
|
||||||
|
"odroid-c2",
|
||||||
|
"odroid-n2",
|
||||||
|
"odroid-xu",
|
||||||
|
"qemuarm-64",
|
||||||
|
"qemuarm",
|
||||||
|
"qemux86-64",
|
||||||
|
"qemux86",
|
||||||
|
"raspberrypi",
|
||||||
|
"raspberrypi2",
|
||||||
|
"raspberrypi3-64",
|
||||||
|
"raspberrypi3",
|
||||||
|
"raspberrypi4-64",
|
||||||
|
"raspberrypi4",
|
||||||
|
"tinker",
|
||||||
|
]
|
||||||
|
|
||||||
|
assert vd.SCHEMA_ADDON_CONFIG(config)
|
||||||
|
|
||||||
|
config["machine"] = [
|
||||||
|
"!intel-nuc",
|
||||||
|
"!odroid-c2",
|
||||||
|
"!odroid-n2",
|
||||||
|
"!odroid-xu",
|
||||||
|
"!qemuarm-64",
|
||||||
|
"!qemuarm",
|
||||||
|
"!qemux86-64",
|
||||||
|
"!qemux86",
|
||||||
|
"!raspberrypi",
|
||||||
|
"!raspberrypi2",
|
||||||
|
"!raspberrypi3-64",
|
||||||
|
"!raspberrypi3",
|
||||||
|
"!raspberrypi4-64",
|
||||||
|
"!raspberrypi4",
|
||||||
|
"!tinker",
|
||||||
|
]
|
||||||
|
|
||||||
|
assert vd.SCHEMA_ADDON_CONFIG(config)
|
||||||
|
|
||||||
|
config["machine"] = [
|
||||||
|
"odroid-n2",
|
||||||
|
"!odroid-xu",
|
||||||
|
"qemuarm-64",
|
||||||
|
"!qemuarm",
|
||||||
|
"qemux86-64",
|
||||||
|
"qemux86",
|
||||||
|
"raspberrypi",
|
||||||
|
"raspberrypi4-64",
|
||||||
|
"raspberrypi4",
|
||||||
|
"!tinker",
|
||||||
|
]
|
||||||
|
|
||||||
|
assert vd.SCHEMA_ADDON_CONFIG(config)
|
||||||
|
|
||||||
|
|
||||||
|
def test_invalid_machine():
|
||||||
|
"""Validate invalid machine config."""
|
||||||
|
config = load_json_fixture("basic-addon-config.json")
|
||||||
|
|
||||||
|
config["machine"] = [
|
||||||
|
"intel-nuc",
|
||||||
|
"raspberrypi3",
|
||||||
|
"raspberrypi4-64",
|
||||||
|
"raspberrypi4",
|
||||||
|
"tinkerxy",
|
||||||
|
]
|
||||||
|
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
assert vd.SCHEMA_ADDON_CONFIG(config)
|
||||||
|
|
||||||
|
config["machine"] = [
|
||||||
|
"intel-nuc",
|
||||||
|
"intel-nuc",
|
||||||
|
]
|
||||||
|
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
assert vd.SCHEMA_ADDON_CONFIG(config)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user