From 94805a39ac0712219f7dc08faa2cfdbf371dd177 Mon Sep 17 00:00:00 2001 From: Sumukha Tumkur Vani Date: Wed, 15 Dec 2021 15:14:36 -0800 Subject: [PATCH] Identify and report Vnet GUID for conflicting VNI (#99) --- go-server-server/go/default.go | 2 +- test/test_restapi.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/go-server-server/go/default.go b/go-server-server/go/default.go index 05268af..7c704d4 100644 --- a/go-server-server/go/default.go +++ b/go-server-server/go/default.go @@ -917,7 +917,7 @@ func ConfigVrouterVrfIdPost(w http.ResponseWriter, r *http.Request) { guid := CacheGetVniId(uint32(attr.Vnid)) if guid != "" { WriteRequestErrorWithSubCode(w, http.StatusConflict, RESRC_EXISTS, - "Object already exists: " + strconv.Itoa(attr.Vnid), []string{}, "") + "Object already exists {\"vni\":\"" + strconv.Itoa(attr.Vnid) + "\", \"vnet_name\":\"" + guid +"\"}", []string{}, "") return } diff --git a/test/test_restapi.py b/test/test_restapi.py index f2dec0a..0b7b378 100644 --- a/test/test_restapi.py +++ b/test/test_restapi.py @@ -135,6 +135,27 @@ def test_post_vrouter(self, setup_restapi_client): b'guid': b'vnet-guid-1' } + def test_post_vrouter_duplicate(self, setup_restapi_client): + _, _, configdb, restapi_client = setup_restapi_client + restapi_client.post_generic_vxlan_tunnel() + r = restapi_client.post_config_vrouter_vrf_id("vnet-guid-1", { + 'vnid': 1001 + }) + assert r.status_code == 204 + + vrouter_table = configdb.hgetall(VNET_TB + '|' + VNET_NAME_PREF + '1') + assert vrouter_table == { + b'vxlan_tunnel': b'default_vxlan_tunnel', + b'vni': b'1001', + b'guid': b'vnet-guid-1' + } + + r = restapi_client.post_config_vrouter_vrf_id("vnet-guid-2", { + 'vnid': 1001 + }) + assert r.status_code == 409 + assert r.json()['error']['message'] == "Object already exists {\"vni\":\"1001\", \"vnet_name\":\"vnet-guid-1\"}" + def test_post_vrouter_default(self, setup_restapi_client): _, _, configdb, restapi_client = setup_restapi_client restapi_client.post_generic_vxlan_tunnel()