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 <cardoe@cardoe.com>
This commit is contained in:
Doug Goldstein
2025-11-06 16:11:55 -06:00
parent e3b943a34b
commit 90b5853346
3 changed files with 12 additions and 3 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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.