mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-15 13:16:29 +00:00
Fix journald add-on option to work with default Debian (#2742)
This commit is contained in:
parent
bedb37ca6b
commit
2a892544c2
@ -27,7 +27,8 @@ MACHINE_ID = Path("/etc/machine-id")
|
|||||||
SOCKET_DBUS = Path("/run/dbus/system_bus_socket")
|
SOCKET_DBUS = Path("/run/dbus/system_bus_socket")
|
||||||
SOCKET_DOCKER = Path("/run/docker.sock")
|
SOCKET_DOCKER = Path("/run/docker.sock")
|
||||||
RUN_SUPERVISOR_STATE = Path("/run/supervisor")
|
RUN_SUPERVISOR_STATE = Path("/run/supervisor")
|
||||||
SYSTEMD_JOURNAL = Path("/var/logs/journal")
|
SYSTEMD_JOURNAL_PERSISTENT = Path("/var/logs/journal")
|
||||||
|
SYSTEMD_JOURNAL_VOLATILE = Path("/run/log/journal")
|
||||||
|
|
||||||
DOCKER_NETWORK = "hassio"
|
DOCKER_NETWORK = "hassio"
|
||||||
DOCKER_NETWORK_MASK = ip_network("172.30.32.0/23")
|
DOCKER_NETWORK_MASK = ip_network("172.30.32.0/23")
|
||||||
|
@ -26,7 +26,8 @@ from ..const import (
|
|||||||
MAP_SSL,
|
MAP_SSL,
|
||||||
SECURITY_DISABLE,
|
SECURITY_DISABLE,
|
||||||
SECURITY_PROFILE,
|
SECURITY_PROFILE,
|
||||||
SYSTEMD_JOURNAL,
|
SYSTEMD_JOURNAL_PERSISTENT,
|
||||||
|
SYSTEMD_JOURNAL_VOLATILE,
|
||||||
)
|
)
|
||||||
from ..coresys import CoreSys
|
from ..coresys import CoreSys
|
||||||
from ..exceptions import CoreDNSError, DockerError, DockerNotFound, HardwareNotFound
|
from ..exceptions import CoreDNSError, DockerError, DockerNotFound, HardwareNotFound
|
||||||
@ -416,10 +417,15 @@ class DockerAddon(DockerInterface):
|
|||||||
|
|
||||||
# System Journal access
|
# System Journal access
|
||||||
if self.addon.with_journald:
|
if self.addon.with_journald:
|
||||||
|
# Systemd uses volatile by default, unless persistent location exists.
|
||||||
|
bind = SYSTEMD_JOURNAL_VOLATILE
|
||||||
|
if SYSTEMD_JOURNAL_PERSISTENT.exists():
|
||||||
|
bind = SYSTEMD_JOURNAL_PERSISTENT
|
||||||
|
|
||||||
volumes.update(
|
volumes.update(
|
||||||
{
|
{
|
||||||
str(SYSTEMD_JOURNAL): {
|
str(SYSTEMD_JOURNAL_PERSISTENT): {
|
||||||
"bind": str(SYSTEMD_JOURNAL),
|
"bind": str(bind),
|
||||||
"mode": "ro",
|
"mode": "ro",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import pytest
|
|||||||
from supervisor.addons import validate as vd
|
from supervisor.addons import validate as vd
|
||||||
from supervisor.addons.addon import Addon
|
from supervisor.addons.addon import Addon
|
||||||
from supervisor.addons.model import Data
|
from supervisor.addons.model import Data
|
||||||
from supervisor.const import SYSTEMD_JOURNAL
|
from supervisor.const import SYSTEMD_JOURNAL_PERSISTENT, SYSTEMD_JOURNAL_VOLATILE
|
||||||
from supervisor.coresys import CoreSys
|
from supervisor.coresys import CoreSys
|
||||||
from supervisor.docker.addon import DockerAddon
|
from supervisor.docker.addon import DockerAddon
|
||||||
|
|
||||||
@ -97,16 +97,35 @@ def test_addon_map_folder_defaults(
|
|||||||
assert str(docker_addon.sys_config.path_extern_share) not in volumes
|
assert str(docker_addon.sys_config.path_extern_share) not in volumes
|
||||||
|
|
||||||
|
|
||||||
def test_journald_addon(coresys: CoreSys, addonsdata_system: Dict[str, Data]):
|
def test_journald_addon_volatile(coresys: CoreSys, addonsdata_system: Dict[str, Data]):
|
||||||
"""Validate volume for journald option."""
|
"""Validate volume for journald option, with volatile logs."""
|
||||||
docker_addon = get_docker_addon(
|
docker_addon = get_docker_addon(
|
||||||
coresys, addonsdata_system, "journald-addon-config.json"
|
coresys, addonsdata_system, "journald-addon-config.json"
|
||||||
)
|
)
|
||||||
volumes = docker_addon.volumes
|
volumes = docker_addon.volumes
|
||||||
|
|
||||||
assert str(SYSTEMD_JOURNAL) in volumes
|
assert str(SYSTEMD_JOURNAL_PERSISTENT) in volumes
|
||||||
assert volumes.get(str(SYSTEMD_JOURNAL)).get("bind") == str(SYSTEMD_JOURNAL)
|
assert volumes.get(str(SYSTEMD_JOURNAL_PERSISTENT)).get("bind") == str(
|
||||||
assert volumes.get(str(SYSTEMD_JOURNAL)).get("mode") == "ro"
|
SYSTEMD_JOURNAL_VOLATILE
|
||||||
|
)
|
||||||
|
assert volumes.get(str(SYSTEMD_JOURNAL_PERSISTENT)).get("mode") == "ro"
|
||||||
|
|
||||||
|
|
||||||
|
def test_journald_addon_persistent(
|
||||||
|
coresys: CoreSys, addonsdata_system: Dict[str, Data]
|
||||||
|
):
|
||||||
|
"""Validate volume for journald option, with persistent logs."""
|
||||||
|
with patch("pathlib.Path.exists", return_value=True):
|
||||||
|
docker_addon = get_docker_addon(
|
||||||
|
coresys, addonsdata_system, "journald-addon-config.json"
|
||||||
|
)
|
||||||
|
volumes = docker_addon.volumes
|
||||||
|
|
||||||
|
assert str(SYSTEMD_JOURNAL_PERSISTENT) in volumes
|
||||||
|
assert volumes.get(str(SYSTEMD_JOURNAL_PERSISTENT)).get("bind") == str(
|
||||||
|
SYSTEMD_JOURNAL_PERSISTENT
|
||||||
|
)
|
||||||
|
assert volumes.get(str(SYSTEMD_JOURNAL_PERSISTENT)).get("mode") == "ro"
|
||||||
|
|
||||||
|
|
||||||
def test_not_journald_addon(coresys: CoreSys, addonsdata_system: Dict[str, Data]):
|
def test_not_journald_addon(coresys: CoreSys, addonsdata_system: Dict[str, Data]):
|
||||||
@ -116,4 +135,4 @@ def test_not_journald_addon(coresys: CoreSys, addonsdata_system: Dict[str, Data]
|
|||||||
)
|
)
|
||||||
volumes = docker_addon.volumes
|
volumes = docker_addon.volumes
|
||||||
|
|
||||||
assert str(SYSTEMD_JOURNAL) not in volumes
|
assert str(SYSTEMD_JOURNAL_PERSISTENT) not in volumes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user