diff --git a/cloudbaseinit/metadata/services/osconfigdrive/windows.py b/cloudbaseinit/metadata/services/osconfigdrive/windows.py index 43ee300d..a9163832 100644 --- a/cloudbaseinit/metadata/services/osconfigdrive/windows.py +++ b/cloudbaseinit/metadata/services/osconfigdrive/windows.py @@ -106,9 +106,15 @@ class WindowsConfigDriveManager(base.BaseConfigDriveManager): offset += bytes_to_read def _extract_files_from_iso(self, iso_file_path): - args = [CONF.bsdtar_path, '-xf', iso_file_path, - '-C', self.target_path] - (out, err, exit_code) = self._osutils.execute_process(args, False) + bsdtar_args = [CONF.bsdtar_path, '-xf', iso_file_path, + '-C', self.target_path] + + if not os.path.exists(CONF.bsdtar_path): + raise exception.CloudbaseInitException( + 'Bsdtar path "%s" does not exist.' % CONF.bsdtar_path) + + (out, err, exit_code) = self._osutils.execute_process(bsdtar_args, + False) if exit_code: raise exception.CloudbaseInitException( diff --git a/cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py b/cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py index 68b81e63..efc6a186 100644 --- a/cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py +++ b/cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py @@ -176,10 +176,13 @@ class TestWindowsConfigDriveManager(unittest.TestCase): device.read.assert_has_calls(device_read_calls) OPEN.return_value.write.assert_has_calls(stream_write_calls) - def _test_extract_files_from_iso(self, exit_code): + @mock.patch('os.path.exists') + def _test_extract_files_from_iso(self, os_path_exists, exit_code, + enforce_os_path_exists=True): fake_path = os.path.join('fake', 'path') fake_target_path = os.path.join(fake_path, 'target') self._config_manager.target_path = fake_target_path + os_path_exists.return_code = enforce_os_path_exists args = [CONF.bsdtar_path, '-xf', fake_path, '-C', fake_target_path] self.osutils.execute_process.return_value = ('fake out', 'fake err', @@ -199,6 +202,10 @@ class TestWindowsConfigDriveManager(unittest.TestCase): def test_extract_files_from_iso_fail(self): self._test_extract_files_from_iso(exit_code=1) + def test_extract_files_from_iso_fail_bsdtar_does_not_exist(self): + self._test_extract_files_from_iso(exit_code=1, + enforce_os_path_exists=False) + @mock.patch('cloudbaseinit.metadata.services.osconfigdrive.windows.' 'WindowsConfigDriveManager._extract_files_from_iso') @mock.patch('cloudbaseinit.metadata.services.osconfigdrive.windows.' diff --git a/doc/source/tutorial.rst b/doc/source/tutorial.rst index 770afdad..e76e5cb4 100644 --- a/doc/source/tutorial.rst +++ b/doc/source/tutorial.rst @@ -55,7 +55,7 @@ services and plugins ready for execution and also customizing user experience. # Which devices to inspect for a possible configuration drive (metadata). config_drive_raw_hhd=true config_drive_cdrom=true - # Path to tar implementation from Ubuntu. + # Path to tar implementation from FreeBSD: https://www.freebsd.org/cgi/man.cgi?tar(1). bsdtar_path=C:\Program Files (x86)\Cloudbase Solutions\Cloudbase-Init\bin\bsdtar.exe # Logging debugging level. verbose=true