From 90b58533460ce081164c8581faf7c67af723c8af Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Thu, 6 Nov 2025 16:11:55 -0600 Subject: [PATCH] fix: local_link_connection inspection hook does not fail on missing port The code intended to not fail when a Port object was missing but to instead skip the handling of that node but instead there is an unhandled exception because the get_by_address() method throws PortNotFound instead of returning None when a port couldn't be found. Change-Id: I04dfa09ada7e6a9d22ba16051cb5737daf3bc668 Signed-off-by: Doug Goldstein --- .../modules/inspector/hooks/local_link_connection.py | 6 ++++-- .../modules/inspector/hooks/test_local_link_connection.py | 3 ++- ...t-hook-local-link-connection-crash-394edb1c35354968.yaml | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/inspect-hook-local-link-connection-crash-394edb1c35354968.yaml diff --git a/ironic/drivers/modules/inspector/hooks/local_link_connection.py b/ironic/drivers/modules/inspector/hooks/local_link_connection.py index a3fb9fc718..17bc82f014 100644 --- a/ironic/drivers/modules/inspector/hooks/local_link_connection.py +++ b/ironic/drivers/modules/inspector/hooks/local_link_connection.py @@ -117,8 +117,10 @@ class LocalLinkConnectionHook(base.InspectionHook): continue mac_address = iface['mac_address'] - port = ironic_port.Port.get_by_address(task.context, mac_address) - if not port: + try: + port = ironic_port.Port.get_by_address(task.context, + mac_address) + except exception.PortNotFound: LOG.debug('Skipping LLDP processing for interface %s of node ' '%s: matching port not found in Ironic.', mac_address, task.node.uuid) diff --git a/ironic/tests/unit/drivers/modules/inspector/hooks/test_local_link_connection.py b/ironic/tests/unit/drivers/modules/inspector/hooks/test_local_link_connection.py index 2668d3086f..5f06b30f55 100644 --- a/ironic/tests/unit/drivers/modules/inspector/hooks/test_local_link_connection.py +++ b/ironic/tests/unit/drivers/modules/inspector/hooks/test_local_link_connection.py @@ -15,6 +15,7 @@ from unittest import mock from oslo_utils import uuidutils +from ironic.common import exception from ironic.conductor import task_manager from ironic.conf import CONF from ironic.drivers.modules.inspector.hooks import local_link_connection as \ @@ -86,7 +87,7 @@ class LocalLinkConnectionTestCase(db_base.DbTestCase): @mock.patch.object(port.Port, 'get_by_address', autospec=True) @mock.patch.object(port.Port, 'save', autospec=True) def test_no_port_in_ironic(self, mock_port_save, mock_get_port, mock_log): - mock_get_port.return_value = None + mock_get_port.side_effect = exception.PortNotFound with task_manager.acquire(self.context, self.node.id) as task: hook.LocalLinkConnectionHook().__call__(task, self.inventory, self.plugin_data) diff --git a/releasenotes/notes/inspect-hook-local-link-connection-crash-394edb1c35354968.yaml b/releasenotes/notes/inspect-hook-local-link-connection-crash-394edb1c35354968.yaml new file mode 100644 index 0000000000..98c6df851a --- /dev/null +++ b/releasenotes/notes/inspect-hook-local-link-connection-crash-394edb1c35354968.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Avoid an unhandled exception in the local_link_connection inspection hook + which would cause inspection to fail instead of skipping past missing ports + as originally intended.