Skip to content

Commit b384b8d

Browse files
authored
Merge pull request #721 from rackerlabs/selective-svis
feat: Only create SVIs for Prefixes of service_type "network:understack_svi"
2 parents d869c53 + fc23ae7 commit b384b8d

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

python/neutron-understack/neutron_understack/neutron_understack_mech.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ def create_subnet_postcommit(self, context):
138138
Don't have an SVI, which means we don't associate them with a VNI in
139139
nautobot.
140140
"""
141-
subnet_uuid = context.current["id"]
142-
network_uuid = context.current["network_id"]
143-
prefix = context.current["cidr"]
144-
external = context.current["router:external"]
141+
subnet_uuid: str = context.current["id"]
142+
network_uuid: str = context.current["network_id"]
143+
prefix: str = context.current["cidr"]
144+
external: bool = context.current["router:external"]
145+
service_types: list[str] = context.current["service_types"]
145146

146147
if external:
147148
namespace = cfg.CONF.ml2_understack.shared_nautobot_namespace_name
@@ -154,7 +155,7 @@ def create_subnet_postcommit(self, context):
154155
namespace_name=namespace,
155156
)
156157

157-
if external:
158+
if external and "network:understack_svi" in service_types:
158159
self.nb.associate_subnet_with_network(
159160
role="svi_vxlan_anycast_gateway",
160161
network_uuid=network_uuid,

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def test_create_subnet_postcommit_private(nautobot_client):
170170
"network_id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
171171
"cidr": "1.0.0.0/24",
172172
"router:external": False,
173+
"service_types": [],
173174
}
174175
)
175176

@@ -183,13 +184,14 @@ def test_create_subnet_postcommit_private(nautobot_client):
183184
)
184185

185186

186-
def test_create_subnet_postcommit_public(nautobot_client, undersync_client):
187+
def test_create_subnet_postcommit_public_svi(nautobot_client, undersync_client):
187188
context = MagicMock(
188189
current={
189190
"id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
190191
"network_id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
191192
"cidr": "1.0.0.0/24",
192193
"router:external": True,
194+
"service_types": ["network:understack_svi"],
193195
}
194196
)
195197

@@ -203,6 +205,27 @@ def test_create_subnet_postcommit_public(nautobot_client, undersync_client):
203205
prefix="1.0.0.0/24",
204206
namespace_name="Global",
205207
)
208+
nautobot_client.associate_subnet_with_network.assert_called_once()
209+
210+
211+
def test_create_subnet_postcommit_public_non_svi(nautobot_client, undersync_client):
212+
context = MagicMock(
213+
current={
214+
"id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
215+
"network_id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
216+
"cidr": "1.0.0.0/24",
217+
"router:external": True,
218+
"service_types": ["not_an_svi_type"],
219+
}
220+
)
221+
222+
driver.nb = nautobot_client
223+
driver.undersync = undersync_client
224+
225+
driver.create_subnet_postcommit(context)
226+
227+
nautobot_client.subnet_create.assert_called_once()
228+
nautobot_client.associate_subnet_with_network.assert_not_called()
206229

207230

208231
def test_delete_subnet_postcommit_public(nautobot_client, undersync_client):

0 commit comments

Comments
 (0)