Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions python/neutron-understack/neutron_understack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@
"is used to trunk all vlans used by a neutron router."
),
),
cfg.StrOpt(
"network_node_trunk_uuid",
help=(
"UUID of the trunk that is used to trunk all vlans used by a Neutron"
" router."
),
),
cfg.StrOpt(
"network_node_switchport_physnet",
help=(
Expand Down
14 changes: 14 additions & 0 deletions python/neutron-understack/neutron_understack/ironic.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ def _port_by_local_link(self, local_link_info: dict) -> BaremetalPort | None:
)
except StopIteration:
return None

def baremetal_node_name(self, node_uuid: str) -> str | None:
try:
node = self.irclient.get_node(node_uuid)
return node.name if node else None
except Exception:
return None

def baremetal_node_uuid(self, node_name: str) -> str | None:
try:
node = self.irclient.get_node(node_name)
return node.id if node else None
except Exception:
return None
7 changes: 4 additions & 3 deletions python/neutron-understack/neutron_understack/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ def add_subport_to_trunk(shared_port: PortDict, segment: NetworkSegmentDict) ->
},
]
}
trunk_id = utils.fetch_network_node_trunk_id()

utils.fetch_trunk_plugin().add_subports(
context=n_context.get_admin_context(),
trunk_id=cfg.CONF.ml2_understack.network_node_trunk_uuid,
trunk_id=trunk_id,
subports=subports,
)

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

def handle_subport_removal(port: Port) -> None:
"""Removes router's subport from a network node trunk."""
# trunk_id will be discovered dynamically at some point
trunk_id = cfg.CONF.ml2_understack.network_node_trunk_uuid
trunk_id = utils.fetch_network_node_trunk_id()
LOG.debug("Router, Removing subport: %s(port)s", {"port": port})
port_id = port["id"]
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def test_when_successful(self, mocker):
port = {"id": "port-123"}
segment = {"segmentation_id": 42}
mocker.patch(
"oslo_config.cfg.CONF.ml2_understack.network_node_trunk_uuid",
trunk_id,
"neutron_understack.utils.fetch_network_node_trunk_id",
return_value=trunk_id,
)
mocker.patch(
"neutron_lib.context.get_admin_context", return_value="admin_context"
Expand Down Expand Up @@ -70,7 +70,8 @@ def test_when_successful(self, mocker):
class TestHandleSubportRemoval:
def test_when_successful(self, mocker, port_id, trunk_id):
mocker.patch(
"oslo_config.cfg.CONF.ml2_understack.network_node_trunk_uuid", str(trunk_id)
"neutron_understack.utils.fetch_network_node_trunk_id",
return_value=str(trunk_id),
)
mock_remove = mocker.patch("neutron_understack.utils.remove_subport_from_trunk")
port = {"id": str(port_id)}
Expand Down
18 changes: 14 additions & 4 deletions python/neutron-understack/neutron_understack/tests/test_trunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,13 @@ class TestCheckSubportsSegmentationId:
def test_when_trunk_id_is_network_node_trunk_id(
self,
mocker,
oslo_config,
understack_trunk_driver,
trunk_id,
):
oslo_config.config(
network_node_trunk_uuid=str(trunk_id),
group="ml2_understack",
# Mock fetch_network_node_trunk_id to return the trunk_id
mocker.patch(
"neutron_understack.utils.fetch_network_node_trunk_id",
return_value=str(trunk_id),
)
# Mock to ensure the function returns early and doesn't call this
allowed_ranges_mock = mocker.patch(
Expand All @@ -362,6 +362,11 @@ def test_when_segmentation_id_is_in_allowed_range(
trunk_id,
subport,
):
# Mock fetch_network_node_trunk_id to return a different trunk ID
mocker.patch(
"neutron_understack.utils.fetch_network_node_trunk_id",
return_value="different-trunk-id",
)
allowed_ranges = mocker.patch(
"neutron_understack.utils.allowed_tenant_vlan_id_ranges",
return_value=[(1, 1500)],
Expand All @@ -380,6 +385,11 @@ def test_when_segmentation_id_is_not_in_allowed_range(
trunk_id,
subport,
):
# Mock fetch_network_node_trunk_id to return a different trunk ID
mocker.patch(
"neutron_understack.utils.fetch_network_node_trunk_id",
return_value="different-trunk-id",
)
mocker.patch(
"neutron_understack.utils.allowed_tenant_vlan_id_ranges",
return_value=[(1, 1500)],
Expand Down
Loading
Loading