diff --git a/cloudbaseinit/metadata/services/osconfigdrive/windows.py b/cloudbaseinit/metadata/services/osconfigdrive/windows.py index 81a6238a..a2fcc3b1 100644 --- a/cloudbaseinit/metadata/services/osconfigdrive/windows.py +++ b/cloudbaseinit/metadata/services/osconfigdrive/windows.py @@ -176,14 +176,20 @@ class WindowsConfigDriveManager(base.BaseConfigDriveManager): return False def _get_config_drive_files(self, cd_type, cd_location): - get_config_drive = self.config_drive_type_location.get( - "{}_{}".format(cd_location, cd_type)) - if get_config_drive: - return get_config_drive() - else: - LOG.debug("Irrelevant type %(type)s in %(location)s location; " - "skip", - {"type": cd_type, "location": cd_location}) + try: + get_config_drive = self.config_drive_type_location.get( + "{}_{}".format(cd_location, cd_type)) + if get_config_drive: + return get_config_drive() + else: + LOG.debug("Irrelevant type %(type)s in %(location)s " + "location; skip", + {"type": cd_type, "location": cd_location}) + except Exception as exc: + LOG.warning("Config type %(type)s not found in %(loc)s " + "location; Error: '%(err)r'", + {"type": cd_type, "loc": cd_location, "err": exc}) + return False def get_config_drive_files(self, searched_types=None, diff --git a/cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py b/cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py index f972b3d4..70fbab0a 100644 --- a/cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py +++ b/cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py @@ -394,6 +394,14 @@ class TestWindowsConfigDriveManager(unittest.TestCase): self._test__get_config_drive_files( "iso", "cdrom", func) + @mock.patch('cloudbaseinit.metadata.services.osconfigdrive.windows.' + 'WindowsConfigDriveManager.' + '_get_config_drive_from_cdrom_drive') + def test__get_config_drive_files_cdrom_iso_failed(self, func): + func.side_effect = Exception + self._test__get_config_drive_files( + "iso", "cdrom", func, found=False) + def test__get_config_drive_files_cdrom_vfat(self): self._test__get_config_drive_files( "vfat", "cdrom", None) diff --git a/cloudbaseinit/tests/utils/windows/test_vfat.py b/cloudbaseinit/tests/utils/windows/test_vfat.py index 35468b61..53219717 100644 --- a/cloudbaseinit/tests/utils/windows/test_vfat.py +++ b/cloudbaseinit/tests/utils/windows/test_vfat.py @@ -105,6 +105,19 @@ class TestVfat(unittest.TestCase): expected_logging=expected_logging, expected_response=expected_response) + def test_is_vfat_drive_with_wrong_label(self): + mock_out = b"Not volu label \r\n" + expected_logging = [ + "Obtained label information for drive %r: %r" + % (mock.sentinel.drive, mock_out) + ] + execute_process_value = (mock_out, None, 0) + expected_response = False + + self._test_is_vfat_drive(execute_process_value=execute_process_value, + expected_logging=expected_logging, + expected_response=expected_response) + @testutils.ConfPatcher('mtools_path', 'mtools_path') @mock.patch('os.chdir') def test_copy(self, mock_os_chdir): diff --git a/cloudbaseinit/utils/windows/vfat.py b/cloudbaseinit/utils/windows/vfat.py index 60b91df6..9705d965 100644 --- a/cloudbaseinit/utils/windows/vfat.py +++ b/cloudbaseinit/utils/windows/vfat.py @@ -50,7 +50,7 @@ def is_vfat_drive(osutils, drive_path): LOG.debug("Obtained label information for drive %r: %r", drive_path, out) out = out.decode().strip() match = VOLUME_LABEL_REGEX.search(out) - return match.group(1) in CONFIG_DRIVE_LABELS + return match.group(1) in CONFIG_DRIVE_LABELS if match else False def copy_from_vfat_drive(osutils, drive_path, target_path):