mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-15 13:16:29 +00:00
Imrove the LXC detection (#2599)
This commit is contained in:
parent
7e7e3a7876
commit
785dc64787
@ -2,7 +2,6 @@
|
|||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from ipaddress import IPv4Address
|
from ipaddress import IPv4Address
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
@ -56,11 +55,6 @@ class DockerInfo:
|
|||||||
"""Return true, if docker version is supported."""
|
"""Return true, if docker version is supported."""
|
||||||
return self.version >= MIN_SUPPORTED_DOCKER
|
return self.version >= MIN_SUPPORTED_DOCKER
|
||||||
|
|
||||||
@property
|
|
||||||
def inside_lxc(self) -> bool:
|
|
||||||
"""Return True if the docker run inside lxc."""
|
|
||||||
return Path("/dev/lxd/sock").exists()
|
|
||||||
|
|
||||||
|
|
||||||
class DockerConfig(JsonConfig):
|
class DockerConfig(JsonConfig):
|
||||||
"""Home Assistant core object for Docker configuration."""
|
"""Home Assistant core object for Docker configuration."""
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Evaluation class for lxc."""
|
"""Evaluation class for lxc."""
|
||||||
|
from contextlib import suppress
|
||||||
|
from pathlib import Path
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from ...const import CoreState
|
from ...const import CoreState
|
||||||
@ -26,4 +28,7 @@ class EvaluateLxc(EvaluateBase):
|
|||||||
|
|
||||||
async def evaluate(self):
|
async def evaluate(self):
|
||||||
"""Run evaluation."""
|
"""Run evaluation."""
|
||||||
return self.sys_docker.info.inside_lxc
|
with suppress(OSError):
|
||||||
|
if "container=lxc" in Path("/proc/1/environ").read_text():
|
||||||
|
return True
|
||||||
|
return Path("/dev/lxd/sock").exists()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""Test evaluation base."""
|
"""Test evaluation base."""
|
||||||
# pylint: disable=import-error,protected-access
|
# pylint: disable=import-error,protected-access
|
||||||
|
from pathlib import Path
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from supervisor.const import CoreState
|
from supervisor.const import CoreState
|
||||||
@ -14,12 +15,14 @@ async def test_evaluation(coresys: CoreSys):
|
|||||||
|
|
||||||
assert lxc.reason not in coresys.resolution.unsupported
|
assert lxc.reason not in coresys.resolution.unsupported
|
||||||
|
|
||||||
coresys.docker.info.inside_lxc = True
|
with patch.object(Path, "exists") as mock_exists:
|
||||||
await lxc()
|
mock_exists.return_value = True
|
||||||
|
await lxc()
|
||||||
assert lxc.reason in coresys.resolution.unsupported
|
assert lxc.reason in coresys.resolution.unsupported
|
||||||
|
|
||||||
coresys.docker.info.inside_lxc = False
|
with patch.object(Path, "exists") as mock_exists:
|
||||||
await lxc()
|
mock_exists.return_value = False
|
||||||
|
await lxc()
|
||||||
assert lxc.reason not in coresys.resolution.unsupported
|
assert lxc.reason not in coresys.resolution.unsupported
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user