@@ -145,12 +145,60 @@ def test_with_valid_storage_port(mocker, caplog):
145145 "switch_id" : "88:5a:92:ec:54:59" ,
146146 "switch_info" : "f20-3-1f.iad3.rackspace.net" ,
147147 }
148- assert mock_port .physical_network is None
148+ # Storage-client physnets are preserved (previously nulled).
149+ assert mock_port .physical_network == "f20-3-storage"
149150 assert mock_port .category == "storage"
150151 assert mock_port .pxe_enabled is False
151152 mock_port .save .assert_called ()
152153
153154
155+ def test_non_realized_physnet_is_nulled (mocker , caplog ):
156+ """A "-storage-appliance" physnet is still nulled; only its category survives."""
157+ caplog .set_level (logging .DEBUG )
158+
159+ node_uuid = uuidutils .generate_uuid ()
160+ mock_traits = mocker .Mock ()
161+ mock_context = mocker .Mock ()
162+ mock_node = mocker .Mock (id = 1234 , traits = mock_traits )
163+ mock_task = mocker .Mock (node = mock_node , context = mock_context )
164+ mock_port = mocker .Mock (
165+ uuid = uuidutils .generate_uuid (),
166+ node_id = node_uuid ,
167+ address = "33:33:33:33:33:33" ,
168+ local_link_connection = {},
169+ physical_network = "original_value" ,
170+ category = None ,
171+ pxe_enabled = True ,
172+ )
173+
174+ # Derive "f20-3-storage-appliance" from the connected suffixes.
175+ appliance_mapping = {
176+ "1" : "network" ,
177+ "2" : "network" ,
178+ "1f" : "storage-appliance" ,
179+ "2f" : "storage-appliance" ,
180+ }
181+
182+ mocker .patch (
183+ "ironic_understack.hooks.inspect_hook_update_baremetal_ports.ironic_ports_for_node" ,
184+ return_value = [mock_port ],
185+ )
186+ mocker .patch (
187+ "ironic_understack.hooks.inspect_hook_update_baremetal_ports.CONF.ironic_understack.switch_name_vlan_group_mapping" ,
188+ appliance_mapping ,
189+ )
190+ mocker .patch (
191+ "ironic_understack.hooks.inspect_hook_update_baremetal_ports.objects.TraitList.create"
192+ )
193+ mock_traits .get_trait_names .return_value = ["CUSTOM_BMC_SWITCH" , "bar" ]
194+
195+ InspectHookUpdateBaremetalPorts ().__call__ (mock_task , _INVENTORY , _PLUGIN_DATA )
196+
197+ assert mock_port .physical_network is None
198+ assert mock_port .category == "appliance"
199+ mock_port .save .assert_called ()
200+
201+
154202def test_secondary_network_port_has_pxe_disabled (mocker , caplog ):
155203 caplog .set_level (logging .DEBUG )
156204
0 commit comments