mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-05-03 01:18:39 +00:00

* Next generation hardware handling * need daemon for some details * fix tests * fix wrong coresys lookup * test initial import * test device lookup * validate if device exists * Add cgroups rules manager * mapping udev from host * Modify validation/options handling * lookup devices * add support for host udev mapping * next * Add policy support to add-ons * Depricate hardware trigger call * next cleanup round * detect USB linking * optimize * readd udev utils for backwards compatibility * fix tests * Add more tests * fix tests * Make device explicit * Add filter * work on tests * Add migration step * clean out auto_uart * Fix all tests * Expose all device information * small improvment * Fix loop over right devices * Use migration for new device format * Update rootfs/etc/cont-init.d/udev.sh Co-authored-by: Franck Nijhof <git@frenck.dev> * Fix old helper * Fix API * add helper for by-id * fix tests * Fix serial helper * Fix hardware API schema * Hide some virtual devices from tracking * Apply suggestions from code review Co-authored-by: Stefan Agner <stefan@agner.ch> * Update supervisor/addons/validate.py Co-authored-by: Stefan Agner <stefan@agner.ch> * Update supervisor/addons/validate.py Co-authored-by: Stefan Agner <stefan@agner.ch> * fix lint * Apply suggestions from code review Co-authored-by: Joakim Sørensen <joasoe@gmail.com> * Apply suggestions from code review Co-authored-by: Joakim Sørensen <joasoe@gmail.com> * fix black * fix lint Co-authored-by: Franck Nijhof <git@frenck.dev> Co-authored-by: Stefan Agner <stefan@agner.ch> Co-authored-by: Joakim Sørensen <joasoe@gmail.com>
210 lines
5.1 KiB
Python
210 lines
5.1 KiB
Python
"""Validate Add-on configs."""
|
|
|
|
import pytest
|
|
import voluptuous as vol
|
|
|
|
from supervisor.addons import validate as vd
|
|
|
|
from ..common import load_json_fixture
|
|
|
|
|
|
def test_basic_config():
|
|
"""Validate basic config and check the default values."""
|
|
config = load_json_fixture("basic-addon-config.json")
|
|
|
|
valid_config = vd.SCHEMA_ADDON_CONFIG(config)
|
|
|
|
assert valid_config["name"] == "Test Add-on"
|
|
assert valid_config["image"] == "test/{arch}-my-custom-addon"
|
|
|
|
# Check defaults
|
|
assert not valid_config["host_network"]
|
|
assert not valid_config["host_ipc"]
|
|
assert not valid_config["host_dbus"]
|
|
assert not valid_config["host_pid"]
|
|
|
|
assert not valid_config["hassio_api"]
|
|
assert not valid_config["homeassistant_api"]
|
|
assert not valid_config["docker_api"]
|
|
|
|
|
|
def test_migration_startup():
|
|
"""Migrate Startup Type."""
|
|
config = load_json_fixture("basic-addon-config.json")
|
|
|
|
config["startup"] = "before"
|
|
|
|
valid_config = vd.SCHEMA_ADDON_CONFIG(config)
|
|
|
|
assert valid_config["startup"].value == "services"
|
|
|
|
config["startup"] = "after"
|
|
|
|
valid_config = vd.SCHEMA_ADDON_CONFIG(config)
|
|
|
|
assert valid_config["startup"].value == "application"
|
|
|
|
|
|
def test_migration_auto_uart():
|
|
"""Migrate auto uart Type."""
|
|
config = load_json_fixture("basic-addon-config.json")
|
|
|
|
config["auto_uart"] = True
|
|
|
|
valid_config = vd.SCHEMA_ADDON_CONFIG(config)
|
|
|
|
assert valid_config["uart"]
|
|
assert "auto_uart" not in valid_config
|
|
|
|
|
|
def test_migration_devices():
|
|
"""Migrate devices Type."""
|
|
config = load_json_fixture("basic-addon-config.json")
|
|
|
|
config["devices"] = ["test:test:rw", "bla"]
|
|
|
|
valid_config = vd.SCHEMA_ADDON_CONFIG(config)
|
|
|
|
assert valid_config["devices"] == ["test", "bla"]
|
|
|
|
|
|
def test_invalid_repository():
|
|
"""Validate basic config with invalid repositories."""
|
|
config = load_json_fixture("basic-addon-config.json")
|
|
|
|
config["image"] = "something"
|
|
with pytest.raises(vol.Invalid):
|
|
vd.SCHEMA_ADDON_CONFIG(config)
|
|
|
|
config["image"] = "homeassistant/no-valid-repo:no-tag-allow"
|
|
with pytest.raises(vol.Invalid):
|
|
vd.SCHEMA_ADDON_CONFIG(config)
|
|
|
|
config[
|
|
"image"
|
|
] = "registry.gitlab.com/company/add-ons/test-example/text-example:no-tag-allow"
|
|
with pytest.raises(vol.Invalid):
|
|
vd.SCHEMA_ADDON_CONFIG(config)
|
|
|
|
|
|
def test_valid_repository():
|
|
"""Validate basic config with different valid repositories."""
|
|
config = load_json_fixture("basic-addon-config.json")
|
|
|
|
custom_registry = "registry.gitlab.com/company/add-ons/core/test-example"
|
|
config["image"] = custom_registry
|
|
valid_config = vd.SCHEMA_ADDON_CONFIG(config)
|
|
assert valid_config["image"] == custom_registry
|
|
|
|
|
|
def test_valid_map():
|
|
"""Validate basic config with different valid maps."""
|
|
config = load_json_fixture("basic-addon-config.json")
|
|
|
|
config["map"] = ["backup:rw", "ssl:ro", "config"]
|
|
vd.SCHEMA_ADDON_CONFIG(config)
|
|
|
|
|
|
def test_valid_basic_build():
|
|
"""Validate basic build config."""
|
|
config = load_json_fixture("basic-build-config.json")
|
|
|
|
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)
|
|
|
|
|
|
def test_watchdog_url():
|
|
"""Test Valid watchdog options."""
|
|
config = load_json_fixture("basic-addon-config.json")
|
|
|
|
for test_options in (
|
|
"tcp://[HOST]:[PORT:8123]",
|
|
"http://[HOST]:[PORT:8080]/health",
|
|
"https://[HOST]:[PORT:80]/",
|
|
):
|
|
config["watchdog"] = test_options
|
|
assert vd.SCHEMA_ADDON_CONFIG(config)
|