Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ def create_subnet_postcommit(self, context):
Don't have an SVI, which means we don't associate them with a VNI in
nautobot.
"""
subnet_uuid = context.current["id"]
network_uuid = context.current["network_id"]
prefix = context.current["cidr"]
external = context.current["router:external"]
subnet_uuid: str = context.current["id"]
network_uuid: str = context.current["network_id"]
prefix: str = context.current["cidr"]
external: bool = context.current["router:external"]
service_types: list[str] = context.current["service_types"]

if external:
namespace = cfg.CONF.ml2_understack.shared_nautobot_namespace_name
Expand All @@ -154,7 +155,7 @@ def create_subnet_postcommit(self, context):
namespace_name=namespace,
)

if external:
if external and "network:understack_svi" in service_types:
self.nb.associate_subnet_with_network(
role="svi_vxlan_anycast_gateway",
network_uuid=network_uuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def test_create_subnet_postcommit_private(nautobot_client):
"network_id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"cidr": "1.0.0.0/24",
"router:external": False,
"service_types": [],
}
)

Expand All @@ -183,13 +184,14 @@ def test_create_subnet_postcommit_private(nautobot_client):
)


def test_create_subnet_postcommit_public(nautobot_client, undersync_client):
def test_create_subnet_postcommit_public_svi(nautobot_client, undersync_client):
context = MagicMock(
current={
"id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
"network_id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"cidr": "1.0.0.0/24",
"router:external": True,
"service_types": ["network:understack_svi"],
}
)

Expand All @@ -203,6 +205,27 @@ def test_create_subnet_postcommit_public(nautobot_client, undersync_client):
prefix="1.0.0.0/24",
namespace_name="Global",
)
nautobot_client.associate_subnet_with_network.assert_called_once()


def test_create_subnet_postcommit_public_non_svi(nautobot_client, undersync_client):
context = MagicMock(
current={
"id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
"network_id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"cidr": "1.0.0.0/24",
"router:external": True,
"service_types": ["not_an_svi_type"],
}
)

driver.nb = nautobot_client
driver.undersync = undersync_client

driver.create_subnet_postcommit(context)

nautobot_client.subnet_create.assert_called_once()
nautobot_client.associate_subnet_with_network.assert_not_called()


def test_delete_subnet_postcommit_public(nautobot_client, undersync_client):
Expand Down