diff --git a/oci/remote/oci_managed_volumes.py b/oci/remote/oci_managed_volumes.py index 20be099e..a0068939 100644 --- a/oci/remote/oci_managed_volumes.py +++ b/oci/remote/oci_managed_volumes.py @@ -84,10 +84,7 @@ def remove_empty_format_directories(rootfs, deployment, backed_only=True, target if not paths: return 0 flags = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW - try: - root = os.open(rootfs, flags) - except FileNotFoundError: - return 0 + root = os.open(rootfs, flags) removed = 0 try: for path in paths: @@ -98,8 +95,6 @@ def remove_empty_format_directories(rootfs, deployment, backed_only=True, target os.close(current) current = following removed += int(remove_empty_at(current)) - except FileNotFoundError: - continue except OSError as error: if error.errno in (errno.ELOOP, errno.ENOTDIR): raise ValueError('Symbolic link or invalid managed volume path') from error diff --git a/oci/tests/test_managed_volume_startup.py b/oci/tests/test_managed_volume_startup.py index 2af33395..e2a4ef8d 100644 --- a/oci/tests/test_managed_volume_startup.py +++ b/oci/tests/test_managed_volume_startup.py @@ -174,6 +174,21 @@ class FormatDirectoryTests(unittest.TestCase): opened.assert_not_called() + def test_missing_rootfs_is_an_error_without_remove(self): + with tempfile.TemporaryDirectory() as tmp, patch.object(volumes.os, 'rmdir') as remove: + with self.assertRaises(FileNotFoundError): + volumes.remove_empty_format_directories(Path(tmp) / 'missing', {'mounts': [ + {'container_path': '/config', 'type': 'managed-volume', 'backup': True}]}) + remove.assert_not_called() + + def test_missing_managed_mount_is_an_error_without_remove(self): + with tempfile.TemporaryDirectory() as tmp, patch.object(volumes.os, 'rmdir') as remove: + with self.assertRaises(FileNotFoundError): + volumes.remove_empty_format_directories(Path(tmp), {'mounts': [ + {'container_path': '/missing', 'type': 'managed-volume', 'backup': True}]}) + remove.assert_not_called() + + class StartupContractTests(unittest.TestCase): def setUp(self): directory = tempfile.TemporaryDirectory(); self.addCleanup(directory.cleanup)