Skip to content

Commit 123798a

Browse files
authored
Merge pull request #983 from rackerlabs/port_groups
fix: change ironic client to get port by local link info
2 parents 5f9af7f + 89b5c95 commit 123798a

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

python/neutron-understack/neutron_understack/ironic.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ def _get_ironic_client(self) -> BaremetalService:
2121
session=session, oslo_conf=cfg.CONF, connect_retries=cfg.CONF.http_retries
2222
).baremetal
2323

24-
def baremetal_port_by_mac(self, mac_addr: str) -> BaremetalPort | None:
24+
def baremetal_port_physical_network(self, local_link_info: dict) -> str | None:
25+
port = self._port_by_local_link(local_link_info)
26+
return port.physical_network if port else None
27+
28+
def _port_by_local_link(self, local_link_info: dict) -> BaremetalPort | None:
2529
try:
26-
return next(self.irclient.ports(details=True, address=mac_addr))
30+
return next(
31+
self.irclient.ports(details=True, local_link_connection=local_link_info)
32+
)
2733
except StopIteration:
2834
return None
29-
30-
def baremetal_port_physical_network(self, mac_addr: str) -> str | None:
31-
port = self.baremetal_port_by_mac(mac_addr)
32-
return port.physical_network if port else None

python/neutron-understack/neutron_understack/neutron_understack_mech.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,16 @@ def _update_port_baremetal(self, context: PortContext) -> None:
258258
original_vif_other = context.original_vif_type == portbindings.VIF_TYPE_OTHER
259259
current_vif_other = context.vif_type == portbindings.VIF_TYPE_OTHER
260260

261+
if current_vif_unbound and original_vif_other:
262+
local_link_info = utils.local_link_from_binding_profile(
263+
context.original[portbindings.PROFILE]
264+
)
265+
else:
266+
local_link_info = utils.local_link_from_binding_profile(
267+
context.current[portbindings.PROFILE]
268+
)
261269
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
262-
context.current["mac_address"]
270+
local_link_info
263271
)
264272

265273
if current_vif_unbound and original_vif_other:
@@ -323,8 +331,11 @@ def _delete_port_baremetal(self, context: PortContext) -> None:
323331
# Only clean up provisioning ports. Ports with tenant networks are cleaned
324332
# up in _tenant_network_port_cleanup
325333

334+
local_link_info = utils.local_link_from_binding_profile(
335+
context.current[portbindings.PROFILE]
336+
)
326337
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
327-
context.current["mac_address"]
338+
local_link_info
328339
)
329340

330341
if vlan_group_name and is_provisioning_network(context.current["network_id"]):
@@ -383,8 +394,11 @@ def _bind_port_segment(self, context: PortContext, segment):
383394
)
384395
mac_address = context.current["mac_address"]
385396

397+
local_link_info = utils.local_link_from_binding_profile(
398+
context.current[portbindings.PROFILE]
399+
)
386400
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
387-
mac_address
401+
local_link_info
388402
)
389403

390404
if not vlan_group_name:

python/neutron-understack/neutron_understack/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ def subport_model(vlan_num) -> SubPortModel:
219219

220220

221221
@pytest.fixture
222-
def port_model(mac_address) -> PortModel:
223-
return PortModel(mac_address=mac_address)
222+
def port_model(mac_address, port_id) -> PortModel:
223+
return PortModel(mac_address=mac_address, id=str(port_id))
224224

225225

226226
@pytest.fixture

python/neutron-understack/neutron_understack/trunk.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ def _add_subports_networks_to_parent_port_switchport(
205205
binding_profile, self.nb
206206
)
207207

208+
local_link_info = utils.local_link_from_binding_profile(binding_profile)
208209
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
209-
parent_port.mac_address
210+
local_link_info
210211
)
211212
allowed_vlan_ids = self._handle_segment_allocation(
212213
subports, vlan_group_name, binding_host
@@ -237,8 +238,9 @@ def _clean_parent_port_switchport_config(
237238
return
238239
binding_profile = parent_port_obj.bindings[0].profile
239240
binding_host = parent_port_obj.bindings[0].host
241+
local_link_info = utils.local_link_from_binding_profile(binding_profile)
240242
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
241-
parent_port_obj.mac_address
243+
local_link_info
242244
)
243245
self._handle_subports_removal(
244246
binding_profile=binding_profile,
@@ -308,8 +310,10 @@ def subports_added_post(self, resource, event, trunk_plugin, payload):
308310
parent_port = utils.fetch_port_object(trunk.port_id)
309311

310312
if utils.parent_port_is_bound(parent_port):
313+
binding_profile = parent_port.bindings[0].profile
314+
local_link_info = utils.local_link_from_binding_profile(binding_profile)
311315
vlan_group_name = self.ironic_client.baremetal_port_physical_network(
312-
parent_port.mac_address
316+
local_link_info
313317
)
314318
LOG.debug("subports_added_post found vlan_group_name=%s", vlan_group_name)
315319
self._trigger_undersync(vlan_group_name)

python/neutron-understack/neutron_understack/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ def is_dynamic_network_segment(segment_id: str) -> bool:
195195
return segment.is_dynamic
196196

197197

198+
def local_link_from_binding_profile(binding_profile: dict) -> dict | None:
199+
return binding_profile.get("local_link_information", [None])[0]
200+
201+
198202
def fetch_connected_interface_uuid(binding_profile: dict, nautobot: Nautobot) -> str:
199203
"""Fetches the connected interface UUID from the port's binding profile.
200204

0 commit comments

Comments
 (0)