Protect backup manager from setup failures for mount down (#4327)

This commit is contained in:
Mike Degatano 2023-05-31 11:51:52 -04:00 committed by GitHub
parent b86a6d292f
commit 3c3846240d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -33,9 +33,12 @@ _LOGGER: logging.Logger = logging.getLogger(__name__)
def _list_backup_files(path: Path) -> Iterable[Path]: def _list_backup_files(path: Path) -> Iterable[Path]:
"""Return iterable of backup files, suppress and log OSError for network mounts.""" """Return iterable of backup files, suppress and log OSError for network mounts."""
try: try:
# is_dir does a stat syscall which raises if the mount is down
if path.is_dir():
return path.glob("*.tar") return path.glob("*.tar")
except OSError as err: except OSError as err:
_LOGGER.error("Could not list backups from %s: %s", path.as_posix(), err) _LOGGER.error("Could not list backups from %s: %s", path.as_posix(), err)
return [] return []

View File

@ -690,7 +690,7 @@ async def test_load_network_error(
# This should not raise, manager should just ignore backup locations with errors # This should not raise, manager should just ignore backup locations with errors
mock_path = MagicMock() mock_path = MagicMock()
mock_path.glob.side_effect = OSError("Host is down") mock_path.is_dir.side_effect = OSError("Host is down")
mock_path.as_posix.return_value = "/data/backup_test" mock_path.as_posix.return_value = "/data/backup_test"
with patch.object(Mount, "local_where", new=PropertyMock(return_value=mock_path)): with patch.object(Mount, "local_where", new=PropertyMock(return_value=mock_path)):
await coresys.backups.load() await coresys.backups.load()