Skip to content

Commit

Permalink
Catch duplicate usage of vni
Browse files Browse the repository at this point in the history
  • Loading branch information
sumukhatv committed Dec 9, 2021
1 parent 5cc4358 commit 0e254bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go-server-server/go/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
21 changes: 21 additions & 0 deletions test/test_restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0e254bd

Please sign in to comment.