Skip to content

Commit fd032c5

Browse files
committed
Add workflow to update Nautobot based on openstack CRUD events
This does part of what the ml2 driver was doing to update networks and subnets in Nautobot.
1 parent 0409ac7 commit fd032c5

17 files changed

+596
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
The openstack event payloads published via Rabbitmq can be snooped on with commands like:
2+
3+
```sh
4+
kubectl -n openstack exec -it rabbitmq-server-0 -c rabbitmq -- \
5+
rabbitmqadmin --vhost=neutron get \
6+
queue=notifications.info \
7+
ackmode=ack_requeue_true \
8+
count=1000 \
9+
| awk -F\| '{print $5}' \
10+
| fgrep network.create.end
11+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"oslo.version": "2.0", "oslo.message": "{\"message_id\": \"8994f9f2-851b-4279-ba38-1e55d0307926\", \"publisher_id\": \"network.neutron-server-7d76968979-6np4r\", \"event_type\": \"network.create.end\", \"priority\": \"INFO\", \"payload\": {\"network\": {\"id\": \"5dddb3dc-b6d6-4247-a02e-8089c4374290\", \"name\": \"marek-storage-test-network\", \"tenant_id\": \"962f6e0dfb314d43bdee2a9d5c7bd7f6\", \"admin_state_up\": true, \"mtu\": 9000, \"status\": \"ACTIVE\", \"subnets\": [], \"shared\": false, \"project_id\": \"46c1e917980e4485915b1444e8c50cc2\", \"port_security_enabled\": true, \"router:external\": false, \"provider:network_type\": \"vxlan\", \"provider:physical_network\": null, \"provider:segmentation_id\": 1862, \"is_default\": false, \"availability_zone_hints\": [], \"availability_zones\": [], \"ipv4_address_scope\": null, \"ipv6_address_scope\": null, \"description\": \"\", \"l2_adjacency\": true, \"tags\": [], \"created_at\": \"2025-09-11T16:25:54Z\", \"updated_at\": \"2025-09-11T16:25:55Z\", \"revision_number\": 1}}, \"timestamp\": \"2025-09-11 16:26:01.168699\", \"_unique_id\": \"23fdf96e8a7d4452ab57b05042244d9b\", \"_context_user\": \"5f9179b7e200cd85c55e8a26400e266c6b4f7209f6d3fb2adc3cf8e1113c378c\", \"_context_project_id\": \"32e02632f4f04415bab5895d1e7247b7\", \"_context_system_scope\": null, \"_context_project\": \"32e02632f4f04415bab5895d1e7247b7\", \"_context_domain\": null, \"_context_user_domain\": \"1f75c3b20fcb41ec924a71be83a5ee94\", \"_context_project_domain\": \"7f46f53fcb3c4625a343eaa35b5e0d04\", \"_context_is_admin\": true, \"_context_read_only\": false, \"_context_show_deleted\": false, \"_context_auth_token\": null, \"_context_request_id\": \"req-3297674b-4d51-44ad-b787-e2667f43ff53\", \"_context_global_request_id\": null, \"_context_resource_uuid\": null, \"_context_roles\": [\"manager\", \"reader\", \"member\", \"admin\"], \"_context_user_identity\": \"5f9179b7e200cd85c55e8a26400e266c6b4f7209f6d3fb2adc3cf8e1113c378c 32e02632f4f04415bab5895d1e7247b7 - 1f75c3b20fcb41ec924a71be83a5ee94 7f46f53fcb3c4625a343eaa35b5e0d04\", \"_context_is_admin_project\": true, \"_context_user_id\": \"5f9179b7e200cd85c55e8a26400e266c6b4f7209f6d3fb2adc3cf8e1113c378c\", \"_context_tenant_id\": \"32e02632f4f04415bab5895d1e7247b7\", \"_context_timestamp\": \"2025-09-11 16:26:01.168178\", \"_context_tenant_name\": \"baremetal\", \"_context_project_name\": \"baremetal\", \"_context_user_name\": \"[email protected]\"}"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"oslo.version": "2.0", "oslo.message": "{\"message_id\": \"f1d4303d-3870-4513-8696-f1732b22e227\", \"publisher_id\": \"network.neutron-server-7d76968979-9f6wd\", \"event_type\": \"network.delete.end\", \"priority\": \"INFO\", \"payload\": {\"network\": {\"id\": \"5dddb3dc-b6d6-4247-a02e-8089c4374290\", \"name\": \"marek-storage-test-network\", \"tenant_id\": \"46c1e917980e4485915b1444e8c50cc2\", \"admin_state_up\": true, \"mtu\": 9000, \"status\": \"ACTIVE\", \"subnets\": [], \"standard_attr_id\": 13740, \"shared\": false, \"availability_zone_hints\": [], \"availability_zones\": [], \"ipv4_address_scope\": null, \"ipv6_address_scope\": null, \"router:external\": false, \"vlan_transparent\": null, \"description\": \"\", \"port_security_enabled\": true, \"l2_adjacency\": true, \"tags\": [], \"created_at\": \"2025-09-11T16:25:54Z\", \"updated_at\": \"2025-09-11T16:31:21Z\", \"revision_number\": 3, \"project_id\": \"4cde1e465a5d41e482755f7d1ce12b28\", \"provider:network_type\": \"vxlan\", \"provider:physical_network\": null, \"provider:segmentation_id\": 1862}, \"network_id\": \"5dddb3dc-b6d6-4247-a02e-8089c4374290\"}, \"timestamp\": \"2025-09-11 16:31:58.734463\", \"_unique_id\": \"5e4090d2069440209794e0c6d29dee5b\", \"_context_user\": \"5f9179b7e200cd85c55e8a26400e266c6b4f7209f6d3fb2adc3cf8e1113c378c\", \"_context_project_id\": \"32e02632f4f04415bab5895d1e7247b7\", \"_context_system_scope\": null, \"_context_project\": \"32e02632f4f04415bab5895d1e7247b7\", \"_context_domain\": null, \"_context_user_domain\": \"1f75c3b20fcb41ec924a71be83a5ee94\", \"_context_project_domain\": \"7f46f53fcb3c4625a343eaa35b5e0d04\", \"_context_is_admin\": true, \"_context_read_only\": false, \"_context_show_deleted\": false, \"_context_auth_token\": null, \"_context_request_id\": \"req-7164140a-3ff6-4eeb-b4b0-191e4312344c\", \"_context_global_request_id\": null, \"_context_resource_uuid\": null, \"_context_roles\": [\"manager\", \"reader\", \"member\", \"admin\"], \"_context_user_identity\": \"5f9179b7e200cd85c55e8a26400e266c6b4f7209f6d3fb2adc3cf8e1113c378c 32e02632f4f04415bab5895d1e7247b7 - 1f75c3b20fcb41ec924a71be83a5ee94 7f46f53fcb3c4625a343eaa35b5e0d04\", \"_context_is_admin_project\": true, \"_context_user_id\": \"5f9179b7e200cd85c55e8a26400e266c6b4f7209f6d3fb2adc3cf8e1113c378c\", \"_context_tenant_id\": \"32e02632f4f04415bab5895d1e7247b7\", \"_context_timestamp\": \"2025-09-11 16:31:58.733890\", \"_context_tenant_name\": \"baremetal\", \"_context_project_name\": \"baremetal\", \"_context_user_name\": \"[email protected]\"}"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"oslo.version": "2.0", "oslo.message": "{\"message_id\": \"65fc1389-1981-4a8d-9799-0fd41f051023\", \"publisher_id\": \"network.neutron-server-5bb5c5b5d9-cl6lv\", \"event_type\": \"network.update.end\", \"priority\": \"INFO\", \"payload\": {\"network\": {\"id\": \"f4aa4b99-2c2f-4698-a2f0-ac9920b1ee81\", \"name\": \"service-net\", \"tenant_id\": \"a4a74dbf982a471e8150db2babcac8c2\", \"admin_state_up\": true, \"mtu\": 9000, \"status\": \"ACTIVE\", \"subnets\": [\"1600eeef-6b3c-47fe-981a-e9ae83e23ce7\"], \"shared\": false, \"availability_zone_hints\": [], \"availability_zones\": [], \"ipv4_address_scope\": \"73bb6292-e015-4607-aac9-9a7095efa1a9\", \"ipv6_address_scope\": null, \"router:external\": false, \"description\": \"test-servicenet-network\", \"port_security_enabled\": true, \"l2_adjacency\": true, \"tags\": [], \"created_at\": \"2025-08-20T13:15:46Z\", \"updated_at\": \"2025-09-16T16:15:04Z\", \"revision_number\": 5, \"project_id\": \"a4a74dbf982a471e8150db2babcac8c2\", \"provider:network_type\": \"vxlan\", \"provider:physical_network\": null, \"provider:segmentation_id\": 1860}}, \"timestamp\": \"2025-09-16 16:15:05.161384\", \"_unique_id\": \"d5da8774d7d8447cb0d6476729f21c70\", \"_context_user\": \"e63aa434bf761337c4588ed49af49f6a7a2a86501a66a11d7da13ec0ead25ed4\", \"_context_project_id\": \"32e02632f4f04415bab5895d1e7247b7\", \"_context_system_scope\": null, \"_context_project\": \"32e02632f4f04415bab5895d1e7247b7\", \"_context_domain\": null, \"_context_user_domain\": \"1f75c3b20fcb41ec924a71be83a5ee94\", \"_context_project_domain\": \"7f46f53fcb3c4625a343eaa35b5e0d04\", \"_context_is_admin\": true, \"_context_read_only\": false, \"_context_show_deleted\": false, \"_context_auth_token\": null, \"_context_request_id\": \"req-23005bcf-c8e2-4b30-8b89-b911358b734e\", \"_context_global_request_id\": null, \"_context_resource_uuid\": null, \"_context_roles\": [\"manager\", \"reader\", \"member\", \"admin\"], \"_context_user_identity\": \"e63aa434bf761337c4588ed49af49f6a7a2a86501a66a11d7da13ec0ead25ed4 32e02632f4f04415bab5895d1e7247b7 - 1f75c3b20fcb41ec924a71be83a5ee94 7f46f53fcb3c4625a343eaa35b5e0d04\", \"_context_is_admin_project\": true, \"_context_user_id\": \"e63aa434bf761337c4588ed49af49f6a7a2a86501a66a11d7da13ec0ead25ed4\", \"_context_tenant_id\": \"32e02632f4f04415bab5895d1e7247b7\", \"_context_timestamp\": \"2025-09-16 16:15:05.160974\", \"_context_tenant_name\": \"baremetal\", \"_context_project_name\": \"baremetal\", \"_context_user_name\": \"[email protected]\"}"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"oslo.version": "2.0", "oslo.message": "{\"message_id\": \"60b24028-342c-4337-93f3-d0853ee753a4\", \"publisher_id\": \"network.neutron-server-7bb5fc5987-w8srl\", \"event_type\": \"subnet.create.end\", \"priority\": \"INFO\", \"payload\": {\"subnet\": {\"id\": \"eb9edeef-cc57-45ca-9caf-42be046822ff\", \"name\": \"c_rally_49fb715e_XGTdOFQF\", \"tenant_id\": \"3a69b98463964e19b295f87cffa5db52\", \"network_id\": \"b69b1a1d-5620-48fa-8fc2-fb0d1e90cf1c\", \"ip_version\": 4, \"subnetpool_id\": null, \"enable_dhcp\": true, \"ipv6_ra_mode\": null, \"ipv6_address_mode\": null, \"gateway_ip\": \"192.168.91.1\", \"cidr\": \"192.168.91.0/24\", \"allocation_pools\": [{\"start\": \"192.168.91.2\", \"end\": \"192.168.91.254\"}], \"host_routes\": [], \"dns_nameservers\": [\"8.8.8.8\"], \"description\": \"\", \"router:external\": false, \"service_types\": [], \"tags\": [], \"created_at\": \"2025-09-15T00:19:56Z\", \"updated_at\": \"2025-09-15T00:19:56Z\", \"revision_number\": 0, \"project_id\": \"3a69b98463964e19b295f87cffa5db52\"}}, \"timestamp\": \"2025-09-15 00:19:56.545912\", \"_unique_id\": \"46a2d701444f4f07aadc3c6c77dd4d08\", \"_context_user\": \"592e424b165948288c86687057c88fe8\", \"_context_project_id\": \"3a69b98463964e19b295f87cffa5db52\", \"_context_system_scope\": null, \"_context_project\": \"3a69b98463964e19b295f87cffa5db52\", \"_context_domain\": null, \"_context_user_domain\": \"default\", \"_context_project_domain\": \"default\", \"_context_is_admin\": false, \"_context_read_only\": false, \"_context_show_deleted\": false, \"_context_auth_token\": null, \"_context_request_id\": \"req-b1617d34-e375-45fd-ae90-5c14c8bef0d0\", \"_context_global_request_id\": null, \"_context_resource_uuid\": null, \"_context_roles\": [\"member\", \"reader\"], \"_context_user_identity\": \"592e424b165948288c86687057c88fe8 3a69b98463964e19b295f87cffa5db52 - default default\", \"_context_is_admin_project\": true, \"_context_user_id\": \"592e424b165948288c86687057c88fe8\", \"_context_tenant_id\": \"3a69b98463964e19b295f87cffa5db52\", \"_context_timestamp\": \"2025-09-15 00:19:56.544749\", \"_context_tenant_name\": \"c_rally_49fb715e_K771F0gL\", \"_context_project_name\": \"c_rally_49fb715e_K771F0gL\", \"_context_user_name\": \"c_rally_49fb715e_DAKXu9bI\"}"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"oslo.version": "2.0", "oslo.message": "{\"message_id\": \"7dac063f-e339-42e2-aa02-a02796aa9ee0\", \"publisher_id\": \"network.neutron-server-7bb5fc5987-w8srl\", \"event_type\": \"subnet.delete.end\", \"priority\": \"INFO\", \"payload\": {\"subnet\": {\"id\": \"eb9edeef-cc57-45ca-9caf-42be046822ff\", \"name\": \"c_rally_49fb715e_XGTdOFQF\", \"tenant_id\": \"3a69b98463964e19b295f87cffa5db52\", \"network_id\": \"b69b1a1d-5620-48fa-8fc2-fb0d1e90cf1c\", \"ip_version\": 4, \"subnetpool_id\": null, \"enable_dhcp\": true, \"ipv6_ra_mode\": null, \"ipv6_address_mode\": null, \"standard_attr_id\": 14245, \"gateway_ip\": \"192.168.91.1\", \"cidr\": \"192.168.91.0/24\", \"allocation_pools\": [{\"start\": \"192.168.91.2\", \"end\": \"192.168.91.254\"}], \"host_routes\": [], \"dns_nameservers\": [\"8.8.8.8\"], \"shared\": false, \"description\": \"\", \"router:external\": false, \"service_types\": [], \"segment_id\": null, \"tags\": [], \"created_at\": \"2025-09-15T00:19:56Z\", \"updated_at\": \"2025-09-15T00:19:56Z\", \"revision_number\": 0, \"project_id\": \"3a69b98463964e19b295f87cffa5db52\"}, \"subnet_id\": \"eb9edeef-cc57-45ca-9caf-42be046822ff\"}, \"timestamp\": \"2025-09-15 00:28:41.377712\", \"_unique_id\": \"df61372c5814497d99892c9b5d485475\", \"_context_user\": \"592e424b165948288c86687057c88fe8\", \"_context_project_id\": \"3a69b98463964e19b295f87cffa5db52\", \"_context_system_scope\": null, \"_context_project\": \"3a69b98463964e19b295f87cffa5db52\", \"_context_domain\": null, \"_context_user_domain\": \"default\", \"_context_project_domain\": \"default\", \"_context_is_admin\": false, \"_context_read_only\": false, \"_context_show_deleted\": false, \"_context_auth_token\": null, \"_context_request_id\": \"req-9bb860ee-02be-4b0f-a45a-6c1042440555\", \"_context_global_request_id\": null, \"_context_resource_uuid\": null, \"_context_roles\": [\"member\", \"reader\"], \"_context_user_identity\": \"592e424b165948288c86687057c88fe8 3a69b98463964e19b295f87cffa5db52 - default default\", \"_context_is_admin_project\": true, \"_context_user_id\": \"592e424b165948288c86687057c88fe8\", \"_context_tenant_id\": \"3a69b98463964e19b295f87cffa5db52\", \"_context_timestamp\": \"2025-09-15 00:28:41.376637\", \"_context_tenant_name\": \"c_rally_49fb715e_K771F0gL\", \"_context_project_name\": \"c_rally_49fb715e_K771F0gL\", \"_context_user_name\": \"c_rally_49fb715e_DAKXu9bI\"}"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"oslo.version": "2.0", "oslo.message": "{\"message_id\": \"3c72f869-d29b-4eaf-91d5-2d0606477367\", \"publisher_id\": \"network.neutron-server-5bb5c5b5d9-c82x2\", \"event_type\": \"subnet.update.end\", \"priority\": \"INFO\", \"payload\": {\"subnet\": {\"id\": \"1600eeef-6b3c-47fe-981a-e9ae83e23ce7\", \"name\": \"my-servicenet\", \"tenant_id\": \"a4a74dbf982a471e8150db2babcac8c2\", \"network_id\": \"f4aa4b99-2c2f-4698-a2f0-ac9920b1ee81\", \"ip_version\": 4, \"subnetpool_id\": \"eed7e843-645f-43b6-85e4-6272dd395a9d\", \"enable_dhcp\": false, \"ipv6_ra_mode\": null, \"ipv6_address_mode\": null, \"gateway_ip\": \"10.148.4.33\", \"cidr\": \"10.148.4.32/27\", \"allocation_pools\": [{\"start\": \"10.148.4.34\", \"end\": \"10.148.4.62\"}], \"host_routes\": [], \"dns_nameservers\": [], \"description\": \"\", \"router:external\": false, \"service_types\": [], \"segment_id\": null, \"tags\": [], \"created_at\": \"2025-08-20T13:16:18Z\", \"updated_at\": \"2025-09-16T16:12:01Z\", \"revision_number\": 2, \"project_id\": \"a4a74dbf982a471e8150db2babcac8c2\"}}, \"timestamp\": \"2025-09-16 16:12:01.737116\", \"_unique_id\": \"844c0977a501475cbb9dea8207ccaf02\", \"_context_user\": \"e63aa434bf761337c4588ed49af49f6a7a2a86501a66a11d7da13ec0ead25ed4\", \"_context_project_id\": \"32e02632f4f04415bab5895d1e7247b7\", \"_context_system_scope\": null, \"_context_project\": \"32e02632f4f04415bab5895d1e7247b7\", \"_context_domain\": null, \"_context_user_domain\": \"1f75c3b20fcb41ec924a71be83a5ee94\", \"_context_project_domain\": \"7f46f53fcb3c4625a343eaa35b5e0d04\", \"_context_is_admin\": true, \"_context_read_only\": false, \"_context_show_deleted\": false, \"_context_auth_token\": null, \"_context_request_id\": \"req-4483343f-a44e-4716-b835-cd605c4e0898\", \"_context_global_request_id\": null, \"_context_resource_uuid\": null, \"_context_roles\": [\"manager\", \"reader\", \"member\", \"admin\"], \"_context_user_identity\": \"e63aa434bf761337c4588ed49af49f6a7a2a86501a66a11d7da13ec0ead25ed4 32e02632f4f04415bab5895d1e7247b7 - 1f75c3b20fcb41ec924a71be83a5ee94 7f46f53fcb3c4625a343eaa35b5e0d04\", \"_context_is_admin_project\": true, \"_context_user_id\": \"e63aa434bf761337c4588ed49af49f6a7a2a86501a66a11d7da13ec0ead25ed4\", \"_context_tenant_id\": \"32e02632f4f04415bab5895d1e7247b7\", \"_context_timestamp\": \"2025-09-16 16:12:01.736781\", \"_context_tenant_name\": \"baremetal\", \"_context_project_name\": \"baremetal\", \"_context_user_name\": \"[email protected]\"}"}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import json
2+
from unittest.mock import Mock
3+
4+
import pynautobot
5+
import pytest
6+
7+
from understack_workflows.oslo_event import neutron_network
8+
9+
10+
def _sample_fixture_data(name: str) -> dict:
11+
"""Load example event data from JSON fixture file."""
12+
with open(f"tests/json_samples/{name}.json") as f:
13+
data = json.loads(f.read())
14+
return json.loads(data["oslo.message"])
15+
16+
17+
@pytest.fixture
18+
def network_create_event_data():
19+
return _sample_fixture_data("oslo-event-network.create.end")
20+
21+
22+
@pytest.fixture
23+
def network_update_event_data():
24+
return _sample_fixture_data("oslo-event-network.update.end")
25+
26+
27+
@pytest.fixture
28+
def network_delete_event_data():
29+
return _sample_fixture_data("oslo-event-network.delete.end")
30+
31+
32+
def test_handle_network_create(network_create_event_data):
33+
mock_nautobot = Mock()
34+
mock_nautobot.ipam.namespaces.create.return_value = "123"
35+
36+
result = neutron_network.handle_network_create_or_update(
37+
None, mock_nautobot, network_create_event_data, ucvni_group_name="FOO"
38+
)
39+
40+
mock_nautobot.ipam.namespaces.create.assert_called_once_with(
41+
name="5dddb3dc-b6d6-4247-a02e-8089c4374290"
42+
)
43+
mock_nautobot.plugins.undercloud_vni.ucvnis.create.assert_called_once_with(
44+
{
45+
"id": "5dddb3dc-b6d6-4247-a02e-8089c4374290",
46+
"name": "marek-storage-test-network",
47+
"status": {
48+
"name": "Active",
49+
},
50+
"tenant": "46c1e917-980e-4485-915b-1444e8c50cc2",
51+
"ucvni_group": {
52+
"name": "FOO",
53+
},
54+
},
55+
)
56+
assert result == 0
57+
58+
59+
def test_handle_network_update(network_update_event_data):
60+
mock_nautobot = Mock()
61+
mock_nautobot.ipam.namespaces.update.return_value = "123"
62+
63+
result = neutron_network.handle_network_create_or_update(
64+
None, mock_nautobot, network_update_event_data, ucvni_group_name="FOO"
65+
)
66+
67+
mock_nautobot.ipam.namespaces.create.assert_called_once_with(
68+
name="f4aa4b99-2c2f-4698-a2f0-ac9920b1ee81"
69+
)
70+
mock_nautobot.plugins.undercloud_vni.ucvnis.create.assert_called_once_with(
71+
{
72+
"id": "f4aa4b99-2c2f-4698-a2f0-ac9920b1ee81",
73+
"name": "service-net",
74+
"status": {
75+
"name": "Active",
76+
},
77+
"tenant": "a4a74dbf-982a-471e-8150-db2babcac8c2",
78+
"ucvni_group": {
79+
"name": "FOO",
80+
},
81+
},
82+
)
83+
assert result == 0
84+
85+
86+
def test_handle_network_create_idempotent_namespace(network_create_event_data):
87+
mock_pynautobot_req = Mock()
88+
mock_pynautobot_req.status_code = 400
89+
mock_pynautobot_req.text = "namespace with this name already exists"
90+
91+
mock_nautobot = Mock()
92+
mock_nautobot.ipam.namespaces.create.side_effect = pynautobot.RequestError(
93+
mock_pynautobot_req
94+
)
95+
96+
result = neutron_network.handle_network_create_or_update(
97+
None, mock_nautobot, network_create_event_data, ucvni_group_name="FOO"
98+
)
99+
assert result == 0
100+
101+
102+
def test_handle_network_create_idempotent_ucvni(network_create_event_data):
103+
mock_nautobot = Mock()
104+
mock_nautobot.ipam.namespaces.create.return_value = "123"
105+
106+
mock_pynautobot_req = Mock()
107+
mock_pynautobot_req.status_code = 400
108+
mock_pynautobot_req.text = "this Id already exists"
109+
110+
mock_nautobot.plugins.undercloud_vni.ucvnis.create.side_effect = (
111+
pynautobot.RequestError(mock_pynautobot_req)
112+
)
113+
114+
result = neutron_network.handle_network_create_or_update(
115+
None, mock_nautobot, network_create_event_data, ucvni_group_name="FOO"
116+
)
117+
assert result == 0
118+
119+
120+
def test_handle_network_delete(network_delete_event_data):
121+
mock_nautobot_namespace = Mock()
122+
mock_nautobot_namespace.delete.return_value = "123"
123+
124+
mock_nautobot_prefix = Mock()
125+
mock_nautobot_prefix.delete.return_value = "123"
126+
127+
mock_nautobot = Mock()
128+
mock_nautobot.ipam.namespaces.get.return_value = mock_nautobot_namespace
129+
mock_nautobot.ipam.prefixes.filter.return_value = [mock_nautobot_prefix]
130+
131+
result = neutron_network.handle_network_delete(
132+
None, mock_nautobot, network_delete_event_data
133+
)
134+
135+
mock_nautobot.ipam.namespaces.get.assert_called_once_with(
136+
name="5dddb3dc-b6d6-4247-a02e-8089c4374290"
137+
)
138+
mock_nautobot_namespace.delete.assert_called_once()
139+
mock_nautobot.plugins.undercloud_vni.ucvnis.delete.assert_called_once_with(
140+
["5dddb3dc-b6d6-4247-a02e-8089c4374290"]
141+
)
142+
mock_nautobot_prefix.delete.assert_called_once()
143+
assert result == 0

0 commit comments

Comments
 (0)