|
1 | 1 | from swsscommon import swsscommon
|
2 | 2 | from dvslib.dvs_database import DVSDatabase
|
3 | 3 | import ast
|
| 4 | +import time |
4 | 5 |
|
5 | 6 | class TestVirtualChassis(object):
|
6 | 7 |
|
@@ -239,156 +240,175 @@ def test_chassis_system_neigh(self, vct):
|
239 | 240 | # Test neighbor on Ethernet4 since Ethernet0 is used as Inband port
|
240 | 241 | test_neigh_dev = "Ethernet4"
|
241 | 242 | test_neigh_ip = "10.8.104.3"
|
242 |
| - test_neigh_mac = "00:01:02:03:04:05" |
243 | 243 |
|
244 |
| - dvss = vct.dvss |
245 |
| - print("name {}".format(dvss.keys())) |
246 |
| - for name in dvss.keys(): |
247 |
| - dvs = dvss[name] |
248 |
| - |
249 |
| - config_db = dvs.get_config_db() |
250 |
| - metatbl = config_db.get_entry("DEVICE_METADATA", "localhost") |
251 |
| - |
252 |
| - cfg_switch_type = metatbl.get("switch_type") |
253 |
| - |
254 |
| - # Neighbor record verifiation done in line card |
255 |
| - if cfg_switch_type == "voq": |
256 |
| - lc_switch_id = metatbl.get("switch_id") |
257 |
| - assert lc_switch_id != "", "Got error in getting switch_id from CONFIG_DB DEVICE_METADATA" |
258 |
| - if lc_switch_id == "0": |
259 |
| - |
260 |
| - # Add a static neighbor |
261 |
| - _, res = dvs.runcmd(['sh', "-c", "ip neigh show"]) |
262 |
| - _, res = dvs.runcmd(['sh', "-c", f"ip neigh add {test_neigh_ip} lladdr {test_neigh_mac} dev {test_neigh_dev}"]) |
263 |
| - assert res == "", "Error configuring static neigh" |
| 244 | + # Grouping together the checks done during neighbor entry create into a function chassis_system_neigh_create() |
| 245 | + # if action is "add" it creates a new neighbor entry in local asic |
| 246 | + # if action is "change" it updates an existing neighbor entry with the mac_address |
| 247 | + def chassis_system_neigh_create(): |
| 248 | + dvss = vct.dvss |
| 249 | + print("name {}".format(dvss.keys())) |
| 250 | + for name in dvss.keys(): |
| 251 | + dvs = dvss[name] |
264 | 252 |
|
265 |
| - asic_db = dvs.get_asic_db() |
266 |
| - asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", 1) |
267 |
| - neighkeys = asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") |
268 |
| - assert len(neighkeys), "No neigh entries in ASIC_DB" |
269 |
| - |
270 |
| - # Check for presence of the neighbor in ASIC_DB |
271 |
| - test_neigh = "" |
272 |
| - for nkey in neighkeys: |
273 |
| - ne = ast.literal_eval(nkey) |
274 |
| - if ne['ip'] == test_neigh_ip: |
275 |
| - test_neigh = nkey |
276 |
| - break |
| 253 | + config_db = dvs.get_config_db() |
| 254 | + metatbl = config_db.get_entry("DEVICE_METADATA", "localhost") |
| 255 | + |
| 256 | + cfg_switch_type = metatbl.get("switch_type") |
| 257 | + |
| 258 | + # Neighbor record verifiation done in line card |
| 259 | + if cfg_switch_type == "voq": |
| 260 | + lc_switch_id = metatbl.get("switch_id") |
| 261 | + assert lc_switch_id != "", "Got error in getting switch_id from CONFIG_DB DEVICE_METADATA" |
| 262 | + if lc_switch_id == "0": |
| 263 | + |
| 264 | + # Add a static neighbor |
| 265 | + _, res = dvs.runcmd(['sh', "-c", "ip neigh show"]) |
| 266 | + _, res = dvs.runcmd(['sh', "-c", f"ip neigh {action} {test_neigh_ip} lladdr {mac_address} dev {test_neigh_dev}"]) |
| 267 | + assert res == "", "Error configuring static neigh" |
| 268 | + |
| 269 | + asic_db = dvs.get_asic_db() |
| 270 | + asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", 1) |
| 271 | + neighkeys = asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") |
| 272 | + assert len(neighkeys), "No neigh entries in ASIC_DB" |
| 273 | + |
| 274 | + # Check for presence of the neighbor in ASIC_DB |
| 275 | + test_neigh = "" |
| 276 | + for nkey in neighkeys: |
| 277 | + ne = ast.literal_eval(nkey) |
| 278 | + if ne['ip'] == test_neigh_ip: |
| 279 | + test_neigh = nkey |
| 280 | + break |
277 | 281 |
|
278 |
| - assert test_neigh != "", "Neigh not found in ASIC_DB" |
| 282 | + assert test_neigh != "", "Neigh not found in ASIC_DB" |
279 | 283 |
|
280 |
| - # Preserve test neigh asic db key for delete verification later |
281 |
| - test_neigh_asic_db_key = test_neigh |
| 284 | + # Preserve test neigh asic db key for delete verification later |
| 285 | + test_neigh_asic_db_key = test_neigh |
282 | 286 |
|
283 |
| - # Check for presence of encap index, retrieve and store it for sync verification |
284 |
| - test_neigh_entry = asic_db.wait_for_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", test_neigh) |
285 |
| - test_neigh_entry_attrs = asic_db.wait_for_fields("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", test_neigh, ["SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX"]) |
286 |
| - print(test_neigh) |
287 |
| - print(test_neigh_entry) |
288 |
| - print(test_neigh_entry_attrs) |
289 |
| - encap_index = test_neigh_entry_attrs["SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX"] |
290 |
| - assert encap_index != "" and encap_index != None, "VOQ encap index is not programmed in ASIC_DB" |
| 287 | + # Check for presence of encap index, retrieve and store it for sync verification |
| 288 | + test_neigh_entry = asic_db.wait_for_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", test_neigh) |
| 289 | + test_neigh_entry_attrs = asic_db.wait_for_fields("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", test_neigh, ["SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX"]) |
| 290 | + print(test_neigh) |
| 291 | + print(test_neigh_entry) |
| 292 | + print(test_neigh_entry_attrs) |
| 293 | + encap_index = test_neigh_entry_attrs["SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX"] |
| 294 | + assert encap_index != "" and encap_index != None, "VOQ encap index is not programmed in ASIC_DB" |
291 | 295 |
|
292 |
| - break |
293 |
| - |
294 |
| - # Verify neighbor record syncing with encap index |
295 |
| - for name in dvss.keys(): |
296 |
| - if name.startswith("supervisor"): |
297 |
| - dvs = dvss[name] |
298 |
| - chassis_app_db = DVSDatabase(swsscommon.CHASSIS_APP_DB, dvs.redis_chassis_sock) |
299 |
| - chassis_app_db.wait_for_n_keys("SYSTEM_NEIGH", 1) |
300 |
| - sysneighkeys = chassis_app_db.get_keys("SYSTEM_NEIGH") |
301 |
| - |
302 |
| - print(sysneighkeys) |
303 |
| - test_sysneigh = "" |
304 |
| - for sysnk in sysneighkeys: |
305 |
| - sysnk_tok = sysnk.split("|") |
306 |
| - assert len(sysnk_tok) == 3, "Invalid system neigh key in chassis app db" |
307 |
| - if sysnk_tok[2] == test_neigh_ip: |
308 |
| - test_sysneigh = sysnk |
309 | 296 | break
|
310 | 297 |
|
311 |
| - assert test_sysneigh != "", "Neigh is not sync-ed to chassis app db" |
| 298 | + # Verify neighbor record syncing with encap index |
| 299 | + for name in dvss.keys(): |
| 300 | + if name.startswith("supervisor"): |
| 301 | + dvs = dvss[name] |
| 302 | + chassis_app_db = DVSDatabase(swsscommon.CHASSIS_APP_DB, dvs.redis_chassis_sock) |
| 303 | + chassis_app_db.wait_for_n_keys("SYSTEM_NEIGH", 1) |
| 304 | + sysneighkeys = chassis_app_db.get_keys("SYSTEM_NEIGH") |
| 305 | + |
| 306 | + print(sysneighkeys) |
| 307 | + test_sysneigh = "" |
| 308 | + for sysnk in sysneighkeys: |
| 309 | + sysnk_tok = sysnk.split("|") |
| 310 | + assert len(sysnk_tok) == 3, "Invalid system neigh key in chassis app db" |
| 311 | + if sysnk_tok[2] == test_neigh_ip: |
| 312 | + test_sysneigh = sysnk |
| 313 | + break |
312 | 314 |
|
313 |
| - # Preserve test sys neigh chassis app db key for delete verification later |
314 |
| - test_sysneigh_chassis_app_db_key = test_sysneigh |
| 315 | + assert test_sysneigh != "", "Neigh is not sync-ed to chassis app db" |
315 | 316 |
|
316 |
| - test_sysneigh_entry = chassis_app_db.get_entry("SYSTEM_NEIGH", test_sysneigh) |
317 |
| - sys_neigh_encap_index = test_sysneigh_entry.get("encap_index") |
318 |
| - assert sys_neigh_encap_index != "", "System neigh in chassis app db does not have encap index" |
| 317 | + # Preserve test sys neigh chassis app db key for delete verification later |
| 318 | + test_sysneigh_chassis_app_db_key = test_sysneigh |
319 | 319 |
|
320 |
| - assert encap_index == sys_neigh_encap_index, "Encap index not sync-ed correctly" |
| 320 | + test_sysneigh_entry = chassis_app_db.get_entry("SYSTEM_NEIGH", test_sysneigh) |
| 321 | + sys_neigh_encap_index = test_sysneigh_entry.get("encap_index") |
| 322 | + assert sys_neigh_encap_index != "", "System neigh in chassis app db does not have encap index" |
321 | 323 |
|
322 |
| - break |
| 324 | + assert encap_index == sys_neigh_encap_index, "Encap index not sync-ed correctly" |
323 | 325 |
|
324 |
| - # Verify programming of remote neighbor in asic db and programming of static route and static |
325 |
| - # neigh in the kernel for the remote neighbor. The neighbor created in linecard 1 will be a |
326 |
| - # remote neighbor in other linecards. Verity existence of the test neighbor in linecards other |
327 |
| - # than linecard 1 |
328 |
| - for name in dvss.keys(): |
329 |
| - dvs = dvss[name] |
| 326 | + break |
330 | 327 |
|
331 |
| - config_db = dvs.get_config_db() |
332 |
| - metatbl = config_db.get_entry("DEVICE_METADATA", "localhost") |
| 328 | + # Add a delay for the programming of neighbor in remote LC |
| 329 | + time.sleep(10) |
333 | 330 |
|
334 |
| - cfg_switch_type = metatbl.get("switch_type") |
| 331 | + # Verify programming of remote neighbor in asic db and programming of static route and static |
| 332 | + # neigh in the kernel for the remote neighbor. The neighbor created in linecard 1 will be a |
| 333 | + # remote neighbor in other linecards. Verity existence of the test neighbor in linecards other |
| 334 | + # than linecard 1 |
| 335 | + for name in dvss.keys(): |
| 336 | + dvs = dvss[name] |
335 | 337 |
|
336 |
| - # Neighbor record verifiation done in line card |
337 |
| - if cfg_switch_type == "voq": |
338 |
| - lc_switch_id = metatbl.get("switch_id") |
339 |
| - assert lc_switch_id != "", "Got error in getting switch_id from CONFIG_DB DEVICE_METADATA" |
340 |
| - if lc_switch_id != "0": |
341 |
| - # Linecard other than linecard 1 |
342 |
| - asic_db = dvs.get_asic_db() |
343 |
| - asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", 1) |
344 |
| - neighkeys = asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") |
345 |
| - assert len(neighkeys), "No neigh entries in ASIC_DB" |
346 |
| - |
347 |
| - # Check for presence of the remote neighbor in ASIC_DB |
348 |
| - remote_neigh = "" |
349 |
| - for nkey in neighkeys: |
350 |
| - ne = ast.literal_eval(nkey) |
351 |
| - if ne['ip'] == test_neigh_ip: |
352 |
| - remote_neigh = nkey |
353 |
| - break |
| 338 | + config_db = dvs.get_config_db() |
| 339 | + metatbl = config_db.get_entry("DEVICE_METADATA", "localhost") |
| 340 | + |
| 341 | + cfg_switch_type = metatbl.get("switch_type") |
| 342 | + |
| 343 | + # Neighbor record verifiation done in line card |
| 344 | + if cfg_switch_type == "voq": |
| 345 | + lc_switch_id = metatbl.get("switch_id") |
| 346 | + assert lc_switch_id != "", "Got error in getting switch_id from CONFIG_DB DEVICE_METADATA" |
| 347 | + if lc_switch_id != "0": |
| 348 | + # Linecard other than linecard 1 |
| 349 | + asic_db = dvs.get_asic_db() |
| 350 | + asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", 1) |
| 351 | + neighkeys = asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") |
| 352 | + assert len(neighkeys), "No neigh entries in ASIC_DB" |
| 353 | + |
| 354 | + # Check for presence of the remote neighbor in ASIC_DB |
| 355 | + remote_neigh = "" |
| 356 | + for nkey in neighkeys: |
| 357 | + ne = ast.literal_eval(nkey) |
| 358 | + if ne['ip'] == test_neigh_ip: |
| 359 | + remote_neigh = nkey |
| 360 | + break |
354 | 361 |
|
355 |
| - assert remote_neigh != "", "Remote neigh not found in ASIC_DB" |
| 362 | + assert remote_neigh != "", "Remote neigh not found in ASIC_DB" |
356 | 363 |
|
357 |
| - # Preserve remote neigh asic db neigh key for delete verification later |
358 |
| - test_remote_neigh_asic_db_key = remote_neigh |
| 364 | + # Preserve remote neigh asic db neigh key for delete verification later |
| 365 | + test_remote_neigh_asic_db_key = remote_neigh |
359 | 366 |
|
360 |
| - # Check for kernel entries |
| 367 | + # Check for kernel entries |
361 | 368 |
|
362 |
| - _, output = dvs.runcmd("ip neigh show") |
363 |
| - assert f"{test_neigh_ip} dev {inband_port}" in output, "Kernel neigh not found for remote neighbor" |
| 369 | + _, output = dvs.runcmd("ip neigh show") |
| 370 | + assert f"{test_neigh_ip} dev {inband_port}" in output, "Kernel neigh not found for remote neighbor" |
364 | 371 |
|
365 |
| - _, output = dvs.runcmd("ip route show") |
366 |
| - assert f"{test_neigh_ip} dev {inband_port} scope link" in output, "Kernel route not found for remote neighbor" |
| 372 | + _, output = dvs.runcmd("ip route show") |
| 373 | + assert f"{test_neigh_ip} dev {inband_port} scope link" in output, "Kernel route not found for remote neighbor" |
367 | 374 |
|
368 |
| - # Check for ASIC_DB entries. |
| 375 | + # Check for ASIC_DB entries. |
369 | 376 |
|
370 |
| - # Check for presence of encap index, retrieve and store it for sync verification |
371 |
| - remote_neigh_entry = asic_db.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", remote_neigh) |
| 377 | + # Check for presence of encap index, retrieve and store it for sync verification |
| 378 | + remote_neigh_entry = asic_db.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", remote_neigh) |
372 | 379 |
|
373 |
| - # Validate encap index |
374 |
| - remote_encap_index = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX") |
375 |
| - assert remote_encap_index != "", "VOQ encap index is not programmed for remote neigh in ASIC_DB" |
376 |
| - assert remote_encap_index == encap_index, "Encap index of remote neigh mismatch with allocated encap index" |
| 380 | + # Validate encap index |
| 381 | + remote_encap_index = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX") |
| 382 | + assert remote_encap_index != "", "VOQ encap index is not programmed for remote neigh in ASIC_DB" |
| 383 | + assert remote_encap_index == encap_index, "Encap index of remote neigh mismatch with allocated encap index" |
377 | 384 |
|
378 |
| - # Validate MAC |
379 |
| - mac = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS") |
380 |
| - assert mac != "", "MAC address is not programmed for remote neigh in ASIC_DB" |
381 |
| - assert mac == test_neigh_mac, "Encap index of remote neigh mismatch with allocated encap index" |
| 385 | + # Validate MAC |
| 386 | + mac = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS") |
| 387 | + assert mac != "", "MAC address is not programmed for remote neigh in ASIC_DB" |
| 388 | + assert mac == mac_address, "Encap index of remote neigh mismatch with allocated encap index" |
382 | 389 |
|
383 |
| - # Check for other mandatory attributes |
384 |
| - # For remote neighbors, is_local must be "false" |
385 |
| - is_local = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_IS_LOCAL") |
386 |
| - assert is_local != "", "is_local attribute is not programmed for remote neigh in ASIC_DB" |
387 |
| - assert is_local == "false", "is_local attribute is true for remote neigh" |
| 390 | + # Check for other mandatory attributes |
| 391 | + # For remote neighbors, is_local must be "false" |
| 392 | + is_local = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_IS_LOCAL") |
| 393 | + assert is_local != "", "is_local attribute is not programmed for remote neigh in ASIC_DB" |
| 394 | + assert is_local == "false", "is_local attribute is true for remote neigh" |
388 | 395 |
|
389 |
| - break |
| 396 | + break |
| 397 | + |
| 398 | + return test_neigh_asic_db_key, test_sysneigh_chassis_app_db_key, test_remote_neigh_asic_db_key |
| 399 | + |
| 400 | + # First step is to add a new neighbor and check local/chassis_db/remote entry creation |
| 401 | + mac_address = "00:01:02:03:04:77" |
| 402 | + action = "add" |
| 403 | + chassis_system_neigh_create() |
| 404 | + |
| 405 | + # Second step to update the mac address and check local/chassis_db/remote entry creation |
| 406 | + mac_address = "00:01:02:03:04:05" |
| 407 | + action = "change" |
| 408 | + test_neigh_asic_db_key, test_sysneigh_chassis_app_db_key, test_remote_neigh_asic_db_key = chassis_system_neigh_create() |
390 | 409 |
|
391 | 410 | # Verify system neighbor delete and clearing
|
| 411 | + dvss = vct.dvss |
392 | 412 | for name in dvss.keys():
|
393 | 413 | dvs = dvss[name]
|
394 | 414 |
|
|
0 commit comments