From 165e66e92e00bc0ad48b8b5cfa6fadb4cb14505b Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 2 Dec 2024 17:07:14 +0100 Subject: [PATCH] topotests: save bgp_bmp json temp files to bmp log folder instead of /tmp Some temporary files are hardwritten in /tmp folder. Use the bmp log folder instead. Replace the bmp log file argument with bmp log folder. Signed-off-by: Philippe Guibert --- tests/topotests/bgp_bmp/bgpbmp.py | 33 ++++++++++++++++++----- tests/topotests/bgp_bmp/test_bgp_bmp_1.py | 2 +- tests/topotests/bgp_bmp/test_bgp_bmp_2.py | 2 +- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/tests/topotests/bgp_bmp/bgpbmp.py b/tests/topotests/bgp_bmp/bgpbmp.py index 950ffef2f71f..41995e2b5e53 100644 --- a/tests/topotests/bgp_bmp/bgpbmp.py +++ b/tests/topotests/bgp_bmp/bgpbmp.py @@ -49,11 +49,19 @@ def bmp_update_seq(bmp_collector, bmp_log_file): def bmp_update_expected_files( - bmp_actual, expected_prefixes, bmp_log_type, policy, step, bmp_client + bmp_actual, + expected_prefixes, + bmp_log_type, + policy, + step, + bmp_client, + bmp_log_folder, ): tgen = get_topogen() - with open(f"/tmp/bmp-{bmp_log_type}-{policy}-step{step}.json", "w") as json_file: + with open( + f"{bmp_log_folder}/tmp/bmp-{bmp_log_type}-{policy}-step{step}.json", "w" + ) as json_file: json.dump(bmp_actual, json_file, indent=4) out = bmp_client.vtysh_cmd("show bgp vrf vrf1 ipv4 json", isjson=True) @@ -70,8 +78,10 @@ def bmp_update_expected_files( continue filtered_out["routes"][pfx] = None - # ls /tmp/show*json | while read file; do egrep -v 'prefix|network|metric|ocPrf|version|weight|peerId|vrf|Version|valid|Reason|fe80' $file >$(basename $file); echo >> $(basename $file); done - with open(f"/tmp/show-bgp-ipv4-{bmp_log_type}-step{step}.json", "w") as json_file: + # ls {bmp_log_folder}/tmp/show*json | while read file; do egrep -v 'prefix|network|metric|ocPrf|version|weight|peerId|vrf|Version|valid|Reason|fe80' $file >$(basename $file); echo >> $(basename $file); done + with open( + f"{bmp_log_folder}/tmp/show-bgp-ipv4-{bmp_log_type}-step{step}.json", "w" + ) as json_file: json.dump(filtered_out, json_file, indent=4) out = tgen.gears["r1"].vtysh_cmd("show bgp vrf vrf1 ipv6 json", isjson=True) @@ -88,7 +98,9 @@ def bmp_update_expected_files( continue filtered_out["routes"][pfx] = None - with open(f"/tmp/show-bgp-ipv6-{bmp_log_type}-step{step}.json", "w") as json_file: + with open( + f"{bmp_log_folder}/tmp/show-bgp-ipv6-{bmp_log_type}-step{step}.json", "w" + ) as json_file: json.dump(filtered_out, json_file, indent=4) @@ -98,7 +110,7 @@ def bmp_check_for_prefixes( policy, step, bmp_collector, - bmp_log_file, + bmp_log_folder, bmp_client, expected_json_path, update_expected_json, @@ -111,6 +123,7 @@ def bmp_check_for_prefixes( """ global SEQ + bmp_log_file = f"{bmp_log_folder}/bmp.log" # we care only about the new messages messages = [ m @@ -173,7 +186,13 @@ def bmp_check_for_prefixes( == set(expected_prefixes) ): bmp_update_expected_files( - actual, expected_prefixes, bmp_log_type, policy, step, bmp_client + actual, + expected_prefixes, + bmp_log_type, + policy, + step, + bmp_client, + bmp_log_folder, ) return topotest.json_cmp(actual, expected, exact=True) diff --git a/tests/topotests/bgp_bmp/test_bgp_bmp_1.py b/tests/topotests/bgp_bmp/test_bgp_bmp_1.py index 9fc8e127720f..61428634414c 100644 --- a/tests/topotests/bgp_bmp/test_bgp_bmp_1.py +++ b/tests/topotests/bgp_bmp/test_bgp_bmp_1.py @@ -158,7 +158,7 @@ def _test_prefixes(policy, vrf=None, step=0): policy, step, tgen.gears["bmp1"], - os.path.join(tgen.logdir, "bmp1", "bmp.log"), + os.path.join(tgen.logdir, "bmp1"), tgen.gears["r1"], f"{CWD}/bmp1", UPDATE_EXPECTED_JSON, diff --git a/tests/topotests/bgp_bmp/test_bgp_bmp_2.py b/tests/topotests/bgp_bmp/test_bgp_bmp_2.py index 21e4ce8abeae..b45452e7c475 100644 --- a/tests/topotests/bgp_bmp/test_bgp_bmp_2.py +++ b/tests/topotests/bgp_bmp/test_bgp_bmp_2.py @@ -166,7 +166,7 @@ def _test_prefixes(policy, step=1): policy, step, tgen.gears["bmp1vrf"], - os.path.join(tgen.logdir, "bmp1vrf", "bmp.log"), + os.path.join(tgen.logdir, "bmp1vrf"), tgen.gears["r1vrf"], f"{CWD}/bmp1vrf", UPDATE_EXPECTED_JSON,