Skip to content

Commit 910796b

Browse files
fix: fail the workflow to investigate the segmentation ID collision
1 parent 292cca5 commit 910796b

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

python/understack-workflows/tests/test_oslo_event_neutron_network.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,34 @@ def test_handle_network_create_idempotent_ucvni(network_create_event_data):
127127
assert result == 0
128128

129129

130+
def test_handle_network_create_duplicate_ucvni_group_and_id(network_create_event_data):
131+
"""Test that duplicate ucvni_group + ucvni_id combination fails the sync."""
132+
mock_nautobot = Mock()
133+
mock_nautobot.ipam.namespaces.create.return_value = "123"
134+
135+
# Mock update to return 404 so create path is taken
136+
mock_update_req = Mock()
137+
mock_update_req.status_code = 404
138+
mock_nautobot.plugins.undercloud_vni.ucvnis.update.side_effect = (
139+
pynautobot.RequestError(mock_update_req)
140+
)
141+
142+
# Mock create to fail with duplicate ucvni_group + ucvni_id error
143+
mock_create_req = Mock()
144+
mock_create_req.status_code = 400
145+
mock_create_req.text = "UCVNI with this Ucvni group and UCVNI_ID already exists."
146+
147+
mock_nautobot.plugins.undercloud_vni.ucvnis.create.side_effect = (
148+
pynautobot.RequestError(mock_create_req)
149+
)
150+
151+
result = neutron_network.handle_network_create_or_update(
152+
None, mock_nautobot, network_create_event_data, ucvni_group_name="FOO"
153+
)
154+
# Should return 1 (failure) due to segmentation ID conflict
155+
assert result == 1
156+
157+
130158
def test_handle_network_delete(network_delete_event_data):
131159
mock_nautobot_namespace = Mock()
132160
mock_nautobot_namespace.delete.return_value = "123"

python/understack-workflows/understack_workflows/oslo_event/neutron_network.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ def _create_nautobot_ucvni(
8989
except pynautobot.RequestError as error:
9090
if error.req.status_code == 400 and "this Id already exists" in error.error:
9191
logger.debug("UCVNI %s already existed in Nautobot", id)
92+
elif (
93+
error.req.status_code == 400
94+
and "UCVNI with this Ucvni group and UCVNI_ID already exists" in error.error
95+
):
96+
raise RuntimeError(
97+
f"Segmentation ID conflict: ucvni_id={event.provider_segmentation_id} "
98+
f"already exists in ucvni_group={ucvni_group_name}. "
99+
f"Cannot create UCVNI for network {id} ({event.network_name}). "
100+
f"This indicates a duplicate VXLAN VNI assignment in OpenStack."
101+
) from error
92102
else:
93103
raise NautobotRequestError(error) from error
94104

0 commit comments

Comments
 (0)