From ec40757f33d6ebb9e3fd87cebe633ad291494ef7 Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Fri, 21 Oct 2022 16:44:45 +0000 Subject: [PATCH] topotests: test_ospf_p2mp.py - check for full adjacencies and basic DB info Signed-off-by: Lou Berger (cherry picked from commit 675ba67d89b1bc3fc2364ff2aabc50392456d1d0) --- .../test_ospf_p2mp.py | 156 +++++++++++++++++- 1 file changed, 155 insertions(+), 1 deletion(-) diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py b/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py index 3b84a99cdf..e131fba0c3 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py @@ -47,10 +47,12 @@ from lib.common_config import ( step, create_interfaces_cfg, topo_daemons, + retry, + run_frr_cmd, ) from lib.topolog import logger from lib.topojson import build_config_from_json -from lib.topotest import frr_unicode +from lib.topotest import frr_unicode, json_cmp from lib.ospf import ( verify_ospf_interface, @@ -378,6 +380,158 @@ def test_ospf_p2mp_tc1_p0(request): write_test_footer(tc_name) +@retry(retry_timeout=30) +def verify_ospf_json(tgen, dut, input_dict, cmd="show ip ospf database json"): + del tgen + show_ospf_json = run_frr_cmd(dut, cmd, isjson=True) + if not bool(show_ospf_json): + return "ospf is not running" + result = json_cmp(show_ospf_json, input_dict) + return str(result) if result else None + + +@pytest.mark.parametrize("tgen", [2], indirect=True) +def test_ospf_nbrs(tgen): + db_full = { + "areas": { + "0.0.0.0": { + "routerLinkStates": [ + { + "lsId": "100.1.1.0", + "advertisedRouter": "100.1.1.0", + "numOfRouterLinks": 6, + }, + { + "lsId": "100.1.1.1", + "advertisedRouter": "100.1.1.1", + "numOfRouterLinks": 6, + }, + { + "lsId": "100.1.1.2", + "advertisedRouter": "100.1.1.2", + "numOfRouterLinks": 6, + }, + { + "lsId": "100.1.1.3", + "advertisedRouter": "100.1.1.3", + "numOfRouterLinks": 7, + }, + ] + } + } + } + input = [ + [ + "r0", + "show ip ospf n json", + { + "neighbors": { + "100.1.1.1": [ + { + "state": "Full/DROther", + } + ], + "100.1.1.2": [ + { + "state": "Full/DROther", + } + ], + "100.1.1.3": [ + { + "state": "Full/DROther", + } + ], + } + }, + ], + [ + "r1", + "show ip ospf n json", + { + "neighbors": { + "100.1.1.0": [ + { + "state": "Full/DROther", + } + ], + "100.1.1.2": [ + { + "state": "Full/DROther", + } + ], + "100.1.1.3": [ + { + "state": "Full/DROther", + } + ], + } + }, + ], + [ + "r2", + "show ip ospf n json", + { + "neighbors": { + "100.1.1.0": [ + { + "state": "Full/DROther", + } + ], + "100.1.1.1": [ + { + "state": "Full/DROther", + } + ], + "100.1.1.3": [ + { + "state": "Full/DROther", + } + ], + } + }, + ], + [ + "r3", + "show ip ospf n json", + { + "neighbors": { + "100.1.1.0": [ + { + "state": "Full/DROther", + } + ], + "100.1.1.1": [ + { + "state": "Full/DROther", + } + ], + "100.1.1.2": [ + { + "state": "Full/DROther", + } + ], + } + }, + ], + ["r0", "show ip ospf database json", db_full], + ["r1", "show ip ospf database json", db_full], + ["r2", "show ip ospf database json", db_full], + ["r3", "show ip ospf database json", db_full], + ["r0", "show ip ospf database json", db_full], + ["r0", "show ip ospf database router json", {}], + ["r0", "show ip ospf interface traffic json", {}], + ["r1", "show ip ospf interface traffic json", {}], + ["r2", "show ip ospf interface traffic json", {}], + ["r3", "show ip ospf interface traffic json", {}], + ] + for cmd_set in input: + step("test_ospf: %s - %s" % (cmd_set[0], cmd_set[1])) + assert ( + verify_ospf_json(tgen, tgen.gears[cmd_set[0]], cmd_set[2], cmd_set[1]) + is None + ) + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) -- 2.39.5