mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-14 20:56:30 +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 ipaddress import IPv4Address
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
import attr
|
||||
@ -56,11 +55,6 @@ class DockerInfo:
|
||||
"""Return true, if docker version is supported."""
|
||||
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):
|
||||
"""Home Assistant core object for Docker configuration."""
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Evaluation class for lxc."""
|
||||
from contextlib import suppress
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from ...const import CoreState
|
||||
@ -26,4 +28,7 @@ class EvaluateLxc(EvaluateBase):
|
||||
|
||||
async def evaluate(self):
|
||||
"""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."""
|
||||
# pylint: disable=import-error,protected-access
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from supervisor.const import CoreState
|
||||
@ -14,12 +15,14 @@ async def test_evaluation(coresys: CoreSys):
|
||||
|
||||
assert lxc.reason not in coresys.resolution.unsupported
|
||||
|
||||
coresys.docker.info.inside_lxc = True
|
||||
await lxc()
|
||||
with patch.object(Path, "exists") as mock_exists:
|
||||
mock_exists.return_value = True
|
||||
await lxc()
|
||||
assert lxc.reason in coresys.resolution.unsupported
|
||||
|
||||
coresys.docker.info.inside_lxc = False
|
||||
await lxc()
|
||||
with patch.object(Path, "exists") as mock_exists:
|
||||
mock_exists.return_value = False
|
||||
await lxc()
|
||||
assert lxc.reason not in coresys.resolution.unsupported
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user