From 2905398814bed538c841c49c5ece769d40dd5d97 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Sun, 22 Aug 2021 02:24:58 -0400 Subject: [PATCH] tests: add generic exa-receive.py script Signed-off-by: Christian Hopps --- tests/topotests/lib/exa-receive.py | 39 ++++++++++++++++++++++++++++++ tests/topotests/lib/topogen.py | 1 + 2 files changed, 40 insertions(+) create mode 100755 tests/topotests/lib/exa-receive.py diff --git a/tests/topotests/lib/exa-receive.py b/tests/topotests/lib/exa-receive.py new file mode 100755 index 0000000000..9b27bddeaf --- /dev/null +++ b/tests/topotests/lib/exa-receive.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +""" +exa-receive.py: Save received routes form ExaBGP into file +""" + +import argparse +import os +from sys import stdin +from datetime import datetime + +parser = argparse.ArgumentParser() +parser.add_argument("--no-timestamp", dest="timestamp", action="store_false", help='Disable timestamps') +parser.add_argument("--logdir", default="/tmp/gearlogdir", help='The directory to store the peer log in') +parser.add_argument("peer", type=int, help='The peer number') +args = parser.parse_args() + +savepath = os.path.join(args.logdir, "peer{}-received.log".format(args.peer)) +routesavefile = open(savepath, "w") + +while True: + try: + line = stdin.readline() + if not line: + break + + if not args.timestamp: + routesavefile.write(line) + else: + timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") + routesavefile.write(timestamp + line) + routesavefile.flush() + except KeyboardInterrupt: + pass + except IOError: + # most likely a signal during readline + pass + +routesavefile.close() diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 495c286b13..6d60e3d003 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -1123,6 +1123,7 @@ class TopoExaBGP(TopoHost): self.run("mkdir -p /etc/exabgp") self.run("chmod 755 /etc/exabgp") + self.run("cp {}/exa-* /etc/exabgp/".format(CWD)) self.run("cp {}/* /etc/exabgp/".format(peer_dir)) if env_file is not None: self.run("cp {} /etc/exabgp/exabgp.env".format(env_file)) -- 2.39.5