Skip to content

Commit

Permalink
topotests: save bgp_bmp json temp files to bmp log folder instead of …
Browse files Browse the repository at this point in the history
…/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 <[email protected]>
  • Loading branch information
pguibert6WIND committed Dec 2, 2024
1 parent f2eb14d commit d1301f1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
33 changes: 26 additions & 7 deletions tests/topotests/bgp_bmp/bgpbmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)


Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/topotests/bgp_bmp/test_bgp_bmp_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/topotests/bgp_bmp/test_bgp_bmp_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d1301f1

Please sign in to comment.