From 7f587c9c9d0291bae775cc0c3e2c8c7f8267407c Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Fri, 30 Aug 2024 14:41:08 +0200 Subject: [PATCH] tests: check show ip nhrp shorcut in nhrp_redundancy Check show ip nhrp shorcut in nhrp_redundancy Signed-off-by: Louis Scalbert --- .../nhc1/nhrp_shortcut_absent.json | 5 ++ .../nhc1/nhrp_shortcut_present.json | 9 ++++ .../nhrp_redundancy/test_nhrp_redundancy.py | 53 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 tests/topotests/nhrp_redundancy/nhc1/nhrp_shortcut_absent.json create mode 100644 tests/topotests/nhrp_redundancy/nhc1/nhrp_shortcut_present.json diff --git a/tests/topotests/nhrp_redundancy/nhc1/nhrp_shortcut_absent.json b/tests/topotests/nhrp_redundancy/nhc1/nhrp_shortcut_absent.json new file mode 100644 index 000000000000..78563cb90221 --- /dev/null +++ b/tests/topotests/nhrp_redundancy/nhc1/nhrp_shortcut_absent.json @@ -0,0 +1,5 @@ +{ + "attr":{ + "entriesCount":0 + } +} diff --git a/tests/topotests/nhrp_redundancy/nhc1/nhrp_shortcut_present.json b/tests/topotests/nhrp_redundancy/nhc1/nhrp_shortcut_present.json new file mode 100644 index 000000000000..40a7086b1c60 --- /dev/null +++ b/tests/topotests/nhrp_redundancy/nhc1/nhrp_shortcut_present.json @@ -0,0 +1,9 @@ +{ + "table":[ + { + "type":"dynamic", + "prefix":"5.5.5.0/24", + "via":"176.16.1.5" + } + ] +} diff --git a/tests/topotests/nhrp_redundancy/test_nhrp_redundancy.py b/tests/topotests/nhrp_redundancy/test_nhrp_redundancy.py index 70266740148b..9b4933e43d58 100644 --- a/tests/topotests/nhrp_redundancy/test_nhrp_redundancy.py +++ b/tests/topotests/nhrp_redundancy/test_nhrp_redundancy.py @@ -363,6 +363,33 @@ def test_redundancy_shortcut(): assertmsg = '"{}" JSON output mismatches'.format(nhc1.name) assert result is None, assertmsg + json_file = "{}/{}/nhrp_shortcut_present.json".format(CWD, nhc1.name) + expected = json.loads(open(json_file).read()) + test_func = partial( + topotest.router_json_cmp, nhc1, "show ip nhrp shortcut json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=40, wait=0.5) + + output = nhc1.vtysh_cmd("show ip nhrp shortcut") + logger.info(output) + + assertmsg = '"{}" JSON output mismatches'.format(nhc1.name) + assert result is None, assertmsg + + # check the shortcut disappears because of no traffic + json_file = "{}/{}/nhrp_shortcut_absent.json".format(CWD, nhc1.name) + expected = json.loads(open(json_file).read()) + test_func = partial( + topotest.router_json_cmp, nhc1, "show ip nhrp shortcut json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=40, wait=0.5) + + output = nhc1.vtysh_cmd("show ip nhrp shortcut") + logger.info(output) + + assertmsg = '"{}" JSON output mismatches'.format(nhc1.name) + assert result is None, assertmsg + def test_redundancy_shortcut_backup(): """ @@ -449,6 +476,19 @@ def test_redundancy_shortcut_backup(): output = nhc1.vtysh_cmd("show ip route nhrp") logger.info(output) + json_file = "{}/{}/nhrp_shortcut_present.json".format(CWD, nhc1.name) + expected = json.loads(open(json_file).read()) + test_func = partial( + topotest.router_json_cmp, nhc1, "show ip nhrp shortcut json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=40, wait=0.5) + + output = nhc1.vtysh_cmd("show ip nhrp shortcut") + logger.info(output) + + assertmsg = '"{}" JSON output mismatches'.format(nhc1.name) + assert result is None, assertmsg + # Now verify shortcut is purged with lack of traffic json_file = "{}/{}/nhrp_route_nhs1_down.json".format(CWD, nhc1.name) assertmsg = "No nhrp_route file found" @@ -466,6 +506,19 @@ def test_redundancy_shortcut_backup(): assertmsg = '"{}" JSON output mismatches'.format(nhc1.name) assert result is None, assertmsg + json_file = "{}/{}/nhrp_shortcut_absent.json".format(CWD, nhc1.name) + expected = json.loads(open(json_file).read()) + test_func = partial( + topotest.router_json_cmp, nhc1, "show ip nhrp shortcut json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=40, wait=0.5) + + output = nhc1.vtysh_cmd("show ip nhrp shortcut") + logger.info(output) + + assertmsg = '"{}" JSON output mismatches'.format(nhc1.name) + assert result is None, assertmsg + def test_memory_leak(): "Run the memory leak test and report results."