Merge pull request #1213 from home-assistant/dev

Release 175
This commit is contained in:
Pascal Vizeli 2019-08-15 11:36:06 +02:00 committed by GitHub
commit abbd3d1078
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 6 deletions

View File

@ -3,7 +3,7 @@ from pathlib import Path
from ipaddress import ip_network
HASSIO_VERSION = "174"
HASSIO_VERSION = "175"
URL_HASSIO_ADDONS = "https://github.com/home-assistant/hassio-addons"
URL_HASSIO_VERSION = "https://version.home-assistant.io/{channel}.json"

View File

@ -19,6 +19,7 @@ from .validate import SCHEMA_DNS_CONFIG
_LOGGER = logging.getLogger(__name__)
COREDNS_TMPL: Path = Path(__file__).parents[0].joinpath("data/coredns.tmpl")
RESOLV_CONF: Path = Path("/etc/resolv.conf")
class CoreDNS(JsonConfig, CoreSysAttributes):
@ -73,6 +74,11 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
"""Return True if a task is in progress."""
return self.instance.in_progress
@property
def need_update(self) -> bool:
"""Return True if an update is available."""
return self.version != self.latest_version
async def load(self) -> None:
"""Load DNS setup."""
with suppress(CoreDNSError):
@ -100,6 +106,9 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
# Start DNS forwarder
self.sys_create_task(self.forwarder.start(self.sys_docker.network.dns))
with suppress(CoreDNSError):
self._update_local_resolv()
# Start is not Running
if await self.instance.is_running():
return
@ -293,7 +302,7 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
"""
return self.instance.is_fails()
async def repair(self):
async def repair(self) -> None:
"""Repair CoreDNS plugin."""
if await self.instance.exists():
return
@ -303,3 +312,31 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
await self.instance.install(self.version)
except DockerAPIError:
_LOGGER.error("Repairing of CoreDNS fails")
def _update_local_resolv(self) -> None:
"""Update local resolv file."""
resolv_lines: List[str] = []
nameserver = f"nameserver {self.sys_docker.network.dns!s}"
# Read resolv config
try:
with RESOLV_CONF.open("r") as resolv:
for line in resolv.readlines():
resolv_lines.append(line)
except OSError as err:
_LOGGER.error("Can't read local resolve: %s", err)
raise CoreDNSError() from None
if nameserver in resolv_lines:
return
_LOGGER.info("Update resolv from Supervisor")
# Write config back to resolv
resolv_lines.append(nameserver)
try:
with RESOLV_CONF.open("w") as resolv:
for line in resolv_lines:
resolv.write(line)
except OSError as err:
_LOGGER.error("Can't write local resolve: %s", err)
raise CoreDNSError() from None

View File

@ -9,7 +9,7 @@ import async_timeout
_LOGGER = logging.getLogger(__name__)
COMMAND = "socat UDP-RECVFROM:53,fork UDP-SENDTO:{!s}"
COMMAND = "socat UDP-RECVFROM:53,fork UDP-SENDTO:{!s}:53"
class DNSForward:

View File

@ -11,12 +11,13 @@ HASS_WATCHDOG_API = "HASS_WATCHDOG_API"
RUN_UPDATE_SUPERVISOR = 29100
RUN_UPDATE_ADDONS = 57600
RUN_UPDATE_HASSOSCLI = 29100
RUN_UPDATE_HASSOSCLI = 28100
RUN_UPDATE_DNS = 30100
RUN_RELOAD_ADDONS = 21600
RUN_RELOAD_ADDONS = 10800
RUN_RELOAD_SNAPSHOTS = 72000
RUN_RELOAD_HOST = 72000
RUN_RELOAD_UPDATER = 21600
RUN_RELOAD_UPDATER = 7200
RUN_RELOAD_INGRESS = 930
RUN_WATCHDOG_HOMEASSISTANT_DOCKER = 15
@ -50,6 +51,9 @@ class Tasks(CoreSysAttributes):
self._update_hassos_cli, RUN_UPDATE_HASSOSCLI
)
)
self.jobs.add(
self.sys_scheduler.register_task(self._update_dns, RUN_UPDATE_DNS)
)
# Reload
self.jobs.add(
@ -202,6 +206,19 @@ class Tasks(CoreSysAttributes):
_LOGGER.info("Found new HassOS CLI version")
await self.sys_hassos.update_cli()
async def _update_dns(self):
"""Check and run update of CoreDNS plugin."""
if not self.sys_dns.need_update:
return
# don't perform an update on dev channel
if self.sys_dev:
_LOGGER.warning("Ignore CoreDNS update on dev channel!")
return
_LOGGER.info("Found new CoreDNS plugin version")
await self.sys_dns.update()
async def _watchdog_dns_docker(self):
"""Check running state of Docker and start if they is close."""
# if Home Assistant is active