diff options
author | Dmitry Tantsur <dtantsur@protonmail.com> | 2020-10-12 16:50:29 +0200 |
---|---|---|
committer | Riccardo Pittau <elfosardo@gmail.com> | 2021-01-06 09:30:16 +0100 |
commit | 401f1af79118f1f7e071a742d509710a327004bf (patch) | |
tree | eacf0fe51cfecf77a6d696b8c938501cc3f2ec54 /ironic/tests | |
parent | 88a1e954fa29b1f89b145afff4c646baac655335 (diff) | |
download | ironic-401f1af79118f1f7e071a742d509710a327004bf.tar.gz |
Simplify injecting network data into an ISO image
Currently we're building a VFAT image with the network data just
to unpack it back on the next step. Just pass the file directly.
This fixes a permission denied problem on Bifrost on Fedora
(at least).
As a nice side effect, the change reduces the amount of IO done
for virtual media quite substantially.
Also re-enable ironic-tempest-partition-uefi-redfish-vmedia
Change-Id: I5499fa42c1d82a1a29099fbbba6f45d440448b72
(cherry picked from commit d48479b52da7ede21f26299db4bd0370bb71ec21)
Diffstat (limited to 'ironic/tests')
-rw-r--r-- | ironic/tests/unit/common/test_images.py | 82 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/test_image_utils.py | 30 |
2 files changed, 48 insertions, 64 deletions
diff --git a/ironic/tests/unit/common/test_images.py b/ironic/tests/unit/common/test_images.py index 8a90ab55b..f5cb8ac83 100644 --- a/ironic/tests/unit/common/test_images.py +++ b/ironic/tests/unit/common/test_images.py @@ -250,34 +250,28 @@ class IronicImagesTestCase(base.TestCase): class FsImageTestCase(base.TestCase): + @mock.patch.object(builtins, 'open', autospec=True) @mock.patch.object(shutil, 'copyfile', autospec=True) @mock.patch.object(os, 'makedirs', autospec=True) - @mock.patch.object(os.path, 'dirname', autospec=True) - @mock.patch.object(os.path, 'exists', autospec=True) - def test__create_root_fs(self, path_exists_mock, - dirname_mock, mkdir_mock, cp_mock): - - def path_exists_mock_func(path): - return path == 'root_dir' - + def test__create_root_fs(self, mkdir_mock, cp_mock, open_mock): files_info = { 'a1': 'b1', 'a2': 'b2', - 'a3': 'sub_dir/b3'} + 'a3': 'sub_dir/b3', + b'a4': 'b4'} - path_exists_mock.side_effect = path_exists_mock_func - dirname_mock.side_effect = ['root_dir', 'root_dir', 'root_dir/sub_dir', - 'root_dir/sub_dir'] images._create_root_fs('root_dir', files_info) + cp_mock.assert_any_call('a1', 'root_dir/b1') cp_mock.assert_any_call('a2', 'root_dir/b2') cp_mock.assert_any_call('a3', 'root_dir/sub_dir/b3') - path_exists_mock.assert_any_call('root_dir/sub_dir') - dirname_mock.assert_any_call('root_dir/b1') - dirname_mock.assert_any_call('root_dir/b2') - dirname_mock.assert_any_call('root_dir/sub_dir/b3') - mkdir_mock.assert_called_once_with('root_dir/sub_dir') + open_mock.assert_called_once_with('root_dir/b4', 'wb') + fp = open_mock.return_value.__enter__.return_value + fp.write.assert_called_once_with(b'a4') + + mkdir_mock.assert_any_call('root_dir', exist_ok=True) + mkdir_mock.assert_any_call('root_dir/sub_dir', exist_ok=True) @mock.patch.object(images, '_create_root_fs', autospec=True) @mock.patch.object(utils, 'tempdir', autospec=True) @@ -413,21 +407,6 @@ class FsImageTestCase(base.TestCase): options) self.assertEqual(expected_cfg, cfg) - @mock.patch.object(images, 'os', autospec=True) - def test__read_dir(self, mock_os): - mock_os.path.join = os.path.join - mock_os.path.isdir.side_effect = (False, True, False) - mock_os.listdir.side_effect = [['a', 'b'], ['c']] - - file_info = images._read_dir('/mnt') - - expected = { - '/mnt/a': 'a', - '/mnt/b/c': 'b/c' - } - - self.assertEqual(expected, file_info) - @mock.patch.object(os.path, 'relpath', autospec=True) @mock.patch.object(os, 'walk', autospec=True) @mock.patch.object(utils, 'mount', autospec=True) @@ -599,7 +578,8 @@ class FsImageTestCase(base.TestCase): @mock.patch.object(images, '_generate_cfg', autospec=True) def _test_create_isolinux_image_for_bios( self, gen_cfg_mock, execute_mock, tempdir_mock, - write_to_file_mock, create_root_fs_mock, ldlinux_path=None): + write_to_file_mock, create_root_fs_mock, ldlinux_path=None, + inject_files=None): mock_file_handle = mock.MagicMock(spec=io.BytesIO) mock_file_handle.__enter__.return_value = 'tmpdir' @@ -616,13 +596,16 @@ class FsImageTestCase(base.TestCase): images.create_isolinux_image_for_bios('tgt_file', 'path/to/kernel', 'path/to/ramdisk', - kernel_params=params) + kernel_params=params, + inject_files=inject_files) files_info = { 'path/to/kernel': 'vmlinuz', 'path/to/ramdisk': 'initrd', CONF.isolinux_bin: 'isolinux/isolinux.bin' } + if inject_files: + files_info.update(inject_files) if ldlinux_path: files_info[ldlinux_path] = 'isolinux/ldlinux.c32' create_root_fs_mock.assert_called_once_with('tmpdir', files_info) @@ -653,6 +636,12 @@ class FsImageTestCase(base.TestCase): self._test_create_isolinux_image_for_bios( ldlinux_path='/usr/share/syslinux/ldlinux.c32') + @mock.patch.object(os.path, 'isfile', autospec=True) + def test_create_isolinux_image_for_bios_inject_files(self, mock_isfile): + mock_isfile.return_value = False + self._test_create_isolinux_image_for_bios( + inject_files={'/source': 'target'}) + @mock.patch.object(images, '_umount_without_raise', autospec=True) @mock.patch.object(images, '_create_root_fs', autospec=True) @mock.patch.object(utils, 'tempdir', autospec=True) @@ -765,7 +754,7 @@ class FsImageTestCase(base.TestCase): create_isolinux_mock.assert_called_once_with( 'output_file', 'tmpdir/kernel-uuid', 'tmpdir/ramdisk-uuid', deploy_iso='tmpdir/deploy_iso-uuid', - esp_image=None, kernel_params=params, configdrive=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, 'fetch', autospec=True) @@ -793,7 +782,7 @@ class FsImageTestCase(base.TestCase): create_isolinux_mock.assert_called_once_with( 'output_file', 'tmpdir/kernel-uuid', 'tmpdir/ramdisk-uuid', deploy_iso=None, esp_image='tmpdir/efiboot-uuid', - kernel_params=params, configdrive=None) + kernel_params=params, inject_files=None) @mock.patch.object(images, 'create_esp_image_for_uefi', autospec=True) @mock.patch.object(images, 'fetch', autospec=True) @@ -821,7 +810,7 @@ class FsImageTestCase(base.TestCase): create_isolinux_mock.assert_called_once_with( 'output_file', 'tmpdir/kernel-href', 'tmpdir/ramdisk-href', deploy_iso='tmpdir/deploy_iso-href', - esp_image=None, kernel_params=params, configdrive=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, 'fetch', autospec=True) @@ -849,7 +838,7 @@ class FsImageTestCase(base.TestCase): create_isolinux_mock.assert_called_once_with( 'output_file', 'tmpdir/kernel-href', 'tmpdir/ramdisk-href', deploy_iso=None, esp_image='tmpdir/efiboot-href', - kernel_params=params, configdrive=None) + kernel_params=params, inject_files=None) @mock.patch.object(images, 'create_isolinux_image_for_bios', autospec=True) @mock.patch.object(images, 'fetch', autospec=True) @@ -863,26 +852,24 @@ class FsImageTestCase(base.TestCase): images.create_boot_iso('ctx', 'output_file', 'kernel-uuid', 'ramdisk-uuid', 'deploy_iso-uuid', 'efiboot-uuid', 'root-uuid', - 'kernel-params', 'bios', 'configdrive') + 'kernel-params', 'bios') fetch_images_mock.assert_any_call( 'ctx', 'kernel-uuid', 'tmpdir/kernel-uuid') fetch_images_mock.assert_any_call( 'ctx', 'ramdisk-uuid', 'tmpdir/ramdisk-uuid') - fetch_images_mock.assert_any_call( - 'ctx', 'configdrive', 'tmpdir/configdrive') # Note (NobodyCam): the original assert asserted that fetch_images # was not called with parameters, this did not # work, So I instead assert that there were only # Two calls to the mock validating the above # asserts. - self.assertEqual(3, fetch_images_mock.call_count) + self.assertEqual(2, fetch_images_mock.call_count) params = ['root=UUID=root-uuid', 'kernel-params'] create_isolinux_mock.assert_called_once_with( 'output_file', 'tmpdir/kernel-uuid', 'tmpdir/ramdisk-uuid', - kernel_params=params, configdrive='tmpdir/configdrive') + kernel_params=params, inject_files=None) @mock.patch.object(images, 'create_isolinux_image_for_bios', autospec=True) @mock.patch.object(images, 'fetch', autospec=True) @@ -897,19 +884,17 @@ class FsImageTestCase(base.TestCase): images.create_boot_iso('ctx', 'output_file', 'kernel-uuid', 'ramdisk-uuid', 'deploy_iso-uuid', 'efiboot-uuid', 'root-uuid', - 'kernel-params', None, 'http://configdrive') + 'kernel-params', None) fetch_images_mock.assert_any_call( 'ctx', 'kernel-uuid', 'tmpdir/kernel-uuid') fetch_images_mock.assert_any_call( 'ctx', 'ramdisk-uuid', 'tmpdir/ramdisk-uuid') - fetch_images_mock.assert_any_call( - 'ctx', 'http://configdrive', 'tmpdir/configdrive') params = ['root=UUID=root-uuid', 'kernel-params'] create_isolinux_mock.assert_called_once_with( 'output_file', 'tmpdir/kernel-uuid', 'tmpdir/ramdisk-uuid', - configdrive='tmpdir/configdrive', kernel_params=params) + kernel_params=params, inject_files=None) @mock.patch.object(images, 'create_isolinux_image_for_bios', autospec=True) @mock.patch.object(images, 'fetch', autospec=True) @@ -924,8 +909,7 @@ class FsImageTestCase(base.TestCase): images.create_boot_iso('ctx', 'output_file', 'kernel-uuid', 'ramdisk-uuid', 'deploy_iso-uuid', 'efiboot-uuid', None, - None, None, 'http://configdrive', - base_iso=base_iso) + None, None, base_iso=base_iso) fetch_images_mock.assert_any_call( 'ctx', base_iso, 'output_file') diff --git a/ironic/tests/unit/drivers/modules/test_image_utils.py b/ironic/tests/unit/drivers/modules/test_image_utils.py index e5dd94849..7c177a552 100644 --- a/ironic/tests/unit/drivers/modules/test_image_utils.py +++ b/ironic/tests/unit/drivers/modules/test_image_utils.py @@ -252,10 +252,9 @@ class RedfishImageUtilsTestCase(db_base.DbTestCase): mock_create_boot_iso.assert_called_once_with( mock.ANY, mock.ANY, 'http://kernel/img', 'http://ramdisk/img', boot_mode='uefi', esp_image_href='http://bootloader/img', - configdrive_href=mock.ANY, kernel_params='nofb nomodeset vga=normal', root_uuid='1be26c0b-03f2-4d2e-ae87-c02d7f33c123', - base_iso=None) + base_iso=None, inject_files=None) self.assertEqual(expected_url, url) @@ -275,10 +274,9 @@ class RedfishImageUtilsTestCase(db_base.DbTestCase): mock_create_boot_iso.assert_called_once_with( mock.ANY, mock.ANY, 'http://kernel/img', 'http://ramdisk/img', boot_mode='uefi', esp_image_href=None, - configdrive_href=mock.ANY, kernel_params='nofb nomodeset vga=normal', root_uuid='1be26c0b-03f2-4d2e-ae87-c02d7f33c123', - base_iso='/path/to/baseiso') + base_iso='/path/to/baseiso', inject_files=None) @mock.patch.object(image_utils.ImageHandler, 'publish_image', autospec=True) @@ -304,10 +302,9 @@ class RedfishImageUtilsTestCase(db_base.DbTestCase): mock_create_boot_iso.assert_called_once_with( mock.ANY, mock.ANY, 'http://kernel/img', 'http://ramdisk/img', boot_mode='bios', esp_image_href=None, - configdrive_href=mock.ANY, kernel_params='nofb nomodeset vga=normal', root_uuid='1be26c0b-03f2-4d2e-ae87-c02d7f33c123', - base_iso=None) + base_iso=None, inject_files=None) self.assertEqual(expected_url, url) @@ -330,10 +327,9 @@ class RedfishImageUtilsTestCase(db_base.DbTestCase): mock_create_boot_iso.assert_called_once_with( mock.ANY, mock.ANY, 'http://kernel/img', 'http://ramdisk/img', boot_mode='bios', esp_image_href=None, - configdrive_href=mock.ANY, kernel_params=kernel_params, root_uuid='1be26c0b-03f2-4d2e-ae87-c02d7f33c123', - base_iso='/path/to/baseiso') + base_iso='/path/to/baseiso', inject_files=None) def test__find_param(self): param_dict = { @@ -385,16 +381,15 @@ class RedfishImageUtilsTestCase(db_base.DbTestCase): image_utils.prepare_deploy_iso(task, {}, 'deploy', d_info) mock__prepare_iso_image.assert_called_once_with( - task, 'kernel', 'ramdisk', 'bootloader', params={}) + task, 'kernel', 'ramdisk', 'bootloader', params={}, + inject_files={}) find_mock.assert_has_calls(find_call_list) @mock.patch.object(image_utils, '_find_param', autospec=True) @mock.patch.object(image_utils, '_prepare_iso_image', autospec=True) - @mock.patch.object(images, 'create_vfat_image', autospec=True) def test_prepare_deploy_iso_network_data( - self, mock_create_vfat_image, mock__prepare_iso_image, - find_mock): + self, mock__prepare_iso_image, find_mock): with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: @@ -421,12 +416,17 @@ class RedfishImageUtilsTestCase(db_base.DbTestCase): image_utils.prepare_deploy_iso(task, {}, 'deploy', d_info) - mock_create_vfat_image.assert_called_once_with( - mock.ANY, mock.ANY) + expected_files = { + b"""{ + "a": [ + "b" + ] +}""": 'openstack/latest/network_data.json' + } mock__prepare_iso_image.assert_called_once_with( task, 'kernel', 'ramdisk', bootloader_href=None, - configdrive=mock.ANY, params={}) + params={}, inject_files=expected_files) find_mock.assert_has_calls(find_call_list) |