From f10958a542dd58ff301c386ce0981ec218e9eef6 Mon Sep 17 00:00:00 2001 From: Jacob Anders Date: Mon, 17 Apr 2023 14:39:50 +1000 Subject: [PATCH] Handle MissingAttributeError when using OOB inspections to fetch MACs Currently, if an attempt is made to fetch MAC address information using OOB inspection on a Redfish-managed node and EthernetInterfaces attribute is missing on the node, inspection fails due to a MissingAttributeError exception being raised by sushy. This change adds catching and handling this exception. Change-Id: I6f16da05e19c7efc966128fdf79f13546f51b5a6 --- ironic/drivers/modules/redfish/management.py | 11 ++++++++++- .../unit/drivers/modules/redfish/test_management.py | 10 ++++++++++ ...sing-ethernetinterfaces-attr-7e52f7259fe66762.yaml | 9 +++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/handle-missing-ethernetinterfaces-attr-7e52f7259fe66762.yaml diff --git a/ironic/drivers/modules/redfish/management.py b/ironic/drivers/modules/redfish/management.py index a669d09bc8..8bd7058a55 100644 --- a/ironic/drivers/modules/redfish/management.py +++ b/ironic/drivers/modules/redfish/management.py @@ -1197,9 +1197,18 @@ class RedfishManagement(base.ManagementInterface): :raises: RedfishError on an error from the Sushy library :returns: A list of MAC addresses for the node """ + system = redfish_utils.get_system(task.node) try: - system = redfish_utils.get_system(task.node) return list(redfish_utils.get_enabled_macs(task, system)) + # NOTE(janders) we should handle MissingAttributeError separately + # from other SushyErrors - some servers (e.g. some Cisco UCSB and UCSX + # blades) are missing EthernetInterfaces attribute yet could be + # provisioned successfully if MAC information is provided manually AND + # this exception is caught and handled accordingly. + except sushy.exceptions.MissingAttributeError as exc: + LOG.warning('Cannot get MAC addresses for node %(node)s: %(exc)s', + {'node': task.node.uuid, 'exc': exc}) + # if the exception is not a MissingAttributeError, raise it except sushy.exceptions.SushyError as exc: msg = (_('Failed to get network interface information on node ' '%(node)s: %(exc)s') diff --git a/ironic/tests/unit/drivers/modules/redfish/test_management.py b/ironic/tests/unit/drivers/modules/redfish/test_management.py index f8c82949a6..1d752d909a 100644 --- a/ironic/tests/unit/drivers/modules/redfish/test_management.py +++ b/ironic/tests/unit/drivers/modules/redfish/test_management.py @@ -1598,3 +1598,13 @@ class RedfishManagementTestCase(db_base.DbTestCase): shared=True) as task: self.assertEqual([], task.driver.management.get_mac_addresses(task)) + + @mock.patch.object(redfish_utils, 'get_enabled_macs', autospec=True) + @mock.patch.object(redfish_utils, 'get_system', autospec=True) + def test_get_mac_addresses_missing_attr(self, mock_get_system, + mock_get_enabled_macs): + redfish_utils.get_enabled_macs.side_effect = (sushy.exceptions. + MissingAttributeError) + with task_manager.acquire(self.context, self.node.uuid, + shared=True) as task: + self.assertIsNone(task.driver.management.get_mac_addresses(task)) diff --git a/releasenotes/notes/handle-missing-ethernetinterfaces-attr-7e52f7259fe66762.yaml b/releasenotes/notes/handle-missing-ethernetinterfaces-attr-7e52f7259fe66762.yaml new file mode 100644 index 0000000000..2252385069 --- /dev/null +++ b/releasenotes/notes/handle-missing-ethernetinterfaces-attr-7e52f7259fe66762.yaml @@ -0,0 +1,9 @@ +--- +fixes: + - | + Fixes the bug where provisioning a Redfish managed node fails if the BMC + doesn't support EthernetInterfaces attribute, even if MAC address + information is provided manually. This is done by handling of + MissingAttributeError sushy exception in get_mac_addresses() method. + This fix is needed to successfully provision machines such as Cisco UCSB + and UCSX.