Prune network/interface on repair (#1340)

* Prune network/interface on repair

* Force disconnect
This commit is contained in:
Pascal Vizeli 2019-10-22 14:30:14 +02:00 committed by GitHub
parent 615e68b29b
commit 74485262e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 0 deletions

View File

@ -285,6 +285,9 @@ class AddonManager(CoreSysAttributes):
for addon in needs_repair:
_LOGGER.info("Start repair for add-on: %s", addon.slug)
await self.sys_run_in_executor(
self.sys_docker.network.stale_cleanup, addon.instance.name
)
with suppress(DockerAPIError, KeyError):
# Need pull a image again

View File

@ -178,3 +178,10 @@ class DockerAPI:
_LOGGER.debug("Volumes prune: %s", output)
except docker.errors.APIError as err:
_LOGGER.warning("Error for volumes prune: %s", err)
_LOGGER.info("Prune stale networks")
try:
output = self.docker.api.prune_networks()
_LOGGER.debug("Networks prune: %s", output)
except docker.errors.APIError as err:
_LOGGER.warning("Error for networks prune: %s", err)

View File

@ -1,4 +1,5 @@
"""Internal network manager for Hass.io."""
from contextlib import suppress
from ipaddress import IPv4Address
import logging
from typing import List, Optional
@ -107,3 +108,11 @@ class DockerNetwork:
except docker.errors.APIError as err:
_LOGGER.warning("Can't disconnect container from default: %s", err)
raise DockerAPIError() from None
def stale_cleanup(self, container_name: str):
"""Remove force a container from Network.
Fix: https://github.com/moby/moby/issues/23302
"""
with suppress(docker.errors.APIError):
self.network.disconnect(container_name, force=True)

View File

@ -605,6 +605,11 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
return
_LOGGER.info("Repair Home Assistant %s", self.version)
await self.sys_run_in_executor(
self.sys_docker.network.stale_cleanup, self.instance.name
)
# Pull image
try:
await self.instance.install(self.version)
except DockerAPIError: