Fix handling with shm and shared /dev (#2499)

* Fix handling with shm and shared /dev

* address commends

* let's share shm
This commit is contained in:
Pascal Vizeli 2021-02-01 14:44:02 +01:00 committed by GitHub
parent 2ad5df420c
commit 657bafd458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 17 deletions

View File

@ -301,11 +301,6 @@ class AddonModel(CoreSysAttributes, ABC):
"""Return static devices of add-on."""
return [Path(node) for node in self.data.get(ATTR_DEVICES, [])]
@property
def tmpfs(self) -> Optional[str]:
"""Return tmpfs of add-on."""
return self.data.get(ATTR_TMPFS)
@property
def environment(self) -> Optional[Dict[str, str]]:
"""Return environment of add-on."""
@ -410,6 +405,11 @@ class AddonModel(CoreSysAttributes, ABC):
"""Return True if the add-on read access to devicetree."""
return self.data[ATTR_DEVICETREE]
@property
def with_tmpfs(self) -> Optional[str]:
"""Return if tmp is in memory of add-on."""
return self.data[ATTR_TMPFS]
@property
def access_auth_api(self) -> bool:
"""Return True if the add-on access to login/auth backend."""

View File

@ -176,6 +176,15 @@ def _migrate_addon_config(protocol=False):
)
config[ATTR_DEVICES] = [line.split(":")[0] for line in config[ATTR_DEVICES]]
# TMPFS 2021-02-01
if ATTR_TMPFS in config and not isinstance(config[ATTR_TMPFS], bool):
if protocol:
_LOGGER.warning(
"Add-on config 'tmpfs' use a deprecated format, new it's only a boolean. Please report this to the maintainer of %s",
name,
)
config[ATTR_TMPFS] = True
return config
return _migrate
@ -221,7 +230,7 @@ _SCHEMA_ADDON_CONFIG = vol.Schema(
vol.Optional(ATTR_HOST_DBUS, default=False): vol.Boolean(),
vol.Optional(ATTR_DEVICES): [str],
vol.Optional(ATTR_UDEV, default=False): vol.Boolean(),
vol.Optional(ATTR_TMPFS): vol.Match(r"^size=(\d)*[kmg](,uid=\d{1,4})?(,rw)?$"),
vol.Optional(ATTR_TMPFS, default=False): vol.Boolean(),
vol.Optional(ATTR_MAP, default=list): [vol.Match(RE_VOLUME)],
vol.Optional(ATTR_ENVIRONMENT): {vol.Match(r"\w*"): str},
vol.Optional(ATTR_PRIVILEGED): [vol.In(PRIVILEGED_ALL)],

View File

@ -92,13 +92,6 @@ class DockerAddon(DockerInterface):
"""Return name of Docker container."""
return f"addon_{self.addon.slug}"
@property
def ipc(self) -> Optional[str]:
"""Return the IPC namespace."""
if self.addon.host_ipc:
return "host"
return None
@property
def full_access(self) -> bool:
"""Return True if full access is enabled."""
@ -196,9 +189,17 @@ class DockerAddon(DockerInterface):
@property
def tmpfs(self) -> Optional[Dict[str, str]]:
"""Return tmpfs for Docker add-on."""
options = self.addon.tmpfs
if options:
return {"/tmpfs": f"{options}"}
tmpfs = {}
if self.addon.with_tmpfs:
tmpfs["/tmpfs"] = ""
if not self.addon.host_ipc:
tmpfs["/dev/shm"] = ""
# Return None if no tmpfs is present
if tmpfs:
return tmpfs
return None
@property
@ -377,7 +378,6 @@ class DockerAddon(DockerInterface):
detach=True,
init=self.addon.default_init,
privileged=self.full_access,
ipc_mode=self.ipc,
stdin_open=self.addon.with_stdin,
network_mode=self.network_mode,
pid_mode=self.pid_mode,

View File

@ -144,6 +144,7 @@ class DockerHomeAssistant(DockerInterface):
ENV_TOKEN: self.sys_homeassistant.supervisor_token,
ENV_TOKEN_HASSIO: self.sys_homeassistant.supervisor_token,
},
tmpfs={"/tmp": ""},
)
self._meta = docker_container.attrs

View File

@ -68,6 +68,17 @@ def test_migration_devices():
assert valid_config["devices"] == ["test", "bla"]
def test_migration_tmpfs():
"""Migrate tmpfs Type."""
config = load_json_fixture("basic-addon-config.json")
config["tmpfs"] = "test:test:rw"
valid_config = vd.SCHEMA_ADDON_CONFIG(config)
assert valid_config["tmpfs"]
def test_invalid_repository():
"""Validate basic config with invalid repositories."""
config = load_json_fixture("basic-addon-config.json")