diff --git a/ironic/drivers/modules/redfish/boot.py b/ironic/drivers/modules/redfish/boot.py index 7305dace0a..68eec3d8dc 100644 --- a/ironic/drivers/modules/redfish/boot.py +++ b/ironic/drivers/modules/redfish/boot.py @@ -155,19 +155,18 @@ def _test_retry(exception): @retrying.retry(wait_fixed=3000, stop_max_attempt_number=3, retry_on_exception=_test_retry) -def _insert_vmedia(task, boot_url, boot_device): +def _insert_vmedia(task, managers, boot_url, boot_device): """Insert bootable ISO image into virtual CD or DVD :param task: A task from TaskManager. + :param managers: A list of System managers. :param boot_url: URL to a bootable ISO image :param boot_device: sushy boot device e.g. `VIRTUAL_MEDIA_CD`, `VIRTUAL_MEDIA_DVD` or `VIRTUAL_MEDIA_FLOPPY` :raises: InvalidParameterValue, if no suitable virtual CD or DVD is found on the node. """ - system = redfish_utils.get_system(task.node) - - for manager in system.managers: + for manager in managers: for v_media in manager.virtual_media.get_members(): if boot_device not in v_media.media_types: continue @@ -201,19 +200,18 @@ def _insert_vmedia(task, boot_url, boot_device): _('No suitable virtual media device found')) -def eject_vmedia(task, boot_device=None): +def _eject_vmedia(task, managers, boot_device=None): """Eject virtual CDs and DVDs :param task: A task from TaskManager. + :param managers: A list of System managers. :param boot_device: sushy boot device e.g. `VIRTUAL_MEDIA_CD`, `VIRTUAL_MEDIA_DVD` or `VIRTUAL_MEDIA_FLOPPY` or `None` to eject everything (default). :raises: InvalidParameterValue, if no suitable virtual CD or DVD is found on the node. """ - system = redfish_utils.get_system(task.node) - - for manager in system.managers: + for manager in managers: for v_media in manager.virtual_media.get_members(): if boot_device and boot_device not in v_media.media_types: continue @@ -230,19 +228,32 @@ def eject_vmedia(task, boot_device=None): 'boot_device': v_media.name}) -def _has_vmedia_device(task, boot_device): - """Indicate if device exists at any of the managers +def eject_vmedia(task, boot_device=None): + """Eject virtual CDs and DVDs :param task: A task from TaskManager. :param boot_device: sushy boot device e.g. `VIRTUAL_MEDIA_CD`, - `VIRTUAL_MEDIA_DVD` or `VIRTUAL_MEDIA_FLOPPY`. + `VIRTUAL_MEDIA_DVD` or `VIRTUAL_MEDIA_FLOPPY` or `None` to + eject everything (default). + :raises: InvalidParameterValue, if no suitable virtual CD or DVD is + found on the node. """ system = redfish_utils.get_system(task.node) + _eject_vmedia(task, system.managers, boot_device=boot_device) - for manager in system.managers: + +def _has_vmedia_device(managers, boot_device): + """Indicate if device exists at any of the managers + + :param managers: A list of System managers. + :param boot_device: sushy boot device e.g. `VIRTUAL_MEDIA_CD`, + `VIRTUAL_MEDIA_DVD` or `VIRTUAL_MEDIA_FLOPPY`. + """ + for manager in managers: for v_media in manager.virtual_media.get_members(): if boot_device in v_media.media_types: return True + return False def _parse_deploy_info(node): @@ -438,9 +449,11 @@ class RedfishVirtualMediaBoot(base.BootInterface): if CONF.debug and 'ipa-debug' not in ramdisk_params: ramdisk_params['ipa-debug'] = '1' + managers = redfish_utils.get_system(task.node).managers + if config_via_floppy: - if _has_vmedia_device(task, sushy.VIRTUAL_MEDIA_FLOPPY): + if _has_vmedia_device(managers, sushy.VIRTUAL_MEDIA_FLOPPY): # NOTE (etingof): IPA will read the diskette only if # we tell it to ramdisk_params['boot_method'] = 'vmedia' @@ -448,9 +461,9 @@ class RedfishVirtualMediaBoot(base.BootInterface): floppy_ref = image_utils.prepare_floppy_image( task, params=ramdisk_params) - eject_vmedia(task, sushy.VIRTUAL_MEDIA_FLOPPY) + _eject_vmedia(task, managers, sushy.VIRTUAL_MEDIA_FLOPPY) _insert_vmedia( - task, floppy_ref, sushy.VIRTUAL_MEDIA_FLOPPY) + task, managers, floppy_ref, sushy.VIRTUAL_MEDIA_FLOPPY) LOG.debug('Inserted virtual floppy with configuration for ' 'node %(node)s', {'node': task.node.uuid}) @@ -465,8 +478,10 @@ class RedfishVirtualMediaBoot(base.BootInterface): iso_ref = image_utils.prepare_deploy_iso(task, ramdisk_params, mode, d_info) - eject_vmedia(task, sushy.VIRTUAL_MEDIA_CD) - _insert_vmedia(task, iso_ref, sushy.VIRTUAL_MEDIA_CD) + _eject_vmedia(task, managers, sushy.VIRTUAL_MEDIA_CD) + _insert_vmedia(task, managers, iso_ref, sushy.VIRTUAL_MEDIA_CD) + + del managers boot_mode_utils.sync_boot_mode(task) @@ -492,12 +507,14 @@ class RedfishVirtualMediaBoot(base.BootInterface): LOG.debug("Cleaning up deploy boot for " "%(node)s", {'node': task.node.uuid}) - eject_vmedia(task, sushy.VIRTUAL_MEDIA_CD) + managers = redfish_utils.get_system(task.node).managers + + _eject_vmedia(task, managers, sushy.VIRTUAL_MEDIA_CD) image_utils.cleanup_iso_image(task) if (config_via_floppy - and _has_vmedia_device(task, sushy.VIRTUAL_MEDIA_FLOPPY)): - eject_vmedia(task, sushy.VIRTUAL_MEDIA_FLOPPY) + and _has_vmedia_device(managers, sushy.VIRTUAL_MEDIA_FLOPPY)): + _eject_vmedia(task, managers, sushy.VIRTUAL_MEDIA_FLOPPY) image_utils.cleanup_floppy_image(task) @@ -551,22 +568,27 @@ class RedfishVirtualMediaBoot(base.BootInterface): params.update(root_uuid=root_uuid) + managers = redfish_utils.get_system(task.node).managers + deploy_info = _parse_deploy_info(node) configdrive = node.instance_info.get('configdrive') iso_ref = image_utils.prepare_boot_iso(task, deploy_info, **params) - eject_vmedia(task, sushy.VIRTUAL_MEDIA_CD) - _insert_vmedia(task, iso_ref, sushy.VIRTUAL_MEDIA_CD) + _eject_vmedia(task, managers, sushy.VIRTUAL_MEDIA_CD) + _insert_vmedia(task, managers, iso_ref, sushy.VIRTUAL_MEDIA_CD) if configdrive and boot_option == 'ramdisk': - eject_vmedia(task, sushy.VIRTUAL_MEDIA_USBSTICK) + _eject_vmedia(task, managers, sushy.VIRTUAL_MEDIA_USBSTICK) cd_ref = image_utils.prepare_configdrive_image(task, configdrive) try: - _insert_vmedia(task, cd_ref, sushy.VIRTUAL_MEDIA_USBSTICK) + _insert_vmedia(task, managers, cd_ref, + sushy.VIRTUAL_MEDIA_USBSTICK) except exception.InvalidParameterValue: raise exception.InstanceDeployFailure( _('Cannot attach configdrive for node %s: no suitable ' 'virtual USB slot has been found') % node.uuid) + del managers + self._set_boot_device(task, boot_devices.CDROM, persistent=True) LOG.debug("Node %(node)s is set to permanently boot from " @@ -585,16 +607,18 @@ class RedfishVirtualMediaBoot(base.BootInterface): LOG.debug("Cleaning up instance boot for " "%(node)s", {'node': task.node.uuid}) - eject_vmedia(task, sushy.VIRTUAL_MEDIA_CD) + managers = redfish_utils.get_system(task.node).managers + + _eject_vmedia(task, managers, sushy.VIRTUAL_MEDIA_CD) d_info = task.node.driver_info config_via_floppy = d_info.get('config_via_floppy') if config_via_floppy: - eject_vmedia(task, sushy.VIRTUAL_MEDIA_FLOPPY) + _eject_vmedia(task, managers, sushy.VIRTUAL_MEDIA_FLOPPY) boot_option = deploy_utils.get_boot_option(task.node) if (boot_option == 'ramdisk' and task.node.instance_info.get('configdrive')): - eject_vmedia(task, sushy.VIRTUAL_MEDIA_USBSTICK) + _eject_vmedia(task, managers, sushy.VIRTUAL_MEDIA_USBSTICK) image_utils.cleanup_disk_image(task, prefix='configdrive') image_utils.cleanup_iso_image(task) diff --git a/ironic/tests/unit/drivers/modules/redfish/test_boot.py b/ironic/tests/unit/drivers/modules/redfish/test_boot.py index c632d8615b..18457760ae 100644 --- a/ironic/tests/unit/drivers/modules/redfish/test_boot.py +++ b/ironic/tests/unit/drivers/modules/redfish/test_boot.py @@ -326,17 +326,19 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): @mock.patch.object(redfish_boot.manager_utils, 'node_set_boot_device', autospec=True) @mock.patch.object(image_utils, 'prepare_deploy_iso', autospec=True) - @mock.patch.object(redfish_boot, 'eject_vmedia', autospec=True) + @mock.patch.object(redfish_boot, '_eject_vmedia', autospec=True) @mock.patch.object(redfish_boot, '_insert_vmedia', autospec=True) @mock.patch.object(redfish_boot, '_parse_driver_info', autospec=True) @mock.patch.object(redfish_boot.manager_utils, 'node_power_action', autospec=True) @mock.patch.object(redfish_boot, 'boot_mode_utils', autospec=True) + @mock.patch.object(redfish_utils, 'get_system', autospec=True) def test_prepare_ramdisk_with_params( - self, mock_boot_mode_utils, mock_node_power_action, + self, mock_system, mock_boot_mode_utils, mock_node_power_action, mock__parse_driver_info, mock__insert_vmedia, mock__eject_vmedia, mock_prepare_deploy_iso, mock_node_set_boot_device): + managers = mock_system.return_value.managers with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: task.node.provision_state = states.DEPLOYING @@ -350,10 +352,10 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): task, states.POWER_OFF) mock__eject_vmedia.assert_called_once_with( - task, sushy.VIRTUAL_MEDIA_CD) + task, managers, sushy.VIRTUAL_MEDIA_CD) mock__insert_vmedia.assert_called_once_with( - task, 'image-url', sushy.VIRTUAL_MEDIA_CD) + task, managers, 'image-url', sushy.VIRTUAL_MEDIA_CD) expected_params = { 'ipa-agent-token': mock.ANY, @@ -371,17 +373,19 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): @mock.patch.object(redfish_boot.manager_utils, 'node_set_boot_device', autospec=True) @mock.patch.object(image_utils, 'prepare_deploy_iso', autospec=True) - @mock.patch.object(redfish_boot, 'eject_vmedia', autospec=True) + @mock.patch.object(redfish_boot, '_eject_vmedia', autospec=True) @mock.patch.object(redfish_boot, '_insert_vmedia', autospec=True) @mock.patch.object(redfish_boot, '_parse_driver_info', autospec=True) @mock.patch.object(redfish_boot.manager_utils, 'node_power_action', autospec=True) @mock.patch.object(redfish_boot, 'boot_mode_utils', autospec=True) + @mock.patch.object(redfish_utils, 'get_system', autospec=True) def test_prepare_ramdisk_no_debug( - self, mock_boot_mode_utils, mock_node_power_action, + self, mock_system, mock_boot_mode_utils, mock_node_power_action, mock__parse_driver_info, mock__insert_vmedia, mock__eject_vmedia, mock_prepare_deploy_iso, mock_node_set_boot_device): self.config(debug=False) + managers = mock_system.return_value.managers with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: task.node.provision_state = states.DEPLOYING @@ -395,10 +399,10 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): task, states.POWER_OFF) mock__eject_vmedia.assert_called_once_with( - task, sushy.VIRTUAL_MEDIA_CD) + task, managers, sushy.VIRTUAL_MEDIA_CD) mock__insert_vmedia.assert_called_once_with( - task, 'image-url', sushy.VIRTUAL_MEDIA_CD) + task, managers, 'image-url', sushy.VIRTUAL_MEDIA_CD) expected_params = { 'ipa-agent-token': mock.ANY, @@ -417,18 +421,20 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): @mock.patch.object(image_utils, 'prepare_floppy_image', autospec=True) @mock.patch.object(image_utils, 'prepare_deploy_iso', autospec=True) @mock.patch.object(redfish_boot, '_has_vmedia_device', autospec=True) - @mock.patch.object(redfish_boot, 'eject_vmedia', autospec=True) + @mock.patch.object(redfish_boot, '_eject_vmedia', autospec=True) @mock.patch.object(redfish_boot, '_insert_vmedia', autospec=True) @mock.patch.object(redfish_boot, '_parse_driver_info', autospec=True) @mock.patch.object(redfish_boot.manager_utils, 'node_power_action', autospec=True) @mock.patch.object(redfish_boot, 'boot_mode_utils', autospec=True) + @mock.patch.object(redfish_utils, 'get_system', autospec=True) def test_prepare_ramdisk_with_floppy( - self, mock_boot_mode_utils, mock_node_power_action, + self, mock_system, mock_boot_mode_utils, mock_node_power_action, mock__parse_driver_info, mock__insert_vmedia, mock__eject_vmedia, mock__has_vmedia_device, mock_prepare_deploy_iso, mock_prepare_floppy_image, mock_node_set_boot_device): + managers = mock_system.return_value.managers with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: task.node.provision_state = states.DEPLOYING @@ -449,19 +455,20 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): task, states.POWER_OFF) mock__has_vmedia_device.assert_called_once_with( - task, sushy.VIRTUAL_MEDIA_FLOPPY) + managers, sushy.VIRTUAL_MEDIA_FLOPPY) eject_calls = [ - mock.call(task, sushy.VIRTUAL_MEDIA_FLOPPY), - mock.call(task, sushy.VIRTUAL_MEDIA_CD) + mock.call(task, managers, dev) + for dev in (sushy.VIRTUAL_MEDIA_FLOPPY, + sushy.VIRTUAL_MEDIA_CD) ] mock__eject_vmedia.assert_has_calls(eject_calls) insert_calls = [ - mock.call(task, 'floppy-image-url', + mock.call(task, managers, 'floppy-image-url', sushy.VIRTUAL_MEDIA_FLOPPY), - mock.call(task, 'cd-image-url', + mock.call(task, managers, 'cd-image-url', sushy.VIRTUAL_MEDIA_CD), ] @@ -482,15 +489,17 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): mock_boot_mode_utils.sync_boot_mode.assert_called_once_with(task) @mock.patch.object(redfish_boot, '_has_vmedia_device', autospec=True) - @mock.patch.object(redfish_boot, 'eject_vmedia', autospec=True) + @mock.patch.object(redfish_boot, '_eject_vmedia', autospec=True) @mock.patch.object(image_utils, 'cleanup_iso_image', autospec=True) @mock.patch.object(image_utils, 'cleanup_floppy_image', autospec=True) @mock.patch.object(redfish_boot, '_parse_driver_info', autospec=True) + @mock.patch.object(redfish_utils, 'get_system', autospec=True) def test_clean_up_ramdisk( - self, mock__parse_driver_info, mock_cleanup_floppy_image, - mock_cleanup_iso_image, mock__eject_vmedia, - mock__has_vmedia_device): + self, mock_system, mock__parse_driver_info, + mock_cleanup_floppy_image, mock_cleanup_iso_image, + mock__eject_vmedia, mock__has_vmedia_device): + managers = mock_system.return_value.managers with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: task.node.provision_state = states.DEPLOYING @@ -505,11 +514,11 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): mock_cleanup_floppy_image.assert_called_once_with(task) mock__has_vmedia_device.assert_called_once_with( - task, sushy.VIRTUAL_MEDIA_FLOPPY) + managers, sushy.VIRTUAL_MEDIA_FLOPPY) eject_calls = [ - mock.call(task, sushy.VIRTUAL_MEDIA_CD), - mock.call(task, sushy.VIRTUAL_MEDIA_FLOPPY) + mock.call(task, managers, sushy.VIRTUAL_MEDIA_CD), + mock.call(task, managers, sushy.VIRTUAL_MEDIA_FLOPPY) ] mock__eject_vmedia.assert_has_calls(eject_calls) @@ -517,17 +526,19 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): @mock.patch.object(redfish_boot.RedfishVirtualMediaBoot, 'clean_up_instance', autospec=True) @mock.patch.object(image_utils, 'prepare_boot_iso', autospec=True) - @mock.patch.object(redfish_boot, 'eject_vmedia', autospec=True) + @mock.patch.object(redfish_boot, '_eject_vmedia', autospec=True) @mock.patch.object(redfish_boot, '_insert_vmedia', autospec=True) @mock.patch.object(redfish_boot, '_parse_deploy_info', autospec=True) @mock.patch.object(redfish_boot, 'manager_utils', autospec=True) @mock.patch.object(redfish_boot, 'deploy_utils', autospec=True) @mock.patch.object(redfish_boot, 'boot_mode_utils', autospec=True) + @mock.patch.object(redfish_utils, 'get_system', autospec=True) def test_prepare_instance_normal_boot( - self, mock_boot_mode_utils, mock_deploy_utils, mock_manager_utils, - mock__parse_deploy_info, mock__insert_vmedia, mock__eject_vmedia, - mock_prepare_boot_iso, mock_clean_up_instance): + self, mock_system, mock_boot_mode_utils, mock_deploy_utils, + mock_manager_utils, mock__parse_deploy_info, mock__insert_vmedia, + mock__eject_vmedia, mock_prepare_boot_iso, mock_clean_up_instance): + managers = mock_system.return_value.managers with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: task.node.provision_state = states.DEPLOYING @@ -556,10 +567,10 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): task, d_info, **expected_params) mock__eject_vmedia.assert_called_once_with( - task, sushy.VIRTUAL_MEDIA_CD) + task, managers, sushy.VIRTUAL_MEDIA_CD) mock__insert_vmedia.assert_called_once_with( - task, 'image-url', sushy.VIRTUAL_MEDIA_CD) + task, managers, 'image-url', sushy.VIRTUAL_MEDIA_CD) mock_manager_utils.node_set_boot_device.assert_called_once_with( task, boot_devices.CDROM, persistent=True) @@ -570,17 +581,21 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): 'clean_up_instance', autospec=True) @mock.patch.object(image_utils, 'prepare_configdrive_image', autospec=True) @mock.patch.object(image_utils, 'prepare_boot_iso', autospec=True) - @mock.patch.object(redfish_boot, 'eject_vmedia', autospec=True) + @mock.patch.object(redfish_boot, '_eject_vmedia', autospec=True) @mock.patch.object(redfish_boot, '_insert_vmedia', autospec=True) @mock.patch.object(redfish_boot, '_parse_deploy_info', autospec=True) @mock.patch.object(redfish_boot, 'manager_utils', autospec=True) @mock.patch.object(redfish_boot, 'deploy_utils', autospec=True) @mock.patch.object(redfish_boot, 'boot_mode_utils', autospec=True) + @mock.patch.object(redfish_utils, 'get_system', autospec=True) def test_prepare_instance_ramdisk_boot( - self, mock_boot_mode_utils, mock_deploy_utils, mock_manager_utils, - mock__parse_deploy_info, mock__insert_vmedia, mock__eject_vmedia, - mock_prepare_boot_iso, mock_prepare_disk, mock_clean_up_instance): + self, mock_system, mock_boot_mode_utils, mock_deploy_utils, + mock_manager_utils, mock__parse_deploy_info, mock__insert_vmedia, + mock__eject_vmedia, mock_prepare_boot_iso, mock_prepare_disk, + mock_clean_up_instance): + configdrive = 'Y29udGVudA==' + managers = mock_system.return_value.managers with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: task.node.provision_state = states.DEPLOYING @@ -608,13 +623,15 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): mock_prepare_disk.assert_called_once_with(task, configdrive) mock__eject_vmedia.assert_has_calls([ - mock.call(task, sushy.VIRTUAL_MEDIA_CD), - mock.call(task, sushy.VIRTUAL_MEDIA_USBSTICK), + mock.call(task, managers, sushy.VIRTUAL_MEDIA_CD), + mock.call(task, managers, sushy.VIRTUAL_MEDIA_USBSTICK), ]) mock__insert_vmedia.assert_has_calls([ - mock.call(task, 'image-url', sushy.VIRTUAL_MEDIA_CD), - mock.call(task, 'cd-url', sushy.VIRTUAL_MEDIA_USBSTICK), + mock.call(task, managers, + 'image-url', sushy.VIRTUAL_MEDIA_CD), + mock.call(task, managers, + 'cd-url', sushy.VIRTUAL_MEDIA_USBSTICK), ]) mock_manager_utils.node_set_boot_device.assert_called_once_with( @@ -625,17 +642,19 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): @mock.patch.object(redfish_boot.RedfishVirtualMediaBoot, 'clean_up_instance', autospec=True) @mock.patch.object(image_utils, 'prepare_boot_iso', autospec=True) - @mock.patch.object(redfish_boot, 'eject_vmedia', autospec=True) + @mock.patch.object(redfish_boot, '_eject_vmedia', autospec=True) @mock.patch.object(redfish_boot, '_insert_vmedia', autospec=True) @mock.patch.object(redfish_boot, '_parse_deploy_info', autospec=True) @mock.patch.object(redfish_boot, 'manager_utils', autospec=True) @mock.patch.object(redfish_boot, 'deploy_utils', autospec=True) @mock.patch.object(redfish_boot, 'boot_mode_utils', autospec=True) + @mock.patch.object(redfish_utils, 'get_system', autospec=True) def test_prepare_instance_ramdisk_boot_iso( - self, mock_boot_mode_utils, mock_deploy_utils, mock_manager_utils, - mock__parse_deploy_info, mock__insert_vmedia, mock__eject_vmedia, - mock_prepare_boot_iso, mock_clean_up_instance): + self, mock_system, mock_boot_mode_utils, mock_deploy_utils, + mock_manager_utils, mock__parse_deploy_info, mock__insert_vmedia, + mock__eject_vmedia, mock_prepare_boot_iso, mock_clean_up_instance): + managers = mock_system.return_value.managers with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: task.node.provision_state = states.DEPLOYING @@ -659,10 +678,10 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): mock_prepare_boot_iso.assert_called_once_with(task, d_info) mock__eject_vmedia.assert_called_once_with( - task, sushy.VIRTUAL_MEDIA_CD) + task, managers, sushy.VIRTUAL_MEDIA_CD) mock__insert_vmedia.assert_called_once_with( - task, 'image-url', sushy.VIRTUAL_MEDIA_CD) + task, managers, 'image-url', sushy.VIRTUAL_MEDIA_CD) mock_manager_utils.node_set_boot_device.assert_called_once_with( task, boot_devices.CDROM, persistent=True) @@ -672,17 +691,19 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): @mock.patch.object(redfish_boot.RedfishVirtualMediaBoot, 'clean_up_instance', autospec=True) @mock.patch.object(image_utils, 'prepare_boot_iso', autospec=True) - @mock.patch.object(redfish_boot, 'eject_vmedia', autospec=True) + @mock.patch.object(redfish_boot, '_eject_vmedia', autospec=True) @mock.patch.object(redfish_boot, '_insert_vmedia', autospec=True) @mock.patch.object(redfish_boot, '_parse_deploy_info', autospec=True) @mock.patch.object(redfish_boot, 'manager_utils', autospec=True) @mock.patch.object(redfish_boot, 'deploy_utils', autospec=True) @mock.patch.object(redfish_boot, 'boot_mode_utils', autospec=True) + @mock.patch.object(redfish_utils, 'get_system', autospec=True) def test_prepare_instance_ramdisk_boot_iso_boot( - self, mock_boot_mode_utils, mock_deploy_utils, mock_manager_utils, - mock__parse_deploy_info, mock__insert_vmedia, mock__eject_vmedia, - mock_prepare_boot_iso, mock_clean_up_instance): + self, mock_system, mock_boot_mode_utils, mock_deploy_utils, + mock_manager_utils, mock__parse_deploy_info, mock__insert_vmedia, + mock__eject_vmedia, mock_prepare_boot_iso, mock_clean_up_instance): + managers = mock_system.return_value.managers with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: task.node.provision_state = states.DEPLOYING @@ -700,10 +721,10 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): mock_prepare_boot_iso.assert_called_once_with(task, {}) mock__eject_vmedia.assert_called_once_with( - task, sushy.VIRTUAL_MEDIA_CD) + task, managers, sushy.VIRTUAL_MEDIA_CD) mock__insert_vmedia.assert_called_once_with( - task, 'image-url', sushy.VIRTUAL_MEDIA_CD) + task, managers, 'image-url', sushy.VIRTUAL_MEDIA_CD) mock_manager_utils.node_set_boot_device.assert_called_once_with( task, boot_devices.CDROM, persistent=True) @@ -711,11 +732,12 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): mock_boot_mode_utils.sync_boot_mode.assert_called_once_with(task) @mock.patch.object(boot_mode_utils, 'sync_boot_mode', autospec=True) - @mock.patch.object(redfish_boot, 'eject_vmedia', autospec=True) + @mock.patch.object(redfish_boot, '_eject_vmedia', autospec=True) @mock.patch.object(image_utils, 'cleanup_iso_image', autospec=True) @mock.patch.object(redfish_boot, 'manager_utils', autospec=True) + @mock.patch.object(redfish_utils, 'get_system', autospec=True) def _test_prepare_instance_local_boot( - self, mock_manager_utils, + self, mock_system, mock_manager_utils, mock_cleanup_iso_image, mock__eject_vmedia, mock_sync_boot_mode): with task_manager.acquire(self.context, self.node.uuid, @@ -730,7 +752,8 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): task, boot_devices.DISK, persistent=True) mock_cleanup_iso_image.assert_called_once_with(task) mock__eject_vmedia.assert_called_once_with( - task, sushy.VIRTUAL_MEDIA_CD) + task, mock_system.return_value.managers, + sushy.VIRTUAL_MEDIA_CD) mock_sync_boot_mode.assert_called_once_with(task) def test_prepare_instance_local_whole_disk_image(self): @@ -745,20 +768,22 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): self.node.save() self._test_prepare_instance_local_boot() - @mock.patch.object(redfish_boot, 'eject_vmedia', autospec=True) + @mock.patch.object(redfish_boot, '_eject_vmedia', autospec=True) @mock.patch.object(image_utils, 'cleanup_iso_image', autospec=True) - def _test_clean_up_instance(self, mock_cleanup_iso_image, + @mock.patch.object(redfish_utils, 'get_system', autospec=True) + def _test_clean_up_instance(self, mock_system, mock_cleanup_iso_image, mock__eject_vmedia): - + managers = mock_system.return_value.managers with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: task.driver.boot.clean_up_instance(task) mock_cleanup_iso_image.assert_called_once_with(task) - eject_calls = [mock.call(task, sushy.VIRTUAL_MEDIA_CD)] + eject_calls = [mock.call(task, managers, sushy.VIRTUAL_MEDIA_CD)] if task.node.driver_info.get('config_via_floppy'): - eject_calls.append(mock.call(task, sushy.VIRTUAL_MEDIA_FLOPPY)) + eject_calls.append(mock.call(task, managers, + sushy.VIRTUAL_MEDIA_FLOPPY)) mock__eject_vmedia.assert_has_calls(eject_calls) @@ -773,13 +798,16 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): self._test_clean_up_instance() @mock.patch.object(deploy_utils, 'get_boot_option', autospec=True) - @mock.patch.object(redfish_boot, 'eject_vmedia', autospec=True) + @mock.patch.object(redfish_boot, '_eject_vmedia', autospec=True) @mock.patch.object(image_utils, 'cleanup_disk_image', autospec=True) @mock.patch.object(image_utils, 'cleanup_iso_image', autospec=True) - def test_clean_up_instance_ramdisk(self, mock_cleanup_iso_image, + @mock.patch.object(redfish_utils, 'get_system', autospec=True) + def test_clean_up_instance_ramdisk(self, mock_system, + mock_cleanup_iso_image, mock_cleanup_disk_image, mock__eject_vmedia, mock_get_boot_option): + managers = mock_system.return_value.managers with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: @@ -790,13 +818,14 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): mock_cleanup_iso_image.assert_called_once_with(task) mock_cleanup_disk_image.assert_called_once_with( task, prefix='configdrive') - eject_calls = [mock.call(task, sushy.VIRTUAL_MEDIA_CD), - mock.call(task, sushy.VIRTUAL_MEDIA_USBSTICK)] + eject_calls = [ + mock.call(task, managers, sushy.VIRTUAL_MEDIA_CD), + mock.call(task, managers, sushy.VIRTUAL_MEDIA_USBSTICK), + ] mock__eject_vmedia.assert_has_calls(eject_calls) - @mock.patch.object(redfish_boot, 'redfish_utils', autospec=True) - def test__insert_vmedia_anew(self, mock_redfish_utils): + def test__insert_vmedia_anew(self): with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: @@ -812,19 +841,15 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): mock_manager.virtual_media.get_members.return_value = [ mock_vmedia_cd, mock_vmedia_floppy] - mock_redfish_utils.get_system.return_value.managers = [ - mock_manager] - redfish_boot._insert_vmedia( - task, 'img-url', sushy.VIRTUAL_MEDIA_CD) + task, [mock_manager], 'img-url', sushy.VIRTUAL_MEDIA_CD) mock_vmedia_cd.insert_media.assert_called_once_with( 'img-url', inserted=True, write_protected=True) self.assertFalse(mock_vmedia_floppy.insert_media.call_count) - @mock.patch.object(redfish_boot, 'redfish_utils', autospec=True) - def test__insert_vmedia_already_inserted(self, mock_redfish_utils): + def test__insert_vmedia_already_inserted(self): with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: @@ -837,17 +862,13 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): mock_manager.virtual_media.get_members.return_value = [ mock_vmedia_cd] - mock_redfish_utils.get_system.return_value.managers = [ - mock_manager] - redfish_boot._insert_vmedia( - task, 'img-url', sushy.VIRTUAL_MEDIA_CD) + task, [mock_manager], 'img-url', sushy.VIRTUAL_MEDIA_CD) self.assertFalse(mock_vmedia_cd.insert_media.call_count) - @mock.patch.object(redfish_boot, 'redfish_utils', autospec=True) @mock.patch('time.sleep', lambda *args, **kwargs: None) - def test__insert_vmedia_while_ejecting(self, mock_redfish_utils): + def test__insert_vmedia_while_ejecting(self): with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: @@ -866,17 +887,13 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): mock_manager.virtual_media.get_members.return_value = [ mock_vmedia_cd] - mock_redfish_utils.get_system.return_value.managers = [ - mock_manager] - redfish_boot._insert_vmedia( - task, 'img-url', sushy.VIRTUAL_MEDIA_CD) + task, [mock_manager], 'img-url', sushy.VIRTUAL_MEDIA_CD) self.assertEqual(mock_vmedia_cd.insert_media.call_count, 2) - @mock.patch.object(redfish_boot, 'redfish_utils', autospec=True) @mock.patch('time.sleep', lambda *args, **kwargs: None) - def test__insert_vmedia_bad_device(self, mock_redfish_utils): + def test__insert_vmedia_bad_device(self): with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: @@ -888,14 +905,10 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): mock_manager.virtual_media.get_members.return_value = [ mock_vmedia_floppy] - mock_redfish_utils.get_system.return_value.managers = [ - mock_manager] - self.assertRaises( exception.InvalidParameterValue, redfish_boot._insert_vmedia, - task, 'img-url', sushy.VIRTUAL_MEDIA_CD) - self.assertEqual(mock_redfish_utils.get_system.call_count, 1) + task, [mock_manager], 'img-url', sushy.VIRTUAL_MEDIA_CD) @mock.patch.object(redfish_boot, 'redfish_utils', autospec=True) def test_eject_vmedia_everything(self, mock_redfish_utils): diff --git a/releasenotes/notes/redfish-vmedia-opt-59cafdde83fb2be7.yaml b/releasenotes/notes/redfish-vmedia-opt-59cafdde83fb2be7.yaml new file mode 100644 index 0000000000..47f2294e57 --- /dev/null +++ b/releasenotes/notes/redfish-vmedia-opt-59cafdde83fb2be7.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + The ``redfish-virtual-media`` boot interface now makes fewer calls to + the BMC when preparing boot.