From 58e515aaae86189efa871c9585b85c13ca35ae97 Mon Sep 17 00:00:00 2001 From: Sumukha Tumkur Vani Date: Sun, 3 Oct 2021 21:19:29 -0700 Subject: [PATCH] [RESTAPI] Test configuring routes with incorrect CIDR addresses (#4378) Configuring incorrect CIDR addresses as routes is not permitted in SONiC and REST-API is designed to reject such incorrect routes. --- tests/restapi/test_restapi.py | 52 ++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/tests/restapi/test_restapi.py b/tests/restapi/test_restapi.py index a8aeb92fa79..22ff8f45f6b 100644 --- a/tests/restapi/test_restapi.py +++ b/tests/restapi/test_restapi.py @@ -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) @@ -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 @@ -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) @@ -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