From 86103467941c3b957643deedb0a9a41b02d08eb1 Mon Sep 17 00:00:00 2001 From: Julia Kreger Date: Tue, 18 Feb 2025 11:29:18 -0800 Subject: [PATCH] Don't log PXE when your not doing PXE. So... the neutron common code is modeled around PXE, and when you go to do something with vmedia, you can get errors logged about not having PXE enabled ports which is misleading. The reality is the common code needs to base the decision on if all ports need to be added or if just PXE enabled ports need to be added based upon the loaded driver via configuration. As such, now we consult the boot interface's capabilities field and alternatively pull in the additional interfaces as appropriate for virtual media users. Which then also fixes the misleading error! Closes-Bug: 2098791 Change-Id: I8c9d07e2ded75f138897ece6a67016a6f0020ce6 --- ironic/common/neutron.py | 3 ++- ironic/tests/unit/common/test_neutron.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ironic/common/neutron.py b/ironic/common/neutron.py index 31ceefebd0..3282dc8583 100644 --- a/ironic/common/neutron.py +++ b/ironic/common/neutron.py @@ -259,7 +259,8 @@ def add_ports_to_network(task, network_uuid, security_groups=None): """ client = get_client(context=task.context) node = task.node - add_all_ports = CONF.neutron.add_all_ports + pxe_capability = 'pxe_boot' in task.driver.boot.capabilities + add_all_ports = CONF.neutron.add_all_ports or not pxe_capability # If Security Groups are specified, verify that they exist _verify_security_groups(security_groups, client) diff --git a/ironic/tests/unit/common/test_neutron.py b/ironic/tests/unit/common/test_neutron.py index dc6a07893d..ccc3c4facf 100644 --- a/ironic/tests/unit/common/test_neutron.py +++ b/ironic/tests/unit/common/test_neutron.py @@ -224,7 +224,8 @@ class TestNeutronNetworkActions(db_base.DbTestCase): @mock.patch.object(neutron, 'update_neutron_port', autospec=True) def _test_add_ports_to_network(self, update_mock, is_client_id, security_groups=None, - add_all_ports=False): + add_all_ports=False, + boot_not_pxe=False): # Ports will be created only if pxe_enabled is True self.node.network_interface = 'neutron' self.node.save() @@ -263,7 +264,7 @@ class TestNeutronNetworkActions(db_base.DbTestCase): expected_create_attrs['extra_dhcp_opts'] = ( [{'opt_name': '61', 'opt_value': self._CLIENT_ID}]) - if add_all_ports: + if add_all_ports or boot_not_pxe: expected_create_attrs2 = copy.deepcopy(expected_create_attrs) expected_update_attrs2 = copy.deepcopy(expected_update_attrs) expected_update_attrs2['mac_address'] = port2.address @@ -284,10 +285,13 @@ class TestNeutronNetworkActions(db_base.DbTestCase): expected = {port.uuid: self.neutron_port['id']} with task_manager.acquire(self.context, self.node.uuid) as task: + if boot_not_pxe: + # force override of driver properties, just to keep it simple. + task.driver.boot.capabilities = ['not_pxe'] ports = neutron.add_ports_to_network( task, self.network_uuid, security_groups=security_groups) self.assertEqual(expected, ports) - if add_all_ports: + if add_all_ports or boot_not_pxe: create_calls = [mock.call(**expected_create_attrs), mock.call(**expected_create_attrs2)] update_calls = [ @@ -313,6 +317,10 @@ class TestNeutronNetworkActions(db_base.DbTestCase): security_groups=None, add_all_ports=True) + def test_add_ports_to_network_all_ports_via_not_pxe(self): + self._test_add_ports_to_network(is_client_id=False, + boot_not_pxe=True) + @mock.patch.object(neutron, '_verify_security_groups', autospec=True) def test_add_ports_to_network_with_sg(self, verify_mock): sg_ids = []