Skip to content

Commit 1a28d39

Browse files
committed
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
1 parent e09af5f commit 1a28d39

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

cloudbaseinit/metadata/services/osconfigdrive/windows.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,15 @@ def _write_iso_file(self, device, iso_file_path, iso_file_size):
106106
offset += bytes_to_read
107107

108108
def _extract_files_from_iso(self, iso_file_path):
109-
args = [CONF.bsdtar_path, '-xf', iso_file_path,
110-
'-C', self.target_path]
111-
(out, err, exit_code) = self._osutils.execute_process(args, False)
109+
bsdtar_args = [CONF.bsdtar_path, '-xf', iso_file_path,
110+
'-C', self.target_path]
111+
112+
if not os.path.exists(CONF.bsdtar_path):
113+
raise exception.CloudbaseInitException(
114+
'Bsdtar path "%s" does not exist.' % CONF.bsdtar_path)
115+
116+
(out, err, exit_code) = self._osutils.execute_process(bsdtar_args,
117+
False)
112118

113119
if exit_code:
114120
raise exception.CloudbaseInitException(

cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,13 @@ def test_write_iso_file(self):
176176
device.read.assert_has_calls(device_read_calls)
177177
OPEN.return_value.write.assert_has_calls(stream_write_calls)
178178

179-
def _test_extract_files_from_iso(self, exit_code):
179+
@mock.patch('os.path.exists')
180+
def _test_extract_files_from_iso(self, os_path_exists, exit_code,
181+
enforce_os_path_exists=True):
180182
fake_path = os.path.join('fake', 'path')
181183
fake_target_path = os.path.join(fake_path, 'target')
182184
self._config_manager.target_path = fake_target_path
185+
os_path_exists.return_code = enforce_os_path_exists
183186
args = [CONF.bsdtar_path, '-xf', fake_path, '-C', fake_target_path]
184187

185188
self.osutils.execute_process.return_value = ('fake out', 'fake err',
@@ -199,6 +202,10 @@ def test_extract_files_from_iso(self):
199202
def test_extract_files_from_iso_fail(self):
200203
self._test_extract_files_from_iso(exit_code=1)
201204

205+
def test_extract_files_from_iso_fail_bsdtar_does_not_exist(self):
206+
self._test_extract_files_from_iso(exit_code=1,
207+
enforce_os_path_exists=False)
208+
202209
@mock.patch('cloudbaseinit.metadata.services.osconfigdrive.windows.'
203210
'WindowsConfigDriveManager._extract_files_from_iso')
204211
@mock.patch('cloudbaseinit.metadata.services.osconfigdrive.windows.'

doc/source/tutorial.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ services and plugins ready for execution and also customizing user experience.
5555
# Which devices to inspect for a possible configuration drive (metadata).
5656
config_drive_raw_hhd=true
5757
config_drive_cdrom=true
58-
# Path to tar implementation from Ubuntu.
58+
# Path to tar implementation from FreeBSD: https://www.freebsd.org/cgi/man.cgi?tar(1).
5959
bsdtar_path=C:\Program Files (x86)\Cloudbase Solutions\Cloudbase-Init\bin\bsdtar.exe
6060
# Logging debugging level.
6161
verbose=true

0 commit comments

Comments
 (0)