mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-17 06:06:29 +00:00
Fix resp may be undefined end_backup issue (#5224)
This commit is contained in:
parent
61034dfa7b
commit
17ee234be4
@ -373,7 +373,7 @@ class HomeAssistant(FileConfiguration, CoreSysAttributes):
|
|||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Error resuming normal operations after backup of Home Assistant Core. Check HA Core logs."
|
"Error resuming normal operations after backup of Home Assistant Core. Check HA Core logs."
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
if resp and not resp.get(ATTR_SUCCESS):
|
if resp and not resp.get(ATTR_SUCCESS):
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Error resuming normal operations after backup of Home Assistant Core due to: %s. Check HA Core logs.",
|
"Error resuming normal operations after backup of Home Assistant Core due to: %s. Check HA Core logs.",
|
||||||
|
@ -5,12 +5,17 @@ import errno
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from pytest import LogCaptureFixture
|
from pytest import LogCaptureFixture, raises
|
||||||
|
|
||||||
from supervisor.const import CoreState
|
from supervisor.const import CoreState
|
||||||
from supervisor.coresys import CoreSys
|
from supervisor.coresys import CoreSys
|
||||||
from supervisor.docker.interface import DockerInterface
|
from supervisor.docker.interface import DockerInterface
|
||||||
|
from supervisor.exceptions import (
|
||||||
|
HomeAssistantBackupError,
|
||||||
|
HomeAssistantWSConnectionError,
|
||||||
|
)
|
||||||
from supervisor.homeassistant.secrets import HomeAssistantSecrets
|
from supervisor.homeassistant.secrets import HomeAssistantSecrets
|
||||||
|
from supervisor.homeassistant.websocket import HomeAssistantWebSocket
|
||||||
|
|
||||||
|
|
||||||
async def test_load(
|
async def test_load(
|
||||||
@ -21,12 +26,14 @@ async def test_load(
|
|||||||
secrets.write("hello: world\n")
|
secrets.write("hello: world\n")
|
||||||
|
|
||||||
# Unwrap read_secrets to prevent throttling between tests
|
# Unwrap read_secrets to prevent throttling between tests
|
||||||
with patch.object(DockerInterface, "attach") as attach, patch.object(
|
with (
|
||||||
DockerInterface, "check_image"
|
patch.object(DockerInterface, "attach") as attach,
|
||||||
) as check_image, patch.object(
|
patch.object(DockerInterface, "check_image") as check_image,
|
||||||
|
patch.object(
|
||||||
HomeAssistantSecrets,
|
HomeAssistantSecrets,
|
||||||
"_read_secrets",
|
"_read_secrets",
|
||||||
new=HomeAssistantSecrets._read_secrets.__wrapped__,
|
new=HomeAssistantSecrets._read_secrets.__wrapped__,
|
||||||
|
),
|
||||||
):
|
):
|
||||||
await coresys.homeassistant.load()
|
await coresys.homeassistant.load()
|
||||||
|
|
||||||
@ -70,3 +77,34 @@ def test_write_pulse_error(coresys: CoreSys, caplog: LogCaptureFixture):
|
|||||||
|
|
||||||
assert "can't write pulse/client.config" in caplog.text
|
assert "can't write pulse/client.config" in caplog.text
|
||||||
assert coresys.core.healthy is False
|
assert coresys.core.healthy is False
|
||||||
|
|
||||||
|
|
||||||
|
async def test_begin_backup_ws_error(coresys: CoreSys):
|
||||||
|
"""Test WS error when beginning backup."""
|
||||||
|
# pylint: disable-next=protected-access
|
||||||
|
coresys.homeassistant.websocket._client.async_send_command.side_effect = (
|
||||||
|
HomeAssistantWSConnectionError
|
||||||
|
)
|
||||||
|
with (
|
||||||
|
patch.object(HomeAssistantWebSocket, "_can_send", return_value=True),
|
||||||
|
raises(
|
||||||
|
HomeAssistantBackupError,
|
||||||
|
match="Preparing backup of Home Assistant Core failed. Check HA Core logs.",
|
||||||
|
),
|
||||||
|
):
|
||||||
|
await coresys.homeassistant.begin_backup()
|
||||||
|
|
||||||
|
|
||||||
|
async def test_end_backup_ws_error(coresys: CoreSys, caplog: LogCaptureFixture):
|
||||||
|
"""Test WS error when ending backup."""
|
||||||
|
# pylint: disable-next=protected-access
|
||||||
|
coresys.homeassistant.websocket._client.async_send_command.side_effect = (
|
||||||
|
HomeAssistantWSConnectionError
|
||||||
|
)
|
||||||
|
with patch.object(HomeAssistantWebSocket, "_can_send", return_value=True):
|
||||||
|
await coresys.homeassistant.end_backup()
|
||||||
|
|
||||||
|
assert (
|
||||||
|
"Error resuming normal operations after backup of Home Assistant Core. Check HA Core logs."
|
||||||
|
in caplog.text
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user