Skip to content

Commit 51eaffc

Browse files
committed
fix(neutron): read physical_network from port binding if able
If we are able to read the physical_network from the port binding information then we should do that over looking it up. Uses: https://review.opendev.org/c/openstack/ironic/+/964570
1 parent 016f524 commit 51eaffc

File tree

2 files changed

+49
-32
lines changed

2 files changed

+49
-32
lines changed

python/neutron-understack/neutron_understack/neutron_understack_mech.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,18 @@ def _update_port_baremetal(self, context: PortContext) -> None:
115115
current_vif_other = context.vif_type == portbindings.VIF_TYPE_OTHER
116116

117117
if current_vif_unbound and original_vif_other:
118-
local_link_info = utils.local_link_from_binding_profile(
119-
context.original[portbindings.PROFILE]
120-
)
118+
port = context.original
121119
else:
120+
port = context.current
121+
122+
vlan_group_name = port[portbindings.PROFILE].get("physical_network")
123+
if vlan_group_name is None:
122124
local_link_info = utils.local_link_from_binding_profile(
123-
context.current[portbindings.PROFILE]
125+
port[portbindings.PROFILE]
126+
)
127+
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
128+
local_link_info
124129
)
125-
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
126-
local_link_info
127-
)
128130

129131
if current_vif_unbound and original_vif_other:
130132
self._tenant_network_port_cleanup(context)
@@ -178,14 +180,18 @@ def _delete_port_baremetal(self, context: PortContext) -> None:
178180
# Only clean up provisioning ports. Ports with tenant networks are cleaned
179181
# up in _tenant_network_port_cleanup
180182

181-
local_link_info = utils.local_link_from_binding_profile(
182-
context.current[portbindings.PROFILE]
183-
)
184-
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
185-
local_link_info
186-
)
183+
port = context.current
187184

188-
if vlan_group_name and is_provisioning_network(context.current["network_id"]):
185+
vlan_group_name = port[portbindings.PROFILE].get("physical_network")
186+
if vlan_group_name is None:
187+
local_link_info = utils.local_link_from_binding_profile(
188+
port[portbindings.PROFILE]
189+
)
190+
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
191+
local_link_info
192+
)
193+
194+
if vlan_group_name and is_provisioning_network(port["network_id"]):
189195
# Signals end of the provisioning / cleaning cycle, so we
190196
# put the port back to its normal tenant mode:
191197
self.invoke_undersync(vlan_group_name)
@@ -232,12 +238,16 @@ def _bind_port_segment(self, context: PortContext, segment):
232238
network_id = context.current["network_id"]
233239
mac_address = context.current["mac_address"]
234240

235-
local_link_info = utils.local_link_from_binding_profile(
236-
context.current[portbindings.PROFILE]
237-
)
238-
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
239-
local_link_info
240-
)
241+
port = context.current
242+
243+
vlan_group_name = port[portbindings.PROFILE].get("physical_network")
244+
if vlan_group_name is None:
245+
local_link_info = utils.local_link_from_binding_profile(
246+
port[portbindings.PROFILE]
247+
)
248+
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
249+
local_link_info
250+
)
241251

242252
if not vlan_group_name:
243253
LOG.error(

python/neutron-understack/neutron_understack/trunk.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,12 @@ def _add_subports_networks_to_parent_port_switchport(
181181
binding_profile = parent_port.bindings[0].profile
182182
binding_host = parent_port.bindings[0].host
183183

184-
local_link_info = utils.local_link_from_binding_profile(binding_profile)
185-
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
186-
local_link_info
187-
)
184+
vlan_group_name = binding_profile.get("physical_network")
185+
if vlan_group_name is None:
186+
local_link_info = utils.local_link_from_binding_profile(binding_profile)
187+
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
188+
local_link_info
189+
)
188190

189191
self._handle_segment_allocation(subports, vlan_group_name, binding_host)
190192

@@ -207,10 +209,13 @@ def _clean_parent_port_switchport_config(
207209
return
208210
binding_profile = parent_port_obj.bindings[0].profile
209211
binding_host = parent_port_obj.bindings[0].host
210-
local_link_info = utils.local_link_from_binding_profile(binding_profile)
211-
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
212-
local_link_info
213-
)
212+
213+
vlan_group_name = binding_profile.get("physical_network")
214+
if vlan_group_name is None:
215+
local_link_info = utils.local_link_from_binding_profile(binding_profile)
216+
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
217+
local_link_info
218+
)
214219
self._handle_subports_removal(
215220
binding_profile=binding_profile,
216221
binding_host=binding_host,
@@ -265,10 +270,12 @@ def subports_added_post(self, resource, event, trunk_plugin, payload):
265270

266271
if utils.parent_port_is_bound(parent_port):
267272
binding_profile = parent_port.bindings[0].profile
268-
local_link_info = utils.local_link_from_binding_profile(binding_profile)
269-
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
270-
local_link_info
271-
)
273+
vlan_group_name = binding_profile.get("physical_network")
274+
if vlan_group_name is None:
275+
local_link_info = utils.local_link_from_binding_profile(binding_profile)
276+
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
277+
local_link_info
278+
)
272279
LOG.debug("subports_added_post found vlan_group_name=%s", vlan_group_name)
273280
self._trigger_undersync(vlan_group_name)
274281

0 commit comments

Comments
 (0)