Skip to content

Commit

Permalink
[RESTAPI] Test configuring routes with incorrect CIDR addresses (#4378)
Browse files Browse the repository at this point in the history
Configuring incorrect CIDR addresses as routes is not permitted in SONiC and REST-API is designed to reject such incorrect routes.
  • Loading branch information
sumukhatv authored Oct 4, 2021
1 parent e49d7dd commit 58e515a
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions tests/restapi/test_restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def test_data_path(construct_url, vlan_members):
# Add routes
params = '[{"cmd": "add", "ip_prefix": "100.0.20.4/32", "nexthop": "100.3.152.52", "vnid": 7036001, "mac_address": null}, \
{"cmd": "add", "ip_prefix": "101.0.20.5/32", "nexthop": "100.3.152.52", "vnid": 7036001, "mac_address": "1c:34:da:72:b0:8a"}, \
{"cmd": "add", "ip_prefix": "192.168.20.4/32", "nexthop": "100.3.152.52", "vnid": 7036001, "mac_address": null}]'
{"cmd": "add", "ip_prefix": "192.168.20.4/32", "nexthop": "100.3.152.52", "vnid": 7036001, "mac_address": null}, \
{"cmd": "add", "ip_prefix": "100.0.30.0/24", "nexthop": "100.3.152.52", "vnid": 7036001, "mac_address": null}]'
logger.info("Adding routes with vnid: 7036001 to VNET vnet-guid-2")
r = restapi.patch_config_vrouter_vrf_id_routes(construct_url, 'vnet-guid-2', params)
pytest_assert(r.status_code == 204)
Expand All @@ -114,11 +115,32 @@ def test_data_path(construct_url, vlan_members):
logger.info(r.json())
expected = [{"nexthop": "100.3.152.52", "ip_prefix": "192.168.20.4/32", "vnid": 7036001},
{"nexthop": "100.3.152.52", "ip_prefix": "101.0.20.5/32", "mac_address": "1c:34:da:72:b0:8a", "vnid": 7036001},
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.20.4/32", "vnid": 7036001}]
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.20.4/32", "vnid": 7036001},
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.30.0/24", "vnid": 7036001}]
for route in expected:
pytest_assert(route in r.json())
logger.info("Routes with vnid: 7036001 to VNET vnet-guid-2 have been added successfully")

# Add routes
params = '[{"cmd": "add", "ip_prefix": "100.0.50.4/24", "nexthop": "100.3.152.52", "vnid": 7036001, "mac_address": null}, \
{"cmd": "add", "ip_prefix": "100.0.70.0/16", "nexthop": "100.3.152.52", "vnid": 7036001, "mac_address": null}]'
logger.info("Adding routes with incorrect CIDR addresses with vnid: 7036001 to VNET vnet-guid-2")
r = restapi.patch_config_vrouter_vrf_id_routes(construct_url, 'vnet-guid-2', params)
pytest_assert(r.status_code == 207)

# Verify routes have not been added
# Add some delay before query
time.sleep(5)
params = '{}'
r = restapi.get_config_vrouter_vrf_id_routes(construct_url, 'vnet-guid-2', params)
pytest_assert(r.status_code == 200)
logger.info(r.json())
expected = [{"nexthop": "100.3.152.52", "ip_prefix": "100.0.50.4/24", "vnid": 7036001},
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.70.0/16", "vnid": 7036001}]
for route in expected:
pytest_assert(route not in r.json())
logger.info("Routes with incorrect CIDR addresses with vnid: 7036001 to VNET vnet-guid-2 have not been added successfully")


#
# Create second VNET and add VLAN, VLAN member, VLAN neighbor and routes to it
Expand Down Expand Up @@ -186,7 +208,8 @@ def test_data_path(construct_url, vlan_members):
# Add routes
params = '[{"cmd": "add", "ip_prefix": "100.0.20.4/32", "nexthop": "100.3.152.52", "vnid": 7036002, "mac_address": null}, \
{"cmd": "add", "ip_prefix": "101.0.20.5/32", "nexthop": "100.3.152.52", "vnid": 7036002, "mac_address": "1c:34:da:72:b0:8a"}, \
{"cmd": "add", "ip_prefix": "192.168.20.4/32", "nexthop": "100.3.152.52", "vnid": 7036002, "mac_address": null}]'
{"cmd": "add", "ip_prefix": "192.168.20.4/32", "nexthop": "100.3.152.52", "vnid": 7036002, "mac_address": null}, \
{"cmd": "add", "ip_prefix": "100.0.30.0/24", "nexthop": "100.3.152.52", "vnid": 7036002, "mac_address": null}]'
logger.info("Adding routes with vnid: 7036002 to VNET vnet-guid-3")
r = restapi.patch_config_vrouter_vrf_id_routes(construct_url, 'vnet-guid-3', params)
pytest_assert(r.status_code == 204)
Expand All @@ -198,11 +221,32 @@ def test_data_path(construct_url, vlan_members):
logger.info(r.json())
expected = [{"nexthop": "100.3.152.52", "ip_prefix": "192.168.20.4/32", "vnid": 7036002},
{"nexthop": "100.3.152.52", "ip_prefix": "101.0.20.5/32", "mac_address": "1c:34:da:72:b0:8a", "vnid": 7036002},
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.20.4/32", "vnid": 7036002}]
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.20.4/32", "vnid": 7036002},
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.30.0/24", "vnid": 7036002}]
for route in expected:
pytest_assert(route in r.json())
logger.info("Routes with vnid: 3000 to VNET vnet-guid-3 have been added successfully")

# Add routes
params = '[{"cmd": "add", "ip_prefix": "100.0.50.4/24", "nexthop": "100.3.152.52", "vnid": 7036002, "mac_address": null}, \
{"cmd": "add", "ip_prefix": "100.0.70.0/16", "nexthop": "100.3.152.52", "vnid": 7036002, "mac_address": null}]'
logger.info("Adding routes with incorrect CIDR addresses with vnid: 7036002 to VNET vnet-guid-3")
r = restapi.patch_config_vrouter_vrf_id_routes(construct_url, 'vnet-guid-3', params)
pytest_assert(r.status_code == 207)

# Verify routes have not been added
# Add some delay before query
time.sleep(5)
params = '{}'
r = restapi.get_config_vrouter_vrf_id_routes(construct_url, 'vnet-guid-3', params)
pytest_assert(r.status_code == 200)
logger.info(r.json())
expected = [{"nexthop": "100.3.152.52", "ip_prefix": "100.0.50.4/24", "vnid": 7036002},
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.70.0/16", "vnid": 7036002}]
for route in expected:
pytest_assert(route not in r.json())
logger.info("Routes with incorrect CIDR addresses with vnid: 7036002 to VNET vnet-guid-3 have not been added successfully")


'''
This test creates a VNET. It adds routes to the VNET and deletes them
Expand Down

0 comments on commit 58e515a

Please sign in to comment.