From 25347872bf6c62ae596d95571edfec3df38333a1 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 29 Oct 2021 08:47:05 -0400 Subject: [PATCH 1/2] tests: zebra_seg6local has a race condition The test is checking installing of seg6 routes by this loop: for up to 5 times: sharp install seg6 route show ip route and is it installed The problem is that if the system is under heavy load the installation may not have happened yet and by immediately reinstalling the same route the same thing could happen again. Modify the code to pull the route installation outside of the loop and to increase to 10 attempts in case there is very heavy system load. Signed-off-by: Donald Sharp --- .../test_zebra_seg6local_route.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/topotests/zebra_seg6local_route/test_zebra_seg6local_route.py b/tests/topotests/zebra_seg6local_route/test_zebra_seg6local_route.py index 1062c306a0..0da51cc8b2 100755 --- a/tests/topotests/zebra_seg6local_route/test_zebra_seg6local_route.py +++ b/tests/topotests/zebra_seg6local_route/test_zebra_seg6local_route.py @@ -79,11 +79,7 @@ def test_zebra_seg6local_routes(): logger.info("Test for seg6local route install via ZAPI was start.") r1 = tgen.gears["r1"] - def check(router, dest, context, expected): - router.vtysh_cmd( - "sharp install seg6local-routes {} " - "nexthop-seg6local dum0 {} 1".format(dest, context) - ) + def check(router, dest, expected): output = json.loads(router.vtysh_cmd("show ipv6 route {} json".format(dest))) output = output.get("{}/128".format(dest)) if output is None: @@ -92,14 +88,20 @@ def test_zebra_seg6local_routes(): manifests = open_json_file(os.path.join(CWD, "{}/routes.json".format("r1"))) for manifest in manifests: - logger.info( - "CHECK {} {}".format(manifest["in"]["dest"], manifest["in"]["context"]) + dest = manifest["in"]["dest"] + context = manifest["in"]["context"] + + logger.info("CHECK {} {}".format(dest, context)) + + r1.vtysh_cmd( + "sharp install seg6local-routes {} nexthop-seg6local dum0 {} 1".format( + dest, context + ) ) test_func = partial( check, r1, - manifest["in"]["dest"], - manifest["in"]["context"], + dest, manifest["out"], ) success, result = topotest.run_and_expect(test_func, None, count=5, wait=1) From 7d2cf93636c1bb93cbd59c5a3a7ab0fb12079b69 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 29 Oct 2021 10:21:28 -0400 Subject: [PATCH 2/2] tests: Fix zebra_seg6_route to not always reinstall the same route This code has two issues: a) The loop to test for successful installation re-installs the route every time it loops. A system under load will have issues ensuring the route is installed and repeated attempts does not help b) The nexthop group installation was always failing but never noticed (because of the previous commit) and the test was always passing, when it should have never passed. Signed-off-by: Donald Sharp --- .../topotests/zebra_seg6_route/r1/routes.json | 2 +- .../zebra_seg6_route/test_zebra_seg6_route.py | 26 +++++++------------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/tests/topotests/zebra_seg6_route/r1/routes.json b/tests/topotests/zebra_seg6_route/r1/routes.json index a0c15b8fe4..50ac4f7174 100644 --- a/tests/topotests/zebra_seg6_route/r1/routes.json +++ b/tests/topotests/zebra_seg6_route/r1/routes.json @@ -2,7 +2,7 @@ { "in": { "dest": "1::1", - "nh": "2001::1", + "nh": "2001::2", "sid": "a::" }, "out":[{ diff --git a/tests/topotests/zebra_seg6_route/test_zebra_seg6_route.py b/tests/topotests/zebra_seg6_route/test_zebra_seg6_route.py index cdad988b81..399af748a1 100755 --- a/tests/topotests/zebra_seg6_route/test_zebra_seg6_route.py +++ b/tests/topotests/zebra_seg6_route/test_zebra_seg6_route.py @@ -79,11 +79,7 @@ def test_zebra_seg6local_routes(): logger.info("Test for seg6local route install via ZAPI was start.") r1 = tgen.gears["r1"] - def check(router, dest, nh, sid, expected): - router.vtysh_cmd( - "sharp install seg6-routes {} " - "nexthop-seg6 {} encap {} 1".format(dest, nh, sid) - ) + def check(router, dest, expected): output = json.loads(router.vtysh_cmd("show ipv6 route {} json".format(dest))) output = output.get("{}/128".format(dest)) if output is None: @@ -92,19 +88,17 @@ def test_zebra_seg6local_routes(): manifests = open_json_file(os.path.join(CWD, "{}/routes.json".format("r1"))) for manifest in manifests: - logger.info( - "CHECK {} {} {}".format( - manifest["in"]["dest"], manifest["in"]["nh"], manifest["in"]["sid"] + dest = manifest["in"]["dest"] + nh = manifest["in"]["nh"] + sid = manifest["in"]["sid"] + + r1.vtysh_cmd( + "sharp install seg6-routes {} nexthop-seg6 {} encap {} 1".format( + dest, nh, sid ) ) - test_func = partial( - check, - r1, - manifest["in"]["dest"], - manifest["in"]["nh"], - manifest["in"]["sid"], - manifest["out"], - ) + logger.info("CHECK {} {} {}".format(dest, nh, sid)) + test_func = partial(check, r1, dest, manifest["out"]) success, result = topotest.run_and_expect(test_func, None, count=5, wait=1) assert result is None, "Failed"