Skip to content

Commit

Permalink
bsdtar: check if tool path exists
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ader1990 committed Jan 19, 2023
1 parent e09af5f commit 1a28d39
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
12 changes: 9 additions & 3 deletions cloudbaseinit/metadata/services/osconfigdrive/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,15 @@ def _write_iso_file(self, device, iso_file_path, iso_file_size):
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,13 @@ def test_write_iso_file(self):
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',
Expand All @@ -199,6 +202,10 @@ def test_extract_files_from_iso(self):
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.'
Expand Down
2 changes: 1 addition & 1 deletion doc/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1a28d39

Please sign in to comment.