bsdtar: check if tool path exists
Check if the configuration value of bsdtar_path does exist as a path before trying to execute the binary. Updated the tutorial reference of bsdtar to FreeBSD instead of Ubuntu. Change-Id: Ieba5da2f330aa11c40cce6c2ae9de40155f33b07
This commit is contained in:
parent
e09af5f15b
commit
1a28d39c72
@ -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,
|
||||
bsdtar_args = [CONF.bsdtar_path, '-xf', iso_file_path,
|
||||
'-C', self.target_path]
|
||||
(out, err, exit_code) = self._osutils.execute_process(args, False)
|
||||
|
||||
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(
|
||||
|
@ -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.'
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user