From 3c3846240d5252ab43b61ee777d32608b28e3bff Mon Sep 17 00:00:00 2001 From: Mike Degatano Date: Wed, 31 May 2023 11:51:52 -0400 Subject: [PATCH] Protect backup manager from setup failures for mount down (#4327) --- supervisor/backups/manager.py | 7 +++++-- tests/backups/test_manager.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/supervisor/backups/manager.py b/supervisor/backups/manager.py index a3e14cc49..d7cd3ef72 100644 --- a/supervisor/backups/manager.py +++ b/supervisor/backups/manager.py @@ -33,10 +33,13 @@ _LOGGER: logging.Logger = logging.getLogger(__name__) def _list_backup_files(path: Path) -> Iterable[Path]: """Return iterable of backup files, suppress and log OSError for network mounts.""" try: - return path.glob("*.tar") + # is_dir does a stat syscall which raises if the mount is down + if path.is_dir(): + return path.glob("*.tar") except OSError as err: _LOGGER.error("Could not list backups from %s: %s", path.as_posix(), err) - return [] + + return [] class BackupManager(FileConfiguration, CoreSysAttributes): diff --git a/tests/backups/test_manager.py b/tests/backups/test_manager.py index 55b74ccc6..b395e8e5a 100644 --- a/tests/backups/test_manager.py +++ b/tests/backups/test_manager.py @@ -690,7 +690,7 @@ async def test_load_network_error( # This should not raise, manager should just ignore backup locations with errors 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" with patch.object(Mount, "local_where", new=PropertyMock(return_value=mock_path)): await coresys.backups.load()