From 65583e64172a0188d125117d1f2288e105832395 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Thu, 23 Jun 2022 19:24:44 +0200 Subject: [PATCH] No deploy_kernel/ramdisk with the ramdisk deploy and no cleaning Ramdisk deploys don't use IPA, no need to provide it. Cleaning may need the agent, so only skip verification if cleaning is disabled. Other boot interfaces may need fixing as well, I haven't checked them. Change-Id: Ia2739311f065e19ba539fe3df7268075d6075787 --- ironic/common/pxe_utils.py | 16 ++++++++++++---- ironic/conductor/utils.py | 8 ++++---- ironic/drivers/modules/deploy_utils.py | 14 ++++++++++++++ ironic/drivers/modules/redfish/boot.py | 7 ++++++- ironic/tests/unit/common/test_pxe_utils.py | 13 ++++++++----- .../unit/drivers/modules/redfish/test_boot.py | 10 ++++++++++ ...edfish-ramdisk-no-agent-490b5edb0b2387e5.yaml | 6 ++++++ 7 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 releasenotes/notes/redfish-ramdisk-no-agent-490b5edb0b2387e5.yaml diff --git a/ironic/common/pxe_utils.py b/ironic/common/pxe_utils.py index 5e112ee306..b0f1d906fc 100644 --- a/ironic/common/pxe_utils.py +++ b/ironic/common/pxe_utils.py @@ -229,10 +229,13 @@ def get_kernel_ramdisk_info(node_uuid, driver_info, mode='deploy', image_info = {} labels = KERNEL_RAMDISK_LABELS[mode] for label in labels: - image_info[label] = ( - str(driver_info[label]), - os.path.join(root_dir, node_uuid, label) - ) + try: + image_info[label] = ( + str(driver_info[label]), + os.path.join(root_dir, node_uuid, label) + ) + except KeyError: + pass # may be absent in rare cases, verified in parse_driver_info return image_info @@ -619,6 +622,11 @@ def parse_driver_info(node, mode='deploy'): :returns: A dict with the driver_info values. :raises: MissingParameterValue """ + if not deploy_utils.needs_agent_ramdisk(node, mode=mode): + # Ramdisk deploy does not need an agent, nor does it support any other, + # options. Skipping. + return {} + info = node.driver_info params_to_check = KERNEL_RAMDISK_LABELS[mode] diff --git a/ironic/conductor/utils.py b/ironic/conductor/utils.py index b418d9d0a9..aeb067a7a1 100644 --- a/ironic/conductor/utils.py +++ b/ironic/conductor/utils.py @@ -938,7 +938,7 @@ def notify_conductor_resume_deploy(task): notify_conductor_resume_operation(task, 'deploy') -def skip_automated_cleaning(node): +def skip_automated_cleaning(node, log=True): """Checks if node cleaning needs to be skipped for an specific node. :param node: the node to consider @@ -948,9 +948,9 @@ def skip_automated_cleaning(node): elif node.automated_clean is None: return not CONF.conductor.automated_clean else: - LOG.info("Automated cleaning is disabled via the API for " - "node %(node)s", - {'node': node.uuid}) + if log: + LOG.info("Automated cleaning is disabled via the API for " + "node %(node)s", {'node': node.uuid}) return True diff --git a/ironic/drivers/modules/deploy_utils.py b/ironic/drivers/modules/deploy_utils.py index f6883249f9..89258b134d 100644 --- a/ironic/drivers/modules/deploy_utils.py +++ b/ironic/drivers/modules/deploy_utils.py @@ -1452,3 +1452,17 @@ def get_root_device_for_deploy(node): _('Failed to validate the root device hints %(hints)s (from the ' 'node\'s %(source)s) for node %(node)s: %(error)s') % {'node': node.uuid, 'hints': hints, 'source': source, 'error': e}) + + +def needs_agent_ramdisk(node, mode='deploy'): + """Checks whether the node requires an agent ramdisk now.""" + if mode != 'deploy': + return True # Rescue always needs a ramdisk + + if get_boot_option(node) != 'ramdisk': + return True # Normal deploys need an agent + + # Ramdisk deploys don't need an agent, but cleaning will. Since we don't + # want nodes to be stuck on deletion, require an agent when cleaning is + # enabled. + return not manager_utils.skip_automated_cleaning(node, log=False) diff --git a/ironic/drivers/modules/redfish/boot.py b/ironic/drivers/modules/redfish/boot.py index 1ce05ced9f..25240228e7 100644 --- a/ironic/drivers/modules/redfish/boot.py +++ b/ironic/drivers/modules/redfish/boot.py @@ -91,9 +91,14 @@ def _parse_driver_info(node): :raises: InvalidParameterValue, if any of the parameters have invalid value. """ + mode = deploy_utils.rescue_or_deploy_mode(node) + if not deploy_utils.needs_agent_ramdisk(node, mode=mode): + # Ramdisk deploy does not need an agent, nor does it support any other + # options. Skipping. + return {'can_provide_config': False} + d_info = node.driver_info - mode = deploy_utils.rescue_or_deploy_mode(node) iso_param = f'{mode}_iso' iso_ref = driver_utils.get_agent_iso(node, deprecated_prefix='redfish', mode=mode) diff --git a/ironic/tests/unit/common/test_pxe_utils.py b/ironic/tests/unit/common/test_pxe_utils.py index 77ac5f4d3e..f38e7127ad 100644 --- a/ironic/tests/unit/common/test_pxe_utils.py +++ b/ironic/tests/unit/common/test_pxe_utils.py @@ -921,11 +921,7 @@ class TestPXEUtils(db_base.DbTestCase): def test_get_kernel_ramdisk_info_bad_driver_info(self): self.config(tftp_root='/tftp', group='pxe') node_uuid = 'fake-node' - driver_info = {} - self.assertRaises(KeyError, - pxe_utils.get_kernel_ramdisk_info, - node_uuid, - driver_info) + self.assertEqual({}, pxe_utils.get_kernel_ramdisk_info(node_uuid, {})) def test_get_rescue_kr_info(self): expected_dir = '/tftp' @@ -1189,6 +1185,13 @@ class PXEInterfacesTestCase(db_base.DbTestCase): group='conductor') self._test_parse_driver_info_missing_ramdisk(mode='rescue') + @mock.patch.object(deploy_utils, 'get_boot_option', lambda node: 'ramdisk') + def test_parse_driver_info_ramdisk(self): + self.node.driver_info = {} + self.node.automated_clean = False + image_info = pxe_utils.parse_driver_info(self.node, mode='deploy') + self.assertEqual({}, image_info) + def test__get_deploy_image_info(self): expected_info = {'deploy_ramdisk': (DRV_INFO_DICT['deploy_ramdisk'], diff --git a/ironic/tests/unit/drivers/modules/redfish/test_boot.py b/ironic/tests/unit/drivers/modules/redfish/test_boot.py index e69c29dcad..7993703947 100644 --- a/ironic/tests/unit/drivers/modules/redfish/test_boot.py +++ b/ironic/tests/unit/drivers/modules/redfish/test_boot.py @@ -58,6 +58,16 @@ class RedfishVirtualMediaBootTestCase(db_base.DbTestCase): 'Unable to import the sushy library', redfish_boot.RedfishVirtualMediaBoot) + @mock.patch.object(deploy_utils, 'get_boot_option', lambda node: 'ramdisk') + def test_parse_driver_info_ramdisk(self): + with task_manager.acquire(self.context, self.node.uuid, + shared=True) as task: + task.node.driver_info = {} + task.node.automated_clean = False + actual_driver_info = redfish_boot._parse_driver_info(task.node) + self.assertEqual({'can_provide_config': False}, + actual_driver_info) + def test_parse_driver_info_deploy(self): with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: diff --git a/releasenotes/notes/redfish-ramdisk-no-agent-490b5edb0b2387e5.yaml b/releasenotes/notes/redfish-ramdisk-no-agent-490b5edb0b2387e5.yaml new file mode 100644 index 0000000000..cbb49c4475 --- /dev/null +++ b/releasenotes/notes/redfish-ramdisk-no-agent-490b5edb0b2387e5.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + When the ``ramdisk`` deploy interface is used and automated cleaning is + disabled, the ``pxe``, ``ipxe`` and ``redfish-virtual-media`` boot + interfaces no longer require a deploy kernel/ramdisk to be provided.