Skip to content

Commit 3813b60

Browse files
automatic discovery of the network node trunk ID via OVN Gateway agent.
Previously, the network node trunk ID had to be manually configured in ml2 config. This had operational overhead and made the system less flexible when underling nodes used to deploy neutron is changed.
1 parent ac1272d commit 3813b60

File tree

8 files changed

+662
-18
lines changed

8 files changed

+662
-18
lines changed

python/neutron-understack/neutron_understack/config.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@
5050
"is used to trunk all vlans used by a neutron router."
5151
),
5252
),
53-
cfg.StrOpt(
54-
"network_node_trunk_uuid",
55-
help=(
56-
"UUID of the trunk that is used to trunk all vlans used by a Neutron"
57-
" router."
58-
),
59-
),
6053
cfg.StrOpt(
6154
"network_node_switchport_physnet",
6255
help=(

python/neutron-understack/neutron_understack/ironic.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,17 @@ def _port_by_local_link(self, local_link_info: dict) -> BaremetalPort | None:
3232
)
3333
except StopIteration:
3434
return None
35+
36+
def baremetal_node_name(self, node_uuid: str) -> str | None:
37+
try:
38+
node = self.irclient.get_node(node_uuid)
39+
return node.name if node else None
40+
except Exception:
41+
return None
42+
43+
def baremetal_node_uuid(self, node_name: str) -> str | None:
44+
try:
45+
node = self.irclient.get_node(node_name)
46+
return node.id if node else None
47+
except Exception:
48+
return None

python/neutron-understack/neutron_understack/routers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ def add_subport_to_trunk(shared_port: PortDict, segment: NetworkSegmentDict) ->
9898
},
9999
]
100100
}
101+
trunk_id = utils.fetch_network_node_trunk_id()
102+
101103
utils.fetch_trunk_plugin().add_subports(
102104
context=n_context.get_admin_context(),
103-
trunk_id=cfg.CONF.ml2_understack.network_node_trunk_uuid,
105+
trunk_id=trunk_id,
104106
subports=subports,
105107
)
106108

@@ -251,8 +253,7 @@ def handle_router_interface_removal(_resource, _event, trigger, payload) -> None
251253

252254
def handle_subport_removal(port: Port) -> None:
253255
"""Removes router's subport from a network node trunk."""
254-
# trunk_id will be discovered dynamically at some point
255-
trunk_id = cfg.CONF.ml2_understack.network_node_trunk_uuid
256+
trunk_id = utils.fetch_network_node_trunk_id()
256257
LOG.debug("Router, Removing subport: %s(port)s", {"port": port})
257258
port_id = port["id"]
258259
try:

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def test_when_successful(self, mocker):
3737
port = {"id": "port-123"}
3838
segment = {"segmentation_id": 42}
3939
mocker.patch(
40-
"oslo_config.cfg.CONF.ml2_understack.network_node_trunk_uuid",
41-
trunk_id,
40+
"neutron_understack.utils.fetch_network_node_trunk_id",
41+
return_value=trunk_id,
4242
)
4343
mocker.patch(
4444
"neutron_lib.context.get_admin_context", return_value="admin_context"
@@ -70,7 +70,8 @@ def test_when_successful(self, mocker):
7070
class TestHandleSubportRemoval:
7171
def test_when_successful(self, mocker, port_id, trunk_id):
7272
mocker.patch(
73-
"oslo_config.cfg.CONF.ml2_understack.network_node_trunk_uuid", str(trunk_id)
73+
"neutron_understack.utils.fetch_network_node_trunk_id",
74+
return_value=str(trunk_id),
7475
)
7576
mock_remove = mocker.patch("neutron_understack.utils.remove_subport_from_trunk")
7677
port = {"id": str(port_id)}

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,13 @@ class TestCheckSubportsSegmentationId:
336336
def test_when_trunk_id_is_network_node_trunk_id(
337337
self,
338338
mocker,
339-
oslo_config,
340339
understack_trunk_driver,
341340
trunk_id,
342341
):
343-
oslo_config.config(
344-
network_node_trunk_uuid=str(trunk_id),
345-
group="ml2_understack",
342+
# Mock fetch_network_node_trunk_id to return the trunk_id
343+
mocker.patch(
344+
"neutron_understack.utils.fetch_network_node_trunk_id",
345+
return_value=str(trunk_id),
346346
)
347347
# Mock to ensure the function returns early and doesn't call this
348348
allowed_ranges_mock = mocker.patch(
@@ -362,6 +362,11 @@ def test_when_segmentation_id_is_in_allowed_range(
362362
trunk_id,
363363
subport,
364364
):
365+
# Mock fetch_network_node_trunk_id to return a different trunk ID
366+
mocker.patch(
367+
"neutron_understack.utils.fetch_network_node_trunk_id",
368+
return_value="different-trunk-id",
369+
)
365370
allowed_ranges = mocker.patch(
366371
"neutron_understack.utils.allowed_tenant_vlan_id_ranges",
367372
return_value=[(1, 1500)],
@@ -380,6 +385,11 @@ def test_when_segmentation_id_is_not_in_allowed_range(
380385
trunk_id,
381386
subport,
382387
):
388+
# Mock fetch_network_node_trunk_id to return a different trunk ID
389+
mocker.patch(
390+
"neutron_understack.utils.fetch_network_node_trunk_id",
391+
return_value="different-trunk-id",
392+
)
383393
mocker.patch(
384394
"neutron_understack.utils.allowed_tenant_vlan_id_ranges",
385395
return_value=[(1, 1500)],

0 commit comments

Comments
 (0)