Skip to content

Commit

Permalink
Add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
prsunny committed Oct 13, 2023
1 parent fea5f47 commit 9f0640c
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 5 deletions.
9 changes: 6 additions & 3 deletions go-server-server/go/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,9 +1073,12 @@ func ConfigVrouterVrfIdPost(w http.ResponseWriter, r *http.Request) {

guid := CacheGetVniId(uint32(attr.Vnid))
if guid != "" {
WriteRequestErrorWithSubCode(w, http.StatusConflict, RESRC_EXISTS,
"Object already exists: {\"vni\":\"" + strconv.Itoa(attr.Vnid) + "\", \"vnet_name\":\"" + guid +"\"}", []string{}, "")
return
// Default Vnets can have same Vnid
if !(strings.Contains(guid, "Vnet-default")) {
WriteRequestErrorWithSubCode(w, http.StatusConflict, RESRC_EXISTS,
"Object already exists: {\"vni\":\"" + strconv.Itoa(attr.Vnid) + "\", \"vnet_name\":\"" + guid +"\"}", []string{}, "")
return
}
}

vnet_id = CacheGenAndSetVnetGuidId(vars["vnet_name"], uint32(attr.Vnid))
Expand Down
23 changes: 23 additions & 0 deletions test/apitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,24 @@ def post_generic_vxlan_tunnel(self):
})
self.assertEqual(rv.status_code, 204)

def post_generic_vxlan_v6_tunnel(self):
rv = self.post_config_tunnel_decap_tunnel_type('vxlan', {
'ip_addr': '2000:1000'
})
self.assertEqual(rv.status_code, 204)

def post_generic_default_vrouter_and_deps(self):
self.post_generic_vxlan_tunnel()
self.post_generic_vxlan_v6_tunnel()
rv = self.post_config_vrouter_vrf_id("vnet-default", {
'vnid': 8000
})
self.assertEqual(rv.status_code, 204)
rv = self.post_config_vrouter_vrf_id("vnet-default-v4", {
'vnid': 8000
})
self.assertEqual(rv.status_code, 204)

def post_generic_vrouter_and_deps(self):
self.post_generic_vxlan_tunnel()
rv = self.post_config_vrouter_vrf_id("vnet-guid-1", {
Expand Down Expand Up @@ -415,6 +433,11 @@ def test_get_vrouter(self):
self.post_generic_vrouter_and_deps()
self.check_vrouter_exists("vnet-guid-1",1001)

def test_default_vrouter(self):
self.post_generic_default_vrouter_and_deps()
self.check_vrouter_exists("vnet-default",8000)
self.check_vrouter_exists("vnet-default-v4",8000)

def test_duplicate_vni(self):
self.post_generic_vrouter_and_deps_duplicate()
self.check_vrouter_exists("vnet-guid-1",1001)
Expand Down
19 changes: 19 additions & 0 deletions test/restapi_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,25 @@ def post_generic_vxlan_tunnel(self):
})
assert rv.status_code == 204

def post_generic_vxlan_v6_tunnel(self):
rv = self.post_config_tunnel_decap_tunnel_type('vxlan', {
'ip_addr': '2000::1000'
})
assert rv.status_code == 204

def post_generic_default_vrouter_and_deps(self):
self.post_generic_vxlan_tunnel()
self.post_generic_vxlan_v6_tunnel()
rv = self.post_config_vrouter_vrf_id("Vnet-default", {
'vnid': 8000
})
assert rv.status_code == 204

rv = self.post_config_vrouter_vrf_id("Vnet-default-v4", {
'vnid': 8000
})
assert rv.status_code == 204

