Skip to content

Commit 58e515a

Browse files
authored
[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.
1 parent e49d7dd commit 58e515a

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

tests/restapi/test_restapi.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def test_data_path(construct_url, vlan_members):
100100
# Add routes
101101
params = '[{"cmd": "add", "ip_prefix": "100.0.20.4/32", "nexthop": "100.3.152.52", "vnid": 7036001, "mac_address": null}, \
102102
{"cmd": "add", "ip_prefix": "101.0.20.5/32", "nexthop": "100.3.152.52", "vnid": 7036001, "mac_address": "1c:34:da:72:b0:8a"}, \
103-
{"cmd": "add", "ip_prefix": "192.168.20.4/32", "nexthop": "100.3.152.52", "vnid": 7036001, "mac_address": null}]'
103+
{"cmd": "add", "ip_prefix": "192.168.20.4/32", "nexthop": "100.3.152.52", "vnid": 7036001, "mac_address": null}, \
104+
{"cmd": "add", "ip_prefix": "100.0.30.0/24", "nexthop": "100.3.152.52", "vnid": 7036001, "mac_address": null}]'
104105
logger.info("Adding routes with vnid: 7036001 to VNET vnet-guid-2")
105106
r = restapi.patch_config_vrouter_vrf_id_routes(construct_url, 'vnet-guid-2', params)
106107
pytest_assert(r.status_code == 204)
@@ -114,11 +115,32 @@ def test_data_path(construct_url, vlan_members):
114115
logger.info(r.json())
115116
expected = [{"nexthop": "100.3.152.52", "ip_prefix": "192.168.20.4/32", "vnid": 7036001},
116117
{"nexthop": "100.3.152.52", "ip_prefix": "101.0.20.5/32", "mac_address": "1c:34:da:72:b0:8a", "vnid": 7036001},
117-
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.20.4/32", "vnid": 7036001}]
118+
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.20.4/32", "vnid": 7036001},
119+
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.30.0/24", "vnid": 7036001}]
118120
for route in expected:
119121
pytest_assert(route in r.json())
120122
logger.info("Routes with vnid: 7036001 to VNET vnet-guid-2 have been added successfully")
121123

124+
# Add routes
125+
params = '[{"cmd": "add", "ip_prefix": "100.0.50.4/24", "nexthop": "100.3.152.52", "vnid": 7036001, "mac_address": null}, \
126+
{"cmd": "add", "ip_prefix": "100.0.70.0/16", "nexthop": "100.3.152.52", "vnid": 7036001, "mac_address": null}]'
127+
logger.info("Adding routes with incorrect CIDR addresses with vnid: 7036001 to VNET vnet-guid-2")
128+
r = restapi.patch_config_vrouter_vrf_id_routes(construct_url, 'vnet-guid-2', params)
129+
pytest_assert(r.status_code == 207)
130+
131+
# Verify routes have not been added
132+
# Add some delay before query
133+
time.sleep(5)
134+
params = '{}'
135+
r = restapi.get_config_vrouter_vrf_id_routes(construct_url, 'vnet-guid-2', params)
136+
pytest_assert(r.status_code == 200)
137+
logger.info(r.json())
138+
expected = [{"nexthop": "100.3.152.52", "ip_prefix": "100.0.50.4/24", "vnid": 7036001},
139+
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.70.0/16", "vnid": 7036001}]
140+
for route in expected:
141+
pytest_assert(route not in r.json())
142+
logger.info("Routes with incorrect CIDR addresses with vnid: 7036001 to VNET vnet-guid-2 have not been added successfully")
143+
122144

123145
#
124146
# 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):
186208
# Add routes
187209
params = '[{"cmd": "add", "ip_prefix": "100.0.20.4/32", "nexthop": "100.3.152.52", "vnid": 7036002, "mac_address": null}, \
188210
{"cmd": "add", "ip_prefix": "101.0.20.5/32", "nexthop": "100.3.152.52", "vnid": 7036002, "mac_address": "1c:34:da:72:b0:8a"}, \
189-
{"cmd": "add", "ip_prefix": "192.168.20.4/32", "nexthop": "100.3.152.52", "vnid": 7036002, "mac_address": null}]'
211+
{"cmd": "add", "ip_prefix": "192.168.20.4/32", "nexthop": "100.3.152.52", "vnid": 7036002, "mac_address": null}, \
212+
{"cmd": "add", "ip_prefix": "100.0.30.0/24", "nexthop": "100.3.152.52", "vnid": 7036002, "mac_address": null}]'
190213
logger.info("Adding routes with vnid: 7036002 to VNET vnet-guid-3")
191214
r = restapi.patch_config_vrouter_vrf_id_routes(construct_url, 'vnet-guid-3', params)
192215
pytest_assert(r.status_code == 204)
@@ -198,11 +221,32 @@ def test_data_path(construct_url, vlan_members):
198221
logger.info(r.json())
199222
expected = [{"nexthop": "100.3.152.52", "ip_prefix": "192.168.20.4/32", "vnid": 7036002},
200223
{"nexthop": "100.3.152.52", "ip_prefix": "101.0.20.5/32", "mac_address": "1c:34:da:72:b0:8a", "vnid": 7036002},
201-
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.20.4/32", "vnid": 7036002}]
224+
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.20.4/32", "vnid": 7036002},
225+
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.30.0/24", "vnid": 7036002}]
202226
for route in expected:
203227
pytest_assert(route in r.json())
204228
logger.info("Routes with vnid: 3000 to VNET vnet-guid-3 have been added successfully")
205229

230+
# Add routes
231+
params = '[{"cmd": "add", "ip_prefix": "100.0.50.4/24", "nexthop": "100.3.152.52", "vnid": 7036002, "mac_address": null}, \
232+
{"cmd": "add", "ip_prefix": "100.0.70.0/16", "nexthop": "100.3.152.52", "vnid": 7036002, "mac_address": null}]'
233+
logger.info("Adding routes with incorrect CIDR addresses with vnid: 7036002 to VNET vnet-guid-3")
234+
r = restapi.patch_config_vrouter_vrf_id_routes(construct_url, 'vnet-guid-3', params)
235+
pytest_assert(r.status_code == 207)
236+
237+
# Verify routes have not been added
238+
# Add some delay before query
239+
time.sleep(5)
240+
params = '{}'
241+
r = restapi.get_config_vrouter_vrf_id_routes(construct_url, 'vnet-guid-3', params)
242+
pytest_assert(r.status_code == 200)
243+
logger.info(r.json())
244+
expected = [{"nexthop": "100.3.152.52", "ip_prefix": "100.0.50.4/24", "vnid": 7036002},
245+
{"nexthop": "100.3.152.52", "ip_prefix": "100.0.70.0/16", "vnid": 7036002}]
246+
for route in expected:
247+
pytest_assert(route not in r.json())
248+
logger.info("Routes with incorrect CIDR addresses with vnid: 7036002 to VNET vnet-guid-3 have not been added successfully")
249+
206250

207251
'''
208252
This test creates a VNET. It adds routes to the VNET and deletes them

0 commit comments

Comments
 (0)