mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-15 13:16:29 +00:00
Add share to docker config issue (#4322)
This commit is contained in:
parent
841f68c175
commit
e449205863
@ -387,6 +387,7 @@ class DockerAddon(DockerInterface):
|
|||||||
source=self.sys_config.path_extern_share.as_posix(),
|
source=self.sys_config.path_extern_share.as_posix(),
|
||||||
target="/share",
|
target="/share",
|
||||||
read_only=addon_mapping[MAP_SHARE],
|
read_only=addon_mapping[MAP_SHARE],
|
||||||
|
propagation=PropagationMode.SLAVE.value,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -97,6 +97,7 @@ class DockerHomeAssistant(DockerInterface):
|
|||||||
source=self.sys_config.path_extern_share.as_posix(),
|
source=self.sys_config.path_extern_share.as_posix(),
|
||||||
target="/share",
|
target="/share",
|
||||||
read_only=False,
|
read_only=False,
|
||||||
|
propagation=PropagationMode.SLAVE.value,
|
||||||
),
|
),
|
||||||
Mount(
|
Mount(
|
||||||
type=MountType.BIND.value,
|
type=MountType.BIND.value,
|
||||||
|
@ -14,7 +14,7 @@ def _check_container(container: DockerInterface) -> bool:
|
|||||||
return any(
|
return any(
|
||||||
mount.get("Propagation") != PropagationMode.SLAVE.value
|
mount.get("Propagation") != PropagationMode.SLAVE.value
|
||||||
for mount in container.meta_mounts
|
for mount in container.meta_mounts
|
||||||
if mount.get("Destination") == "/media"
|
if mount.get("Destination") in ["/media", "/share"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,8 +126,20 @@ def test_addon_map_folder_defaults(
|
|||||||
in docker_addon.mounts
|
in docker_addon.mounts
|
||||||
)
|
)
|
||||||
|
|
||||||
# Share not mapped
|
# Share added and propagation set
|
||||||
assert "/share" not in [mount["Target"] for mount in docker_addon.mounts]
|
assert (
|
||||||
|
Mount(
|
||||||
|
type="bind",
|
||||||
|
source=coresys.config.path_extern_share.as_posix(),
|
||||||
|
target="/share",
|
||||||
|
read_only=True,
|
||||||
|
propagation="slave",
|
||||||
|
)
|
||||||
|
in docker_addon.mounts
|
||||||
|
)
|
||||||
|
|
||||||
|
# Backup not added
|
||||||
|
assert "/backup" not in [mount["Target"] for mount in docker_addon.mounts]
|
||||||
|
|
||||||
|
|
||||||
def test_journald_addon(
|
def test_journald_addon(
|
||||||
|
2
tests/fixtures/basic-addon-config.json
vendored
2
tests/fixtures/basic-addon-config.json
vendored
@ -7,7 +7,7 @@
|
|||||||
"url": "https://www.home-assistant.io/",
|
"url": "https://www.home-assistant.io/",
|
||||||
"startup": "application",
|
"startup": "application",
|
||||||
"boot": "auto",
|
"boot": "auto",
|
||||||
"map": ["config:rw", "ssl", "media"],
|
"map": ["config:rw", "ssl", "media", "share"],
|
||||||
"options": {},
|
"options": {},
|
||||||
"schema": {},
|
"schema": {},
|
||||||
"image": "test/{arch}-my-custom-addon"
|
"image": "test/{arch}-my-custom-addon"
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from supervisor.addons.addon import Addon
|
from supervisor.addons.addon import Addon
|
||||||
from supervisor.const import CoreState
|
from supervisor.const import CoreState
|
||||||
from supervisor.coresys import CoreSys
|
from supervisor.coresys import CoreSys
|
||||||
@ -14,24 +16,23 @@ from supervisor.resolution.data import Issue, Suggestion
|
|||||||
from tests.conftest import mock_async_return_true
|
from tests.conftest import mock_async_return_true
|
||||||
|
|
||||||
|
|
||||||
def _make_mock_container_get(bad_config_names: list[str]):
|
def _make_mock_container_get(bad_config_names: list[str], folder: str = "media"):
|
||||||
"""Make mock of container get."""
|
"""Make mock of container get."""
|
||||||
|
mount = {
|
||||||
|
"Type": "bind",
|
||||||
|
"Source": f"/mnt/data/supervisor/{folder}",
|
||||||
|
"Destination": f"/{folder}",
|
||||||
|
"Mode": "rw",
|
||||||
|
"RW": True,
|
||||||
|
"Propagation": "rprivate",
|
||||||
|
}
|
||||||
|
|
||||||
def mock_container_get(name):
|
def mock_container_get(name):
|
||||||
out = MagicMock()
|
out = MagicMock()
|
||||||
out.status = "running"
|
out.status = "running"
|
||||||
out.attrs = {"State": {}, "Mounts": []}
|
out.attrs = {"State": {}, "Mounts": []}
|
||||||
if name in bad_config_names:
|
if name in bad_config_names:
|
||||||
out.attrs["Mounts"].append(
|
out.attrs["Mounts"].append(mount)
|
||||||
{
|
|
||||||
"Type": "bind",
|
|
||||||
"Source": "/mnt/data/supervisor/media",
|
|
||||||
"Destination": "/media",
|
|
||||||
"Mode": "rw",
|
|
||||||
"RW": True,
|
|
||||||
"Propagation": "rprivate",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
@ -45,10 +46,13 @@ async def test_base(coresys: CoreSys):
|
|||||||
assert docker_config.enabled
|
assert docker_config.enabled
|
||||||
|
|
||||||
|
|
||||||
async def test_check(docker: DockerAPI, coresys: CoreSys, install_addon_ssh: Addon):
|
@pytest.mark.parametrize("folder", ["media", "share"])
|
||||||
|
async def test_check(
|
||||||
|
docker: DockerAPI, coresys: CoreSys, install_addon_ssh: Addon, folder: str
|
||||||
|
):
|
||||||
"""Test check reports issue when containers have incorrect config."""
|
"""Test check reports issue when containers have incorrect config."""
|
||||||
docker.containers.get = _make_mock_container_get(
|
docker.containers.get = _make_mock_container_get(
|
||||||
["homeassistant", "hassio_audio", "addon_local_ssh"]
|
["homeassistant", "hassio_audio", "addon_local_ssh"], folder
|
||||||
)
|
)
|
||||||
with patch.object(DockerInterface, "is_running", new=mock_async_return_true):
|
with patch.object(DockerInterface, "is_running", new=mock_async_return_true):
|
||||||
await coresys.plugins.load()
|
await coresys.plugins.load()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user