def post_generic_vrouter_and_deps(self):
self.post_generic_vxlan_tunnel()
rv = self.post_config_vrouter_vrf_id("vnet-guid-1", {
Expand Down
89 changes: 87 additions & 2 deletions test/test_restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ def test_post_config_tunnel_decap_tunnel_type(self, setup_restapi_client):
assert tunnel_table == {b'src_ip': b'34.53.1.0'}
logging.info("Tunnel table is %s", tunnel_table)

# Test V6 tunnel
r = restapi_client.post_config_tunnel_decap_tunnel_type('vxlan', {
'ip_addr': '2000::1000'
})
assert r.status_code == 204

r = restapi_client.post_config_tunnel_decap_tunnel_type('vxlan', {
'ip_addr': '2000::1001'
})
assert r.status_code == 409

tunnel_table = configdb.hgetall(VXLAN_TUNNEL_TB + '|default_vxlan_tunnel')
assert tunnel_table == {b'src_ip': b'2000::1000'}
logging.info("Tunnel v6 table is %s", tunnel_table)

def test_delete_config_tunnel_decap_tunnel_type(self, setup_restapi_client):
_, _, configdb, restapi_client = setup_restapi_client
restapi_client.post_generic_vxlan_tunnel()
Expand Down Expand Up @@ -241,7 +256,7 @@ def test_post_vrouter_with_overlay_dmac(self, setup_restapi_client):
def test_post_vrouter_default(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-default", {
r = restapi_client.post_config_vrouter_vrf_id("Vnet-default-v4", {
'vnid': 2001
})
assert r.status_code == 204
Expand All @@ -250,15 +265,67 @@ def test_post_vrouter_default(self, setup_restapi_client):
assert vrouter_table == {
b'vxlan_tunnel': b'default_vxlan_tunnel_v4',
b'vni': b'2001',
b'guid': b'Vnet-default-v4',
b'scope': b'default'
}

def test_post_vrouter_v6_default(self, setup_restapi_client):
_, _, configdb, restapi_client = setup_restapi_client
restapi_client.post_generic_vxlan_v6_tunnel()
r = restapi_client.post_config_vrouter_vrf_id("Vnet-default", {
'vnid': 2001
})
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'2001',
b'guid': b'Vnet-default',
b'scope': b'default'
}
}

def test_post_vrouter_v4_v6_default(self, setup_restapi_client):
_, _, configdb, restapi_client = setup_restapi_client
restapi_client.post_generic_vxlan_tunnel()
restapi_client.post_generic_vxlan_v6_tunnel()
r = restapi_client.post_config_vrouter_vrf_id("Vnet-default", {
'vnid': 2001
})
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'2001',
b'guid': b'Vnet-default',
b'scope': b'default'
}

r = restapi_client.post_config_vrouter_vrf_id("Vnet-default-v4", {
'vnid': 2001
})
assert r.status_code == 204

vrouter_table = configdb.hgetall(VNET_TB + '|' + VNET_NAME_PREF + '2')
assert vrouter_table == {
b'vxlan_tunnel': b'default_vxlan_tunnel_v4',
b'vni': b'2001',
b'guid': b'Vnet-default-v4',
b'scope': b'default'
}

def test_get_vrouter(self, setup_restapi_client):
_, _, _, restapi_client = setup_restapi_client
restapi_client.post_generic_vrouter_and_deps()
self.check_vrouter_exists(restapi_client, "vnet-guid-1",1001)

def test_default_vrouter(self, setup_restapi_client):
_, _, _, restapi_client = setup_restapi_client
restapi_client.post_generic_default_vrouter_and_deps()
self.check_vrouter_exists(restapi_client,"Vnet-default",8000)
self.check_vrouter_exists(restapi_client,"Vnet-default-v4",8000)

def test_duplicate_vni(self, setup_restapi_client):
_, _, _, restapi_client = setup_restapi_client
restapi_client.post_generic_vrouter_and_deps_duplicate()
Expand Down Expand Up @@ -1895,6 +1962,24 @@ def test_post_vrouter_with_advertise_prefix(self, setup_restapi_client):
})
assert r.status_code == 400

def test_post_vrouter_v4_default(self, setup_restapi_client):
_, _, configdb, restapi_client = setup_restapi_client
#Create V4 only tunnel
restapi_client.post_generic_vxlan_tunnel()
r = restapi_client.post_config_vrouter_vrf_id("Vnet-default", {
'vnid': 2001
})
assert r.status_code == 500

def test_post_vrouter_v6_default(self, setup_restapi_client):
_, _, configdb, restapi_client = setup_restapi_client
#Create V6 only tunnel
restapi_client.post_generic_vxlan_v6_tunnel()
r = restapi_client.post_config_vrouter_vrf_id("Vnet-default-v4", {
'vnid': 2001
})
assert r.status_code == 500

# Vlan
def test_post_vlan_which_exists(self, setup_restapi_client):
_, _, _, restapi_client = setup_restapi_client
Expand Down

0 comments on commit 9f0640c

Please sign in to comment.