Merge "Don't use URLs as part of temporary file names (part 2)"

This commit is contained in:
Zuul 2022-05-30 04:06:05 +00:00 committed by Gerrit Code Review
commit 34afea3af9
3 changed files with 35 additions and 32 deletions

View File

@ -527,8 +527,8 @@ def create_boot_iso(context, output_filename, kernel_href,
:raises: ImageCreationFailed, if creating boot ISO failed. :raises: ImageCreationFailed, if creating boot ISO failed.
""" """
with utils.tempdir() as tmpdir: with utils.tempdir() as tmpdir:
kernel_path = os.path.join(tmpdir, kernel_href.split('/')[-1]) kernel_path = os.path.join(tmpdir, 'kernel')
ramdisk_path = os.path.join(tmpdir, ramdisk_href.split('/')[-1]) ramdisk_path = os.path.join(tmpdir, 'ramdisk')
fetch(context, kernel_href, kernel_path) fetch(context, kernel_href, kernel_path)
fetch(context, ramdisk_href, ramdisk_path) fetch(context, ramdisk_href, ramdisk_path)
@ -543,13 +543,11 @@ def create_boot_iso(context, output_filename, kernel_href,
deploy_iso_path = esp_image_path = None deploy_iso_path = esp_image_path = None
if deploy_iso_href: if deploy_iso_href:
deploy_iso_path = os.path.join( deploy_iso_path = os.path.join(tmpdir, 'iso')
tmpdir, deploy_iso_href.split('/')[-1])
fetch(context, deploy_iso_href, deploy_iso_path) fetch(context, deploy_iso_href, deploy_iso_path)
elif esp_image_href: elif esp_image_href:
esp_image_path = os.path.join( esp_image_path = os.path.join(tmpdir, 'esp')
tmpdir, esp_image_href.split('/')[-1])
fetch(context, esp_image_href, esp_image_path) fetch(context, esp_image_href, esp_image_path)
elif CONF.esp_image: elif CONF.esp_image:

View File

@ -740,16 +740,16 @@ class FsImageTestCase(base.TestCase):
boot_mode='uefi') boot_mode='uefi')
fetch_images_mock.assert_any_call( fetch_images_mock.assert_any_call(
'ctx', 'kernel-uuid', 'tmpdir/kernel-uuid') 'ctx', 'kernel-uuid', 'tmpdir/kernel')
fetch_images_mock.assert_any_call( fetch_images_mock.assert_any_call(
'ctx', 'ramdisk-uuid', 'tmpdir/ramdisk-uuid') 'ctx', 'ramdisk-uuid', 'tmpdir/ramdisk')
fetch_images_mock.assert_any_call( fetch_images_mock.assert_any_call(
'ctx', 'deploy_iso-uuid', 'tmpdir/deploy_iso-uuid') 'ctx', 'deploy_iso-uuid', 'tmpdir/iso')
params = ['root=UUID=root-uuid', 'kernel-params'] params = ['root=UUID=root-uuid', 'kernel-params']
create_isolinux_mock.assert_called_once_with( create_isolinux_mock.assert_called_once_with(
'output_file', 'tmpdir/kernel-uuid', 'tmpdir/ramdisk-uuid', 'output_file', 'tmpdir/kernel', 'tmpdir/ramdisk',
deploy_iso='tmpdir/deploy_iso-uuid', deploy_iso='tmpdir/iso',
esp_image=None, kernel_params=params, inject_files=None) esp_image=None, kernel_params=params, inject_files=None)
@mock.patch.object(images, 'create_esp_image_for_uefi', autospec=True) @mock.patch.object(images, 'create_esp_image_for_uefi', autospec=True)
@ -768,16 +768,16 @@ class FsImageTestCase(base.TestCase):
boot_mode='uefi') boot_mode='uefi')
fetch_images_mock.assert_any_call( fetch_images_mock.assert_any_call(
'ctx', 'kernel-uuid', 'tmpdir/kernel-uuid') 'ctx', 'kernel-uuid', 'tmpdir/kernel')
fetch_images_mock.assert_any_call( fetch_images_mock.assert_any_call(
'ctx', 'ramdisk-uuid', 'tmpdir/ramdisk-uuid') 'ctx', 'ramdisk-uuid', 'tmpdir/ramdisk')
fetch_images_mock.assert_any_call( fetch_images_mock.assert_any_call(
'ctx', 'efiboot-uuid', 'tmpdir/efiboot-uuid') 'ctx', 'efiboot-uuid', 'tmpdir/esp')
params = ['root=UUID=root-uuid', 'kernel-params'] params = ['root=UUID=root-uuid', 'kernel-params']
create_isolinux_mock.assert_called_once_with( create_isolinux_mock.assert_called_once_with(
'output_file', 'tmpdir/kernel-uuid', 'tmpdir/ramdisk-uuid', 'output_file', 'tmpdir/kernel', 'tmpdir/ramdisk',
deploy_iso=None, esp_image='tmpdir/efiboot-uuid', deploy_iso=None, esp_image='tmpdir/esp',
kernel_params=params, inject_files=None) kernel_params=params, inject_files=None)
@mock.patch.object(images, 'create_esp_image_for_uefi', autospec=True) @mock.patch.object(images, 'create_esp_image_for_uefi', autospec=True)
@ -796,16 +796,16 @@ class FsImageTestCase(base.TestCase):
boot_mode='uefi') boot_mode='uefi')
expected_calls = [mock.call('ctx', 'http://kernel-href', expected_calls = [mock.call('ctx', 'http://kernel-href',
'tmpdir/kernel-href'), 'tmpdir/kernel'),
mock.call('ctx', 'http://ramdisk-href', mock.call('ctx', 'http://ramdisk-href',
'tmpdir/ramdisk-href'), 'tmpdir/ramdisk'),
mock.call('ctx', 'http://deploy_iso-href', mock.call('ctx', 'http://deploy_iso-href',
'tmpdir/deploy_iso-href')] 'tmpdir/iso')]
fetch_images_mock.assert_has_calls(expected_calls) fetch_images_mock.assert_has_calls(expected_calls)
params = ['root=UUID=root-uuid', 'kernel-params'] params = ['root=UUID=root-uuid', 'kernel-params']
create_isolinux_mock.assert_called_once_with( create_isolinux_mock.assert_called_once_with(
'output_file', 'tmpdir/kernel-href', 'tmpdir/ramdisk-href', 'output_file', 'tmpdir/kernel', 'tmpdir/ramdisk',
deploy_iso='tmpdir/deploy_iso-href', deploy_iso='tmpdir/iso',
esp_image=None, kernel_params=params, inject_files=None) esp_image=None, kernel_params=params, inject_files=None)
@mock.patch.object(images, 'create_esp_image_for_uefi', autospec=True) @mock.patch.object(images, 'create_esp_image_for_uefi', autospec=True)
@ -824,16 +824,16 @@ class FsImageTestCase(base.TestCase):
boot_mode='uefi') boot_mode='uefi')
expected_calls = [mock.call('ctx', 'http://kernel-href', expected_calls = [mock.call('ctx', 'http://kernel-href',
'tmpdir/kernel-href'), 'tmpdir/kernel'),
mock.call('ctx', 'http://ramdisk-href', mock.call('ctx', 'http://ramdisk-href',
'tmpdir/ramdisk-href'), 'tmpdir/ramdisk'),
mock.call('ctx', 'http://efiboot-href', mock.call('ctx', 'http://efiboot-href',
'tmpdir/efiboot-href')] 'tmpdir/esp')]
fetch_images_mock.assert_has_calls(expected_calls) fetch_images_mock.assert_has_calls(expected_calls)
params = ['root=UUID=root-uuid', 'kernel-params'] params = ['root=UUID=root-uuid', 'kernel-params']
create_isolinux_mock.assert_called_once_with( create_isolinux_mock.assert_called_once_with(
'output_file', 'tmpdir/kernel-href', 'tmpdir/ramdisk-href', 'output_file', 'tmpdir/kernel', 'tmpdir/ramdisk',
deploy_iso=None, esp_image='tmpdir/efiboot-href', deploy_iso=None, esp_image='tmpdir/esp',
kernel_params=params, inject_files=None) kernel_params=params, inject_files=None)
@mock.patch.object(images, 'create_isolinux_image_for_bios', autospec=True) @mock.patch.object(images, 'create_isolinux_image_for_bios', autospec=True)
@ -851,9 +851,9 @@ class FsImageTestCase(base.TestCase):
'kernel-params', 'bios') 'kernel-params', 'bios')
fetch_images_mock.assert_any_call( fetch_images_mock.assert_any_call(
'ctx', 'kernel-uuid', 'tmpdir/kernel-uuid') 'ctx', 'kernel-uuid', 'tmpdir/kernel')
fetch_images_mock.assert_any_call( fetch_images_mock.assert_any_call(
'ctx', 'ramdisk-uuid', 'tmpdir/ramdisk-uuid') 'ctx', 'ramdisk-uuid', 'tmpdir/ramdisk')
# Note (NobodyCam): the original assert asserted that fetch_images # Note (NobodyCam): the original assert asserted that fetch_images
# was not called with parameters, this did not # was not called with parameters, this did not
@ -864,7 +864,7 @@ class FsImageTestCase(base.TestCase):
params = ['root=UUID=root-uuid', 'kernel-params'] params = ['root=UUID=root-uuid', 'kernel-params']
create_isolinux_mock.assert_called_once_with( create_isolinux_mock.assert_called_once_with(
'output_file', 'tmpdir/kernel-uuid', 'tmpdir/ramdisk-uuid', 'output_file', 'tmpdir/kernel', 'tmpdir/ramdisk',
kernel_params=params, inject_files=None) kernel_params=params, inject_files=None)
@mock.patch.object(images, 'create_isolinux_image_for_bios', autospec=True) @mock.patch.object(images, 'create_isolinux_image_for_bios', autospec=True)
@ -883,13 +883,13 @@ class FsImageTestCase(base.TestCase):
'kernel-params', None) 'kernel-params', None)
fetch_images_mock.assert_any_call( fetch_images_mock.assert_any_call(
'ctx', 'kernel-uuid', 'tmpdir/kernel-uuid') 'ctx', 'kernel-uuid', 'tmpdir/kernel')
fetch_images_mock.assert_any_call( fetch_images_mock.assert_any_call(
'ctx', 'ramdisk-uuid', 'tmpdir/ramdisk-uuid') 'ctx', 'ramdisk-uuid', 'tmpdir/ramdisk')
params = ['root=UUID=root-uuid', 'kernel-params'] params = ['root=UUID=root-uuid', 'kernel-params']
create_isolinux_mock.assert_called_once_with( create_isolinux_mock.assert_called_once_with(
'output_file', 'tmpdir/kernel-uuid', 'tmpdir/ramdisk-uuid', 'output_file', 'tmpdir/kernel', 'tmpdir/ramdisk',
kernel_params=params, inject_files=None) kernel_params=params, inject_files=None)
@mock.patch.object(image_service, 'get_image_service', autospec=True) @mock.patch.object(image_service, 'get_image_service', autospec=True)

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Fixes ``OSError: [Errno 36] File name too long`` when building a virtual
media ISO from a long kernel, ramdisk or ESP URL.