From 49549fe2d7d62944c4e126eaba56bf275c96e8a5 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Sun, 18 Jul 2021 16:03:44 +0000 Subject: [PATCH 01/25] tests: summarize XML test results Signed-off-by: Christian Hopps --- tests/topotests/analyze.py | 249 +++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100755 tests/topotests/analyze.py diff --git a/tests/topotests/analyze.py b/tests/topotests/analyze.py new file mode 100755 index 0000000000..aea5fae00e --- /dev/null +++ b/tests/topotests/analyze.py @@ -0,0 +1,249 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# +# July 9 2021, Christian Hopps +# +# Copyright (c) 2021, LabN Consulting, L.L.C. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; see the file COPYING; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +import argparse +import glob +import json +import logging +import os +import pdb +import re +import subprocess +import sys +from collections import OrderedDict + +import xmltodict + + +def get_summary(results): + ntest = int(results["@tests"]) + nfail = int(results["@failures"]) + nerror = int(results["@errors"]) + nskip = int(results["@skipped"]) + npass = ntest - nfail - nskip - nerror + return ntest, npass, nfail, nerror, nskip + + +def print_summary(results, args): + ntest, npass, nfail, nerror, nskip = (0, 0, 0, 0, 0) + for group in results: + _ntest, _npass, _nfail, _nerror, _nskip = get_summary(results[group]) + if args.verbose: + print(f"Group: {group} Total: {_ntest} PASSED: {_npass}" + " FAIL: {_nfail} ERROR: {_nerror} SKIP: {_nskip}") + ntest += _ntest + npass += _npass + nfail += _nfail + nerror += _nerror + nskip += _nskip + print(f"Total: {ntest} PASSED: {npass} FAIL: {nfail} ERROR: {nerror} SKIP: {nskip}") + + +def get_global_testcase(results): + for group in results: + for testcase in results[group]["testcase"]: + if "@file" not in testcase: + return testcase + return None + + +def get_filtered(tfilters, results, args): + if isinstance(tfilters, str) or tfilters is None: + tfilters = [tfilters] + found_files = OrderedDict() + for group in results: + if isinstance(results[group]["testcase"], list): + tlist = results[group]["testcase"] + else: + tlist = [results[group]["testcase"]] + for testcase in tlist: + for tfilter in tfilters: + if tfilter is None: + if ( + "failure" not in testcase + and "error" not in testcase + and "skipped" not in testcase + ): + break + elif tfilter in testcase: + break + else: + continue + #cname = testcase["@classname"] + fname = testcase.get("@file", "") + cname = testcase.get("@classname", "") + if not fname and not cname: + name = testcase.get("@name", "") + if not name: + continue + # If we had a failure at the module level we could be here. + fname = name.replace(".", "/") + ".py" + tcname = fname + else: + if not fname: + fname = cname.replace(".", "/") + ".py" + if args.files_only or "@name" not in testcase: + tcname = fname + else: + tcname = fname + "::" + testcase["@name"] + found_files[tcname] = testcase + return found_files + + + +def dump_testcase(testcase): + expand_keys = ("failure", "error", "skipped") + + s = "" + for key, val in testcase.items(): + if isinstance(val, str) or isinstance(val, float) or isinstance(val, int): + s += "{}: {}\n".format(key, val) + else: + for k2, v2 in val.items(): + s += "{}: {}\n".format(k2, v2) + return s + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("-A", "--save", action="store_true", help="Save /tmp/topotests{,.xml} in --rundir if --rundir does not yet exist") + parser.add_argument("-F", "--files-only", action="store_true", help="print test file names rather than individual full testcase names") + parser.add_argument("-S", "--select", default="fe", help="select results combination of letters: 'e'rrored 'f'ailed 'p'assed 's'kipped.") + parser.add_argument("-r", "--results", help="xml results file or directory containing xml results file") + parser.add_argument("--rundir", help=argparse.SUPPRESS) + parser.add_argument( + "-E", + "--enumerate", + action="store_true", + help="enumerate each item (results scoped)", + ) + parser.add_argument( + "-T", "--test", help="print testcase at enumeration" + ) + parser.add_argument( + "--errmsg", action="store_true", help="print testcase error message" + ) + parser.add_argument( + "--errtext", action="store_true", help="print testcase error text" + ) + parser.add_argument( + "--time", action="store_true", help="print testcase run times" + ) + + parser.add_argument("-s", "--summary", action="store_true", help="print summary") + parser.add_argument("-v", "--verbose", action="store_true", help="be verbose") + args = parser.parse_args() + + if args.save and args.results and not os.path.exists(args.results): + if not os.path.exists("/tmp/topotests"): + logging.critical("No \"/tmp/topotests\" directory to save") + sys.exit(1) + subprocess.run(["mv", "/tmp/topotests", args.results]) + # # Old location for results + # if os.path.exists("/tmp/topotests.xml", args.results): + # subprocess.run(["mv", "/tmp/topotests.xml", args.results]) + + assert args.test is None or not args.files_only, "Can't have both --files and --test" + + results = {} + ttfiles = [] + if args.rundir: + basedir = os.path.realpath(args.rundir) + os.chdir(basedir) + + newfiles = glob.glob("tt-group-*/topotests.xml") + if newfiles: + ttfiles.extend(newfiles) + if os.path.exists("topotests.xml"): + ttfiles.append("topotests.xml") + else: + if args.results: + if os.path.exists(os.path.join(args.results, "topotests.xml")): + args.results = os.path.join(args.results, "topotests.xml") + if not os.path.exists(args.results): + logging.critical("%s doesn't exist", args.results) + sys.exit(1) + ttfiles = [args.results] + + if not ttfiles and os.path.exists("/tmp/topotests.xml"): + ttfiles.append("/tmp/topotests.xml") + + for f in ttfiles: + m = re.match(r"tt-group-(\d+)/topotests.xml", f) + group = int(m.group(1)) if m else 0 + with open(f) as xml_file: + results[group] = xmltodict.parse(xml_file.read())["testsuites"]["testsuite"] + + filters = [] + if "e" in args.select: + filters.append("error") + if "f" in args.select: + filters.append("failure") + if "s" in args.select: + filters.append("skipped") + if "p" in args.select: + filters.append(None) + + found_files = get_filtered(filters, results, args) + if found_files: + if args.test is not None: + if args.test == "all": + keys = found_files.keys() + else: + keys = [list(found_files.keys())[int(args.test)]] + for key in keys: + testcase = found_files[key] + if args.errtext: + if "error" in testcase: + errmsg = testcase["error"]["#text"] + elif "failure" in testcase: + errmsg = testcase["failure"]["#text"] + else: + errmsg = "none found" + s = "{}: {}".format(key, errmsg) + elif args.time: + text = testcase["@time"] + s = "{}: {}".format(text, key) + elif args.errmsg: + if "error" in testcase: + errmsg = testcase["error"]["@message"] + elif "failure" in testcase: + errmsg = testcase["failure"]["@message"] + else: + errmsg = "none found" + s = "{}: {}".format(key, errmsg) + else: + s = dump_testcase(testcase) + print(s) + elif filters: + if args.enumerate: + print( + "\n".join(["{} {}".format(i, x) for i, x in enumerate(found_files)]) + ) + else: + print("\n".join(found_files)) + + if args.summary: + print_summary(results, args) + + +if __name__ == "__main__": + main() From bc51ce681068076cdee50e6e5f232a8ba4d8dd4a Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Sun, 18 Jul 2021 18:03:53 +0000 Subject: [PATCH 02/25] tests: improve vxlan test determinism Signed-off-by: Christian Hopps --- .../bgp_evpn_vxlan_topo1/PE1/evpn.vni.json | 2 - .../bgp_evpn_vxlan_topo1/PE2/evpn.vni.json | 2 - .../test_bgp_evpn_vxlan.py | 37 ++++++++++++++++--- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/tests/topotests/bgp_evpn_vxlan_topo1/PE1/evpn.vni.json b/tests/topotests/bgp_evpn_vxlan_topo1/PE1/evpn.vni.json index e500a1d85c..ce7915c4af 100644 --- a/tests/topotests/bgp_evpn_vxlan_topo1/PE1/evpn.vni.json +++ b/tests/topotests/bgp_evpn_vxlan_topo1/PE1/evpn.vni.json @@ -6,8 +6,6 @@ "vtepIp":"10.10.10.10", "mcastGroup":"0.0.0.0", "advertiseGatewayMacip":"No", - "numMacs":6, - "numArpNd":6, "numRemoteVteps":[ "10.30.30.30" ] diff --git a/tests/topotests/bgp_evpn_vxlan_topo1/PE2/evpn.vni.json b/tests/topotests/bgp_evpn_vxlan_topo1/PE2/evpn.vni.json index 0a56a235bd..6c69202642 100644 --- a/tests/topotests/bgp_evpn_vxlan_topo1/PE2/evpn.vni.json +++ b/tests/topotests/bgp_evpn_vxlan_topo1/PE2/evpn.vni.json @@ -6,8 +6,6 @@ "vtepIp":"10.30.30.30", "mcastGroup":"0.0.0.0", "advertiseGatewayMacip":"No", - "numMacs":6, - "numArpNd":6, "numRemoteVteps":[ "10.10.10.10" ] diff --git a/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py b/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py index fd5bb38b98..763cf9c156 100755 --- a/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py +++ b/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py @@ -28,6 +28,7 @@ test_bgp_evpn_vxlan.py: Test VXLAN EVPN MAC a route signalling over BGP. import os import sys import json +import re from functools import partial from time import sleep import pytest @@ -156,6 +157,17 @@ def show_vni_json_elide_ifindex(pe, vni, expected): return topotest.json_cmp(output_json, expected) +def check_vni_macs_present(tgen, router, vni, maclist): + result = router.vtysh_cmd("show evpn mac vni {} json".format(vni), isjson=True) + for rname, ifname in maclist: + m = tgen.net.macs[(rname, ifname)] + if m not in result["macs"]: + return "MAC ({}) for interface {} on {} missing on {} from {}".format( + m, ifname, rname, router.name, json.dumps(result, indent=4) + ) + return None + + def test_pe1_converge_evpn(): "Wait for protocol convergence" @@ -169,10 +181,17 @@ def test_pe1_converge_evpn(): expected = json.loads(open(json_file).read()) test_func = partial(show_vni_json_elide_ifindex, pe1, 101, expected) - _, result = topotest.run_and_expect(test_func, None, count=125, wait=1) + _, result = topotest.run_and_expect(test_func, None, count=45, wait=1) assertmsg = '"{}" JSON output mismatches'.format(pe1.name) - assert result is None, assertmsg - # tgen.mininet_cli() + + test_func = partial(check_vni_macs_present, tgen, pe1, 101, ( + ("host1", "host1-eth0"), + ("host2", "host2-eth0") + )) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + if result: + logger.warning("%s", result) + assert None, '"{}" missing expected MACs'.format(pe1.name) def test_pe2_converge_evpn(): @@ -188,10 +207,18 @@ def test_pe2_converge_evpn(): expected = json.loads(open(json_file).read()) test_func = partial(show_vni_json_elide_ifindex, pe2, 101, expected) - _, result = topotest.run_and_expect(test_func, None, count=125, wait=1) + _, result = topotest.run_and_expect(test_func, None, count=45, wait=1) assertmsg = '"{}" JSON output mismatches'.format(pe2.name) assert result is None, assertmsg - # tgen.mininet_cli() + + test_func = partial(check_vni_macs_present, tgen, pe2, 101, ( + ("host1", "host1-eth0"), + ("host2", "host2-eth0") + )) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + if result: + logger.warning("%s", result) + assert None, '"{}" missing expected MACs'.format(pe2.name) def mac_learn_test(host, local): From 6a5433ef0be0819f8d662189d870cde9042eaff0 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Wed, 14 Jul 2021 20:51:15 +0000 Subject: [PATCH 03/25] tests: NEW micronet replacement for mininet Signed-off-by: Christian Hopps --- tests/topotests/lib/micronet.py | 949 +++++++++++++++++++++++++ tests/topotests/lib/micronet_cli.py | 312 ++++++++ tests/topotests/lib/micronet_compat.py | 379 ++++++++++ 3 files changed, 1640 insertions(+) create mode 100644 tests/topotests/lib/micronet.py create mode 100644 tests/topotests/lib/micronet_cli.py create mode 100644 tests/topotests/lib/micronet_compat.py diff --git a/tests/topotests/lib/micronet.py b/tests/topotests/lib/micronet.py new file mode 100644 index 0000000000..da6a6915d2 --- /dev/null +++ b/tests/topotests/lib/micronet.py @@ -0,0 +1,949 @@ +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# +# July 9 2021, Christian Hopps +# +# Copyright (c) 2021, LabN Consulting, L.L.C. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; see the file COPYING; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +import datetime +import logging +import os +import pdb +import re +import readline +import shlex +import subprocess +import sys +import tempfile +import time as time_mod +import traceback + +root_hostname = subprocess.check_output("hostname") + +# This allows us to cleanup any leftovers later on +os.environ["MICRONET_PID"] = str(os.getpid()) + + +class Timeout(object): + def __init__(self, delta): + self.started_on = datetime.datetime.now() + self.expires_on = self.started_on + datetime.timedelta(seconds=delta) + + def elapsed(self): + elapsed = datetime.datetime.now() - self.started_on + return elapsed.total_seconds() + + def is_expired(self): + return datetime.datetime.now() > self.expires_on + + +def is_string(value): + """Return True if value is a string.""" + try: + return isinstance(value, basestring) # type: ignore + except NameError: + return isinstance(value, str) + + +def shell_quote(command): + """Return command wrapped in single quotes.""" + if sys.version_info[0] >= 3: + return shlex.quote(command) + return "'{}'".format(command.replace("'", "'\"'\"'")) # type: ignore + + +def cmd_error(rc, o, e): + s = "rc {}".format(rc) + o = "\n\tstdout: " + o.strip() if o and o.strip() else "" + e = "\n\tstderr: " + e.strip() if e and e.strip() else "" + return s + o + e + + +def proc_error(p, o, e): + args = p.args if is_string(p.args) else " ".join(p.args) + s = "rc {} pid {}\n\targs: {}".format(p.returncode, p.pid, args) + o = "\n\tstdout: " + o.strip() if o and o.strip() else "" + e = "\n\tstderr: " + e.strip() if e and e.strip() else "" + return s + o + e + + +def comm_error(p): + rc = p.poll() + assert rc is not None + if not hasattr(p, "saved_output"): + p.saved_output = p.communicate() + return proc_error(p, *p.saved_output) + + +class Commander(object): # pylint: disable=R0205 + """ + Commander. + + An object that can execute commands. + """ + + tmux_wait_gen = 0 + + def __init__(self, name, logger=None): + """Create a Commander.""" + self.name = name + self.last = None + self.exec_paths = {} + self.pre_cmd = [] + self.pre_cmd_str = "" + + if not logger: + self.logger = logging.getLogger(__name__ + ".commander." + name) + else: + self.logger = logger + + self.cwd = self.cmd_raises("pwd").strip() + + def set_logger(self, logfile): + self.logger = logging.getLogger(__name__ + ".commander." + self.name) + if is_string(logfile): + handler = logging.FileHandler(logfile, mode="w") + else: + handler = logging.StreamHandler(logfile) + + fmtstr = "%(asctime)s.%(msecs)03d %(levelname)s: {}({}): %(message)s".format( + self.__class__.__name__, self.name + ) + handler.setFormatter(logging.Formatter(fmt=fmtstr)) + self.logger.addHandler(handler) + + def set_pre_cmd(self, pre_cmd=None): + if not pre_cmd: + self.pre_cmd = [] + self.pre_cmd_str = "" + else: + self.pre_cmd = pre_cmd + self.pre_cmd_str = " ".join(self.pre_cmd) + " " + + def __str__(self): + return "Commander({})".format(self.name) + + def get_exec_path(self, binary): + """Return the full path to the binary executable. + + `binary` :: binary name or list of binary names + """ + if is_string(binary): + bins = [binary] + else: + bins = binary + for b in bins: + if b in self.exec_paths: + return self.exec_paths[b] + + rc, output, _ = self.cmd_status("which " + b, warn=False) + if not rc: + return os.path.abspath(output.strip()) + return None + + def get_tmp_dir(self, uniq): + return os.path.join(tempfile.mkdtemp(), uniq) + + def test(self, flags, arg): + """Run test binary, with flags and arg""" + test_path = self.get_exec_path(["test"]) + rc, output, _ = self.cmd_status([test_path, flags, arg], warn=False) + return not rc + + def path_exists(self, path): + """Check if path exists.""" + return self.test("-e", path) + + def _get_cmd_str(self, cmd): + if is_string(cmd): + return self.pre_cmd_str + cmd + cmd = self.pre_cmd + cmd + return " ".join(cmd) + + def _get_sub_args(self, cmd, defaults, **kwargs): + if is_string(cmd): + defaults["shell"] = True + pre_cmd = self.pre_cmd_str + else: + defaults["shell"] = False + pre_cmd = self.pre_cmd + cmd = [str(x) for x in cmd] + defaults.update(kwargs) + return pre_cmd, cmd, defaults + + def _popen(self, method, cmd, skip_pre_cmd=False, **kwargs): + if sys.version_info[0] >= 3: + defaults = { + "encoding": "utf-8", + "stdout": subprocess.PIPE, + "stderr": subprocess.PIPE, + } + else: + defaults = { + "stdout": subprocess.PIPE, + "stderr": subprocess.PIPE, + } + pre_cmd, cmd, defaults = self._get_sub_args(cmd, defaults, **kwargs) + + self.logger.debug('%s: %s("%s", kwargs: %s)', self, method, cmd, defaults) + + actual_cmd = cmd if skip_pre_cmd else pre_cmd + cmd + p = subprocess.Popen(actual_cmd, **defaults) + if not hasattr(p, "args"): + p.args = actual_cmd + return p, actual_cmd + + def set_cwd(self, cwd): + self.logger.warning("%s: 'cd' (%s) does not work outside namespaces", self, cwd) + self.cwd = cwd + + def popen(self, cmd, **kwargs): + """ + Creates a pipe with the given `command`. + + Args: + command: `str` or `list` of command to open a pipe with. + **kwargs: kwargs is eventually passed on to Popen. If `command` is a string + then will be invoked with shell=True, otherwise `command` is a list and + will be invoked with shell=False. + + Returns: + a subprocess.Popen object. + """ + p, _ = self._popen("popen", cmd, **kwargs) + return p + + def cmd_status(self, cmd, raises=False, warn=True, stdin=None, **kwargs): + """Execute a command.""" + + # We are not a shell like mininet, so we need to intercept this + chdir = False + if not is_string(cmd): + cmds = cmd + else: + # XXX we can drop this when the code stops assuming it works + m = re.match(r"cd(\s*|\s+(\S+))$", cmd) + if m and m.group(2): + self.logger.warning( + "Bad call to 'cd' (chdir) emulating, use self.set_cwd():\n%s", + "".join(traceback.format_stack(limit=12)), + ) + assert is_string(cmd) + chdir = True + cmd += " && pwd" + + # If we are going to run under bash then we don't need shell=True! + cmds = ["/bin/bash", "-c", cmd] + + pinput = None + + if is_string(stdin) or isinstance(stdin, bytes): + pinput = stdin + stdin = subprocess.PIPE + + p, actual_cmd = self._popen("cmd_status", cmds, stdin=stdin, **kwargs) + stdout, stderr = p.communicate(input=pinput) + rc = p.wait() + + # For debugging purposes. + self.last = (rc, actual_cmd, cmd, stdout, stderr) + + if rc: + if warn: + self.logger.warning( + "%s: proc failed: %s:", self, proc_error(p, stdout, stderr) + ) + if raises: + # error = Exception("stderr: {}".format(stderr)) + # This annoyingly doesnt' show stderr when printed normally + error = subprocess.CalledProcessError(rc, actual_cmd) + error.stdout, error.stderr = stdout, stderr + raise error + elif chdir: + self.set_cwd(stdout.strip()) + + return rc, stdout, stderr + + def cmd_legacy(self, cmd, **kwargs): + """Execute a command with stdout and stderr joined, *IGNORES ERROR*.""" + + defaults = {"stderr": subprocess.STDOUT} + defaults.update(kwargs) + _, stdout, _ = self.cmd_status(cmd, raises=False, **defaults) + return stdout + + def cmd_raises(self, cmd, **kwargs): + """Execute a command. Raise an exception on errors""" + + rc, stdout, _ = self.cmd_status(cmd, raises=True, **kwargs) + assert rc == 0 + return stdout + + # Run a command in a new window (gnome-terminal, screen, tmux, xterm) + def run_in_window( + self, + cmd, + wait_for=False, + background=False, + name=None, + title=None, + forcex=False, + new_window=False, + tmux_target=None, + ): + """ + Run a command in a new window (TMUX, Screen or XTerm). + + Args: + wait_for: True to wait for exit from command or `str` as channel neme to signal on exit, otherwise False + background: Do not change focus to new window. + title: Title for new pane (tmux) or window (xterm). + name: Name of the new window (tmux) + forcex: Force use of X11. + new_window: Open new window (instead of pane) in TMUX + tmux_target: Target for tmux pane. + + Returns: + the pane/window identifier from TMUX (depends on `new_window`) + """ + + channel = None + if is_string(wait_for): + channel = wait_for + elif wait_for is True: + channel = "{}-wait-{}".format(os.getpid(), Commander.tmux_wait_gen) + Commander.tmux_wait_gen += 1 + + sudo_path = self.get_exec_path(["sudo"]) + nscmd = sudo_path + " " + self.pre_cmd_str + cmd + if "TMUX" in os.environ and not forcex: + cmd = [self.get_exec_path("tmux")] + if new_window: + cmd.append("new-window") + cmd.append("-P") + if name: + cmd.append("-n") + cmd.append(name) + if tmux_target: + cmd.append("-t") + cmd.append(tmux_target) + else: + cmd.append("split-window") + cmd.append("-P") + cmd.append("-h") + if not tmux_target: + tmux_target = os.getenv("TMUX_PANE", "") + if background: + cmd.append("-d") + if tmux_target: + cmd.append("-t") + cmd.append(tmux_target) + if title: + nscmd = "printf '\033]2;{}\033\\'; {}".format(title, nscmd) + if channel: + nscmd = 'trap "tmux wait -S {}; exit 0" EXIT; {}'.format(channel, nscmd) + cmd.append(nscmd) + elif "STY" in os.environ and not forcex: + # wait for not supported in screen for now + channel = None + cmd = [self.get_exec_path("screen")] + if not os.path.exists( + "/run/screen/S-{}/{}".format(os.environ["USER"], os.environ["STY"]) + ): + cmd = ["sudo", "-u", os.environ["SUDO_USER"]] + cmd + cmd.append(nscmd) + elif "DISPLAY" in os.environ: + # We need it broken up for xterm + user_cmd = cmd + cmd = [self.get_exec_path("xterm")] + if "SUDO_USER" in os.environ: + cmd = [self.get_exec_path("sudo"), "-u", os.environ["SUDO_USER"]] + cmd + # if title: + # cmd.append("-T") + # cmd.append(title) + cmd.append("-e") + cmd.append(sudo_path) + cmd.extend(self.pre_cmd) + cmd.append(user_cmd) + # if channel: + # return self.cmd_raises(cmd, skip_pre_cmd=True) + # else: + p = self.popen( + cmd, + skip_pre_cmd=True, + stdin=None, + shell=False, + # stdout=open("/dev/null", "w"), + # stderr=open("/dev/null", "w"), + ) + time_mod.sleep(2) + if p.poll() is not None: + self.logger.error("%s: Failed to launch xterm: %s", self, comm_error(p)) + return "" + else: + self.logger.error( + "DISPLAY, STY, and TMUX not in environment, can't open window" + ) + raise Exception("Window requestd but TMUX, Screen and X11 not available") + + pane_info = self.cmd_raises(cmd, skip_pre_cmd=True).strip() + + # Re-adjust the layout + if "TMUX" in os.environ: + self.cmd_status( + "tmux select-layout -t {} tiled".format( + pane_info if not tmux_target else tmux_target + ), + skip_pre_cmd=True, + ) + + # Wait here if we weren't handed the channel to wait for + if channel and wait_for is True: + cmd = [self.get_exec_path("tmux"), "wait", channel] + self.cmd_status(cmd, skip_pre_cmd=True) + + return pane_info + + def delete(self): + pass + + +class LinuxNamespace(Commander): + """ + A linux Namespace. + + An object that creates and executes commands in a linux namespace + """ + + def __init__( + self, + name, + net=True, + mount=True, + uts=True, + cgroup=False, + ipc=False, + pid=False, + time=False, + user=False, + set_hostname=True, + private_mounts=None, + logger=None, + ): + """ + Create a new linux namespace. + + Args: + name: Internal name for the namespace. + net: Create network namespace. + mount: Create network namespace. + uts: Create UTS (hostname) namespace. + cgroup: Create cgroup namespace. + ipc: Create IPC namespace. + pid: Create PID namespace, also mounts new /proc. + time: Create time namespace. + user: Create user namespace, also keeps capabilities. + set_hostname: Set the hostname to `name`, uts must also be True. + private_mounts: List of strings of the form + "[/external/path:]/internal/path. If no external path is specified a + tmpfs is mounted on the internal path. Any paths specified are first + passed to `mkdir -p`. + logger: Passed to superclass. + """ + super(LinuxNamespace, self).__init__(name, logger) + + self.logger.debug("%s: Creating", self) + + self.intfs = [] + + nslist = [] + cmd = ["/usr/bin/unshare"] + flags = "-" + self.ifnetns = {} + + if cgroup: + nslist.append("cgroup") + flags += "C" + if ipc: + nslist.append("ipc") + flags += "i" + if mount: + nslist.append("mnt") + flags += "m" + if net: + nslist.append("net") + flags += "n" + if pid: + nslist.append("pid") + flags += "p" + cmd.append("--mount-proc") + if time: + # XXX this filename is probably wrong + nslist.append("time") + flags += "T" + if user: + nslist.append("user") + flags += "U" + cmd.append("--keep-caps") + if uts: + nslist.append("uts") + cmd.append("--uts") + + cmd.append(flags) + cmd.append("/bin/cat") + + # Using cat and a stdin PIPE is nice as it will exit when we do. However, we + # also detach it from the pgid so that signals do not propagate to it. This is + # b/c it would exit early (e.g., ^C) then, at least the main micronet proc which + # has no other processes like frr daemons running, will take the main network + # namespace with it, which will remove the bridges and the veth pair (because + # the bridge side veth is deleted). + self.logger.debug("%s: creating namespace process: %s", self, cmd) + p = subprocess.Popen( + cmd, + stdin=subprocess.PIPE, + stdout=open("/dev/null", "w"), + stderr=open("/dev/null", "w"), + preexec_fn=os.setsid, # detach from pgid so signals don't propogate + shell=False, + ) + self.p = p + self.pid = p.pid + + self.logger.debug("%s: namespace pid: %d", self, self.pid) + + # ----------------------------------------------- + # Now let's wait until unshare completes it's job + # ----------------------------------------------- + timeout = Timeout(30) + while p.poll() is None and not timeout.is_expired(): + for fname in tuple(nslist): + ours = os.readlink("/proc/self/ns/{}".format(fname)) + theirs = os.readlink("/proc/{}/ns/{}".format(self.pid, fname)) + # See if their namespace is different + if ours != theirs: + nslist.remove(fname) + if not nslist: + break + elapsed = int(timeout.elapsed()) + if elapsed <= 3: + time_mod.sleep(0.1) + elif elapsed > 10: + self.logger.warning("%s: unshare taking more than %ss", self, elapsed) + time_mod.sleep(3) + else: + self.logger.info("%s: unshare taking more than %ss", self, elapsed) + time_mod.sleep(1) + assert p.poll() is None, "unshare unexpectedly exited!" + assert not nslist, "unshare never unshared!" + + # Set pre-command based on our namespace proc + self.base_pre_cmd = ["/usr/bin/nsenter", "-a", "-t", str(self.pid)] + if not pid: + self.base_pre_cmd.append("-F") + self.set_pre_cmd(self.base_pre_cmd + ["--wd=" + self.cwd]) + + # Remount /sys to pickup any changes + self.cmd_raises("mount -t sysfs sysfs /sys") + + # Set the hostname to the namespace name + if uts and set_hostname: + # Debugging get the root hostname + self.cmd_raises("hostname " + self.name) + nroot = subprocess.check_output("hostname") + if root_hostname != nroot: + result = self.p.poll() + assert root_hostname == nroot, "STATE of namespace process {}".format( + result + ) + + if private_mounts: + if is_string(private_mounts): + private_mounts = [private_mounts] + for m in private_mounts: + s = m.split(":", 1) + if len(s) == 1: + self.tmpfs_mount(s[0]) + else: + self.bind_mount(s[0], s[1]) + + o = self.cmd_legacy("ls -l /proc/{}/ns".format(self.pid)) + self.logger.debug("namespaces:\n %s", o) + + # Doing this here messes up all_protocols ipv6 check + self.cmd_raises("ip link set lo up") + + def __str__(self): + return "LinuxNamespace({})".format(self.name) + + def tmpfs_mount(self, inner): + self.cmd_raises("mkdir -p " + inner) + self.cmd_raises("mount -n -t tmpfs tmpfs " + inner) + + def bind_mount(self, outer, inner): + self.cmd_raises("mkdir -p " + inner) + self.cmd_raises("mount --rbind {} {} ".format(outer, inner)) + + def add_netns(self, ns): + self.logger.debug("Adding network namespace %s", ns) + + ip_path = self.get_exec_path("ip") + assert ip_path, "XXX missing ip command!" + if os.path.exists("/run/netns/{}".format(ns)): + self.logger.warning("%s: Removing existing nsspace %s", self, ns) + try: + self.delete_netns(ns) + except Exception as ex: + self.logger.warning( + "%s: Couldn't remove existing nsspace %s: %s", + self, + ns, + str(ex), + exc_info=True, + ) + self.cmd_raises([ip_path, "netns", "add", ns]) + + def delete_netns(self, ns): + self.logger.debug("Deleting network namespace %s", ns) + + ip_path = self.get_exec_path("ip") + assert ip_path, "XXX missing ip command!" + self.cmd_raises([ip_path, "netns", "delete", ns]) + + def set_intf_netns(self, intf, ns, up=False): + # In case a user hard-codes 1 thinking it "resets" + ns = str(ns) + if ns == "1": + ns = str(self.pid) + + self.logger.debug("Moving interface %s to namespace %s", intf, ns) + + cmd = "ip link set {} netns " + ns + if up: + cmd += " up" + self.intf_ip_cmd(intf, cmd) + if ns == str(self.pid): + # If we are returning then remove from dict + if intf in self.ifnetns: + del self.ifnetns[intf] + else: + self.ifnetns[intf] = ns + + def reset_intf_netns(self, intf): + self.logger.debug("Moving interface %s to default namespace", intf) + self.set_intf_netns(intf, str(self.pid)) + + def intf_ip_cmd(self, intf, cmd): + """Run an ip command for considering an interfaces possible namespace. + + `cmd` - format is run using the interface name on the command + """ + if intf in self.ifnetns: + assert cmd.startswith("ip ") + cmd = "ip -n " + self.ifnetns[intf] + cmd[2:] + self.cmd_raises(cmd.format(intf)) + + def set_cwd(self, cwd): + # Set pre-command based on our namespace proc + self.logger.debug("%s: new CWD %s", self, cwd) + self.set_pre_cmd(self.base_pre_cmd + ["--wd=" + cwd]) + + def register_interface(self, ifname): + if ifname not in self.intfs: + self.intfs.append(ifname) + + def delete(self): + if self.p and self.p.poll() is None: + if sys.version_info[0] >= 3: + try: + self.p.terminate() + self.p.communicate(timeout=10) + except subprocess.TimeoutExpired: + self.p.kill() + self.p.communicate(timeout=2) + else: + self.p.kill() + self.p.communicate() + self.set_pre_cmd(["/bin/false"]) + + +class SharedNamespace(Commander): + """ + Share another namespace. + + An object that executes commands in an existing pid's linux namespace + """ + + def __init__(self, name, pid, logger=None): + """ + Share a linux namespace. + + Args: + name: Internal name for the namespace. + pid: PID of the process to share with. + """ + super(SharedNamespace, self).__init__(name, logger) + + self.logger.debug("%s: Creating", self) + + self.pid = pid + self.intfs = [] + + # Set pre-command based on our namespace proc + self.set_pre_cmd( + ["/usr/bin/nsenter", "-a", "-t", str(self.pid), "--wd=" + self.cwd] + ) + + def __str__(self): + return "SharedNamespace({})".format(self.name) + + def set_cwd(self, cwd): + # Set pre-command based on our namespace proc + self.logger.debug("%s: new CWD %s", self, cwd) + self.set_pre_cmd(["/usr/bin/nsenter", "-a", "-t", str(self.pid), "--wd=" + cwd]) + + def register_interface(self, ifname): + if ifname not in self.intfs: + self.intfs.append(ifname) + + +class Bridge(SharedNamespace): + """ + A linux bridge. + """ + + next_brid_ord = 0 + + @classmethod + def _get_next_brid(cls): + brid_ord = cls.next_brid_ord + cls.next_brid_ord += 1 + return brid_ord + + def __init__(self, name=None, unet=None, logger=None): + """Create a linux Bridge.""" + + self.unet = unet + self.brid_ord = self._get_next_brid() + if name: + self.brid = name + else: + self.brid = "br{}".format(self.brid_ord) + name = self.brid + + super(Bridge, self).__init__(name, unet.pid, logger) + + self.logger.debug("Bridge: Creating") + + assert len(self.brid) <= 16 # Make sure fits in IFNAMSIZE + self.cmd_raises("ip link delete {} || true".format(self.brid)) + self.cmd_raises("ip link add {} type bridge".format(self.brid)) + self.cmd_raises("ip link set {} up".format(self.brid)) + + self.logger.debug("%s: Created, Running", self) + + def __str__(self): + return "Bridge({})".format(self.brid) + + def delete(self): + """Stop the bridge (i.e., delete the linux resources).""" + + rc, o, e = self.cmd_status("ip link show {}".format(self.brid), warn=False) + if not rc: + rc, o, e = self.cmd_status( + "ip link delete {}".format(self.brid), warn=False + ) + if rc: + self.logger.error( + "%s: error deleting bridge %s: %s", + self, + self.brid, + cmd_error(rc, o, e), + ) + else: + self.logger.debug("%s: Deleted.", self) + + +class Micronet(LinuxNamespace): # pylint: disable=R0205 + """ + Micronet. + """ + + def __init__(self): + """Create a Micronet.""" + + self.hosts = {} + self.switches = {} + self.links = {} + self.macs = {} + self.rmacs = {} + + super(Micronet, self).__init__("micronet", mount=True, net=True, uts=True) + + self.logger.debug("%s: Creating", self) + + def __str__(self): + return "Micronet()" + + def __getitem__(self, key): + if key in self.switches: + return self.switches[key] + return self.hosts[key] + + def add_host(self, name, cls=LinuxNamespace, **kwargs): + """Add a host to micronet.""" + + self.logger.debug("%s: add_host %s", self, name) + + self.hosts[name] = cls(name, **kwargs) + # Create a new mounted FS for tracking nested network namespaces creatd by the + # user with `ip netns add` + self.hosts[name].tmpfs_mount("/run/netns") + + def add_link(self, name1, name2, if1, if2): + """Add a link between switch and host to micronet.""" + isp2p = False + if name1 in self.switches: + assert name2 in self.hosts + elif name2 in self.switches: + assert name1 in self.hosts + name1, name2 = name2, name1 + if1, if2 = if2, if1 + else: + # p2p link + assert name1 in self.hosts + assert name2 in self.hosts + isp2p = True + + lname = "{}:{}-{}:{}".format(name1, if1, name2, if2) + self.logger.debug("%s: add_link %s%s", self, lname, " p2p" if isp2p else "") + self.links[lname] = (name1, if1, name2, if2) + + # And create the veth now. + if isp2p: + lhost, rhost = self.hosts[name1], self.hosts[name2] + lifname = "i1{:x}".format(lhost.pid) + rifname = "i2{:x}".format(rhost.pid) + self.cmd_raises( + "ip link add {} type veth peer name {}".format(lifname, rifname) + ) + + self.cmd_raises("ip link set {} netns {}".format(lifname, lhost.pid)) + lhost.cmd_raises("ip link set {} name {}".format(lifname, if1)) + lhost.cmd_raises("ip link set {} up".format(if1)) + lhost.register_interface(if1) + + self.cmd_raises("ip link set {} netns {}".format(rifname, rhost.pid)) + rhost.cmd_raises("ip link set {} name {}".format(rifname, if2)) + rhost.cmd_raises("ip link set {} up".format(if2)) + rhost.register_interface(if2) + else: + switch = self.switches[name1] + host = self.hosts[name2] + + assert len(if1) <= 16 and len(if2) <= 16 # Make sure fits in IFNAMSIZE + + self.logger.debug("%s: Creating veth pair for link %s", self, lname) + self.cmd_raises( + "ip link add {} type veth peer name {} netns {}".format( + if1, if2, host.pid + ) + ) + self.cmd_raises("ip link set {} netns {}".format(if1, switch.pid)) + switch.register_interface(if1) + host.register_interface(if2) + self.cmd_raises("ip link set {} master {}".format(if1, switch.brid)) + self.cmd_raises("ip link set {} up".format(if1)) + host.cmd_raises("ip link set {} up".format(if2)) + + # Cache the MAC values, and reverse mapping + self.get_mac(name1, if1) + self.get_mac(name2, if2) + + def add_switch(self, name): + """Add a switch to micronet.""" + + self.logger.debug("%s: add_switch %s", self, name) + self.switches[name] = Bridge(name, self) + + def get_mac(self, name, ifname): + if name in self.hosts: + dev = self.hosts[name] + else: + dev = self.switches[name] + + if (name, ifname) not in self.macs: + _, output, _ = dev.cmd_status("ip -o link show " + ifname) + m = re.match(".*link/(loopback|ether) ([0-9a-fA-F:]+) .*", output) + mac = m.group(2) + self.macs[(name, ifname)] = mac + self.rmacs[mac] = (name, ifname) + + return self.macs[(name, ifname)] + + def delete(self): + """Delete the micronet topology.""" + + self.logger.debug("%s: Deleting.", self) + + for lname, (_, _, rname, rif) in self.links.items(): + host = self.hosts[rname] + + self.logger.debug("%s: Deleting veth pair for link %s", self, lname) + + rc, o, e = host.cmd_status("ip link delete {}".format(rif), warn=False) + if rc: + self.logger.error( + "Error deleting veth pair %s: %s", lname, cmd_error(rc, o, e) + ) + + self.links = {} + + for host in self.hosts.values(): + try: + host.delete() + except Exception as error: + self.logger.error( + "%s: error while deleting host %s: %s", self, host, error + ) + + self.hosts = {} + + for switch in self.switches.values(): + try: + switch.delete() + except Exception as error: + self.logger.error( + "%s: error while deleting switch %s: %s", self, switch, error + ) + self.switches = {} + + self.logger.debug("%s: Deleted.", self) + + super(Micronet, self).delete() + + +# --------------------------- +# Root level utility function +# --------------------------- + + +def get_exec_path(binary): + base = Commander("base") + return base.get_exec_path(binary) + + +commander = Commander("micronet") diff --git a/tests/topotests/lib/micronet_cli.py b/tests/topotests/lib/micronet_cli.py new file mode 100644 index 0000000000..ac45cbd3d2 --- /dev/null +++ b/tests/topotests/lib/micronet_cli.py @@ -0,0 +1,312 @@ +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# +# July 24 2021, Christian Hopps +# +# Copyright (c) 2021, LabN Consulting, L.L.C. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; see the file COPYING; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +import argparse +import datetime +import logging +import os +import pdb +import pty +import re +import readline +import select +import shlex +import socket +import subprocess +import sys +import tempfile +import termios +import time as time_mod +import traceback +import tty + + +ENDMARKER = b"\x00END\x00" + + +def lineiter(sock): + s = "" + while True: + sb = sock.recv(256) + if not sb: + return + + s += sb.decode("utf-8") + i = s.find("\n") + if i != -1: + yield s[:i] + s = s[i + 1 :] + + +def spawn(unet, host, cmd): + if sys.stdin.isatty(): + old_tty = termios.tcgetattr(sys.stdin) + tty.setraw(sys.stdin.fileno()) + try: + master_fd, slave_fd = pty.openpty() + + # use os.setsid() make it run in a new process group, or bash job + # control will not be enabled + p = unet.hosts[host].popen( + cmd, + preexec_fn=os.setsid, + stdin=slave_fd, + stdout=slave_fd, + stderr=slave_fd, + universal_newlines=True, + ) + + while p.poll() is None: + r, w, e = select.select([sys.stdin, master_fd], [], [], 0.25) + if sys.stdin in r: + d = os.read(sys.stdin.fileno(), 10240) + os.write(master_fd, d) + elif master_fd in r: + o = os.read(master_fd, 10240) + if o: + os.write(sys.stdout.fileno(), o) + finally: + # restore tty settings back + if sys.stdin.isatty(): + termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_tty) + + +def doline(unet, line, writef): + def host_cmd_split(unet, cmd): + csplit = cmd.split() + for i, e in enumerate(csplit): + if e not in unet.hosts: + break + hosts = csplit[:i] + if not hosts: + hosts = sorted(unet.hosts.keys()) + cmd = " ".join(csplit[i:]) + return hosts, cmd + + line = line.strip() + m = re.match(r"^(\S+)(?:\s+(.*))?$", line) + if not m: + return True + + cmd = m.group(1) + oargs = m.group(2) if m.group(2) else "" + if cmd == "q" or cmd == "quit": + return False + if cmd == "hosts": + writef("%% hosts: %s\n" % " ".join(sorted(unet.hosts.keys()))) + elif cmd in ["term", "vtysh", "xterm"]: + args = oargs.split() + if not args or (len(args) == 1 and args[0] == "*"): + args = sorted(unet.hosts.keys()) + hosts = [unet.hosts[x] for x in args] + for host in hosts: + if cmd == "t" or cmd == "term": + host.run_in_window("bash") + elif cmd == "v" or cmd == "vtysh": + host.run_in_window("vtysh") + elif cmd == "x" or cmd == "xterm": + host.run_in_window("bash", forcex=True) + elif cmd == "sh": + hosts, cmd = host_cmd_split(unet, oargs) + for host in hosts: + if sys.stdin.isatty(): + spawn(unet, host, cmd) + else: + if len(hosts) > 1: + writef("------ Host: %s ------\n" % host) + output = unet.hosts[host].cmd_legacy(cmd) + writef(output) + if len(hosts) > 1: + writef("------- End: %s ------\n" % host) + writef("\n") + elif cmd == "h" or cmd == "help": + writef( + """ +Commands: + help :: this help + sh [hosts] :: execute on + term [hosts] :: open shell terminals for hosts + vtysh [hosts] :: open vtysh terminals for hosts + [hosts] :: execute vtysh-command on hosts\n\n""" + ) + else: + hosts, cmd = host_cmd_split(unet, line) + for host in hosts: + if len(hosts) > 1: + writef("------ Host: %s ------\n" % host) + output = unet.hosts[host].cmd_legacy('vtysh -c "{}"'.format(cmd)) + writef(output) + if len(hosts) > 1: + writef("------- End: %s ------\n" % host) + writef("\n") + return True + + +def cli_server_setup(unet): + sockdir = tempfile.mkdtemp("-sockdir", "pyt") + sockpath = os.path.join(sockdir, "cli-server.sock") + try: + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.settimeout(10) + sock.bind(sockpath) + sock.listen(1) + return sock, sockdir, sockpath + except Exception: + unet.cmd_status("rm -rf " + sockdir) + raise + + +def cli_server(unet, server_sock): + sock, addr = server_sock.accept() + + # Go into full non-blocking mode now + sock.settimeout(None) + + for line in lineiter(sock): + line = line.strip() + def writef(x): + xb = x.encode("utf-8") + sock.send(xb) + if not doline(unet, line, writef): + return + sock.send(ENDMARKER) + + +def cli_client(sockpath, prompt="unet> "): + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.settimeout(10) + sock.connect(sockpath) + + # Go into full non-blocking mode now + sock.settimeout(None) + + print("\n--- Micronet CLI Starting ---\n\n") + while True: + if sys.version_info[0] == 2: + line = raw_input(prompt) # pylint: disable=E0602 + else: + line = input(prompt) + if line is None: + return + + # Need to put \n back + line += "\n" + + # Send the CLI command + sock.send(line.encode("utf-8")) + + def bendswith(b, sentinel): + slen = len(sentinel) + return len(b) >= slen and b[-slen:] == sentinel + + # Collect the output + rb = b"" + while not bendswith(rb, ENDMARKER): + lb = sock.recv(4096) + if not lb: + return + rb += lb + + # Remove the marker + rb = rb[:-len(ENDMARKER)] + + # Write the output + sys.stdout.write(rb.decode("utf-8")) + + +def local_cli(unet, outf, prompt="unet> "): + print("\n--- Micronet CLI Starting ---\n\n") + while True: + if sys.version_info[0] == 2: + line = raw_input(prompt) # pylint: disable=E0602 + else: + line = input(prompt) + if line is None: + return + if not doline(unet, line, outf.write): + return + + +def cli(unet, histfile=None, sockpath=None, force_window=False, title=None, prompt=None, background=True): + if prompt is None: + prompt = "unet> " + + if force_window or not sys.stdin.isatty(): + # Run CLI in another window b/c we have no tty. + sock, sockdir, sockpath = cli_server_setup(unet) + + python_path = unet.get_exec_path(["python3", "python"]) + us = os.path.realpath(__file__) + cmd = "{} {}".format(python_path, us) + if histfile: + cmd += " --histfile=" + histfile + if title: + cmd += " --prompt={}".format(title) + cmd += " " + sockpath + + try: + unet.run_in_window(cmd, new_window=True, title=title, background=background) + return cli_server(unet, sock) + finally: + unet.cmd_status("rm -rf " + sockdir) + + if not unet: + logger.debug("client-cli using sockpath %s", sockpath) + + try: + if histfile is None: + histfile = os.path.expanduser("~/.micronet-history.txt") + if not os.path.exists(histfile): + if unet: + unet.cmd("touch " + histfile) + else: + subprocess.run("touch " + histfile) + if histfile: + readline.read_history_file(histfile) + except Exception: + pass + + try: + if sockpath: + cli_client(sockpath, prompt=prompt) + else: + local_cli(unet, sys.stdout, prompt=prompt) + except EOFError: + pass + except Exception as ex: + logger.critical("cli: got exception: %s", ex, exc_info=True) + raise + finally: + readline.write_history_file(histfile) + + +if __name__ == "__main__": + logging.basicConfig(level=logging.DEBUG, filename="/tmp/topotests/cli-client.log") + logger = logging.getLogger("cli-client") + logger.info("Start logging cli-client") + + parser = argparse.ArgumentParser() + parser.add_argument("--histfile", help="file to user for history") + parser.add_argument("--prompt-text", help="prompt string to use") + parser.add_argument("socket", help="path to pair of sockets to communicate over") + args = parser.parse_args() + + prompt = "{}> ".format(args.prompt_text) if args.prompt_text else "unet> " + cli(None, args.histfile, args.socket, prompt=prompt) diff --git a/tests/topotests/lib/micronet_compat.py b/tests/topotests/lib/micronet_compat.py new file mode 100644 index 0000000000..fcf3610a38 --- /dev/null +++ b/tests/topotests/lib/micronet_compat.py @@ -0,0 +1,379 @@ +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# +# July 11 2021, Christian Hopps +# +# Copyright (c) 2021, LabN Consulting, L.L.C +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; see the file COPYING; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +import logging +import os +import subprocess +import traceback + +import glob +import logging +import os +import signal +import time + +from lib.micronet import LinuxNamespace, Micronet +from lib.micronet_cli import cli + + +def get_pids_with_env(has_var, has_val=None): + result = {} + for pidenv in glob.iglob("/proc/*/environ"): + pid = pidenv.split("/")[2] + with open(pidenv, "rb") as rfb: + envlist = [x.decode("utf-8").split("=", 1) for x in rfb.read().split(b"\0")] + envlist = [[x[0], ""] if len(x) == 1 else x for x in envlist] + envdict = dict(envlist) + if has_var not in envdict: + continue + if has_val is None: + result[pid] = envdict + elif envdict[has_var] == str(has_val): + result[pid] = envdict + return result + + +def _kill_piddict(pids_by_upid, sig): + for upid, pids in pids_by_upid: + logging.info( + "Sending %s to (%s) of micronet pid %s", sig, ", ".join(pids), upid + ) + for pid in pids: + try: + os.kill(int(pid), sig) + except Exception: + pass + + +def _get_our_pids(): + ourpid = str(os.getpid()) + piddict = get_pids_with_env("MICRONET_PID", ourpid) + pids = [x for x in piddict if x != ourpid] + if pids: + return {ourpid: pids} + return {} + + +def _get_other_pids(): + piddict = get_pids_with_env("MICRONET_PID") + unet_pids = {d["MICRONET_PID"] for d in piddict.values()} + pids_by_upid = {p: set() for p in unet_pids} + for pid, envdict in piddict.items(): + pids_by_upid[envdict["MICRONET_PID"]].add(pid) + # Filter out any child pid sets whos micronet pid is still running + return {x: y for x, y in pids_by_upid.items() if x not in y} + + +def _get_pids_by_upid(ours): + if ours: + return _get_our_pids() + return _get_other_pids() + + +def _cleanup_pids(ours): + pids_by_upid = _get_pids_by_upid(ours).items() + if not pids_by_upid: + return + + _kill_piddict(pids_by_upid, signal.SIGTERM) + + # Give them 5 second to exit cleanly + logging.info("Waiting up to 5s to allow for clean exit of abandon'd pids") + for _ in range(0, 5): + pids_by_upid = _get_pids_by_upid(ours).items() + if not pids_by_upid: + return + time.sleep(1) + + pids_by_upid = _get_pids_by_upid(ours).items() + _kill_piddict(pids_by_upid, signal.SIGKILL) + + +def cleanup_current(): + """Attempt to cleanup preview runs. + + Currently this only scans for old processes. + """ + logging.info("reaping current micronet processes") + _cleanup_pids(True) + + +def cleanup_previous(): + """Attempt to cleanup preview runs. + + Currently this only scans for old processes. + """ + logging.info("reaping past micronet processes") + _cleanup_pids(False) + + +class Node(LinuxNamespace): + """Node (mininet compat).""" + + def __init__(self, name, **kwargs): + """ + Create a Node. + """ + self.params = kwargs + + if "private_mounts" in kwargs: + private_mounts = kwargs["private_mounts"] + else: + private_mounts = kwargs.get("privateDirs", []) + + logger = kwargs.get("logger") + + super(Node, self).__init__(name, logger=logger, private_mounts=private_mounts) + + def cmd(self, cmd, **kwargs): + """Execute a command, joins stdout, stderr, ignores exit status.""" + + return super(Node, self).cmd_legacy(cmd, **kwargs) + + def config(self, lo="up", **params): + """Called by Micronet when topology is built (but not started).""" + # mininet brings up loopback here. + del params + del lo + + def intfNames(self): + return self.intfs + + def terminate(self): + return + + +class Topo(object): # pylint: disable=R0205 + """ + Topology object passed to Micronet to build actual topology. + """ + + def __init__(self, *args, **kwargs): + self.params = kwargs + self.name = kwargs["name"] if "name" in kwargs else "unnamed" + self.tgen = kwargs["tgen"] if "tgen" in kwargs else None + + self.logger = logging.getLogger(__name__ + ".topo") + + self.logger.debug("%s: Creating", self) + + self.nodes = {} + self.hosts = {} + self.switches = {} + self.links = {} + + # if "no_init_build" in kwargs and kwargs["no_init_build"]: + # return + + # This needs to move outside of here. Current tests count on it being called on init; + # however, b/c of this there is lots of twisty logic to support topogen based tests where + # the build routine must get get_topogen() so topogen can then set it's topogen.topo to the + # class it's in the process of instantiating (this one) b/c build will use topogen before + # the instantiation completes. + self.build(*args, **kwargs) + + def __str__(self): + return "Topo({})".format(self.name) + + def build(self, *args, **kwargs): + "Overriden by real class" + del args + del kwargs + raise NotImplementedError("Needs to be overriden") + + def addHost(self, name, **kwargs): + self.logger.debug("%s: addHost %s", self, name) + self.nodes[name] = dict(**kwargs) + self.hosts[name] = self.nodes[name] + return name + + addNode = addHost + + def addSwitch(self, name, **kwargs): + self.logger.debug("%s: addSwitch %s", self, name) + self.nodes[name] = dict(**kwargs) + if "cls" in self.nodes[name]: + self.logger.warning("Overriding Bridge class with micronet.Bridge") + del self.nodes[name]["cls"] + self.switches[name] = self.nodes[name] + return name + + def addLink(self, name1, name2, **kwargs): + """Link up switch and a router. + + possible kwargs: + - intfName1 :: switch-side interface name - sometimes missing + - intfName2 :: router-side interface name + - addr1 :: switch-side MAC used by test_ldp_topo1 only + - addr2 :: router-side MAC used by test_ldp_topo1 only + """ + if1 = ( + kwargs["intfName1"] + if "intfName1" in kwargs + else "{}-{}".format(name1, name2) + ) + if2 = ( + kwargs["intfName2"] + if "intfName2" in kwargs + else "{}-{}".format(name2, name1) + ) + + self.logger.debug("%s: addLink %s %s if1: %s if2: %s", self, name1, name2, if1, if2) + + if name1 in self.switches: + assert name2 in self.hosts + swname, rname = name1, name2 + elif name2 in self.switches: + assert name1 in self.hosts + swname, rname = name2, name1 + if1, if2 = if2, if1 + else: + # p2p link + assert name1 in self.hosts + assert name2 in self.hosts + swname, rname = name1, name2 + + if swname not in self.links: + self.links[swname] = {} + + if rname not in self.links[swname]: + self.links[swname][rname] = set() + + self.links[swname][rname].add((if1, if2)) + + +class Mininet(Micronet): + """ + Mininet using Micronet. + """ + + g_mnet_inst = None + + def __init__(self, controller=None, topo=None): + """ + Create a Micronet. + """ + assert not controller + + if Mininet.g_mnet_inst is not None: + Mininet.g_mnet_inst.stop() + Mininet.g_mnet_inst = self + + self.configured_hosts = set() + self.host_params = {} + self.prefix_len = 8 + + # SNMPd used to require this, which was set int he mininet shell + # that all commands executed from. This is goofy default so let's not + # do it if we don't have to. The snmpd.conf files have been updated + # to set permissions to root:frr 770 to make this unneeded in that case + # os.umask(0) + + super(Mininet, self).__init__() + + self.logger.debug("%s: Creating", self) + + if topo and topo.hosts: + self.logger.debug("Adding hosts: %s", topo.hosts.keys()) + for name in topo.hosts: + self.add_host(name, **topo.hosts[name]) + + if topo and topo.switches: + self.logger.debug("Adding switches: %s", topo.switches.keys()) + for name in topo.switches: + self.add_switch(name, **topo.switches[name]) + + if topo and topo.links: + self.logger.debug("Adding links: ") + for swname in sorted(topo.links): + for rname in sorted(topo.links[swname]): + for link in topo.links[swname][rname]: + self.add_link(swname, rname, link[0], link[1]) + + if topo: + # Now that topology is built, configure hosts + self.configure_hosts() + + def __str__(self): + return "Mininet()" + + def configure_hosts(self): + """ + Configure hosts once the topology has been built. + + This function can be called multiple times if routers are added to the topology + later. + """ + if not self.hosts: + return + + self.logger.debug("Configuring hosts: %s", self.hosts.keys()) + + for name in sorted(self.hosts.keys()): + if name in self.configured_hosts: + continue + + host = self.hosts[name] + first_intf = host.intfs[0] if host.intfs else None + params = self.host_params[name] + + if first_intf and "ip" in params: + ip = params["ip"] + i = ip.find("/") + if i == -1: + plen = self.prefix_len + else: + plen = int(ip[i + 1 :]) + ip = ip[:i] + + host.cmd_raises("ip addr add {}/{} dev {}".format(ip, plen, first_intf)) + + if "defaultRoute" in params: + host.cmd_raises( + "ip route add default {}".format(params["defaultRoute"]) + ) + + host.config() + + self.configured_hosts.add(name) + + def add_host(self, name, cls=Node, **kwargs): + """Add a host to micronet.""" + + self.host_params[name] = kwargs + super(Mininet, self).add_host(name, cls=cls, **kwargs) + + def start(self): + """Start the micronet topology.""" + self.logger.debug("%s: Starting (no-op).", self) + + def stop(self): + """Stop the mininet topology (deletes).""" + self.logger.debug("%s: Stopping (deleting).", self) + + self.delete() + + self.logger.debug("%s: Stopped (deleted).", self) + + if Mininet.g_mnet_inst == self: + Mininet.g_mnet_inst = None + + def cli(self): + cli(self) From 4958158787ce9179020d024c14416a23e82713b1 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Mon, 26 Jul 2021 23:23:20 +0000 Subject: [PATCH 04/25] tests: micronet: update infra Signed-off-by: Christian Hopps --- .pylintrc | 6 + .../bfd_vrf_topo1/test_bfd_vrf_topo1.py | 4 +- tests/topotests/bgp_evpn_mh/test_evpn_mh.py | 11 +- .../test_bgp_vrf_dynamic_route_leak_topo1.py | 2 - tests/topotests/conftest.py | 236 ++++++- tests/topotests/lib/bgp.py | 57 +- tests/topotests/lib/common_config.py | 438 ++++++------- tests/topotests/lib/fixtures.py | 46 ++ tests/topotests/lib/ltemplate.py | 17 +- tests/topotests/lib/mcast-tester.py | 7 +- tests/topotests/lib/ospf.py | 67 +- tests/topotests/lib/pim.py | 54 +- tests/topotests/lib/snmptest.py | 4 +- tests/topotests/lib/topogen.py | 555 +++++++++------- tests/topotests/lib/topojson.py | 98 ++- tests/topotests/lib/topolog.py | 199 +++--- tests/topotests/lib/topotest.py | 599 +++++++++++------- .../test_multicast_pim_static_rp.py | 15 +- 18 files changed, 1471 insertions(+), 944 deletions(-) create mode 100644 .pylintrc create mode 100644 tests/topotests/lib/fixtures.py diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000000..83a7197481 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,6 @@ +[MASTER] +init-hook="import sys; sys.path.insert(0, '..')" +signature-mutators=common_config.retry,retry + +[MESSAGES CONTROL] +disable=I,C,R,W diff --git a/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py b/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py index a342997912..0e0dd4db4a 100644 --- a/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py +++ b/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py @@ -108,10 +108,10 @@ def setup_module(mod): for rname, router in router_list.items(): # create VRF rx-bfd-cust1 and link rx-eth0 to rx-bfd-cust1 for cmd in cmds: - output = tgen.net[rname].cmd(cmd.format(rname)) + output = tgen.net[rname].cmd_raises(cmd.format(rname)) if rname == "r2": for cmd in cmds2: - output = tgen.net[rname].cmd(cmd.format(rname)) + output = tgen.net[rname].cmd_raises(cmd.format(rname)) for rname, router in router_list.items(): router.load_config( diff --git a/tests/topotests/bgp_evpn_mh/test_evpn_mh.py b/tests/topotests/bgp_evpn_mh/test_evpn_mh.py index 2dcf70f14a..7c2787d557 100644 --- a/tests/topotests/bgp_evpn_mh/test_evpn_mh.py +++ b/tests/topotests/bgp_evpn_mh/test_evpn_mh.py @@ -30,6 +30,9 @@ test_evpn_mh.py: Testing EVPN multihoming import os import re import sys +import subprocess +from functools import partial + import pytest import json import platform @@ -599,18 +602,20 @@ def test_evpn_ead_update(): def ping_anycast_gw(tgen): # ping the anycast gw from the local and remote hosts to populate # the mac address on the PEs + python3_path = tgen.net.get_exec_path(["python3", "python"]) script_path = os.path.abspath(os.path.join(CWD, "../lib/scapy_sendpkt.py")) intf = "torbond" ipaddr = "45.0.0.1" ping_cmd = [ + python3_path, script_path, "--imports=Ether,ARP", "--interface=" + intf, - "'Ether(dst=\"ff:ff:ff:ff:ff:ff\")/ARP(pdst=\"{}\")'".format(ipaddr) + 'Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="{}")'.format(ipaddr) ] for name in ("hostd11", "hostd21"): - host = tgen.net[name] - stdout = host.cmd(ping_cmd) + host = tgen.net.hosts[name] + _, stdout, _ = host.cmd_status(ping_cmd, warn=False, stderr=subprocess.STDOUT) stdout = stdout.strip() if stdout: host.logger.debug("%s: arping on %s for %s returned: %s", name, intf, ipaddr, stdout) diff --git a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py index ea1b1a42d7..1e371f2195 100644 --- a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py +++ b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py @@ -117,8 +117,6 @@ NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"} LOOPBACK_1 = { "ipv4": "10.0.0.7/24", "ipv6": "fd00:0:0:1::7/64", - "ipv4_mask": "255.255.255.0", - "ipv6_mask": None, } LOOPBACK_2 = { "ipv4": "10.0.0.16/24", diff --git a/tests/topotests/conftest.py b/tests/topotests/conftest.py index 76e4714bfa..ef349251f9 100755 --- a/tests/topotests/conftest.py +++ b/tests/topotests/conftest.py @@ -6,15 +6,23 @@ import glob import os import pdb import re -import pytest +import sys +import time -from lib.topogen import get_topogen, diagnose_env -from lib.topotest import json_cmp_result -from lib.topotest import g_extra_config as topotest_extra_config +import pytest +import lib.fixtures +from lib import topolog +from lib.micronet import Commander +from lib.micronet_cli import cli +from lib.micronet_compat import Mininet, cleanup_current, cleanup_previous +from lib.topogen import diagnose_env, get_topogen from lib.topolog import logger +from lib.topotest import g_extra_config as topotest_extra_config +from lib.topotest import json_cmp_result try: from _pytest._code.code import ExceptionInfo + leak_check_ok = True except ImportError: leak_check_ok = False @@ -31,6 +39,12 @@ def pytest_addoption(parser): help="Configure address sanitizer to abort process on error", ) + parser.addoption( + "--cli-on-error", + action="store_true", + help="Mininet cli on test failure", + ) + parser.addoption( "--gdb-breakpoints", metavar="SYMBOL[,SYMBOL...]", @@ -50,17 +64,28 @@ def pytest_addoption(parser): ) parser.addoption( - "--mininet-on-error", - action="store_true", - help="Mininet cli on test failure", - ) - - parser.addoption( - "--pause-after", + "--pause", action="store_true", help="Pause after each test", ) + parser.addoption( + "--pause-on-error", + action="store_true", + help="Do not pause after (disables default when --shell or -vtysh given)", + ) + + parser.addoption( + "--no-pause-on-error", + dest="pause_on_error", + action="store_false", + help="Do not pause after (disables default when --shell or -vtysh given)", + ) + + rundir_help="directory for running in and log files" + parser.addini("rundir", rundir_help, default="/tmp/topotests") + parser.addoption("--rundir", metavar="DIR", help=rundir_help) + parser.addoption( "--shell", metavar="ROUTER[,ROUTER...]", @@ -120,7 +145,7 @@ def check_for_memleaks(): latest = [] existing = [] if tgen is not None: - logdir = "/tmp/topotests/{}".format(tgen.modname) + logdir = tgen.logdir if hasattr(tgen, "valgrind_existing_files"): existing = tgen.valgrind_existing_files latest = glob.glob(os.path.join(logdir, "*.valgrind.*")) @@ -132,7 +157,7 @@ def check_for_memleaks(): vfcontent = vf.read() match = re.search(r"ERROR SUMMARY: (\d+) errors", vfcontent) if match and match.group(1) != "0": - emsg = '{} in {}'.format(match.group(1), vfile) + emsg = "{} in {}".format(match.group(1), vfile) leaks.append(emsg) if leaks: @@ -142,6 +167,16 @@ def check_for_memleaks(): logger.error("Memleaks found:\n\t" + "\n\t".join(leaks)) +def pytest_runtest_logstart(nodeid, location): + # location is (filename, lineno, testname) + topolog.logstart(nodeid, location, topotest_extra_config["rundir"]) + + +def pytest_runtest_logfinish(nodeid, location): + # location is (filename, lineno, testname) + topolog.logfinish(nodeid, location) + + def pytest_runtest_call(): """ This function must be run after setup_module(), it does standarized post @@ -151,7 +186,7 @@ def pytest_runtest_call(): tgen = get_topogen() if tgen is not None: # Allow user to play with the setup. - tgen.mininet_cli() + tgen.cli() pytest.exit("the topology executed successfully") @@ -176,8 +211,56 @@ def pytest_configure(config): Assert that the environment is correctly configured, and get extra config. """ - if not diagnose_env(): - pytest.exit("environment has errors, please read the logs") + if "PYTEST_XDIST_WORKER" not in os.environ: + os.environ["PYTEST_XDIST_MODE"] = config.getoption("dist", "no") + os.environ["PYTEST_TOPOTEST_WORKER"] = "" + is_xdist = os.environ["PYTEST_XDIST_MODE"] != "no" + is_worker = False + else: + os.environ["PYTEST_TOPOTEST_WORKER"] = os.environ["PYTEST_XDIST_WORKER"] + is_xdist = True + is_worker = True + + + # ----------------------------------------------------- + # Set some defaults for the pytest.ini [pytest] section + # --------------------------------------------------- + + rundir = config.getoption("--rundir") + if not rundir: + rundir = config.getini("rundir") + if not rundir: + rundir = "/tmp/topotests" + if not config.getoption("--junitxml"): + config.option.xmlpath = os.path.join(rundir, "topotests.xml") + xmlpath = config.option.xmlpath + + # Save an existing topotest.xml + if os.path.exists(xmlpath): + fmtime = time.localtime(os.path.getmtime(xmlpath)) + suffix = "-" + time.strftime("%Y%m%d%H%M%S", fmtime) + commander = Commander("pytest") + mv_path = commander.get_exec_path("mv") + commander.cmd_status([mv_path, xmlpath, xmlpath + suffix]) + + topotest_extra_config["rundir"] = rundir + + # Set the log_file (exec) to inside the rundir if not specified + if not config.getoption("--log-file") and not config.getini("log_file"): + config.option.log_file = os.path.join(rundir, "exec.log") + + # Turn on live logging if user specified verbose and the config has a CLI level set + if config.getoption("--verbose") and not is_xdist and not config.getini("log_cli"): + if config.getoption("--log-cli-level", None) is None: + # By setting the CLI option to the ini value it enables log_cli=1 + cli_level = config.getini("log_cli_level") + if cli_level is not None: + config.option.log_cli_level = cli_level + # --------------------------------------- + # Record our options in global dictionary + # --------------------------------------- + + topotest_extra_config["rundir"] = rundir asan_abort = config.getoption("--asan-abort") topotest_extra_config["asan_abort"] = asan_abort @@ -194,8 +277,8 @@ def pytest_configure(config): gdb_breakpoints = gdb_breakpoints.split(",") if gdb_breakpoints else [] topotest_extra_config["gdb_breakpoints"] = gdb_breakpoints - mincli_on_error = config.getoption("--mininet-on-error") - topotest_extra_config["mininet_on_error"] = mincli_on_error + cli_on_error = config.getoption("--cli-on-error") + topotest_extra_config["cli_on_error"] = cli_on_error shell = config.getoption("--shell") topotest_extra_config["shell"] = shell.split(",") if shell else [] @@ -203,8 +286,6 @@ def pytest_configure(config): strace = config.getoption("--strace-daemons") topotest_extra_config["strace_daemons"] = strace.split(",") if strace else [] - pause_after = config.getoption("--pause-after") - shell_on_error = config.getoption("--shell-on-error") topotest_extra_config["shell_on_error"] = shell_on_error @@ -217,17 +298,44 @@ def pytest_configure(config): vtysh_on_error = config.getoption("--vtysh-on-error") topotest_extra_config["vtysh_on_error"] = vtysh_on_error - topotest_extra_config["pause_after"] = pause_after or shell or vtysh + pause_on_error = vtysh or shell or config.getoption("--pause-on-error") + if config.getoption("--no-pause-on-error"): + pause_on_error = False + + topotest_extra_config["pause_on_error"] = pause_on_error + topotest_extra_config["pause"] = config.getoption("--pause") topotest_extra_config["topology_only"] = config.getoption("--topology-only") + # Check environment now that we have config + if not diagnose_env(rundir): + pytest.exit("environment has errors, please read the logs") + + +@pytest.fixture(autouse=True, scope="session") +def setup_session_auto(): + if "PYTEST_TOPOTEST_WORKER" not in os.environ: + is_worker = False + elif not os.environ["PYTEST_TOPOTEST_WORKER"]: + is_worker = False + else: + is_worker = True + + logger.debug("Before the run (is_worker: %s)", is_worker) + if not is_worker: + cleanup_previous() + yield + if not is_worker: + cleanup_current() + logger.debug("After the run (is_worker: %s)", is_worker) + def pytest_runtest_makereport(item, call): "Log all assert messages to default logger with error level" # Nothing happened if call.when == "call": - pause = topotest_extra_config["pause_after"] + pause = topotest_extra_config["pause"] else: pause = False @@ -237,6 +345,8 @@ def pytest_runtest_makereport(item, call): except: call.excinfo = ExceptionInfo() + title='unset' + if call.excinfo is None: error = False else: @@ -261,11 +371,15 @@ def pytest_runtest_makereport(item, call): modname, item.name, call.excinfo.value ) ) + title = "{}/{}".format(modname, item.name) # We want to pause, if requested, on any error not just test cases # (e.g., call.when == "setup") if not pause: - pause = topotest_extra_config["pause_after"] + pause = ( + topotest_extra_config["pause_on_error"] + or topotest_extra_config["pause"] + ) # (topogen) Set topology error to avoid advancing in the test. tgen = get_topogen() @@ -273,23 +387,75 @@ def pytest_runtest_makereport(item, call): # This will cause topogen to report error on `routers_have_failure`. tgen.set_error("{}/{}".format(modname, item.name)) - if error and topotest_extra_config["shell_on_error"]: - for router in tgen.routers(): - pause = True - tgen.net[router].runInWindow(os.getenv("SHELL", "bash")) + commander = Commander("pytest") + isatty = sys.stdout.isatty() + error_cmd = None if error and topotest_extra_config["vtysh_on_error"]: - for router in tgen.routers(): + error_cmd = commander.get_exec_path(["vtysh"]) + elif error and topotest_extra_config["shell_on_error"]: + error_cmd = os.getenv("SHELL", commander.get_exec_path(["bash"])) + + if error_cmd: + # Really would like something better than using this global here. + # Not all tests use topogen though so get_topogen() won't work. + win_info = None + wait_for_channels = [] + for node in Mininet.g_mnet_inst.hosts.values(): pause = True - tgen.net[router].runInWindow("vtysh") - if error and topotest_extra_config["mininet_on_error"]: - tgen.mininet_cli() + channel = "{}-{}".format(os.getpid(), Commander.tmux_wait_gen) if not isatty else None + Commander.tmux_wait_gen += 1 + wait_for_channels.append(channel) - if pause: + pane_info = node.run_in_window( + error_cmd, + new_window=win_info is None, + background=True, + title="{} ({})".format(title, node.name), + name=title, + tmux_target=win_info, + wait_for=channel + ) + if win_info is None: + win_info = pane_info + + # Now wait on any channels + for channel in wait_for_channels: + logger.debug("Waiting on TMUX channel %s", channel) + commander.cmd_raises([commander.get_exec_path("tmux"), "wait", channel]) + + if error and topotest_extra_config["cli_on_error"]: + # Really would like something better than using this global here. + # Not all tests use topogen though so get_topogen() won't work. + if Mininet.g_mnet_inst: + cli(Mininet.g_mnet_inst, title=title, background=False) + else: + logger.error("Could not launch CLI b/c no mininet exists yet") + + while pause and isatty: try: - user = raw_input('Testing paused, "pdb" to debug, "Enter" to continue: ') + user = raw_input( + 'PAUSED, "cli" for CLI, "pdb" to debug, "Enter" to continue: ' + ) except NameError: - user = input('Testing paused, "pdb" to debug, "Enter" to continue: ') - if user.strip() == "pdb": + user = input( + 'PAUSED, "cli" for CLI, "pdb" to debug, "Enter" to continue: ' + ) + user = user.strip() + + if user == "cli": + cli(Mininet.g_mnet_inst) + elif user == "pdb": pdb.set_trace() + elif user: + print('Unrecognized input: "%s"' % user) + else: + break + + +# +# Add common fixtures available to all tests as parameters +# +tgen = pytest.fixture(lib.fixtures.tgen) +topo = pytest.fixture(lib.fixtures.topo) diff --git a/tests/topotests/lib/bgp.py b/tests/topotests/lib/bgp.py index 519cd6735b..051b2eb978 100644 --- a/tests/topotests/lib/bgp.py +++ b/tests/topotests/lib/bgp.py @@ -18,40 +18,39 @@ # OF THIS SOFTWARE. # -from copy import deepcopy -from time import sleep -import traceback -import ipaddr import ipaddress import os import sys -from lib import topotest -from lib.topolog import logger +import traceback +from copy import deepcopy +from time import sleep -from lib.topogen import TopoRouter, get_topogen -from lib.topotest import frr_unicode +import ipaddr # Import common_config to use commomnly used APIs from lib.common_config import ( create_common_configurations, - InvalidCLIError, - load_config_to_router, - check_address_types, - generate_ips, - validate_ip_address, - find_interface_with_greater_ip, - run_frr_cmd, FRRCFG_FILE, - retry, + InvalidCLIError, + check_address_types, + create_common_configuration, + find_interface_with_greater_ip, + generate_ips, + get_frr_ipv6_linklocal, get_ipv6_linklocal_address, - get_frr_ipv6_linklocal + load_config_to_router, + retry, + run_frr_cmd, + validate_ip_address, ) +from lib.topogen import TopoRouter, get_topogen +from lib.topolog import logger +from lib.topotest import frr_unicode -LOGDIR = "/tmp/topotests/" -TMPDIR = None +from lib import topotest -def create_router_bgp(tgen, topo, input_dict=None, build=False, load_config=True): +def create_router_bgp(tgen, topo=None, input_dict=None, build=False, load_config=True): """ API to configure bgp on router @@ -139,6 +138,9 @@ def create_router_bgp(tgen, topo, input_dict=None, build=False, load_config=True logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) result = False + if topo is None: + topo = tgen.json_topo + # Flag is used when testing ipv6 over ipv4 or vice-versa afi_test = False @@ -1096,9 +1098,6 @@ def modify_bgp_config_when_bgpd_down(tgen, topo, input_dict): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) try: - - global LOGDIR - result = create_router_bgp( tgen, topo, input_dict, build=False, load_config=False ) @@ -1112,13 +1111,10 @@ def modify_bgp_config_when_bgpd_down(tgen, topo, input_dict): if router != dut: continue - TMPDIR = os.path.join(LOGDIR, tgen.modname) - logger.info("Delete BGP config when BGPd is down in {}".format(router)) - # Reading the config from /tmp/topotests and - # copy to /etc/frr/bgpd.conf + # Reading the config from "rundir" and copy to /etc/frr/bgpd.conf cmd = "cat {}/{}/{} >> /etc/frr/bgpd.conf".format( - TMPDIR, router, FRRCFG_FILE + tgen.logdir, router, FRRCFG_FILE ) router_list[router].run(cmd) @@ -1207,7 +1203,7 @@ def verify_router_id(tgen, topo, input_dict, expected=True): @retry(retry_timeout=150) -def verify_bgp_convergence(tgen, topo, dut=None, expected=True): +def verify_bgp_convergence(tgen, topo=None, dut=None, expected=True): """ API will verify if BGP is converged with in the given time frame. Running "show bgp summary json" command and verify bgp neighbor @@ -1230,6 +1226,9 @@ def verify_bgp_convergence(tgen, topo, dut=None, expected=True): errormsg(str) or True """ + if topo is None: + topo = tgen.json_topo + result = False logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) tgen = get_topogen() diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index 81c7ba4d5c..df0fd83631 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -18,37 +18,36 @@ # OF THIS SOFTWARE. # +import ipaddress +import json +import os +import platform +import signal +import socket +import subprocess +import sys +import traceback from collections import OrderedDict -from datetime import datetime, timedelta -from time import sleep from copy import deepcopy +from datetime import datetime, timedelta from functools import wraps from re import search as re_search from tempfile import mkdtemp - -import json -import logging -import os -import sys -import traceback -import socket -import subprocess -import ipaddress -import platform -import pytest +from time import sleep try: # Imports from python2 - from StringIO import StringIO import ConfigParser as configparser + from StringIO import StringIO except ImportError: # Imports from python3 - from io import StringIO import configparser + from io import StringIO -from lib.topolog import logger, logger_config +from lib.micronet_compat import Mininet from lib.topogen import TopoRouter, get_topogen -from lib.topotest import interface_set_status, version_cmp, frr_unicode +from lib.topolog import get_logger, logger +from lib.topotest import frr_unicode, interface_set_status, version_cmp FRRCFG_FILE = "frr_json.conf" FRRCFG_BKUP_FILE = "frr_json_initial.conf" @@ -60,13 +59,6 @@ ROUTER_LIST = [] CD = os.path.dirname(os.path.realpath(__file__)) PYTESTINI_PATH = os.path.join(CD, "../pytest.ini") -# Creating tmp dir with testsuite name to avoid conflict condition when -# multiple testsuites run together. All temporary files would be created -# in this dir and this dir would be removed once testsuite run is -# completed -LOGDIR = "/tmp/topotests/" -TMPDIR = None - # NOTE: to save execution logs to log file frrtest_log_dir must be configured # in `pytest.ini`. config = configparser.ConfigParser() @@ -138,6 +130,9 @@ DEBUG_LOGS = { ], } +g_iperf_client_procs = {} +g_iperf_server_procs = {} + def is_string(value): try: return isinstance(value, basestring) @@ -146,9 +141,9 @@ def is_string(value): if config.has_option("topogen", "verbosity"): loglevel = config.get("topogen", "verbosity") - loglevel = loglevel.upper() + loglevel = loglevel.lower() else: - loglevel = "INFO" + loglevel = "info" if config.has_option("topogen", "frrtest_log_dir"): frrtest_log_dir = config.get("topogen", "frrtest_log_dir") @@ -157,9 +152,7 @@ if config.has_option("topogen", "frrtest_log_dir"): frrtest_log_file = frrtest_log_dir + logfile_name + str(time_stamp) print("frrtest_log_file..", frrtest_log_file) - logger = logger_config.get_logger( - name="test_execution_logs", log_level=loglevel, target=frrtest_log_file - ) + logger = get_logger("test_execution_logs", log_level=loglevel, target=frrtest_log_file) print("Logs will be sent to logfile: {}".format(frrtest_log_file)) if config.has_option("topogen", "show_router_config"): @@ -284,7 +277,7 @@ def apply_raw_config(tgen, input_dict): if not isinstance(config_cmd, list): config_cmd = [config_cmd] - frr_cfg_file = "{}/{}/{}".format(TMPDIR, router_name, FRRCFG_FILE) + frr_cfg_file = "{}/{}/{}".format(tgen.logdir, router_name, FRRCFG_FILE) with open(frr_cfg_file, "w") as cfg: for cmd in config_cmd: cfg.write("{}\n".format(cmd)) @@ -314,7 +307,6 @@ def create_common_configurations( ------- True or False """ - TMPDIR = os.path.join(LOGDIR, tgen.modname) config_map = OrderedDict( { @@ -342,7 +334,7 @@ def create_common_configurations( routers = config_dict.keys() for router in routers: - fname = "{}/{}/{}".format(TMPDIR, router, FRRCFG_FILE) + fname = "{}/{}/{}".format(tgen.logdir, router, FRRCFG_FILE) try: frr_cfg_fd = open(fname, mode) if config_type: @@ -504,9 +496,9 @@ def reset_config_on_routers(tgen, routerName=None): return True router_list = { routerName: router_list[routerName] } - delta_fmt = TMPDIR + "/{}/delta.conf" - init_cfg_fmt = TMPDIR + "/{}/frr_json_initial.conf" - run_cfg_fmt = TMPDIR + "/{}/frr.sav" + delta_fmt = tgen.logdir + "/{}/delta.conf" + init_cfg_fmt = tgen.logdir + "/{}/frr_json_initial.conf" + run_cfg_fmt = tgen.logdir + "/{}/frr.sav" # # Get all running configs in parallel @@ -532,7 +524,7 @@ def reset_config_on_routers(tgen, routerName=None): procs = {} for rname in router_list: logger.info("Generating delta for router %s to new configuration", rname) - procs[rname] = subprocess.Popen( + procs[rname] = tgen.net.popen( [ "/usr/lib/frr/frr-reload.py", "--test-reset", "--input", @@ -630,8 +622,8 @@ def load_config_to_routers(tgen, routers, save_bkup=False): continue router_list[router] = base_router_list[router] - frr_cfg_file_fmt = TMPDIR + "/{}/" + FRRCFG_FILE - frr_cfg_bkup_fmt = TMPDIR + "/{}/" + FRRCFG_BKUP_FILE + frr_cfg_file_fmt = tgen.logdir + "/{}/" + FRRCFG_FILE + frr_cfg_bkup_fmt = tgen.logdir + "/{}/" + FRRCFG_BKUP_FILE procs = {} for rname in router_list: @@ -642,8 +634,8 @@ def load_config_to_routers(tgen, routers, save_bkup=False): with open(frr_cfg_file, "r+") as cfg: data = cfg.read() logger.info( - "Applying following configuration on router" - " {}:\n{}".format(rname, data) + "Applying following configuration on router %s (gen: %d):\n%s", + rname, gen, data ) if save_bkup: with open(frr_cfg_bkup, "w") as bkup: @@ -808,26 +800,18 @@ def generate_support_bundle(): router_list = tgen.routers() test_name = os.environ.get('PYTEST_CURRENT_TEST').split(':')[-1].split(' ')[0] - TMPDIR = os.path.join(LOGDIR, tgen.modname) - bundle_procs = {} for rname, rnode in router_list.items(): logger.info("Spawn collection of support bundle for %s", rname) - rnode.run("mkdir -p /var/log/frr") - bundle_procs[rname] = tgen.net[rname].popen( - "/usr/lib/frr/generate_support_bundle.py", - stdin=None, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) + dst_bundle = "{}/{}/support_bundles/{}".format(tgen.logdir, rname, test_name) + rnode.run("mkdir -p " + dst_bundle) + + gen_sup_cmd = ["/usr/lib/frr/generate_support_bundle.py", "--log-dir=" + dst_bundle] + bundle_procs[rname] = tgen.net[rname].popen(gen_sup_cmd, stdin=None) for rname, rnode in router_list.items(): - dst_bundle = "{}/{}/support_bundles/{}".format(TMPDIR, rname, test_name) - src_bundle = "/var/log/frr" - + logger.info("Waiting on support bundle for %s", rname) output, error = bundle_procs[rname].communicate() - - logger.info("Saving support bundle for %s", rname) if output: logger.info( "Output from collecting support bundle for %s:\n%s", rname, output @@ -836,9 +820,6 @@ def generate_support_bundle(): logger.warning( "Error from collecting support bundle for %s:\n%s", rname, error ) - rnode.run("rm -rf {}".format(dst_bundle)) - rnode.run("mkdir -p {}".format(dst_bundle)) - rnode.run("mv -f {}/* {}".format(src_bundle, dst_bundle)) return True @@ -850,7 +831,7 @@ def start_topology(tgen, daemon=None): * `tgen` : topogen object """ - global TMPDIR, ROUTER_LIST + global ROUTER_LIST # Starting topology tgen.start_topology() @@ -860,7 +841,6 @@ def start_topology(tgen, daemon=None): ROUTER_LIST = sorted( router_list.keys(), key=lambda x: int(re_search("[0-9]+", x).group(0)) ) - TMPDIR = os.path.join(LOGDIR, tgen.modname) linux_ver = "" router_list = tgen.routers() @@ -874,49 +854,50 @@ def start_topology(tgen, daemon=None): logger.info("Logging platform related details: \n %s \n", linux_ver) try: - os.chdir(TMPDIR) + os.chdir(tgen.logdir) - # Creating router named dir and empty zebra.conf bgpd.conf files - # inside the current directory - if os.path.isdir("{}".format(rname)): - os.system("rm -rf {}".format(rname)) - os.mkdir("{}".format(rname)) - os.system("chmod -R go+rw {}".format(rname)) - os.chdir("{}/{}".format(TMPDIR, rname)) - os.system("touch zebra.conf bgpd.conf") - else: - os.mkdir("{}".format(rname)) - os.system("chmod -R go+rw {}".format(rname)) - os.chdir("{}/{}".format(TMPDIR, rname)) - os.system("touch zebra.conf bgpd.conf") + # # Creating router named dir and empty zebra.conf bgpd.conf files + # # inside the current directory + # if os.path.isdir("{}".format(rname)): + # os.system("rm -rf {}".format(rname)) + # os.mkdir("{}".format(rname)) + # os.system("chmod -R go+rw {}".format(rname)) + # os.chdir("{}/{}".format(tgen.logdir, rname)) + # os.system("touch zebra.conf bgpd.conf") + # else: + # os.mkdir("{}".format(rname)) + # os.system("chmod -R go+rw {}".format(rname)) + # os.chdir("{}/{}".format(tgen.logdir, rname)) + # os.system("touch zebra.conf bgpd.conf") except IOError as err: logger.error("I/O error({0}): {1}".format(err.errno, err.strerror)) + # Loading empty zebra.conf file to router, to start the zebra daemon router.load_config( - TopoRouter.RD_ZEBRA, "{}/{}/zebra.conf".format(TMPDIR, rname) + TopoRouter.RD_ZEBRA, "{}/{}/zebra.conf".format(tgen.logdir, rname) ) # Loading empty bgpd.conf file to router, to start the bgp daemon - router.load_config(TopoRouter.RD_BGP, "{}/{}/bgpd.conf".format(TMPDIR, rname)) + router.load_config(TopoRouter.RD_BGP, "{}/{}/bgpd.conf".format(tgen.logdir, rname)) if daemon and "ospfd" in daemon: # Loading empty ospf.conf file to router, to start the bgp daemon router.load_config( - TopoRouter.RD_OSPF, "{}/{}/ospfd.conf".format(TMPDIR, rname) + TopoRouter.RD_OSPF, "{}/{}/ospfd.conf".format(tgen.logdir, rname) ) if daemon and "ospf6d" in daemon: # Loading empty ospf.conf file to router, to start the bgp daemon router.load_config( - TopoRouter.RD_OSPF6, "{}/{}/ospf6d.conf".format(TMPDIR, rname) + TopoRouter.RD_OSPF6, "{}/{}/ospf6d.conf".format(tgen.logdir, rname) ) if daemon and "pimd" in daemon: # Loading empty pimd.conf file to router, to start the pim deamon router.load_config( - TopoRouter.RD_PIM, "{}/{}/pimd.conf".format(TMPDIR, rname) + TopoRouter.RD_PIM, "{}/{}/pimd.conf".format(tgen.logdir, rname) ) # Starting routers @@ -991,12 +972,15 @@ def number_to_column(routerName): return ord(routerName[0]) - 97 -def topo_daemons(tgen, topo): +def topo_daemons(tgen, topo=None): """ Returns daemon list required for the suite based on topojson. """ daemon_list = [] + if topo is None: + topo = tgen.json_topo + router_list = tgen.routers() ROUTER_LIST = sorted( router_list.keys(), key=lambda x: int(re_search("[0-9]+", x).group(0)) @@ -1047,7 +1031,7 @@ def add_interfaces_to_vlan(tgen, input_dict): router_list = tgen.routers() for dut in input_dict.keys(): - rnode = tgen.routers()[dut] + rnode = router_list[dut] if "vlan" in input_dict[dut]: for vlan, interfaces in input_dict[dut]["vlan"].items(): @@ -1123,7 +1107,7 @@ def tcpdump_capture_start( logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - rnode = tgen.routers()[router] + rnode = tgen.gears[router] if timeout > 0: cmd = "timeout {}".format(timeout) @@ -1140,7 +1124,7 @@ def tcpdump_capture_start( cmdargs += " -s 0 {}".format(str(options)) if cap_file: - file_name = os.path.join(LOGDIR, tgen.modname, router, cap_file) + file_name = os.path.join(tgen.logdir, router, cap_file) cmdargs += " -w {}".format(str(file_name)) # Remove existing capture file rnode.run("rm -rf {}".format(file_name)) @@ -1152,7 +1136,9 @@ def tcpdump_capture_start( if not background: rnode.run(cmdargs) else: - rnode.run("nohup {} & /dev/null 2>&1".format(cmdargs)) + # XXX this & is bogus doesn't work + # rnode.run("nohup {} & /dev/null 2>&1".format(cmdargs)) + rnode.run("nohup {} > /dev/null 2>&1".format(cmdargs)) # Check if tcpdump process is running if background: @@ -1199,7 +1185,7 @@ def tcpdump_capture_stop(tgen, router): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - rnode = tgen.routers()[router] + rnode = tgen.gears[router] # Check if tcpdump process is running result = rnode.run("ps -ef | grep tcpdump") @@ -1209,6 +1195,7 @@ def tcpdump_capture_stop(tgen, router): errormsg = "tcpdump is not running {}".format("tcpdump") return errormsg else: + # XXX this doesn't work with micronet ppid = tgen.net.nameToNode[rnode.name].pid rnode.run("set +m; pkill -P %s tcpdump &> /dev/null" % ppid) logger.info("Stopped tcpdump capture") @@ -1268,7 +1255,7 @@ def create_debug_log_config(tgen, input_dict, build=False): log_file = debug_dict.setdefault("log_file", None) if log_file: - _log_file = os.path.join(LOGDIR, tgen.modname, log_file) + _log_file = os.path.join(tgen.logdir, log_file) debug_config.append("log file {} \n".format(_log_file)) if type(enable_logs) is list: @@ -1374,9 +1361,8 @@ def create_vrf_cfg(tgen, topo, input_dict=None, build=False): config_data_dict = {} for c_router, c_data in input_dict.items(): - rnode = tgen.routers()[c_router] + rnode = tgen.gears[c_router] config_data = [] - if "vrfs" in c_data: for vrf in c_data["vrfs"]: del_action = vrf.setdefault("delete", False) @@ -1490,7 +1476,7 @@ def create_interface_in_kernel( to create """ - rnode = tgen.routers()[dut] + rnode = tgen.gears[dut] if create: cmd = "ip link show {0} >/dev/null || ip link add {0} type dummy".format(name) @@ -1528,7 +1514,7 @@ def shutdown_bringup_interface_in_kernel(tgen, dut, intf_name, ifaceaction=False ineterface """ - rnode = tgen.routers()[dut] + rnode = tgen.gears[dut] cmd = "ip link set dev" if ifaceaction: @@ -1737,7 +1723,7 @@ def interface_status(tgen, topo, input_dict): interface_list = input_dict[router]["interface_list"] status = input_dict[router].setdefault("status", "up") for intf in interface_list: - rnode = tgen.routers()[router] + rnode = tgen.gears[router] interface_set_status(rnode, intf, status) rlist.append(router) @@ -2797,7 +2783,7 @@ def addKernelRoute( logger.debug("Entering lib API: addKernelRoute()") - rnode = tgen.routers()[router] + rnode = tgen.gears[router] if type(group_addr_range) is not list: group_addr_range = [group_addr_range] @@ -2879,7 +2865,7 @@ def configure_vxlan(tgen, input_dict): router_list = tgen.routers() for dut in input_dict.keys(): - rnode = tgen.routers()[dut] + rnode = router_list[dut] if "vxlan" in input_dict[dut]: for vxlan_dict in input_dict[dut]["vxlan"]: @@ -2978,7 +2964,7 @@ def configure_brctl(tgen, topo, input_dict): router_list = tgen.routers() for dut in input_dict.keys(): - rnode = tgen.routers()[dut] + rnode = router_list[dut] if "brctl" in input_dict[dut]: for brctl_dict in input_dict[dut]["brctl"]: @@ -3064,7 +3050,7 @@ def configure_interface_mac(tgen, input_dict): router_list = tgen.routers() for dut in input_dict.keys(): - rnode = tgen.routers()[dut] + rnode = router_list[dut] for intf, mac in input_dict[dut].items(): cmd = "ip link set {} address {}".format(intf, mac) @@ -3535,7 +3521,11 @@ def verify_fib_routes(tgen, addr_type, dut, input_dict, next_hop=None): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) router_list = tgen.routers() + if dut not in router_list: + return + for routerInput in input_dict.keys(): + # XXX replace with router = dut; rnode = router_list[dut] for router, rnode in router_list.items(): if router != dut: continue @@ -3780,11 +3770,11 @@ def verify_admin_distance_for_static_routes(tgen, input_dict): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) + router_list = tgen.routers() for router in input_dict.keys(): - if router not in tgen.routers(): + if router not in router_list: continue - - rnode = tgen.routers()[router] + rnode = router_list[router] for static_route in input_dict[router]["static_routes"]: addr_type = validate_ip_address(static_route["network"]) @@ -3862,11 +3852,12 @@ def verify_prefix_lists(tgen, input_dict): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) + router_list = tgen.routers() for router in input_dict.keys(): - if router not in tgen.routers(): + if router not in router_list: continue - rnode = tgen.routers()[router] + rnode = router_list[router] # Show ip prefix list show_prefix_list = run_frr_cmd(rnode, "show ip prefix-list") @@ -3925,11 +3916,12 @@ def verify_route_maps(tgen, input_dict): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) + router_list = tgen.routers() for router in input_dict.keys(): - if router not in tgen.routers(): + if router not in router_list: continue - rnode = tgen.routers()[router] + rnode = router_list[router] # Show ip route-map show_route_maps = rnode.vtysh_cmd("show route-map") @@ -3978,10 +3970,11 @@ def verify_bgp_community(tgen, addr_type, router, network, input_dict=None): """ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - if router not in tgen.routers(): + router_list = tgen.routers() + if router not in router_list: return False - rnode = tgen.routers()[router] + rnode = router_list[router] logger.debug( "Verifying BGP community attributes on dut %s: for %s " "network %s", @@ -4108,11 +4101,12 @@ def verify_create_community_list(tgen, input_dict): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) + router_list = tgen.routers() for router in input_dict.keys(): - if router not in tgen.routers(): + if router not in router_list: continue - rnode = tgen.routers()[router] + rnode = router_list[router] logger.info("Verifying large-community is created for dut %s:", router) @@ -4163,7 +4157,7 @@ def verify_cli_json(tgen, input_dict): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) for dut in input_dict.keys(): - rnode = tgen.routers()[dut] + rnode = tgen.gears[dut] for cli in input_dict[dut]["cli"]: logger.info( @@ -4225,7 +4219,7 @@ def verify_evpn_vni(tgen, input_dict): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) for dut in input_dict.keys(): - rnode = tgen.routers()[dut] + rnode = tgen.gears[dut] logger.info("[DUT: %s]: Verifying evpn vni details :", dut) @@ -4343,7 +4337,7 @@ def verify_vrf_vni(tgen, input_dict): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) for dut in input_dict.keys(): - rnode = tgen.routers()[dut] + rnode = tgen.gears[dut] logger.info("[DUT: %s]: Verifying vrf vni details :", dut) @@ -4447,9 +4441,7 @@ def required_linux_kernel_version(required_version): return True -def iperfSendIGMPJoin( - tgen, server, bindToAddress, l4Type="UDP", join_interval=1, inc_step=0, repeat=0 -): +def iperfSendIGMPJoin(tgen, server, bindToAddress, l4Type="UDP", join_interval=1): """ Run iperf to send IGMP join and traffic @@ -4461,8 +4453,6 @@ def iperfSendIGMPJoin( * `bindToAddress`: bind to , an interface or multicast address * `join_interval`: seconds between periodic bandwidth reports - * `inc_step`: increamental steps, by default 0 - * `repeat`: Repetition of group, by default 0 returns: -------- @@ -4471,53 +4461,43 @@ def iperfSendIGMPJoin( logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - rnode = tgen.routers()[server] + rnode = tgen.gears[server] - iperfArgs = "iperf -s " + iperf_path = tgen.net.get_exec_path("iperf") - # UDP/TCP - if l4Type == "UDP": - iperfArgs += "-u " - - iperfCmd = iperfArgs - # Group address range to cover - if bindToAddress: - if type(bindToAddress) is not list: - Address = [] - start = ipaddress.IPv4Address(frr_unicode(bindToAddress)) - - Address = [start] - next_ip = start - - count = 1 - while count < repeat: - next_ip += inc_step - Address.append(next_ip) - count += 1 - bindToAddress = Address + if bindToAddress and not isinstance(bindToAddress, list): + bindToAddress = [ipaddress.IPv4Address(frr_unicode(bindToAddress))] for bindTo in bindToAddress: - iperfArgs = iperfCmd - iperfArgs += "-B %s " % bindTo + iperf_args = [iperf_path, "-s"] + + # UDP/TCP + if l4Type == "UDP": + iperf_args.append("-u") + + iperf_args.append("-B") + iperf_args.append(str(bindTo)) # Join interval if join_interval: - iperfArgs += "-i %d " % join_interval + iperf_args.append("-i") + iperf_args.append(str(join_interval)) - iperfArgs += " &>/dev/null &" # Run iperf command to send IGMP join - logger.debug("[DUT: {}]: Running command: [{}]".format(server, iperfArgs)) - output = rnode.run("set +m; {} sleep 0.5".format(iperfArgs)) + logger.debug("[DUT: %s]: Running command: %s",server, iperf_args) - # Check if iperf process is running - if output: - pid = output.split()[1] - rnode.run("touch /var/run/frr/iperf_server.pid") - rnode.run("echo %s >> /var/run/frr/iperf_server.pid" % pid) - else: - errormsg = "IGMP join is not sent for {}. Error: {}".format(bindTo, output) - logger.error(output) - return errormsg + p = rnode.popen(iperf_args, stderr=subprocess.STDOUT) + rc = p.poll() + if rc is not None: + output, _ = p.communicate() + if rc: + errormsg = "IGMP join is not sent for {}. Error: {}".format(bindTo, output) + logger.error("%s", output) + return errormsg + + if server not in g_iperf_server_procs: + g_iperf_server_procs[server] = [] + g_iperf_server_procs[server].append(p) logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name)) return True @@ -4526,13 +4506,11 @@ def iperfSendIGMPJoin( def iperfSendTraffic( tgen, client, - bindToAddress, + sentToAddress, ttl, time=0, l4Type="UDP", - inc_step=0, - repeat=0, - mappedAddress=None, + bindToIntf=None, ): """ Run iperf to send IGMP join and traffic @@ -4542,13 +4520,11 @@ def iperfSendTraffic( * `tgen` : Topogen object * `l4Type`: string, one of [ TCP, UDP ] * `client`: iperf client, from where iperf traffic would be sent - * `bindToAddress`: bind to , an interface or multicast + * `sentToAddress`: bind to , an interface or multicast address * `ttl`: time to live * `time`: time in seconds to transmit for - * `inc_step`: increamental steps, by default 0 - * `repeat`: Repetition of group, by default 0 - * `mappedAddress`: Mapped Interface ip address + * `bindToIntf`: Source interface ip address returns: -------- @@ -4557,64 +4533,56 @@ def iperfSendTraffic( logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - rnode = tgen.routers()[client] + rnode = tgen.gears[client] - iperfArgs = "iperf -c " + iperf_path = tgen.net.get_exec_path("iperf") - iperfCmd = iperfArgs - # Group address range to cover - if bindToAddress: - if type(bindToAddress) is not list: - Address = [] - start = ipaddress.IPv4Address(frr_unicode(bindToAddress)) + if sentToAddress and not isinstance(sentToAddress, list): + sentToAddress = [ipaddress.IPv4Address(frr_unicode(sentToAddress))] - Address = [start] - next_ip = start + for sendTo in sentToAddress: + iperf_args = [iperf_path, "-c", sendTo] - count = 1 - while count < repeat: - next_ip += inc_step - Address.append(next_ip) - count += 1 - bindToAddress = Address - - for bindTo in bindToAddress: - iperfArgs = iperfCmd - iperfArgs += "%s " % bindTo - - # Mapped Interface IP - if mappedAddress: - iperfArgs += "-B %s " % mappedAddress + # Bind to Interface IP + if bindToIntf: + ifaddr = frr_unicode(tgen.json_topo["routers"][client]["links"][bindToIntf]["ipv4"]) + ipaddr = ipaddress.IPv4Interface(ifaddr).ip + iperf_args.append("-B") + iperf_args.append(str(ipaddr)) # UDP/TCP if l4Type == "UDP": - iperfArgs += "-u -b 0.012m " + iperf_args.append("-u") + iperf_args.append("-b") + iperf_args.append("0.012m") # TTL if ttl: - iperfArgs += "-T %d " % ttl + iperf_args.append("-T") + iperf_args.append(str(ttl)) # Time if time: - iperfArgs += "-t %d " % time - - iperfArgs += " &>/dev/null &" + iperf_args.append("-t") + iperf_args.append(str(time)) # Run iperf command to send multicast traffic - logger.debug("[DUT: {}]: Running command: [{}]".format(client, iperfArgs)) - output = rnode.run("set +m; {} sleep 0.5".format(iperfArgs)) + logger.debug("[DUT: {}]: Running command: {}".format(client, iperf_args)) - # Check if iperf process is running - if output: - pid = output.split()[1] - rnode.run("touch /var/run/frr/iperf_client.pid") - rnode.run("echo %s >> /var/run/frr/iperf_client.pid" % pid) - else: - errormsg = "Multicast traffic is not sent for {}. Error {}".format( - bindTo, output - ) - logger.error(output) - return errormsg + p = rnode.popen(iperf_args, stderr=subprocess.STDOUT) + rc = p.poll() + if rc is not None: + output, _ = p.communicate() + if rc: + errormsg = "Multicast traffic is not sent for {}. Error {}".format( + sendTo, output + ) + logger.error(output) + return errormsg + + if client not in g_iperf_client_procs: + g_iperf_client_procs[client] = [] + g_iperf_client_procs[client].append(p) logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name)) return True @@ -4637,24 +4605,36 @@ def kill_iperf(tgen, dut=None, action=None): """ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) + logger.debug("Running iperfs: clients: %s servers: %s", g_iperf_client_procs, g_iperf_server_procs) - router_list = tgen.routers() - for router, rnode in router_list.items(): - # Run iperf command to send IGMP join - pid_client = rnode.run("cat /var/run/frr/iperf_client.pid") - pid_server = rnode.run("cat /var/run/frr/iperf_server.pid") + if dut is not None: + nodes = [dut] + else: + nodes = sorted(tgen.gears.keys()) + + for name in nodes: + logger.debug("Checking for iperfs on %s", name) if action == "remove_join": - pids = pid_server + procs = g_iperf_server_procs[name] if name in g_iperf_server_procs else [] + g_iperf_server_procs[name] = [] elif action == "remove_traffic": - pids = pid_client + procs = g_iperf_client_procs[name] if name in g_iperf_client_procs else [] + g_iperf_client_procs[name] = [] else: - pids = "\n".join([pid_client, pid_server]) - for pid in pids.split("\n"): - pid = pid.strip() - if pid.isdigit(): - cmd = "set +m; kill -9 %s &> /dev/null" % pid - logger.debug("[DUT: {}]: Running command: [{}]".format(router, cmd)) - rnode.run(cmd) + procs = [] + if name in g_iperf_server_procs: + procs.extend(g_iperf_server_procs[name]) + g_iperf_server_procs[name] = [] + if name in g_iperf_client_procs: + procs.extend(g_iperf_client_procs[name]) + g_iperf_client_procs[name] = [] + for p in procs: + logger.info("[DUT: {}]: Terminating iperf: [{}]".format(name, p.pid)) + # p.send_signal(signal.SIGHUP) + p.terminate() + for p in procs: + logger.info("[DUT: {}]: Waiting for iperf to terminate: [{}]".format(name, p.pid)) + p.wait() logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name)) @@ -4689,14 +4669,15 @@ def verify_ip_nht(tgen, input_dict): logger.debug("Entering lib API: verify_ip_nht()") + router_list = tgen.routers() for router in input_dict.keys(): - if router not in tgen.routers(): + if router not in router_list: continue - rnode = tgen.routers()[router] + rnode = router_list[router] nh_list = input_dict[router] - if validate_ip_address(nh_list.keys()[0]) is "ipv6": + if validate_ip_address(next(iter(nh_list))) is "ipv6": show_ip_nht = run_frr_cmd(rnode, "show ipv6 nht") else: show_ip_nht = run_frr_cmd(rnode, "show ip nht") @@ -4714,7 +4695,7 @@ def verify_ip_nht(tgen, input_dict): def scapy_send_raw_packet( - tgen, topo, senderRouter, intf, packet=None, interval=1, count=1 + tgen, topo, senderRouter, intf, packet=None ): """ Using scapy Raw() method to send BSR raw packet from one FRR @@ -4726,8 +4707,6 @@ def scapy_send_raw_packet( * `topo` : json file data * `senderRouter` : Sender router * `packet` : packet in raw format - * `interval` : Interval between the packets - * `count` : Number of packets to be sent returns: -------- @@ -4749,20 +4728,13 @@ def scapy_send_raw_packet( "data" ] - if interval > 1 or count > 1: - cmd = ( - "nohup /usr/bin/python {}/send_bsr_packet.py '{}' '{}' " - "--interval={} --count={} &".format( - CD, packet, sender_interface, interval, count - ) - ) - else: - cmd = ( - "/usr/bin/python {}/send_bsr_packet.py '{}' '{}' " - "--interval={} --count={}".format( - CD, packet, sender_interface, interval, count - ) + python3_path = tgen.net.get_exec_path(["python3", "python"]) + script_path = os.path.join(CD, "send_bsr_packet.py") + cmd = ( + "{} {} '{}' '{}' --interval=1 --count=1".format( + python3_path, script_path, packet, sender_interface ) + ) logger.info("Scapy cmd: \n %s", cmd) result = rnode.run(cmd) diff --git a/tests/topotests/lib/fixtures.py b/tests/topotests/lib/fixtures.py new file mode 100644 index 0000000000..5dac29fd36 --- /dev/null +++ b/tests/topotests/lib/fixtures.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 eval: (yapf-mode 1) -*- +# +# August 27 2021, Christian Hopps +# +# Copyright (c) 2021, LabN Consulting, L.L.C. ("LabN") +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import lib.topojson as topojson +import lib.topogen as topogen +from lib.topolog import logger + +def tgen_json(request): + logger.info("Creating/starting topogen topology for %s", request.module.__name__) + + tgen = topojson.setup_module_from_json(request.module.__file__) + yield tgen + + logger.info("Stopping topogen topology for %s", request.module.__name__) + tgen.stop_topology() + + +def topo(tgen): + """Make tgen json object available as test argument.""" + return tgen.json_topo + + +def tgen(): + """Make global topogen object available as test argument.""" + return topogen.get_topogen() diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py index d211be8836..56eca4be04 100644 --- a/tests/topotests/lib/ltemplate.py +++ b/tests/topotests/lib/ltemplate.py @@ -28,8 +28,8 @@ ltemplate.py: LabN template for FRR tests. import os import sys import platform + import pytest -import imp # pylint: disable=C0413 # Import topogen and topotest helpers @@ -43,7 +43,6 @@ from mininet.topo import Topo customize = None - class LTemplate: test = None testdir = None @@ -54,12 +53,20 @@ class LTemplate: iproute2Ver = None def __init__(self, test, testdir): + pathname = os.path.join(testdir, "customize.py") global customize - customize = imp.load_source("customize", os.path.join(testdir, "customize.py")) + if sys.version_info >= (3, 5): + import importlib.util + spec = importlib.util.spec_from_file_location("customize", pathname) + customize = importlib.util.module_from_spec(spec) + spec.loader.exec_module(customize) + else: + import imp + customize = imp.load_source("customize", pathname) self.test = test self.testdir = testdir self.scriptdir = testdir - self.logdir = "/tmp/topotests/{0}.test_{0}".format(test) + self.logdir = "" logger.info("LTemplate: " + test) def setup_module(self, mod): @@ -69,6 +76,8 @@ class LTemplate: # ... and here it calls Mininet initialization functions. tgen.start_topology() + self.logdir = tgen.logdir + logger.info("Topology started") try: self.prestarthooksuccess = customize.ltemplatePreRouterStartHook() diff --git a/tests/topotests/lib/mcast-tester.py b/tests/topotests/lib/mcast-tester.py index 07e4ab8773..117bf79eb9 100755 --- a/tests/topotests/lib/mcast-tester.py +++ b/tests/topotests/lib/mcast-tester.py @@ -21,14 +21,15 @@ for the multicast group we subscribed to. """ import argparse -import os import json +import os import socket -import subprocess import struct +import subprocess import sys import time + # # Functions # @@ -64,7 +65,7 @@ parser.add_argument('group', help='Multicast IP') parser.add_argument('interface', help='Interface name') parser.add_argument( '--send', - help='Transmit instead of join with interval (defaults to 0.7 sec)', + help='Transmit instead of join with interval', type=float, default=0) args = parser.parse_args() diff --git a/tests/topotests/lib/ospf.py b/tests/topotests/lib/ospf.py index beac768905..ba926bf30e 100644 --- a/tests/topotests/lib/ospf.py +++ b/tests/topotests/lib/ospf.py @@ -18,37 +18,35 @@ # OF THIS SOFTWARE. # -import ipaddr import ipaddress import sys - +import traceback from copy import deepcopy -from time import sleep -from lib.topolog import logger -from lib.topotest import frr_unicode from ipaddress import IPv6Address -import sys +from time import sleep + +import ipaddr # Import common_config to use commomnly used APIs from lib.common_config import ( create_common_configurations, InvalidCLIError, - retry, - generate_ips, check_address_types, - validate_ip_address, + create_common_configuration, + generate_ips, + retry, run_frr_cmd, + validate_ip_address, ) - -LOGDIR = "/tmp/topotests/" -TMPDIR = None +from lib.topolog import logger +from lib.topotest import frr_unicode ################################ # Configure procs ################################ -def create_router_ospf(tgen, topo, input_dict=None, build=False, load_config=True): +def create_router_ospf(tgen, topo=None, input_dict=None, build=False, load_config=True): """ API to configure ospf on router. @@ -79,6 +77,9 @@ def create_router_ospf(tgen, topo, input_dict=None, build=False, load_config=Tru logger.debug("Entering lib API: create_router_ospf()") result = False + if topo is None: + topo = tgen.json_topo + if not input_dict: input_dict = deepcopy(topo) else: @@ -373,7 +374,7 @@ def __create_ospf_global( return config_data -def create_router_ospf6(tgen, topo, input_dict=None, build=False, load_config=True): +def create_router_ospf6(tgen, topo=None, input_dict=None, build=False, load_config=True): """ API to configure ospf on router @@ -400,6 +401,9 @@ def create_router_ospf6(tgen, topo, input_dict=None, build=False, load_config=Tr logger.debug("Entering lib API: create_router_ospf6()") result = False + if topo is None: + topo = tgen.json_topo + if not input_dict: input_dict = deepcopy(topo) else: @@ -431,7 +435,7 @@ def create_router_ospf6(tgen, topo, input_dict=None, build=False, load_config=Tr return result -def config_ospf_interface(tgen, topo, input_dict=None, build=False, load_config=True): +def config_ospf_interface(tgen, topo=None, input_dict=None, build=False, load_config=True): """ API to configure ospf on router. @@ -466,6 +470,10 @@ def config_ospf_interface(tgen, topo, input_dict=None, build=False, load_config= """ logger.debug("Enter lib config_ospf_interface") result = False + + if topo is None: + topo = tgen.json_topo + if not input_dict: input_dict = deepcopy(topo) else: @@ -632,7 +640,7 @@ def redistribute_ospf(tgen, topo, dut, route_type, **kwargs): # Verification procs ################################ @retry(retry_timeout=80) -def verify_ospf_neighbor(tgen, topo, dut=None, input_dict=None, lan=False, expected=True): +def verify_ospf_neighbor(tgen, topo=None, dut=None, input_dict=None, lan=False, expected=True): """ This API is to verify ospf neighborship by running show ip ospf neighbour command, @@ -680,6 +688,9 @@ def verify_ospf_neighbor(tgen, topo, dut=None, input_dict=None, lan=False, expec """ logger.debug("Entering lib API: verify_ospf_neighbor()") result = False + if topo is None: + topo = tgen.json_topo + if input_dict: for router, rnode in tgen.routers().items(): if "ospf" not in topo["routers"][router]: @@ -827,7 +838,7 @@ def verify_ospf_neighbor(tgen, topo, dut=None, input_dict=None, lan=False, expec # Verification procs ################################ @retry(retry_timeout=50) -def verify_ospf6_neighbor(tgen, topo, dut=None, input_dict=None, lan=False): +def verify_ospf6_neighbor(tgen, topo=None, dut=None, input_dict=None, lan=False): """ This API is to verify ospf neighborship by running show ipv6 ospf neighbour command, @@ -875,6 +886,9 @@ def verify_ospf6_neighbor(tgen, topo, dut=None, input_dict=None, lan=False): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) result = False + if topo is None: + topo = tgen.json_topo + if input_dict: for router, rnode in tgen.routers().items(): if "ospf6" not in topo["routers"][router]: @@ -1318,7 +1332,7 @@ def verify_ospf_rib( @retry(retry_timeout=20) -def verify_ospf_interface(tgen, topo, dut=None, lan=False, input_dict=None, expected=True): +def verify_ospf_interface(tgen, topo=None, dut=None, lan=False, input_dict=None, expected=True): """ This API is to verify ospf routes by running show ip ospf interface command. @@ -1360,6 +1374,9 @@ def verify_ospf_interface(tgen, topo, dut=None, lan=False, input_dict=None, expe logger.debug("Entering lib API: verify_ospf_interface()") result = False + if topo is None: + topo = tgen.json_topo + for router, rnode in tgen.routers().items(): if "ospf" not in topo["routers"][router]: continue @@ -1936,7 +1953,7 @@ def verify_ospf6_rib(tgen, dut, input_dict, next_hop=None, @retry(retry_timeout=6) -def verify_ospf6_interface(tgen, topo, dut=None,lan=False, input_dict=None): +def verify_ospf6_interface(tgen, topo=None, dut=None,lan=False, input_dict=None): """ This API is to verify ospf routes by running show ip ospf interface command. @@ -1978,8 +1995,11 @@ def verify_ospf6_interface(tgen, topo, dut=None,lan=False, input_dict=None): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) result = False - for router, rnode in tgen.routers().iteritems(): - if "ospf6" not in topo["routers"][router]: + if topo is None: + topo = tgen.json_topo + + for router, rnode in tgen.routers().items(): + if 'ospf6' not in topo['routers'][router]: continue if dut is not None and dut != router: @@ -2315,7 +2335,7 @@ def verify_ospf6_database(tgen, topo, dut, input_dict): return result -def config_ospf6_interface(tgen, topo, input_dict=None, build=False, load_config=True): +def config_ospf6_interface(tgen, topo=None, input_dict=None, build=False, load_config=True): """ API to configure ospf on router. @@ -2350,6 +2370,9 @@ def config_ospf6_interface(tgen, topo, input_dict=None, build=False, load_config """ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) result = False + if topo is None: + topo = tgen.json_topo + if not input_dict: input_dict = deepcopy(topo) else: diff --git a/tests/topotests/lib/pim.py b/tests/topotests/lib/pim.py index e702e53c00..bb964df7dc 100644 --- a/tests/topotests/lib/pim.py +++ b/tests/topotests/lib/pim.py @@ -16,24 +16,25 @@ # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE # OF THIS SOFTWARE. -import sys +import datetime import os import re -import datetime +import sys import traceback -import pytest -from time import sleep from copy import deepcopy -from lib.topolog import logger +from time import sleep + +import pytest # Import common_config to use commomnly used APIs from lib.common_config import ( - create_common_configuration, create_common_configurations, + create_common_configuration, InvalidCLIError, retry, run_frr_cmd, ) +from lib.topolog import logger #### CWD = os.path.dirname(os.path.realpath(__file__)) @@ -922,7 +923,8 @@ def verify_join_state_and_timer(tgen, dut, iif, src_address, group_addresses, ex error = ( "[DUT %s]: Verifying join timer for" " (%s,%s) [FAILED]!! " - " Expected: %s, Found: %s", + " Expected: %s, Found: %s" + ) % ( dut, src_address, grp_addr, @@ -2028,9 +2030,7 @@ def add_rp_interfaces_and_pim_config(tgen, topo, interface, rp, rp_mapping): return result -def scapy_send_bsr_raw_packet( - tgen, topo, senderRouter, receiverRouter, packet=None, interval=1, count=1 -): +def scapy_send_bsr_raw_packet(tgen, topo, senderRouter, receiverRouter, packet=None): """ Using scapy Raw() method to send BSR raw packet from one FRR to other @@ -2042,8 +2042,6 @@ def scapy_send_bsr_raw_packet( * `senderRouter` : Sender router * `receiverRouter` : Receiver router * `packet` : BSR packet in raw format - * `interval` : Interval between the packets - * `count` : Number of packets to be sent returns: -------- @@ -2054,7 +2052,9 @@ def scapy_send_bsr_raw_packet( result = "" logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - rnode = tgen.routers()[senderRouter] + python3_path = tgen.net.get_exec_path(["python3", "python"]) + script_path = os.path.join(CWD, "send_bsr_packet.py") + node = tgen.net[senderRouter] for destLink, data in topo["routers"][senderRouter]["links"].items(): if "type" in data and data["type"] == "loopback": @@ -2065,26 +2065,16 @@ def scapy_send_bsr_raw_packet( packet = topo["routers"][senderRouter]["bsm"]["bsr_packets"][packet]["data"] - if interval > 1 or count > 1: - cmd = ( - "nohup /usr/bin/python {}/send_bsr_packet.py '{}' '{}' " - "--interval={} --count={} &".format( - CWD, packet, sender_interface, interval, count - ) - ) - else: - cmd = ( - "/usr/bin/python {}/send_bsr_packet.py '{}' '{}' " - "--interval={} --count={}".format( - CWD, packet, sender_interface, interval, count - ) - ) - + cmd = [ + python3_path, + script_path, + packet, + sender_interface, + "--interval=1", + "--count=1", + ] logger.info("Scapy cmd: \n %s", cmd) - result = rnode.run(cmd) - - if result == "": - return result + node.cmd_raises(cmd) logger.debug("Exiting lib API: scapy_send_bsr_raw_packet") return True diff --git a/tests/topotests/lib/snmptest.py b/tests/topotests/lib/snmptest.py index e6b140a0e2..fe5ff28979 100644 --- a/tests/topotests/lib/snmptest.py +++ b/tests/topotests/lib/snmptest.py @@ -30,7 +30,7 @@ Basic usage instructions: * see tests/topotest/simple-snmp-test/test_simple_snmp.py for example """ -from topolog import logger +from lib.topolog import logger class SnmpTester(object): @@ -93,7 +93,7 @@ class SnmpTester(object): return tokens[0].split(".", 1)[1] def _parse_multiline(self, snmp_output): - results = snmp_output.strip().split("\r\n") + results = snmp_output.strip().split("\n") out_dict = {} out_list = [] diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 8888421bf1..c0529c68e2 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -38,31 +38,30 @@ Basic usage instructions: * After running stop Mininet with: tgen.stop_topology() """ -import os -import sys -import io -import logging +import grp +import inspect import json +import logging +import os +import platform +import pwd +import re +import subprocess +import sys +from collections import OrderedDict if sys.version_info[0] > 2: import configparser else: import ConfigParser as configparser -import glob -import grp -import platform -import pwd -import subprocess -import pytest - -from mininet.net import Mininet -from mininet.log import setLogLevel -from mininet.cli import CLI +import lib.topolog as topolog +from lib.micronet import Commander +from lib.micronet_compat import Mininet +from lib.topolog import logger +from lib.topotest import g_extra_config from lib import topotest -from lib.topolog import logger, logger_config -from lib.topotest import set_sysctl CWD = os.path.dirname(os.path.realpath(__file__)) @@ -89,6 +88,51 @@ def set_topogen(tgen): global_tgen = tgen +def is_string(value): + """Return True if value is a string.""" + try: + return isinstance(value, basestring) # type: ignore + except NameError: + return isinstance(value, str) + + +def get_exabgp_cmd(commander=None): + """Return the command to use for ExaBGP version < 4.""" + + if commander is None: + commander = Commander("topogen") + + def exacmd_version_ok(exacmd): + logger.debug("checking %s for exabgp < version 4", exacmd) + _, stdout, _ = commander.cmd_status(exacmd + " -v", warn=False) + m = re.search(r"ExaBGP\s*:\s*((\d+)\.(\d+)(?:\.(\d+))?)", stdout) + if not m: + return False + version = m.group(1) + if topotest.version_cmp(version, "4") >= 0: + logging.debug( + "found exabgp version >= 4 in %s will keep looking", exacmd + ) + return False + logger.info("Using ExaBGP version %s in %s", version, exacmd) + return True + + exacmd = commander.get_exec_path("exabgp") + if exacmd and exacmd_version_ok(exacmd): + return exacmd + py2_path = commander.get_exec_path("python2") + if py2_path: + exacmd = py2_path + " -m exabgp" + if exacmd_version_ok(exacmd): + return exacmd + py2_path = commander.get_exec_path("python") + if py2_path: + exacmd = py2_path + " -m exabgp" + if exacmd_version_ok(exacmd): + return exacmd + return None + + # # Main class: topology builder # @@ -107,10 +151,12 @@ class Topogen(object): CONFIG_SECTION = "topogen" - def __init__(self, cls, modname="unnamed"): + def __init__(self, topodef, modname="unnamed"): """ Topogen initialization function, takes the following arguments: - * `cls`: the topology class that is child of mininet.topo + * `cls`: OLD:uthe topology class that is child of mininet.topo or a build function. + * `topodef`: A dictionary defining the topology, a filename of a json file, or a + function that will do the same * `modname`: module name must be a unique name to identify logs later. """ self.config = None @@ -123,16 +169,22 @@ class Topogen(object): self.errorsd = {} self.errors = "" self.peern = 1 - self._init_topo(cls) + self.cfg_gen = 0 + self.exabgp_cmd = None + self._init_topo(topodef) + logger.info("loading topology: {}".format(self.modname)) - @staticmethod - def _mininet_reset(): - "Reset the mininet environment" - # Clean up the mininet environment - os.system("mn -c > /dev/null 2>&1") + # @staticmethod + # def _mininet_reset(): + # "Reset the mininet environment" + # # Clean up the mininet environment + # os.system("mn -c > /dev/null 2>&1") - def _init_topo(self, cls): + def __str__(self): + return "Topogen()" + + def _init_topo(self, topodef): """ Initialize the topogily provided by the user. The user topology class must call get_topogen() during build() to get the topogen object. @@ -140,6 +192,9 @@ class Topogen(object): # Set the global variable so the test cases can access it anywhere set_topogen(self) + # Increase host based limits + topotest.fix_host_limits() + # Test for MPLS Kernel modules available self.hasmpls = False if not topotest.module_present("mpls-router"): @@ -148,15 +203,90 @@ class Topogen(object): logger.info("MPLS tests will not run (missing mpls-iptunnel kernel module)") else: self.hasmpls = True + # Load the default topology configurations self._load_config() - # Initialize the API - self._mininet_reset() - cls() + # Create new log directory + self.logdir = topotest.get_logs_path(g_extra_config["rundir"]) + subprocess.check_call("mkdir -p {0} && chmod 1777 {0}".format(self.logdir), shell=True) + try: + routertype = self.config.get(self.CONFIG_SECTION, "routertype") + # Only allow group, if it exist. + gid = grp.getgrnam(routertype)[2] + os.chown(self.logdir, 0, gid) + os.chmod(self.logdir, 0o775) + except KeyError: + # Allow anyone, but set the sticky bit to avoid file deletions + os.chmod(self.logdir, 0o1777) + + # Old twisty way of creating sub-classed topology object which has it's build + # method invoked which calls Topogen methods which then call Topo methods to + # create a topology within the Topo object, which is then used by + # Mininet(Micronet) to build the actual topology. + if inspect.isclass(topodef): + self.topo = topodef() + self.net = Mininet(controller=None, topo=self.topo) - for gear in self.gears.values(): - gear.net = self.net + + # New direct way: Either a dictionary defines the topology or a build function + # is supplied, or a json filename all of which build the topology by calling + # Topogen methods which call Mininet(Micronet) methods to create the actual + # topology. + if not inspect.isclass(topodef): + if callable(topodef): + topodef(self) + self.net.configure_hosts() + elif is_string(topodef): + # topojson imports topogen in one function too, + # switch away from this use here to the topojson + # fixutre and remove this case + from lib.topojson import build_topo_from_json + with open(topodef, "r") as topof: + self.json_topo = json.load(topof) + build_topo_from_json(self, self.json_topo) + self.net.configure_hosts() + elif topodef: + self.add_topology_from_dict(topodef) + + def add_topology_from_dict(self, topodef): + + keylist = topodef.keys() if isinstance(topodef, OrderedDict) else sorted(topodef.keys()) + # --------------------------- + # Create all referenced hosts + # --------------------------- + for oname in keylist: + tup = (topodef[oname],) if is_string(topodef[oname]) else topodef[oname] + for e in tup: + desc = e.split(":") + name = desc[0] + if name not in self.gears: + logging.debug("Adding router: %s", name) + self.add_router(name) + + # ------------------------------ + # Create all referenced switches + # ------------------------------ + for oname in keylist: + if oname is not None and oname not in self.gears: + logging.debug("Adding switch: %s", oname) + self.add_switch(oname) + + # ---------------- + # Create all links + # ---------------- + for oname in keylist: + if oname is None: + continue + tup = (topodef[oname],) if is_string(topodef[oname]) else topodef[oname] + for e in tup: + desc = e.split(":") + name = desc[0] + ifname = desc[1] if len(desc) > 1 else None + sifname = desc[2] if len(desc) > 2 else None + self.add_link(self.gears[oname], self.gears[name], sifname, ifname) + + self.net.configure_hosts() def _load_config(self): """ @@ -167,7 +297,7 @@ class Topogen(object): pytestini_path = os.path.join(CWD, "../pytest.ini") self.config.read(pytestini_path) - def add_router(self, name=None, cls=topotest.Router, **params): + def add_router(self, name=None, cls=None, **params): """ Adds a new router to the topology. This function has the following options: @@ -176,6 +306,8 @@ class Topogen(object): * `routertype`: (optional) `frr` Returns a TopoRouter. """ + if cls is None: + cls = topotest.Router if name is None: name = "r{}".format(self.routern) if name in self.gears: @@ -190,7 +322,7 @@ class Topogen(object): self.routern += 1 return self.gears[name] - def add_switch(self, name=None, cls=topotest.LegacySwitch): + def add_switch(self, name=None): """ Adds a new switch to the topology. This function has the following options: @@ -202,7 +334,7 @@ class Topogen(object): if name in self.gears: raise KeyError("switch already exists") - self.gears[name] = TopoSwitch(self, cls, name) + self.gears[name] = TopoSwitch(self, name) self.switchn += 1 return self.gears[name] @@ -258,7 +390,10 @@ class Topogen(object): node1.register_link(ifname1, node2, ifname2) node2.register_link(ifname2, node1, ifname1) - self.topo.addLink(node1.name, node2.name, intfName1=ifname1, intfName2=ifname2) + if self.net: + self.net.add_link(node1.name, node2.name, ifname1, ifname2) + else: + self.topo.addLink(node1.name, node2.name, intfName1=ifname1, intfName2=ifname2) def get_gears(self, geartype): """ @@ -300,27 +435,8 @@ class Topogen(object): """ return self.get_gears(TopoExaBGP) - def start_topology(self, log_level=None): - """ - Starts the topology class. Possible `log_level`s are: - 'debug': all information possible - 'info': informational messages - 'output': default logging level defined by Mininet - 'warning': only warning, error and critical messages - 'error': only error and critical messages - 'critical': only critical messages - """ - # If log_level is not specified use the configuration. - if log_level is None: - log_level = self.config.get(self.CONFIG_SECTION, "verbosity") - - # Set python logger level - logger_config.set_log_level(log_level) - - # Run mininet - if log_level == "debug": - setLogLevel(log_level) - + def start_topology(self): + """Starts the topology class.""" logger.info("starting topology: {}".format(self.modname)) self.net.start() @@ -331,6 +447,7 @@ class Topogen(object): """ if router is None: # pylint: disable=r1704 + # XXX should be hosts? for _, router in self.routers().items(): router.start() else: @@ -358,17 +475,19 @@ class Topogen(object): self.net.stop() - def mininet_cli(self): + def get_exabgp_cmd(self): + if not self.exabgp_cmd: + self.exabgp_cmd = get_exabgp_cmd(self.net) + return self.exabgp_cmd + + def cli(self): """ Interrupt the test and call the command line interface for manual inspection. Should be only used on non production code. """ - if not sys.stdin.isatty(): - raise EnvironmentError( - "you must run pytest with '-s' in order to use mininet CLI" - ) + self.net.cli() - CLI(self.net) + mininet_cli = cli def is_memleak_enabled(self): "Returns `True` if memory leak report is enable, otherwise `False`." @@ -438,13 +557,18 @@ class Topogen(object): class TopoGear(object): "Abstract class for type checking" - def __init__(self): - self.tgen = None - self.name = None - self.cls = None + def __init__(self, tgen, name, **params): + self.tgen = tgen + self.name = name + self.params = params self.links = {} self.linkn = 0 + # Would be nice for this to point at the gears log directory rather than the + # test's. + self.logdir = tgen.logdir + self.gearlogdir = None + def __str__(self): links = "" for myif, dest in self.links.items(): @@ -455,27 +579,42 @@ class TopoGear(object): return 'TopoGear'.format(self.name, links) + @property + def net(self): + return self.tgen.net[self.name] + def start(self): "Basic start function that just reports equipment start" logger.info('starting "{}"'.format(self.name)) def stop(self, wait=True, assertOnError=True): - "Basic start function that just reports equipment stop" - logger.info('stopping "{}"'.format(self.name)) + "Basic stop function that just reports equipment stop" + logger.info('"{}" base stop called'.format(self.name)) return "" - def run(self, command): + def cmd(self, command, **kwargs): """ Runs the provided command string in the router and returns a string with the response. """ - return self.tgen.net[self.name].cmd(command) + return self.net.cmd_legacy(command, **kwargs) + + def cmd_raises(self, command, **kwargs): + """ + Runs the provided command string in the router and returns a string + with the response. Raise an exception on any error. + """ + return self.net.cmd_raises(command, **kwargs) + + run = cmd def popen(self, *params, **kwargs): """ - Popen on the router. + Creates a pipe with the given command. Same args as python Popen. + If `command` is a string then will be invoked with shell, otherwise + `command` is a list and will be invoked w/o shell. Returns a popen object. """ - return self.tgen.net[self.name].popen(*params, **kwargs) + return self.net.popen(*params, **kwargs) def add_link(self, node, myif=None, nodeif=None): """ @@ -508,6 +647,7 @@ class TopoGear(object): extract = "" if netns is not None: extract = "ip netns exec {} ".format(netns) + return self.run("{}ip link set dev {} {}".format(extract, myif, operation)) def peer_link_enable(self, myif, enabled=True, netns=None): @@ -546,6 +686,11 @@ class TopoGear(object): self.links[myif] = (node, nodeif) + def _setup_tmpdir(self): + topotest.setup_node_tmpdir(self.logdir, self.name) + self.gearlogdir = "{}/{}".format(self.logdir, self.name) + return "{}/{}.log".format(self.logdir, self.name) + class TopoRouter(TopoGear): """ @@ -555,6 +700,7 @@ class TopoRouter(TopoGear): # The default required directories by FRR PRIVATE_DIRS = [ "/etc/frr", + "/etc/snmp", "/var/run/frr", "/var/log", ] @@ -608,66 +754,28 @@ class TopoRouter(TopoGear): * daemondir: daemon binary directory * routertype: 'frr' """ - super(TopoRouter, self).__init__() - self.tgen = tgen - self.net = None - self.name = name - self.cls = cls - self.options = {} + super(TopoRouter, self).__init__(tgen, name, **params) self.routertype = params.get("routertype", "frr") if "privateDirs" not in params: params["privateDirs"] = self.PRIVATE_DIRS - self.options["memleak_path"] = params.get("memleak_path", None) - - # Create new log directory - self.logdir = "/tmp/topotests/{}".format(self.tgen.modname) - # Clean up before starting new log files: avoids removing just created - # log files. - self._prepare_tmpfiles() # Propagate the router log directory + logfile = self._setup_tmpdir() params["logdir"] = self.logdir - # setup the per node directory - dir = "{}/{}".format(self.logdir, self.name) - os.system("mkdir -p " + dir) - os.system("chmod -R go+rw /tmp/topotests") + self.logger = topolog.get_logger(name, log_level="debug", target=logfile) + params["logger"] = self.logger + tgen.net.add_host(self.name, cls=cls, **params) + topotest.fix_netns_limits(tgen.net[name]) - # Open router log file - logfile = "{0}/{1}.log".format(self.logdir, name) - self.logger = logger_config.get_logger(name=name, target=logfile) - - self.tgen.topo.addNode(self.name, cls=self.cls, **params) + # Mount gear log directory on a common path + self.net.bind_mount(self.gearlogdir, "/tmp/gearlogdir") def __str__(self): gear = super(TopoRouter, self).__str__() gear += " TopoRouter<>" return gear - def _prepare_tmpfiles(self): - # Create directories if they don't exist - try: - os.makedirs(self.logdir, 0o755) - except OSError: - pass - - # Allow unprivileged daemon user (frr) to create log files - try: - # Only allow group, if it exist. - gid = grp.getgrnam(self.routertype)[2] - os.chown(self.logdir, 0, gid) - os.chmod(self.logdir, 0o775) - except KeyError: - # Allow anyone, but set the sticky bit to avoid file deletions - os.chmod(self.logdir, 0o1777) - - # Try to find relevant old logfiles in /tmp and delete them - map(os.remove, glob.glob("{}/{}/*.log".format(self.logdir, self.name))) - # Remove old valgrind files - map(os.remove, glob.glob("{}/{}.valgrind.*".format(self.logdir, self.name))) - # Remove old core files - map(os.remove, glob.glob("{}/{}/*.dmp".format(self.logdir, self.name))) - def check_capability(self, daemon, param): """ Checks a capability daemon against an argument option @@ -675,7 +783,7 @@ class TopoRouter(TopoGear): """ daemonstr = self.RD.get(daemon) self.logger.info('check capability {} for "{}"'.format(param, daemonstr)) - return self.tgen.net[self.name].checkCapability(daemonstr, param) + return self.net.checkCapability(daemonstr, param) def load_config(self, daemon, source=None, param=None): """ @@ -684,17 +792,20 @@ class TopoRouter(TopoGear): TopoRouter.RD_RIPNG, TopoRouter.RD_OSPF, TopoRouter.RD_OSPF6, TopoRouter.RD_ISIS, TopoRouter.RD_BGP, TopoRouter.RD_LDP, TopoRouter.RD_PIM, TopoRouter.RD_PBR, TopoRouter.RD_SNMP. + + This API unfortunately allows for source to not exist for any and + all routers. """ daemonstr = self.RD.get(daemon) self.logger.info('loading "{}" configuration: {}'.format(daemonstr, source)) - self.tgen.net[self.name].loadConf(daemonstr, source, param) + self.net.loadConf(daemonstr, source, param) def check_router_running(self): """ Run a series of checks and returns a status string. """ self.logger.info("checking if daemons are running") - return self.tgen.net[self.name].checkRouterRunning() + return self.net.checkRouterRunning() def start(self): """ @@ -705,46 +816,41 @@ class TopoRouter(TopoGear): * Start daemons (e.g. FRR) * Configure daemon logging files """ - self.logger.debug("starting") - nrouter = self.tgen.net[self.name] + + nrouter = self.net result = nrouter.startRouter(self.tgen) + # Enable command logging + # Enable all daemon command logging, logging files # and set them to the start dir. for daemon, enabled in nrouter.daemons.items(): - if enabled == 0: - continue - self.vtysh_cmd( - "configure terminal\nlog commands\nlog file {}.log".format(daemon), - daemon=daemon, - ) + if enabled and daemon != "snmpd": + self.vtysh_cmd( + "\n".join(["clear log cmdline-targets", + "conf t", + "log file {}.log debug".format(daemon), + "log commands", + "log timestamp precision 3"]), + daemon=daemon, + ) if result != "": self.tgen.set_error(result) - else: + elif nrouter.daemons["ldpd"] == 1 or nrouter.daemons["pathd"] == 1: # Enable MPLS processing on all interfaces. - for interface in self.links.keys(): - set_sysctl(nrouter, "net.mpls.conf.{}.input".format(interface), 1) + for interface in self.links: + topotest.sysctl_assure(nrouter, "net.mpls.conf.{}.input".format(interface), 1) return result - def __stop_internal(self, wait=True, assertOnError=True): - """ - Stop router, private internal version - * Kill daemons - """ - self.logger.debug("stopping: wait {}, assert {}".format(wait, assertOnError)) - return self.tgen.net[self.name].stopRouter(wait, assertOnError) - def stop(self): """ Stop router cleanly: - * Signal daemons twice, once without waiting, and then a second time - with a wait to ensure the daemons exit cleanly + * Signal daemons twice, once with SIGTERM, then with SIGKILL. """ - self.logger.debug("stopping") - self.__stop_internal(False, False) - return self.__stop_internal(True, False) + self.logger.debug("stopping (no assert)") + return self.net.stopRouter(False) def startDaemons(self, daemons): """ @@ -753,17 +859,23 @@ class TopoRouter(TopoGear): * Configure daemon logging files """ self.logger.debug("starting") - nrouter = self.tgen.net[self.name] + nrouter = self.net result = nrouter.startRouterDaemons(daemons) + if daemons is None: + daemons = nrouter.daemons.keys() + # Enable all daemon command logging, logging files # and set them to the start dir. - for daemon, enabled in nrouter.daemons.items(): - for d in daemons: - if enabled == 0: - continue + for daemon in daemons: + enabled = nrouter.daemons[daemon] + if enabled and daemon != "snmpd": self.vtysh_cmd( - "configure terminal\nlog commands\nlog file {}.log".format(daemon), + "\n".join(["clear log cmdline-targets", + "conf t", + "log file {}.log debug".format(daemon), + "log commands", + "log timestamp precision 3"]), daemon=daemon, ) @@ -778,7 +890,7 @@ class TopoRouter(TopoGear): forcefully using SIGKILL """ self.logger.debug("Killing daemons using SIGKILL..") - return self.tgen.net[self.name].killRouterDaemons(daemons, wait, assertOnError) + return self.net.killRouterDaemons(daemons, wait, assertOnError) def vtysh_cmd(self, command, isjson=False, daemon=None): """ @@ -798,10 +910,17 @@ class TopoRouter(TopoGear): vtysh_command = 'vtysh {} -c "{}" 2>/dev/null'.format(dparam, command) + self.logger.info('vtysh command => "{}"'.format(command)) output = self.run(vtysh_command) - self.logger.info( - "\nvtysh command => {}\nvtysh output <= {}".format(command, output) - ) + + dbgout = output.strip() + if dbgout: + if "\n" in dbgout: + dbgout = dbgout.replace("\n", "\n\t") + self.logger.info('vtysh result:\n\t{}'.format(dbgout)) + else: + self.logger.info('vtysh result: "{}"'.format(dbgout)) + if isjson is False: return output @@ -833,13 +952,20 @@ class TopoRouter(TopoGear): else: vtysh_command = "vtysh {} -f {}".format(dparam, fname) + dbgcmds = commands if is_string(commands) else "\n".join(commands) + dbgcmds = "\t" + dbgcmds.replace("\n", "\n\t") + self.logger.info('vtysh command => FILE:\n{}'.format(dbgcmds)) + res = self.run(vtysh_command) os.unlink(fname) - self.logger.info( - '\nvtysh command => "{}"\nvtysh output <= "{}"'.format(vtysh_command, res) - ) - + dbgres = res.strip() + if dbgres: + if "\n" in dbgres: + dbgres = dbgres.replace("\n", "\n\t") + self.logger.info('vtysh result:\n\t{}'.format(dbgres)) + else: + self.logger.info('vtysh result: "{}"'.format(dbgres)) return res def report_memory_leaks(self, testname): @@ -851,7 +977,7 @@ class TopoRouter(TopoGear): TOPOTESTS_CHECK_MEMLEAK set or memleak_path configured in `pytest.ini`. """ memleak_file = ( - os.environ.get("TOPOTESTS_CHECK_MEMLEAK") or self.options["memleak_path"] + os.environ.get("TOPOTESTS_CHECK_MEMLEAK") or self.params["memleak_path"] ) if memleak_file == "" or memleak_file == None: return @@ -859,7 +985,7 @@ class TopoRouter(TopoGear): self.stop() self.logger.info("running memory leak report") - self.tgen.net[self.name].report_memory_leaks(memleak_file, testname) + self.net.report_memory_leaks(memleak_file, testname) def version_info(self): "Get equipment information from 'show version'." @@ -888,7 +1014,7 @@ class TopoRouter(TopoGear): Usage example: router.has_version('>', '1.0') """ - return self.tgen.net[self.name].checkRouterVersion(cmpop, version) + return self.net.checkRouterVersion(cmpop, version) def has_type(self, rtype): """ @@ -899,8 +1025,7 @@ class TopoRouter(TopoGear): return rtype == curtype def has_mpls(self): - nrouter = self.tgen.net[self.name] - return nrouter.hasmpls + return self.net.hasmpls class TopoSwitch(TopoGear): @@ -912,13 +1037,9 @@ class TopoSwitch(TopoGear): # pylint: disable=too-few-public-methods - def __init__(self, tgen, cls, name): - super(TopoSwitch, self).__init__() - self.tgen = tgen - self.net = None - self.name = name - self.cls = cls - self.tgen.topo.addSwitch(name, cls=self.cls) + def __init__(self, tgen, name, **params): + super(TopoSwitch, self).__init__(tgen, name, **params) + tgen.net.add_switch(name) def __str__(self): gear = super(TopoSwitch, self).__str__() @@ -939,19 +1060,27 @@ class TopoHost(TopoGear): * `privateDirs`: directories that will be mounted on a different domain (e.g. '/etc/important_dir'). """ - super(TopoHost, self).__init__() - self.tgen = tgen - self.net = None - self.name = name - self.options = params - self.tgen.topo.addHost(name, **params) + super(TopoHost, self).__init__(tgen, name, **params) + + # Propagate the router log directory + logfile = self._setup_tmpdir() + params["logdir"] = self.logdir + + # Odd to have 2 logfiles for each host + self.logger = topolog.get_logger(name, log_level="debug", target=logfile) + params["logger"] = self.logger + tgen.net.add_host(name, **params) + topotest.fix_netns_limits(tgen.net[name]) + + # Mount gear log directory on a common path + self.net.bind_mount(self.gearlogdir, "/tmp/gearlogdir") def __str__(self): gear = super(TopoHost, self).__str__() gear += ' TopoHost'.format( - self.options["ip"], - self.options["defaultRoute"], - str(self.options["privateDirs"]), + self.params["ip"], + self.params["defaultRoute"], + str(self.params["privateDirs"]), ) return gear @@ -979,7 +1108,6 @@ class TopoExaBGP(TopoHost): """ params["privateDirs"] = self.PRIVATE_DIRS super(TopoExaBGP, self).__init__(tgen, name, **params) - self.tgen.topo.addHost(name, **params) def __str__(self): gear = super(TopoExaBGP, self).__str__() @@ -994,7 +1122,10 @@ class TopoExaBGP(TopoHost): * Make all python files runnable * Run ExaBGP with env file `env_file` and configuration peer*/exabgp.cfg """ - self.run("mkdir /etc/exabgp") + exacmd = self.tgen.get_exabgp_cmd() + assert exacmd, "Can't find a usabel ExaBGP (must be < version 4)" + + self.run("mkdir -p /etc/exabgp") self.run("chmod 755 /etc/exabgp") self.run("cp {}/* /etc/exabgp/".format(peer_dir)) if env_file is not None: @@ -1002,9 +1133,11 @@ class TopoExaBGP(TopoHost): self.run("chmod 644 /etc/exabgp/*") self.run("chmod a+x /etc/exabgp/*.py") self.run("chown -R exabgp:exabgp /etc/exabgp") - output = self.run("exabgp -e /etc/exabgp/exabgp.env /etc/exabgp/exabgp.cfg") + + output = self.run(exacmd + " -e /etc/exabgp/exabgp.env /etc/exabgp/exabgp.cfg") if output == None or len(output) == 0: output = "" + logger.info("{} exabgp started, output={}".format(self.name, output)) def stop(self, wait=True, assertOnError=True): @@ -1019,42 +1152,38 @@ class TopoExaBGP(TopoHost): # Disable linter branch warning. It is expected to have these here. # pylint: disable=R0912 -def diagnose_env_linux(): +def diagnose_env_linux(rundir): """ Run diagnostics in the running environment. Returns `True` when everything is ok, otherwise `False`. """ ret = True - # Test log path exists before installing handler. - if not os.path.isdir("/tmp"): - logger.warning("could not find /tmp for logs") - else: - os.system("mkdir -p /tmp/topotests") - # Log diagnostics to file so it can be examined later. - fhandler = logging.FileHandler(filename="/tmp/topotests/diagnostics.txt") - fhandler.setLevel(logging.DEBUG) - fhandler.setFormatter( - logging.Formatter(fmt="%(asctime)s %(levelname)s: %(message)s") - ) - logger.addHandler(fhandler) - - logger.info("Running environment diagnostics") - # Load configuration config = configparser.ConfigParser(defaults=tgen_defaults) pytestini_path = os.path.join(CWD, "../pytest.ini") config.read(pytestini_path) + # Test log path exists before installing handler. + os.system("mkdir -p " + rundir) + # Log diagnostics to file so it can be examined later. + fhandler = logging.FileHandler(filename="{}/diagnostics.txt".format(rundir)) + fhandler.setLevel(logging.DEBUG) + fhandler.setFormatter(logging.Formatter(fmt=topolog.FORMAT)) + logger.addHandler(fhandler) + + logger.info("Running environment diagnostics") + + # Assert that we are running as root if os.getuid() != 0: logger.error("you must run topotest as root") ret = False # Assert that we have mininet - if os.system("which mn >/dev/null 2>/dev/null") != 0: - logger.error("could not find mininet binary (mininet is not installed)") - ret = False + # if os.system("which mn >/dev/null 2>/dev/null") != 0: + # logger.error("could not find mininet binary (mininet is not installed)") + # ret = False # Assert that we have iproute installed if os.system("which ip >/dev/null 2>/dev/null") != 0: @@ -1118,7 +1247,7 @@ def diagnose_env_linux(): if fname != "zebra": continue - os.system("{} -v 2>&1 >/tmp/topotests/frr_zebra.txt".format(path)) + os.system("{} -v 2>&1 >{}/frr_zebra.txt".format(path, rundir)) # Test MPLS availability krel = platform.release() @@ -1135,23 +1264,9 @@ def diagnose_env_linux(): if not topotest.module_present("mpls-iptunnel", load=False) != 0: logger.info("LDPd tests will not run (missing mpls-iptunnel kernel module)") - # TODO remove me when we start supporting exabgp >= 4 - try: - p = os.popen("exabgp -v") - line = p.readlines() - version = line[0].split() - if topotest.version_cmp(version[2], "4") >= 0: - logger.warning( - "BGP topologies are still using exabgp version 3, expect failures" - ) - p.close() + if not get_exabgp_cmd(): + logger.warning("Failed to find exabgp < 4") - # We want to catch all exceptions - # pylint: disable=W0702 - except: - logger.warning("failed to find exabgp or returned error") - - # After we logged the output to file, remove the handler. logger.removeHandler(fhandler) fhandler.close() @@ -1162,9 +1277,9 @@ def diagnose_env_freebsd(): return True -def diagnose_env(): +def diagnose_env(rundir): if sys.platform.startswith("linux"): - return diagnose_env_linux() + return diagnose_env_linux(rundir) elif sys.platform.startswith("freebsd"): return diagnose_env_freebsd() diff --git a/tests/topotests/lib/topojson.py b/tests/topotests/lib/topojson.py index 003a971373..710a7b0cc6 100644 --- a/tests/topotests/lib/topojson.py +++ b/tests/topotests/lib/topojson.py @@ -18,34 +18,27 @@ # OF THIS SOFTWARE. # -from collections import OrderedDict -from json import dumps as json_dumps -from re import search as re_search +import json import ipaddress -import pytest -import ipaddr +import os +from collections import OrderedDict from copy import deepcopy +from re import search as re_search +import ipaddr +import pytest -# Import topogen and topotest helpers -from lib.topolog import logger - -# Required to instantiate the topology builder class. -from lib.common_config import ( - number_to_row, - number_to_column, - load_config_to_routers, - create_interfaces_cfg, - create_static_routes, - create_prefix_lists, - create_route_maps, - create_bgp_community_lists, - create_vrf_cfg, -) - -from lib.pim import create_pim_config, create_igmp_config from lib.bgp import create_router_bgp +from lib.common_config import (create_bgp_community_lists, + create_interfaces_cfg, create_prefix_lists, + create_route_maps, create_static_routes, + create_vrf_cfg, load_config_to_routers, + start_topology, + topo_daemons, + number_to_column) from lib.ospf import create_router_ospf, create_router_ospf6 +from lib.pim import create_igmp_config, create_pim_config +from lib.topolog import logger ROUTER_LIST = [] @@ -60,13 +53,13 @@ def build_topo_from_json(tgen, topo): """ ROUTER_LIST = sorted( - topo["routers"].keys(), key=lambda x: int(re_search("\d+", x).group(0)) + topo["routers"].keys(), key=lambda x: int(re_search(r"\d+", x).group(0)) ) SWITCH_LIST = [] if "switches" in topo: SWITCH_LIST = sorted( - topo["switches"].keys(), key=lambda x: int(re_search("\d+", x).group(0)) + topo["switches"].keys(), key=lambda x: int(re_search(r"\d+", x).group(0)) ) listRouters = sorted(ROUTER_LIST[:]) @@ -204,7 +197,7 @@ def build_topo_from_json(tgen, topo): logger.debug( "Generated link data for router: %s\n%s", curRouter, - json_dumps( + json.dumps( topo["routers"][curRouter]["links"], indent=4, sort_keys=True ), ) @@ -287,7 +280,7 @@ def build_topo_from_json(tgen, topo): logger.debug( "Generated link data for router: %s\n%s", curRouter, - json_dumps( + json.dumps( topo["routers"][curRouter]["links"], indent=4, sort_keys=True ), ) @@ -297,7 +290,7 @@ def linux_intf_config_from_json(tgen, topo): """Configure interfaces from linux based on topo.""" routers = topo["routers"] for rname in routers: - router = tgen.gears[rname] + router = tgen.net[rname] links = routers[rname]["links"] for rrname in links: link = links[rrname] @@ -306,9 +299,9 @@ def linux_intf_config_from_json(tgen, topo): else: lname = link["interface"] if "ipv4" in link: - router.run("ip addr add {} dev {}".format(link["ipv4"], lname)) + router.cmd_raises("ip addr add {} dev {}".format(link["ipv4"], lname)) if "ipv6" in link: - router.run("ip -6 addr add {} dev {}".format(link["ipv6"], lname)) + router.cmd_raises("ip -6 addr add {} dev {}".format(link["ipv6"], lname)) def build_config_from_json(tgen, topo, save_bkup=True): @@ -347,3 +340,50 @@ def build_config_from_json(tgen, topo, save_bkup=True): if not result: logger.info("build_config_from_json: failed to configure topology") pytest.exit(1) + + +def create_tgen_from_json(testfile, json_file=None): + """Create a topogen object given a testfile. + + - `testfile` : The path to the testfile. + - `json_file` : The path to the json config file. If None the pathname is derived + from the `testfile` first by trying to replace `.py` by `.json` and if that isn't + present then by removing `test_` prefix as well. + """ + from lib.topogen import Topogen # Topogen imports this module too + thisdir = os.path.dirname(os.path.realpath(testfile)) + basename = os.path.basename(testfile) + logger.debug("starting standard JSON based module setup for %s", basename) + + assert basename.startswith("test_") + assert basename.endswith(".py") + json_file = os.path.join(thisdir, basename[:-3] + ".json") + if not os.path.exists(json_file): + json_file = os.path.join(thisdir, basename[5:-3] + ".json") + assert os.path.exists(json_file) + with open(json_file, "r") as topof: + topo = json.load(topof) + + # Create topology + tgen = Topogen(lambda tgen: build_topo_from_json(tgen, topo), basename[:-3]) + tgen.json_topo = topo + return tgen + + +def setup_module_from_json(testfile, json_file=None): + """Do the standard module setup for JSON based test. + + * `testfile` : The path to the testfile. The name is used to derive the json config + file name as well (removing `test_` prefix and replacing `.py` suffix with `.json` + """ + # Create topology object + tgen = create_tgen_from_json(testfile, json_file) + + # Start routers (and their daemons) + start_topology(tgen, topo_daemons(tgen)) + + # Configure routers + build_config_from_json(tgen) + assert not tgen.routers_have_failure() + + return tgen diff --git a/tests/topotests/lib/topolog.py b/tests/topotests/lib/topolog.py index 9fde01cca0..06e4fa066c 100644 --- a/tests/topotests/lib/topolog.py +++ b/tests/topotests/lib/topolog.py @@ -26,8 +26,23 @@ Logging utilities for topology tests. This file defines our logging abstraction. """ -import sys import logging +import os +import subprocess +import sys + +if sys.version_info[0] > 2: + import configparser +else: + import ConfigParser as configparser + +try: + from xdist import is_xdist_controller +except ImportError: + def is_xdist_controller(): + return False + +BASENAME = "topolog" # Helper dictionary to convert Topogen logging levels to Python's logging. DEBUG_TOPO2LOGGING = { @@ -38,81 +53,121 @@ DEBUG_TOPO2LOGGING = { "error": logging.ERROR, "critical": logging.CRITICAL, } +FORMAT = "%(asctime)s.%(msecs)03d %(levelname)s: %(name)s: %(message)s" + +handlers = {} +logger = logging.getLogger("topolog") -class InfoFilter(logging.Filter): - def filter(self, rec): - return rec.levelno in (logging.DEBUG, logging.INFO) - - -# -# Logger class definition -# - - -class Logger(object): - """ - Logger class that encapsulates logging functions, internaly it uses Python - logging module with a separated instance instead of global. - - Default logging level is 'info'. - """ - - def __init__(self): - # Create default global logger - self.log_level = logging.INFO - self.logger = logging.Logger("topolog", level=self.log_level) - - handler_stdout = logging.StreamHandler(sys.stdout) - handler_stdout.setLevel(logging.DEBUG) - handler_stdout.addFilter(InfoFilter()) - handler_stdout.setFormatter( - logging.Formatter(fmt="%(asctime)s %(levelname)s: %(message)s") - ) - handler_stderr = logging.StreamHandler() - handler_stderr.setLevel(logging.WARNING) - handler_stderr.setFormatter( - logging.Formatter(fmt="%(asctime)s %(levelname)s: %(message)s") - ) - - self.logger.addHandler(handler_stdout) - self.logger.addHandler(handler_stderr) - - # Handle more loggers - self.loggers = {"topolog": self.logger} - - def set_log_level(self, level): - "Set the logging level" - self.log_level = DEBUG_TOPO2LOGGING.get(level) - self.logger.setLevel(self.log_level) - - def get_logger(self, name="topolog", log_level=None, target=sys.stdout): - """ - Get a new logger entry. Allows creating different loggers for formating, - filtering or handling (file, stream or stdout/stderr). - """ - if log_level is None: - log_level = self.log_level - if name in self.loggers: - return self.loggers[name] - - nlogger = logging.Logger(name, level=log_level) +def set_handler(l, target=None): + if target is None: + h = logging.NullHandler() + else: if isinstance(target, str): - handler = logging.FileHandler(filename=target) + h = logging.FileHandler(filename=target, mode="w") else: - handler = logging.StreamHandler(stream=target) - - handler.setFormatter( - logging.Formatter(fmt="%(asctime)s %(levelname)s: %(message)s") - ) - nlogger.addHandler(handler) - self.loggers[name] = nlogger - return nlogger + h = logging.StreamHandler(stream=target) + h.setFormatter(logging.Formatter(fmt=FORMAT)) + # Don't filter anything at the handler level + h.setLevel(logging.DEBUG) + l.addHandler(h) + return h -# -# Global variables -# +def set_log_level(l, level): + "Set the logging level." + # Messages sent to this logger only are created if this level or above. + log_level = DEBUG_TOPO2LOGGING.get(level, level) + l.setLevel(log_level) -logger_config = Logger() -logger = logger_config.logger + +def get_logger(name, log_level=None, target=None): + l = logging.getLogger("{}.{}".format(BASENAME, name)) + + if log_level is not None: + set_log_level(l, log_level) + + if target is not None: + set_handler(l, target) + + return l + + +# nodeid: all_protocol_startup/test_all_protocol_startup.py::test_router_running + +def get_test_logdir(nodeid=None): + """Get log directory relative pathname.""" + xdist_worker = os.getenv("PYTEST_XDIST_WORKER", "") + mode = os.getenv("PYTEST_XDIST_MODE", "no") + + if not nodeid: + nodeid = os.environ["PYTEST_CURRENT_TEST"].split(" ")[0] + + cur_test = nodeid.replace("[", "_").replace("]", "_") + path, testname = cur_test.split("::") + path = path[:-3].replace("/", ".") + + # We use different logdir paths based on how xdist is running. + if mode == "each": + return os.path.join(path, testname, xdist_worker) + elif mode == "load": + return os.path.join(path, testname) + else: + assert ( + mode == "no" or + mode == "loadfile" or + mode == "loadscope" + ), "Unknown dist mode {}".format(mode) + + return path + + +def logstart(nodeid, location, rundir): + """Called from pytest before module setup.""" + + mode = os.getenv("PYTEST_XDIST_MODE", "no") + worker = os.getenv("PYTEST_TOPOTEST_WORKER", "") + + # We only per-test log in the workers (or non-dist) + if not worker and mode != "no": + return + + handler_id = nodeid + worker + assert handler_id not in handlers + + rel_log_dir = get_test_logdir(nodeid) + exec_log_dir = os.path.join(rundir, rel_log_dir) + subprocess.check_call("mkdir -p {0} && chmod 1777 {0}".format(exec_log_dir), shell=True) + exec_log_path = os.path.join(exec_log_dir, "exec.log") + + # Add test based exec log handler + h = set_handler(logger, exec_log_path) + handlers[handler_id] = h + + if worker: + logger.info("Logging on worker %s for %s into %s", worker, handler_id, exec_log_path) + else: + logger.info("Logging for %s into %s", handler_id, exec_log_path) + + +def logfinish(nodeid, location): + """Called from pytest after module teardown.""" + # This function may not be called if pytest is interrupted. + + worker = os.getenv("PYTEST_TOPOTEST_WORKER", "") + handler_id = nodeid + worker + + if handler_id in handlers: + # Remove test based exec log handler + if worker: + logger.info("Closing logs for %s", handler_id) + + h = handlers[handler_id] + logger.removeHandler(handlers[handler_id]) + h.flush() + h.close() + del handlers[handler_id] + + +console_handler = set_handler(logger, None) +set_log_level(logger, "debug") diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index 6112b4b633..611230064f 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -22,38 +22,40 @@ # OF THIS SOFTWARE. # -import json -import os +import difflib import errno -import re -import sys import functools import glob -import subprocess -import tempfile +import json +import os +import pdb import platform -import difflib -import time +import re +import resource import signal - -from lib.topolog import logger +import subprocess +import sys +import tempfile +import time from copy import deepcopy +import lib.topolog as topolog +from lib.topolog import logger + if sys.version_info[0] > 2: import configparser else: import ConfigParser as configparser -from mininet.topo import Topo -from mininet.net import Mininet -from mininet.node import Node, OVSSwitch, Host -from mininet.log import setLogLevel, info -from mininet.cli import CLI -from mininet.link import Intf -from mininet.term import makeTerm +from lib import micronet +from lib.micronet_compat import Node g_extra_config = {} +def get_logs_path(rundir): + logspath = topolog.get_test_logdir() + return os.path.join(rundir, logspath) + def gdb_core(obj, daemon, corefiles): gdbcmds = """ @@ -283,7 +285,7 @@ def json_cmp(d1, d2, exact=False): * `d2`: parsed JSON data structure Returns 'None' when all JSON Object keys and all Array elements of d2 have a match - in d1, e.g. when d2 is a "subset" of d1 without honoring any order. Otherwise an + in d1, i.e., when d2 is a "subset" of d1 without honoring any order. Otherwise an error report is generated and wrapped in a 'json_cmp_result()'. There are special parameters and notations explained below which can be used to cover rather unusual cases: @@ -497,6 +499,8 @@ def get_file(content): """ Generates a temporary file in '/tmp' with `content` and returns the file name. """ + if isinstance(content, list) or isinstance(content, tuple): + content = "\n".join(content) fde = tempfile.NamedTemporaryFile(mode="w", delete=False) fname = fde.name fde.write(content) @@ -991,7 +995,6 @@ def checkAddressSanitizerError(output, router, component, logdir=""): and (callingProc != "checkAddressSanitizerError") and (callingProc != "checkRouterCores") and (callingProc != "stopRouter") - and (callingProc != "__stop_internal") and (callingProc != "stop") and (callingProc != "stop_topology") and (callingProc != "checkRouterRunning") @@ -1026,7 +1029,7 @@ def checkAddressSanitizerError(output, router, component, logdir=""): return addressSanitizerError = re.search( - "(==[0-9]+==)ERROR: AddressSanitizer: ([^\s]*) ", output + r"(==[0-9]+==)ERROR: AddressSanitizer: ([^\s]*) ", output ) if addressSanitizerError: processAddressSanitizerError(addressSanitizerError, output, router, component) @@ -1042,7 +1045,7 @@ def checkAddressSanitizerError(output, router, component, logdir=""): with open(file, "r") as asanErrorFile: asanError = asanErrorFile.read() addressSanitizerError = re.search( - "(==[0-9]+==)ERROR: AddressSanitizer: ([^\s]*) ", asanError + r"(==[0-9]+==)ERROR: AddressSanitizer: ([^\s]*) ", asanError ) if addressSanitizerError: processAddressSanitizerError( @@ -1052,48 +1055,218 @@ def checkAddressSanitizerError(output, router, component, logdir=""): return False -def addRouter(topo, name): - "Adding a FRRouter to Topology" +def _sysctl_atleast(commander, variable, min_value): + if isinstance(min_value, tuple): + min_value = list(min_value) + is_list = isinstance(min_value, list) - MyPrivateDirs = [ - "/etc/frr", - "/var/run/frr", - "/var/log", - ] - if sys.platform.startswith("linux"): - return topo.addNode(name, cls=LinuxRouter, privateDirs=MyPrivateDirs) - elif sys.platform.startswith("freebsd"): - return topo.addNode(name, cls=FreeBSDRouter, privateDirs=MyPrivateDirs) + sval = commander.cmd_raises("sysctl -n " + variable).strip() + if is_list: + cur_val = [int(x) for x in sval.split()] + else: + cur_val = int(sval) + + set_value = False + if is_list: + for i, v in enumerate(cur_val): + if v < min_value[i]: + set_value = True + else: + min_value[i] = v + else: + if cur_val < min_value: + set_value = True + if set_value: + if is_list: + valstr = " ".join([str(x) for x in min_value]) + else: + valstr = str(min_value) + logger.info("Increasing sysctl %s from %s to %s", variable, cur_val, valstr) + commander.cmd_raises("sysctl -w {}=\"{}\"\n".format(variable, valstr)) -def set_sysctl(node, sysctl, value): - "Set a sysctl value and return None on success or an error string" - valuestr = "{}".format(value) - command = "sysctl {0}={1}".format(sysctl, valuestr) - cmdret = node.cmd(command) +def _sysctl_assure(commander, variable, value): + if isinstance(value, tuple): + value = list(value) + is_list = isinstance(value, list) - matches = re.search(r"([^ ]+) = ([^\s]+)", cmdret) - if matches is None: - return cmdret - if matches.group(1) != sysctl: - return cmdret - if matches.group(2) != valuestr: - return cmdret + sval = commander.cmd_raises("sysctl -n " + variable).strip() + if is_list: + cur_val = [int(x) for x in sval.split()] + else: + cur_val = sval - return None + set_value = False + if is_list: + for i, v in enumerate(cur_val): + if v != value[i]: + set_value = True + else: + value[i] = v + else: + if cur_val != str(value): + set_value = True + + if set_value: + if is_list: + valstr = " ".join([str(x) for x in value]) + else: + valstr = str(value) + logger.info("Changing sysctl %s from %s to %s", variable, cur_val, valstr) + commander.cmd_raises("sysctl -w {}=\"{}\"\n".format(variable, valstr)) -def assert_sysctl(node, sysctl, value): - "Set and assert that the sysctl is set with the specified value." - assert set_sysctl(node, sysctl, value) is None +def sysctl_atleast(commander, variable, min_value, raises=False): + try: + if commander is None: + commander = micronet.Commander("topotest") + return _sysctl_atleast(commander, variable, min_value) + except subprocess.CalledProcessError as error: + logger.warning( + "%s: Failed to assure sysctl min value %s = %s", + commander, variable, min_value + ) + if raises: + raise + + +def sysctl_assure(commander, variable, value, raises=False): + try: + if commander is None: + commander = micronet.Commander("topotest") + return _sysctl_assure(commander, variable, value) + except subprocess.CalledProcessError as error: + logger.warning( + "%s: Failed to assure sysctl value %s = %s", + commander, variable, value, exc_info=True + ) + if raises: + raise + + +def rlimit_atleast(rname, min_value, raises=False): + try: + cval = resource.getrlimit(rname) + soft, hard = cval + if soft < min_value: + nval = (min_value, hard if min_value < hard else min_value) + logger.info("Increasing rlimit %s from %s to %s", rname, cval, nval) + resource.setrlimit(rname, nval) + except subprocess.CalledProcessError as error: + logger.warning( + "Failed to assure rlimit [%s] = %s", + rname, min_value, exc_info=True + ) + if raises: + raise + + +def fix_netns_limits(ns): + + # Maximum read and write socket buffer sizes + sysctl_atleast(ns, "net.ipv4.tcp_rmem", [10*1024, 87380, 16*2**20]) + sysctl_atleast(ns, "net.ipv4.tcp_wmem", [10*1024, 87380, 16*2**20]) + + sysctl_assure(ns, "net.ipv4.conf.all.rp_filter", 0) + sysctl_assure(ns, "net.ipv4.conf.default.rp_filter", 0) + sysctl_assure(ns, "net.ipv4.conf.lo.rp_filter", 0) + + sysctl_assure(ns, "net.ipv4.conf.all.forwarding", 1) + sysctl_assure(ns, "net.ipv4.conf.default.forwarding", 1) + + # XXX if things fail look here as this wasn't done previously + sysctl_assure(ns, "net.ipv6.conf.all.forwarding", 1) + sysctl_assure(ns, "net.ipv6.conf.default.forwarding", 1) + + # ARP + sysctl_assure(ns, "net.ipv4.conf.default.arp_announce", 2) + sysctl_assure(ns, "net.ipv4.conf.default.arp_notify", 1) + # Setting this to 1 breaks topotests that rely on lo addresses being proxy arp'd for + sysctl_assure(ns, "net.ipv4.conf.default.arp_ignore", 0) + sysctl_assure(ns, "net.ipv4.conf.all.arp_announce", 2) + sysctl_assure(ns, "net.ipv4.conf.all.arp_notify", 1) + # Setting this to 1 breaks topotests that rely on lo addresses being proxy arp'd for + sysctl_assure(ns, "net.ipv4.conf.all.arp_ignore", 0) + + sysctl_assure(ns, "net.ipv4.icmp_errors_use_inbound_ifaddr", 1) + + # Keep ipv6 permanent addresses on an admin down + sysctl_assure(ns, "net.ipv6.conf.all.keep_addr_on_down", 1) + if version_cmp(platform.release(), "4.20") >= 0: + sysctl_assure(ns, "net.ipv6.route.skip_notify_on_dev_down", 1) + + sysctl_assure(ns, "net.ipv4.conf.all.ignore_routes_with_linkdown", 1) + sysctl_assure(ns, "net.ipv6.conf.all.ignore_routes_with_linkdown", 1) + + # igmp + sysctl_atleast(ns, "net.ipv4.igmp_max_memberships", 1000) + + # Use neigh information on selection of nexthop for multipath hops + sysctl_assure(ns, "net.ipv4.fib_multipath_use_neigh", 1) + + +def fix_host_limits(): + """Increase system limits.""" + + rlimit_atleast(resource.RLIMIT_NPROC, 8*1024) + rlimit_atleast(resource.RLIMIT_NOFILE, 16*1024) + sysctl_atleast(None, "fs.file-max", 16*1024) + sysctl_atleast(None, "kernel.pty.max", 16*1024) + + # Enable coredumps + # Original on ubuntu 17.x, but apport won't save as in namespace + # |/usr/share/apport/apport %p %s %c %d %P + sysctl_assure(None, "kernel.core_pattern", "%e_core-sig_%s-pid_%p.dmp") + sysctl_assure(None, "kernel.core_uses_pid", 1) + sysctl_assure(None, "fs.suid_dumpable", 1) + + # Maximum connection backlog + sysctl_atleast(None, "net.core.netdev_max_backlog", 4*1024) + + # Maximum read and write socket buffer sizes + sysctl_atleast(None, "net.core.rmem_max", 16 * 2**20) + sysctl_atleast(None, "net.core.wmem_max", 16 * 2**20) + + # Garbage Collection Settings for ARP and Neighbors + sysctl_atleast(None, "net.ipv4.neigh.default.gc_thresh2", 4*1024) + sysctl_atleast(None, "net.ipv4.neigh.default.gc_thresh3", 8*1024) + sysctl_atleast(None, "net.ipv6.neigh.default.gc_thresh2", 4*1024) + sysctl_atleast(None, "net.ipv6.neigh.default.gc_thresh3", 8*1024) + # Hold entries for 10 minutes + sysctl_assure(None, "net.ipv4.neigh.default.base_reachable_time_ms", 10 * 60 * 1000) + sysctl_assure(None, "net.ipv6.neigh.default.base_reachable_time_ms", 10 * 60 * 1000) + + # igmp + sysctl_assure(None, "net.ipv4.neigh.default.mcast_solicit", 10) + + # MLD + sysctl_atleast(None, "net.ipv6.mld_max_msf", 512) + + # Increase routing table size to 128K + sysctl_atleast(None, "net.ipv4.route.max_size", 128*1024) + sysctl_atleast(None, "net.ipv6.route.max_size", 128*1024) + + +def setup_node_tmpdir(logdir, name): + # Cleanup old log, valgrind, and core files. + subprocess.check_call( + "rm -rf {0}/{1}.valgrind.* {1}.*.asan {0}/{1}/".format( + logdir, name + ), + shell=True + ) + + # Setup the per node directory. + nodelogdir = "{}/{}".format(logdir, name) + subprocess.check_call("mkdir -p {0} && chmod 1777 {0}".format(nodelogdir), shell=True) + logfile = "{0}/{1}.log".format(logdir, name) + return logfile class Router(Node): "A Node with IPv4/IPv6 forwarding enabled" def __init__(self, name, **params): - super(Router, self).__init__(name, **params) - self.logdir = params.get("logdir") # Backward compatibility: # Load configuration defaults like topogen. @@ -1105,25 +1278,24 @@ class Router(Node): "memleak_path": "", } ) + self.config_defaults.read( os.path.join(os.path.dirname(os.path.realpath(__file__)), "../pytest.ini") ) # If this topology is using old API and doesn't have logdir # specified, then attempt to generate an unique logdir. + self.logdir = params.get("logdir") if self.logdir is None: - cur_test = os.environ["PYTEST_CURRENT_TEST"] - self.logdir = "/tmp/topotests/" + cur_test[ - cur_test.find("/") + 1 : cur_test.find(".py") - ].replace("/", ".") + self.logdir = get_logs_path(g_extra_config["rundir"]) - # If the logdir is not created, then create it and set the - # appropriated permissions. - if not os.path.isdir(self.logdir): - os.system("mkdir -p " + self.logdir + "/" + name) - os.system("chmod -R go+rw /tmp/topotests") - # Erase logs of previous run - os.system("rm -rf " + self.logdir + "/" + name) + if not params.get("logger"): + # If logger is present topogen has already set this up + logfile = setup_node_tmpdir(self.logdir, name) + l = topolog.get_logger(name, log_level="debug", target=logfile) + params["logger"] = l + + super(Router, self).__init__(name, **params) self.daemondir = None self.hasmpls = False @@ -1152,7 +1324,7 @@ class Router(Node): self.reportCores = True self.version = None - self.ns_cmd = "sudo nsenter -m -n -t {} ".format(self.pid) + self.ns_cmd = "sudo nsenter -a -t {} ".format(self.pid) try: # Allow escaping from running inside docker cgroup = open("/proc/1/cgroup").read() @@ -1202,118 +1374,87 @@ class Router(Node): def terminate(self): # Stop running FRR daemons self.stopRouter() - - # Disable forwarding - set_sysctl(self, "net.ipv4.ip_forward", 0) - set_sysctl(self, "net.ipv6.conf.all.forwarding", 0) super(Router, self).terminate() - os.system("chmod -R go+rw /tmp/topotests") + os.system("chmod -R go+rw " + self.logdir) # Return count of running daemons def listDaemons(self): ret = [] - rundaemons = self.cmd("ls -1 /var/run/%s/*.pid" % self.routertype) - errors = "" - if re.search(r"No such file or directory", rundaemons): - return 0 - if rundaemons is not None: - bet = rundaemons.split("\n") - for d in bet[:-1]: - daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip() - if daemonpid.isdigit() and pid_exists(int(daemonpid)): - ret.append(os.path.basename(d.rstrip().rsplit(".", 1)[0])) + rc, stdout, _ = self.cmd_status("ls -1 /var/run/%s/*.pid" % self.routertype, warn=False) + if rc: + return ret + for d in stdout.strip().split("\n"): + pidfile = d.strip() + try: + pid = int(self.cmd_raises("cat %s" % pidfile, warn=False).strip()) + name = os.path.basename(pidfile[:-4]) + # probably not compatible with bsd. + rc, _, _ = self.cmd_status("test -d /proc/{}".format(pid), warn=False) + if rc: + logger.warning("%s: %s exited leaving pidfile %s (%s)", self.name, name, pidfile, pid) + self.cmd("rm -- " + pidfile) + else: + ret.append((name, pid)) + except (subprocess.CalledProcessError, ValueError): + pass return ret - def stopRouter(self, wait=True, assertOnError=True, minErrorVersion="5.1"): + def stopRouter(self, assertOnError=True, minErrorVersion="5.1"): # Stop Running FRR Daemons - rundaemons = self.cmd("ls -1 /var/run/%s/*.pid" % self.routertype) - errors = "" - if re.search(r"No such file or directory", rundaemons): - return errors - if rundaemons is not None: - dmns = rundaemons.split("\n") - # Exclude empty string at end of list - for d in dmns[:-1]: - # Only check if daemonfilepath starts with / - # Avoids hang on "-> Connection closed" in above self.cmd() - if d[0] == '/': - daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip() - if daemonpid.isdigit() and pid_exists(int(daemonpid)): - daemonname = os.path.basename(d.rstrip().rsplit(".", 1)[0]) - logger.info("{}: stopping {}".format(self.name, daemonname)) - try: - os.kill(int(daemonpid), signal.SIGTERM) - except OSError as err: - if err.errno == errno.ESRCH: - logger.error( - "{}: {} left a dead pidfile (pid={})".format( - self.name, daemonname, daemonpid - ) - ) - else: - logger.info( - "{}: {} could not kill pid {}: {}".format( - self.name, daemonname, daemonpid, str(err) - ) - ) + running = self.listDaemons() + if not running: + return "" - if not wait: - return errors + logger.info("%s: stopping %s", self.name, ", ".join([x[0] for x in running])) + for name, pid in running: + logger.info("{}: sending SIGTERM to {}".format(self.name, name)) + try: + os.kill(pid, signal.SIGTERM) + except OSError as err: + logger.info("%s: could not kill %s (%s): %s", self.name, name, pid, str(err)) - running = self.listDaemons() - - if running: + running = self.listDaemons() + if running: + for _ in range(0, 5): sleep( - 0.1, + 0.5, "{}: waiting for daemons stopping: {}".format( - self.name, ", ".join(running) + self.name, ", ".join([x[0] for x in running]) ), ) running = self.listDaemons() + if not running: + break - counter = 20 - while counter > 0 and running: - sleep( - 0.5, - "{}: waiting for daemons stopping: {}".format( - self.name, ", ".join(running) - ), - ) - running = self.listDaemons() - counter -= 1 + if not running: + return "" - if running: - # 2nd round of kill if daemons didn't exit - dmns = rundaemons.split("\n") - # Exclude empty string at end of list - for d in dmns[:-1]: - daemonpid = self.cmd("cat %s" % d.rstrip()).rstrip() - if daemonpid.isdigit() and pid_exists(int(daemonpid)): - logger.info( - "{}: killing {}".format( - self.name, - os.path.basename(d.rstrip().rsplit(".", 1)[0]), - ) - ) - self.cmd("kill -7 %s" % daemonpid) - self.waitOutput() - self.cmd("rm -- {}".format(d.rstrip())) + logger.warning("%s: sending SIGBUS to: %s", self.name, ", ".join([x[0] for x in running])) + for name, pid in running: + pidfile = "/var/run/{}/{}.pid".format(self.routertype, name) + logger.info("%s: killing %s", self.name, name) + self.cmd("kill -SIGBUS %d" % pid) + self.cmd("rm -- " + pidfile) - if not wait: - return errors + sleep(0.5, "%s: waiting for daemons to exit/core after initial SIGBUS" % self.name) errors = self.checkRouterCores(reportOnce=True) if self.checkRouterVersion("<", minErrorVersion): # ignore errors in old versions errors = "" - if assertOnError and errors is not None and len(errors) > 0: + if assertOnError and (errors is not None) and len(errors) > 0: assert "Errors found - details follow:" == 0, errors return errors def removeIPs(self): for interface in self.intfNames(): - self.cmd("ip address flush", interface) + try: + self.intf_ip_cmd(interface, "ip address flush " + interface) + except Exception as ex: + logger.error("%s can't remove IPs %s", self, str(ex)) + # pdb.set_trace() + # assert False, "can't remove IPs %s" % str(ex) def checkCapability(self, daemon, param): if param is not None: @@ -1327,29 +1468,32 @@ class Router(Node): return True def loadConf(self, daemon, source=None, param=None): + # Unfortunately this API allowsfor source to not exist for any and all routers. + # print "Daemons before:", self.daemons if daemon in self.daemons.keys(): self.daemons[daemon] = 1 if param is not None: self.daemons_options[daemon] = param - if source is None: - self.cmd("touch /etc/%s/%s.conf" % (self.routertype, daemon)) - self.waitOutput() + conf_file = "/etc/{}/{}.conf".format(self.routertype, daemon) + if source is None or not os.path.exists(source): + self.cmd_raises("touch " + conf_file) else: - self.cmd("cp %s /etc/%s/%s.conf" % (source, self.routertype, daemon)) - self.waitOutput() - self.cmd("chmod 640 /etc/%s/%s.conf" % (self.routertype, daemon)) - self.waitOutput() - self.cmd( - "chown %s:%s /etc/%s/%s.conf" - % (self.routertype, self.routertype, self.routertype, daemon) - ) - self.waitOutput() + self.cmd_raises("cp {} {}".format(source, conf_file)) + self.cmd_raises("chown {0}:{0} {1}".format(self.routertype, conf_file)) + self.cmd_raises("chmod 664 {}".format(conf_file)) if (daemon == "snmpd") and (self.routertype == "frr"): + # /etc/snmp is private mount now self.cmd('echo "agentXSocket /etc/frr/agentx" > /etc/snmp/frr.conf') + self.cmd('echo "mibs +ALL" > /etc/snmp/snmp.conf') + if (daemon == "zebra") and (self.daemons["staticd"] == 0): # Add staticd with zebra - if it exists - staticd_path = os.path.join(self.daemondir, "staticd") + try: + staticd_path = os.path.join(self.daemondir, "staticd") + except: + pdb.set_trace() + if os.path.isfile(staticd_path): self.daemons["staticd"] = 1 self.daemons_options["staticd"] = "" @@ -1358,27 +1502,8 @@ class Router(Node): logger.info("No daemon {} known".format(daemon)) # print "Daemons after:", self.daemons - # Run a command in a new window (gnome-terminal, screen, tmux, xterm) def runInWindow(self, cmd, title=None): - topo_terminal = os.getenv("FRR_TOPO_TERMINAL") - if topo_terminal or ("TMUX" not in os.environ and "STY" not in os.environ): - term = topo_terminal if topo_terminal else "xterm" - makeTerm(self, title=title if title else cmd, term=term, cmd=cmd) - else: - nscmd = self.ns_cmd + cmd - if "TMUX" in os.environ: - self.cmd("tmux select-layout main-horizontal") - wcmd = "tmux split-window -h" - cmd = "{} {}".format(wcmd, nscmd) - elif "STY" in os.environ: - if os.path.exists( - "/run/screen/S-{}/{}".format(os.environ["USER"], os.environ["STY"]) - ): - wcmd = "screen" - else: - wcmd = "sudo -u {} screen".format(os.environ["SUDO_USER"]) - cmd = "{} {}".format(wcmd, nscmd) - self.cmd(cmd) + return self.run_in_window(cmd, title) def startRouter(self, tgen=None): # Disable integrated-vtysh-config @@ -1430,15 +1555,18 @@ class Router(Node): self.hasmpls = True if self.hasmpls != True: return "LDP/MPLS Tests need mpls kernel modules" + + # Really want to use sysctl_atleast here, but only when MPLS is actually being + # used self.cmd("echo 100000 > /proc/sys/net/mpls/platform_labels") shell_routers = g_extra_config["shell"] if "all" in shell_routers or self.name in shell_routers: - self.runInWindow(os.getenv("SHELL", "bash")) + self.run_in_window(os.getenv("SHELL", "bash")) vtysh_routers = g_extra_config["vtysh"] if "all" in vtysh_routers or self.name in vtysh_routers: - self.runInWindow("vtysh") + self.run_in_window("vtysh") if self.daemons["eigrpd"] == 1: eigrpd_path = os.path.join(self.daemondir, "eigrpd") @@ -1464,7 +1592,7 @@ class Router(Node): return self.cmd("cat {}/{}/{}.{}".format(self.logdir, self.name, daemon, log)) def startRouterDaemons(self, daemons=None, tgen=None): - "Starts all FRR daemons for this router." + "Starts FRR daemons for this router." asan_abort = g_extra_config["asan_abort"] gdb_breakpoints = g_extra_config["gdb_breakpoints"] @@ -1474,20 +1602,22 @@ class Router(Node): valgrind_memleaks = g_extra_config["valgrind_memleaks"] strace_daemons = g_extra_config["strace_daemons"] - bundle_data = "" - - if os.path.exists("/etc/frr/support_bundle_commands.conf"): - bundle_data = subprocess.check_output( - ["cat /etc/frr/support_bundle_commands.conf"], shell=True + # Get global bundle data + if not self.path_exists("/etc/frr/support_bundle_commands.conf"): + # Copy global value if was covered by namespace mount + bundle_data = "" + if os.path.exists("/etc/frr/support_bundle_commands.conf"): + with open("/etc/frr/support_bundle_commands.conf", "r") as rf: + bundle_data = rf.read() + self.cmd_raises( + "cat > /etc/frr/support_bundle_commands.conf", + stdin=bundle_data, ) - self.cmd( - "echo '{}' > /etc/frr/support_bundle_commands.conf".format(bundle_data) - ) # Starts actual daemons without init (ie restart) # cd to per node directory - self.cmd("install -d {}/{}".format(self.logdir, self.name)) - self.cmd("cd {}/{}".format(self.logdir, self.name)) + self.cmd("install -m 775 -o frr -g frr -d {}/{}".format(self.logdir, self.name)) + self.set_cwd("{}/{}".format(self.logdir, self.name)) self.cmd("umask 000") # Re-enable to allow for report per run @@ -1560,13 +1690,25 @@ class Router(Node): gdbcmd += " -ex 'b {}'".format(bp) gdbcmd += " -ex 'run {}'".format(cmdopt) - self.runInWindow(gdbcmd, daemon) + self.run_in_window(gdbcmd, daemon) + + logger.info("%s: %s %s launched in gdb window", self, self.routertype, daemon) else: if daemon != "snmpd": cmdopt += " -d " cmdopt += rediropt - self.cmd(" ".join([cmdenv, binary, cmdopt])) - logger.info("{}: {} {} started".format(self, self.routertype, daemon)) + + try: + self.cmd_raises(" ".join([cmdenv, binary, cmdopt]), warn=False) + except subprocess.CalledProcessError as error: + self.logger.error( + '%s: Failed to launch "%s" daemon (%d) using: %s%s%s:', + self, daemon, error.returncode, error.cmd, + '\n:stdout: "{}"'.format(error.stdout.strip()) if error.stdout else "", + '\n:stderr: "{}"'.format(error.stderr.strip()) if error.stderr else "", + ) + else: + logger.info("%s: %s %s started", self, self.routertype, daemon) # Start Zebra first if "zebra" in daemons_list: @@ -1581,15 +1723,22 @@ class Router(Node): daemons_list.remove("staticd") if "snmpd" in daemons_list: + # Give zerbra a chance to configure interface addresses that snmpd daemon + # may then use. + time.sleep(2) + start_daemon("snmpd") while "snmpd" in daemons_list: daemons_list.remove("snmpd") - # Fix Link-Local Addresses - # Somehow (on Mininet only), Zebra removes the IPv6 Link-Local addresses on start. Fix this - self.cmd( - "for i in `ls /sys/class/net/` ; do mac=`cat /sys/class/net/$i/address`; IFS=':'; set $mac; unset IFS; ip address add dev $i scope link fe80::$(printf %02x $((0x$1 ^ 2)))$2:${3}ff:fe$4:$5$6/64; done" - ) + if daemons is None: + # Fix Link-Local Addresses on initial startup + # Somehow (on Mininet only), Zebra removes the IPv6 Link-Local addresses on start. Fix this + _, output, _ = self.cmd_status( + "for i in `ls /sys/class/net/` ; do mac=`cat /sys/class/net/$i/address`; echo $i: $mac; [ -z \"$mac\" ] && continue; IFS=':'; set $mac; unset IFS; ip address add dev $i scope link fe80::$(printf %02x $((0x$1 ^ 2)))$2:${3}ff:fe$4:$5$6/64; done", + stderr=subprocess.STDOUT + ) + logger.debug("Set MACs:\n%s", output) # Now start all the other daemons for daemon in daemons_list: @@ -1602,6 +1751,10 @@ class Router(Node): if re.search(r"No such file or directory", rundaemons): return "Daemons are not running" + # Update the permissions on the log files + self.cmd("chown frr:frr -R {}/{}".format(self.logdir, self.name)) + self.cmd("chmod ug+rwX,o+r -R {}/{}".format(self.logdir, self.name)) + return "" def killRouterDaemons( @@ -1630,7 +1783,6 @@ class Router(Node): ) ) self.cmd("kill -9 %s" % daemonpid) - self.waitOutput() if pid_exists(int(daemonpid)): numRunning += 1 if wait and numRunning > 0: @@ -1657,7 +1809,6 @@ class Router(Node): ) ) self.cmd("kill -9 %s" % daemonpid) - self.waitOutput() self.cmd("rm -- {}".format(d.rstrip())) if wait: errors = self.checkRouterCores(reportOnce=True) @@ -1914,53 +2065,9 @@ class Router(Node): leakfile.close() -class LinuxRouter(Router): - "A Linux Router Node with IPv4/IPv6 forwarding enabled." - - def __init__(self, name, **params): - Router.__init__(self, name, **params) - - def config(self, **params): - Router.config(self, **params) - # Enable forwarding on the router - assert_sysctl(self, "net.ipv4.ip_forward", 1) - assert_sysctl(self, "net.ipv6.conf.all.forwarding", 1) - # Enable coredumps - assert_sysctl(self, "kernel.core_uses_pid", 1) - assert_sysctl(self, "fs.suid_dumpable", 1) - # this applies to the kernel not the namespace... - # original on ubuntu 17.x, but apport won't save as in namespace - # |/usr/share/apport/apport %p %s %c %d %P - corefile = "%e_core-sig_%s-pid_%p.dmp" - assert_sysctl(self, "kernel.core_pattern", corefile) - - def terminate(self): - """ - Terminate generic LinuxRouter Mininet instance - """ - set_sysctl(self, "net.ipv4.ip_forward", 0) - set_sysctl(self, "net.ipv6.conf.all.forwarding", 0) - Router.terminate(self) - - -class FreeBSDRouter(Router): - "A FreeBSD Router Node with IPv4/IPv6 forwarding enabled." - - def __init__(self, name, **params): - Router.__init__(self, name, **params) - - -class LegacySwitch(OVSSwitch): - "A Legacy Switch without OpenFlow" - - def __init__(self, name, **params): - OVSSwitch.__init__(self, name, failMode="standalone", **params) - self.switchIP = None - - def frr_unicode(s): """Convert string to unicode, depending on python version""" if sys.version_info[0] > 2: return s else: - return unicode(s) + return unicode(s) # pylint: disable=E0602 diff --git a/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py b/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py index 736cb1659c..7c2d13f395 100755 --- a/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py +++ b/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py @@ -156,14 +156,6 @@ from lib.pim import ( pytestmark = [pytest.mark.pimd, pytest.mark.staticd] -# Reading the data from JSON File for topology and configuration creation -jsonFile = "{}/multicast_pim_static_rp.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - TOPO = json.load(topoJson) -except IOError: - logger.info("Could not read file: %s", jsonFile) - # Global variables GROUP_RANGE_ALL = "224.0.0.0/4" GROUP_RANGE = "225.1.1.1/32" @@ -241,7 +233,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/multicast_pim_static_rp.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global TOPO + TOPO = tgen.json_topo # ... and here it calls Mininet initialization functions. @@ -1269,7 +1264,7 @@ def test_send_join_on_higher_preffered_rp_p1(request): shutdown_bringup_interface(tgen, dut, intf, False) dut = "r1" - intf = "r1-r3-eth1" + intf = "r1-r3-eth2" shutdown_bringup_interface(tgen, dut, intf, False) step("r1 : Verify joinTx count before sending join") From 8db751b853560377ebd640c729ecb4e155e6a6d7 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Fri, 27 Aug 2021 14:28:29 -0400 Subject: [PATCH 05/25] tests: micronet: adapt tests Signed-off-by: Christian Hopps --- .../test_all_protocol_startup.py | 19 +- .../test_bfd_bgp_cbit_topo3.py | 30 +-- .../bfd_isis_topo1/test_bfd_isis_topo1.py | 50 +---- .../bfd_ospf_topo1/test_bfd_ospf_topo1.py | 52 +---- .../test_bfd_profiles_topo1.py | 46 +--- tests/topotests/bfd_topo1/test_bfd_topo1.py | 34 +-- tests/topotests/bfd_topo2/test_bfd_topo2.py | 43 ++-- tests/topotests/bfd_topo3/test_bfd_topo3.py | 35 +-- .../bfd_vrf_topo1/test_bfd_vrf_topo1.py | 41 +--- .../test_bgp_aggregate-address_origin.py | 2 +- .../test_bgp_aggregate-address_route-map.py | 2 +- .../test_bgp_aggregate_address_topo1.py | 2 +- .../test_bgp_aggregator_zero.py | 2 +- .../bgp_as_allow_in/test_bgp_as_allow_in.py | 34 +-- .../test_bgp_as_wide_bgp_identifier.py | 2 +- .../bgp_aspath_zero/test_bgp_aspath_zero.py | 2 +- tests/topotests/bgp_auth/test_bgp_auth.py | 2 +- .../test_bgp_basic_functionality.py | 65 +++--- .../test_bgp_blackhole_community.py | 2 +- .../test_bgp_comm-list_delete.py | 2 +- .../test_bgp_communities.py | 2 +- .../test_bgp_communities_topo2.py | 2 +- .../test_bgp-community-alias.py | 2 +- .../test_bgp_community_change_update.py | 2 +- .../test_bgp_conditional_advertisement.py | 2 +- .../test_bgp-default-afi-safi.py | 2 +- .../test_bgp_default-originate.py | 2 +- ...t_bgp_default-originate_route-map_match.py | 2 +- ..._bgp_default-originate_route-map_match2.py | 2 +- ...p_default-originate_route-map_match_set.py | 2 +- ...est_bgp_default-originate_route-map_set.py | 2 +- .../test_bgp_distance_change.py | 2 +- .../test_bgp_dont_capability_negotiate.py | 16 +- ...gp-ebgp-common-subnet-nexthop-unchanged.py | 2 +- .../test_bgp_ebgp_requires_policy.py | 2 +- .../bgp_ecmp_topo1/test_bgp_ecmp_topo1.py | 2 +- .../bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py | 2 +- .../bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py | 2 +- tests/topotests/bgp_evpn_mh/test_evpn_mh.py | 6 +- .../test_bgp_evpn_overlay_index_gateway.py | 73 ++++--- tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py | 59 +++-- .../test_bgp_evpn_vxlan.py | 2 +- .../bgp_features/test_bgp_features.py | 2 +- .../bgp_flowspec/test_bgp_flowspec_topo.py | 2 +- .../test_bgp_gr_functionality_topo1.py | 2 +- .../test_bgp_gr_functionality_topo2.py | 2 +- tests/topotests/bgp_gshut/test_bgp_gshut.py | 2 +- .../bgp_gshut_topo1/test_ebgp_gshut_topo1.py | 2 +- .../bgp_gshut_topo1/test_ibgp_gshut_topo1.py | 2 +- .../bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py | 2 +- .../bgp_l3vpn_to_bgp_direct/customize.py | 6 +- .../bgp_l3vpn_to_bgp_vrf/customize.py | 6 +- .../bgp_large_community_topo_2.json | 2 +- .../test_bgp_large_community_topo_1.py | 2 +- .../test_bgp_large_community_topo_2.py | 2 +- .../bgp_link_bw_ip/test_bgp_linkbw_ip.py | 2 +- .../test_bgp_listen_on_multiple_addresses.py | 2 +- .../test_bgp_local_as_private_remove.py | 2 +- tests/topotests/bgp_lu_topo1/test_bgp_lu.py | 2 +- .../test_bgp_maximum_prefix_invalid_update.py | 2 +- .../test_bgp_maximum_prefix_out.py | 2 +- .../test_bgp_multi_vrf_topo1.py | 2 +- .../test_bgp_multi_vrf_topo2.py | 2 +- .../test_bgp_multiview_topo1.py | 15 +- .../test_bgp_path_attributes.py | 2 +- .../bgp_peer_group/test_bgp_peer-group.py | 2 +- .../test_bgp_peer-type_multipath-relax.py | 2 +- .../test_prefix_lists.py | 2 +- .../bgp_prefix_sid/test_bgp_prefix_sid.py | 2 +- .../bgp_prefix_sid2/test_bgp_prefix_sid2.py | 2 +- ...test_bgp_recursive_route_ebgp_multi_hop.py | 2 +- .../test_bgp_reject_as_sets.py | 2 +- .../bgp_rfapi_basic_sanity/customize.py | 6 +- .../test_bgp_aggregation.py | 2 +- .../bgp_route_map/test_route_map_topo1.py | 2 +- .../bgp_route_map/test_route_map_topo2.py | 2 +- .../bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py | 2 +- .../test_bgp_sender-as-path-loop-detection.py | 2 +- ...t_bgp_set_local-preference_add_subtract.py | 2 +- .../bgp_snmp_mplsl3vpn/ce1/snmpd.conf | 3 + .../bgp_snmp_mplsl3vpn/ce2/snmpd.conf | 3 + .../bgp_snmp_mplsl3vpn/ce3/snmpd.conf | 3 + .../bgp_snmp_mplsl3vpn/ce4/snmpd.conf | 3 + .../bgp_snmp_mplsl3vpn/r1/snmpd.conf | 5 +- .../bgp_snmp_mplsl3vpn/r2/snmpd.conf | 3 + .../bgp_snmp_mplsl3vpn/r3/snmpd.conf | 3 + .../bgp_snmp_mplsl3vpn/r4/snmpd.conf | 3 + .../test_bgp_snmp_mplsvpn.py | 52 ++--- .../test_bgp_srv6l3vpn_to_bgp_vrf.py | 2 +- .../bgp_suppress_fib/test_bgp_suppress_fib.py | 2 +- .../topotests/bgp_tcp_mss/test_bgp_tcp_mss.py | 2 +- .../bgp_update_delay/test_bgp_update_delay.py | 2 +- .../test_bgp_vrf_dynamic_route_leak_topo1.py | 2 +- .../test_bgp_vrf_dynamic_route_leak_topo2.py | 2 +- .../test_bgp_vrf_lite_ipv6_rtadv.py | 2 +- .../bgp_vrf_netns/test_bgp_vrf_netns_topo.py | 37 +--- .../test_bgp-vrf-route-leak-basic.py | 2 +- .../config_timing/test_config_timing.py | 4 +- .../topotests/eigrp_topo1/test_eigrp_topo1.py | 2 +- .../evpn_pim_1/test_evpn_pim_topo1.py | 2 +- .../test_evpn_type5_chaos_topo1.py | 3 +- .../test_evpn_type5_topo1.py | 2 +- tests/topotests/example_test/test_template.py | 12 +- .../test_example_topojson_multiple_links.py | 2 +- .../test_example_topojson.py | 2 +- .../test_example_topojson.py | 2 +- .../isis_lfa_topo1/test_isis_lfa_topo1.py | 156 +++++++------- .../test_isis_lsp_bits_topo1.py | 2 +- .../isis_rlfa_topo1/test_isis_rlfa_topo1.py | 142 ++++++------ tests/topotests/isis_snmp/r1/snmpd.conf | 3 + tests/topotests/isis_snmp/r2/snmpd.conf | 3 + tests/topotests/isis_snmp/r3/snmpd.conf | 3 + tests/topotests/isis_snmp/r4/snmpd.conf | 3 + tests/topotests/isis_snmp/r5/snmpd.conf | 3 + tests/topotests/isis_snmp/test_isis_snmp.py | 21 +- .../isis_sr_te_topo1/test_isis_sr_te_topo1.py | 2 +- .../isis_sr_topo1/test_isis_sr_topo1.py | 2 +- .../isis_tilfa_topo1/test_isis_tilfa_topo1.py | 146 ++++++------- tests/topotests/isis_topo1/test_isis_topo1.py | 2 +- .../isis_topo1_vrf/test_isis_topo1_vrf.py | 2 +- .../ldp_oc_acl_topo1/test_ldp_oc_acl_topo1.py | 2 +- .../ldp_oc_topo1/test_ldp_oc_topo1.py | 2 +- tests/topotests/ldp_snmp/r1/snmpd.conf | 3 + tests/topotests/ldp_snmp/r2/snmpd.conf | 3 + .../topotests/ldp_snmp/test_ldp_snmp_topo1.py | 16 +- .../test_ldp_sync_isis_topo1.py | 20 +- .../test_ldp_sync_ospf_topo1.py | 2 +- tests/topotests/ldp_topo1/test_ldp_topo1.py | 16 +- .../ldp_vpls_topo1/test_ldp_vpls_topo1.py | 2 +- tests/topotests/lib/ltemplate.py | 2 +- tests/topotests/lib/lutil.py | 2 +- .../msdp_mesh_topo1/test_msdp_mesh_topo1.py | 53 +++-- tests/topotests/msdp_topo1/test_msdp_topo1.py | 70 ++++-- .../test_mcast_pim_bsmp_01.py | 69 +++--- .../test_mcast_pim_bsmp_02.py | 52 ++--- .../test_multicast_pim_sm_topo1.py | 111 +++++----- .../test_multicast_pim_sm_topo2.py | 162 ++++++-------- .../test_multicast_pim_sm_topo3.py | 202 ++++++++---------- .../test_multicast_pim_sm_topo4.py | 26 ++- .../test_multicast_pim_static_rp.py | 5 +- tests/topotests/nhrp_topo/test_nhrp_topo.py | 2 +- .../topotests/ospf6_topo1/test_ospf6_topo1.py | 2 +- .../ospf6_topo1_vrf/test_ospf6_topo1_vrf.py | 2 +- .../topotests/ospf6_topo2/test_ospf6_topo2.py | 4 +- .../test_ospf_asbr_summary_topo1.py | 2 +- .../test_ospf_asbr_summary_type7_lsa.py | 2 +- .../test_ospf_authentication.py | 2 +- .../test_ospf_chaos.py | 2 +- .../test_ospf_ecmp.py | 2 +- .../test_ospf_ecmp_lan.py | 2 +- .../ospf_basic_functionality/test_ospf_lan.py | 2 +- .../test_ospf_nssa.py | 2 +- .../test_ospf_p2mp.py | 3 +- .../test_ospf_routemaps.py | 2 +- .../test_ospf_rte_calc.py | 2 +- .../test_ospf_single_area.py | 2 +- .../ospf_dual_stack/test_ospf_dual_stack.py | 2 +- .../ospf_gr_topo1/test_ospf_gr_topo1.py | 2 +- .../ospf_sr_te_topo1/test_ospf_sr_te_topo1.py | 2 +- .../ospf_sr_topo1/test_ospf_sr_topo1.py | 2 +- .../ospf_suppress_fa/test_ospf_suppress_fa.py | 2 +- .../ospf_te_topo1/test_ospf_te_topo1.py | 4 +- .../ospf_tilfa_topo1/test_ospf_tilfa_topo1.py | 2 +- tests/topotests/ospf_topo1/test_ospf_topo1.py | 2 +- .../ospf_topo1_vrf/test_ospf_topo1_vrf.py | 34 +-- tests/topotests/ospf_topo2/test_ospf_topo2.py | 10 +- .../test_ospfv3_asbr_summary_topo1.py | 1 - .../test_ospfv3_ecmp.py | 1 - .../test_ospfv3_routemaps.py | 1 - .../test_ospfv3_rte_calc.py | 2 +- .../test_ospfv3_single_area.py | 2 +- tests/topotests/pbr_topo1/test_pbr_topo1.py | 2 +- tests/topotests/pim_acl/test_pim_acl.py | 2 +- tests/topotests/pim_basic/test_pim.py | 37 ++-- .../pim_basic_topo2/test_pim_basic_topo2.py | 2 +- tests/topotests/rip_topo1/test_rip_topo1.py | 21 +- .../topotests/ripng_topo1/test_ripng_topo1.py | 22 +- .../topotests/route_scale/test_route_scale.py | 37 ++-- .../topotests/simple_snmp_test/r1/snmpd.conf | 3 + .../simple_snmp_test/test_simple_snmp.py | 38 +--- .../srv6_locator/test_srv6_locator.py | 8 +- .../test_static_routes_topo1_ebgp.py | 2 +- .../test_static_routes_topo2_ebgp.py | 2 +- .../test_static_routes_topo3_ebgp.py | 2 +- .../test_static_routes_topo4_ebgp.py | 2 +- .../test_static_routes_topo1_ibgp.py | 2 +- .../test_static_routes_topo2_ibgp.py | 2 +- .../test_static_routes_topo3_ibgp.py | 2 +- .../test_static_routes_topo4_ibgp.py | 2 +- .../zebra_netlink/test_zebra_netlink.py | 27 +-- .../zebra_opaque/test_zebra_opaque.py | 18 +- tests/topotests/zebra_rib/test_zebra_rib.py | 27 +-- .../zebra_seg6_route/test_zebra_seg6_route.py | 9 +- .../test_zebra_seg6local_route.py | 9 +- 194 files changed, 1144 insertions(+), 1466 deletions(-) diff --git a/tests/topotests/all_protocol_startup/test_all_protocol_startup.py b/tests/topotests/all_protocol_startup/test_all_protocol_startup.py index 2d75428f1a..41597c449e 100644 --- a/tests/topotests/all_protocol_startup/test_all_protocol_startup.py +++ b/tests/topotests/all_protocol_startup/test_all_protocol_startup.py @@ -34,12 +34,7 @@ import pytest import glob from time import sleep -from mininet.topo import Topo -from mininet.net import Mininet -from mininet.node import Node, OVSSwitch, Host -from mininet.log import setLogLevel, info -from mininet.cli import CLI -from mininet.link import Intf +from lib.micronet_compat import Mininet, Topo from functools import partial @@ -82,7 +77,7 @@ class NetworkTopo(Topo): switch = {} # for i in range(0, 10): - switch[i] = self.addSwitch("sw%s" % i, cls=topotest.LegacySwitch) + switch[i] = self.addSwitch("sw%s" % i) self.addLink(switch[i], router[1], intfName2="r1-eth%s" % i) @@ -765,7 +760,7 @@ def test_ospfv2_interfaces(): ) # Mask out Bandwidth portion. They may change.. actual = re.sub(r"BW [0-9]+ Mbit", "BW XX Mbit", actual) - actual = re.sub(r"ifindex [0-9]", "ifindex X", actual) + actual = re.sub(r"ifindex [0-9]+", "ifindex X", actual) # Drop time in next due actual = re.sub(r"Hello due in [0-9\.]+s", "Hello due in XX.XXXs", actual) @@ -1155,7 +1150,7 @@ def test_nht(): expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) actual = net["r%s" % i].cmd('vtysh -c "show ip nht" 2> /dev/null').rstrip() - actual = re.sub(r"fd [0-9][0-9]", "fd XX", actual) + actual = re.sub(r"fd [0-9]+", "fd XX", actual) actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) diff = topotest.get_textdiff( @@ -1175,7 +1170,7 @@ def test_nht(): expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) actual = net["r%s" % i].cmd('vtysh -c "show ipv6 nht" 2> /dev/null').rstrip() - actual = re.sub(r"fd [0-9][0-9]", "fd XX", actual) + actual = re.sub(r"fd [0-9]+", "fd XX", actual) actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) diff = topotest.get_textdiff( @@ -1418,7 +1413,7 @@ def test_nexthop_groups_with_route_maps(): net["r1"].cmd('vtysh -c "sharp remove routes %s 1"' % route_str) net["r1"].cmd('vtysh -c "c t" -c "no ip protocol sharp route-map NH-SRC"') net["r1"].cmd( - 'vtysh -c "c t" -c "no route-map NH-SRC permit 111" -c "set src %s"' % src_str + 'vtysh -c "c t" -c "no route-map NH-SRC permit 111" # -c "set src %s"' % src_str ) net["r1"].cmd('vtysh -c "c t" -c "no route-map NH-SRC"') @@ -1659,8 +1654,6 @@ def test_shutdown_check_memleak(): if __name__ == "__main__": - - setLogLevel("info") # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli # retval = pytest.main(["-s", "--tb=no"]) retval = pytest.main(["-s"]) diff --git a/tests/topotests/bfd_bgp_cbit_topo3/test_bfd_bgp_cbit_topo3.py b/tests/topotests/bfd_bgp_cbit_topo3/test_bfd_bgp_cbit_topo3.py index 560d6eebec..29c25bba29 100644 --- a/tests/topotests/bfd_bgp_cbit_topo3/test_bfd_bgp_cbit_topo3.py +++ b/tests/topotests/bfd_bgp_cbit_topo3/test_bfd_bgp_cbit_topo3.py @@ -41,35 +41,17 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -# Required to instantiate the topology builder class. -from mininet.topo import Topo - pytestmark = [pytest.mark.bgpd, pytest.mark.bfdd] -class BFDTopo(Topo): - "Test topology builder" - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # Create 4 routers. - for routern in range(1, 4): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) - - def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(BFDTopo, mod.__name__) + from collections import OrderedDict + topodef = { + "s1": ("r1", "r2"), + "s2": ("r2", "r3"), + } + tgen = Topogen(topodef, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bfd_isis_topo1/test_bfd_isis_topo1.py b/tests/topotests/bfd_isis_topo1/test_bfd_isis_topo1.py index fcb5672dce..6a19b1ea46 100644 --- a/tests/topotests/bfd_isis_topo1/test_bfd_isis_topo1.py +++ b/tests/topotests/bfd_isis_topo1/test_bfd_isis_topo1.py @@ -87,52 +87,18 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -# Required to instantiate the topology builder class. -from mininet.topo import Topo - pytestmark = [pytest.mark.bfdd, pytest.mark.isisd] - -class TemplateTopo(Topo): - "Test topology builder" - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # - # Define FRR Routers - # - for router in ["rt1", "rt2", "rt3", "rt4", "rt5"]: - tgen.add_router(router) - - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["rt1"], nodeif="eth-rt2") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt1") - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["rt1"], nodeif="eth-rt3") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt1") - - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt2") - - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt4") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt3") - - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") - - def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + topodef = { + "s1": ("rt1:eth-rt2", "rt2:eth-rt1"), + "s2": ("rt1:eth-rt3", "rt3:eth-rt1"), + "s3": ("rt2:eth-rt5", "rt5:eth-rt2"), + "s4": ("rt3:eth-rt4", "rt4:eth-rt3"), + "s5": ("rt4:eth-rt5", "rt5:eth-rt4"), + } + tgen = Topogen(topodef, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bfd_ospf_topo1/test_bfd_ospf_topo1.py b/tests/topotests/bfd_ospf_topo1/test_bfd_ospf_topo1.py index ae148f948c..c82b4b590a 100755 --- a/tests/topotests/bfd_ospf_topo1/test_bfd_ospf_topo1.py +++ b/tests/topotests/bfd_ospf_topo1/test_bfd_ospf_topo1.py @@ -84,61 +84,29 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib import topotest +from lib.micronet_compat import Topo from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -# Required to instantiate the topology builder class. -from mininet.topo import Topo - pytestmark = [pytest.mark.bfdd, pytest.mark.ospfd] -class TemplateTopo(Topo): - "Test topology builder" - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # - # Define FRR Routers - # - for router in ["rt1", "rt2", "rt3", "rt4", "rt5"]: - tgen.add_router(router) - - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["rt1"], nodeif="eth-rt2") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt1") - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["rt1"], nodeif="eth-rt3") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt1") - - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt2") - - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt4") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt3") - - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") - - def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + topodef = { + "s1": ("rt1:eth-rt2", "rt2:eth-rt1"), + "s2": ("rt1:eth-rt3", "rt3:eth-rt1"), + "s3": ("rt2:eth-rt5", "rt5:eth-rt2"), + "s4": ("rt3:eth-rt4", "rt4:eth-rt3"), + "s5": ("rt4:eth-rt5", "rt5:eth-rt4"), + } + tgen = Topogen(topodef, mod.__name__) tgen.start_topology() router_list = tgen.routers() # For all registered routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bfd_profiles_topo1/test_bfd_profiles_topo1.py b/tests/topotests/bfd_profiles_topo1/test_bfd_profiles_topo1.py index 4a2c8ee002..02e1d8a20f 100644 --- a/tests/topotests/bfd_profiles_topo1/test_bfd_profiles_topo1.py +++ b/tests/topotests/bfd_profiles_topo1/test_bfd_profiles_topo1.py @@ -42,47 +42,19 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -# Required to instantiate the topology builder class. -from mininet.topo import Topo - pytestmark = [pytest.mark.bfdd, pytest.mark.bgpd, pytest.mark.isisd, pytest.mark.ospfd] - -class BFDProfTopo(Topo): - "Test topology builder" - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # Create 6 routers - for routern in range(1, 7): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) - - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r3"]) - switch.add_link(tgen.gears["r4"]) - - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r4"]) - switch.add_link(tgen.gears["r5"]) - - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r6"]) - - def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(BFDProfTopo, mod.__name__) + + topodef = { + "s1": ("r1", "r2"), + "s2": ("r2", "r3"), + "s3": ("r3", "r4"), + "s4": ("r4", "r5"), + "s5": ("r1", "r6"), + } + tgen = Topogen(topodef, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bfd_topo1/test_bfd_topo1.py b/tests/topotests/bfd_topo1/test_bfd_topo1.py index 86bdcfed04..adf02b02d4 100644 --- a/tests/topotests/bfd_topo1/test_bfd_topo1.py +++ b/tests/topotests/bfd_topo1/test_bfd_topo1.py @@ -42,39 +42,17 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -# Required to instantiate the topology builder class. -from mininet.topo import Topo - pytestmark = [pytest.mark.bfdd, pytest.mark.bgpd] -class BFDTopo(Topo): - "Test topology builder" - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # Create 4 routers - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) - - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r4"]) - - def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(BFDTopo, mod.__name__) + topodef = { + "s1": ("r1", "r2"), + "s2": ("r2", "r3"), + "s3": ("r2", "r4"), + } + tgen = Topogen(topodef, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bfd_topo2/test_bfd_topo2.py b/tests/topotests/bfd_topo2/test_bfd_topo2.py index 2cc12bc7b0..00431ea1ff 100644 --- a/tests/topotests/bfd_topo2/test_bfd_topo2.py +++ b/tests/topotests/bfd_topo2/test_bfd_topo2.py @@ -43,39 +43,40 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -# Required to instantiate the topology builder class. -from mininet.topo import Topo - pytestmark = [pytest.mark.bfdd, pytest.mark.bgpd, pytest.mark.ospfd] -class BFDTopo(Topo): - "Test topology builder" +def build(self, *_args, **_opts): + "Build function" + tgen = get_topogen(self) - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # Create 4 routers. + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) - # Create 4 routers. - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r4"]) - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r4"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(BFDTopo, mod.__name__) + topodef = { + "s1": ("r1", "r2"), + "s2": ("r2", "r3"), + "s3": ("r2", "r4"), + } + tgen = Topogen(topodef, mod.__name__) + # tgen = Topogen(build, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bfd_topo3/test_bfd_topo3.py b/tests/topotests/bfd_topo3/test_bfd_topo3.py index 6bb223e203..9ed8f5fcbf 100644 --- a/tests/topotests/bfd_topo3/test_bfd_topo3.py +++ b/tests/topotests/bfd_topo3/test_bfd_topo3.py @@ -39,42 +39,21 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib import topotest +from lib.micronet_compat import Topo from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -# Required to instantiate the topology builder class. -from mininet.topo import Topo - pytestmark = [pytest.mark.bfdd, pytest.mark.bgpd] -class BFDTopo(Topo): - "Test topology builder" - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # Create 4 routers - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) - - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r3"]) - switch.add_link(tgen.gears["r4"]) - - def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(BFDTopo, mod.__name__) + topodef = { + "s1": ("r1", "r2"), + "s2": ("r2", "r3"), + "s3": ("r3", "r4"), + } + tgen = Topogen(topodef, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py b/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py index 0e0dd4db4a..125cc183c5 100644 --- a/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py +++ b/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py @@ -44,7 +44,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bfdd, pytest.mark.bgpd] @@ -94,24 +94,14 @@ def setup_module(mod): logger.info("Testing with VRF Namespace support") - cmds = [ - "if [ -e /var/run/netns/{0}-bfd-cust1 ] ; then ip netns del {0}-bfd-cust1 ; fi", - "ip netns add {0}-bfd-cust1", - "ip link set dev {0}-eth0 netns {0}-bfd-cust1 up", - ] - cmds2 = [ - "ip link set dev {0}-eth1 netns {0}-bfd-cust1", - "ip netns exec {0}-bfd-cust1 ip link set {0}-eth1 up", - "ip link set dev {0}-eth2 netns {0}-bfd-cust1 up", - ] - for rname, router in router_list.items(): # create VRF rx-bfd-cust1 and link rx-eth0 to rx-bfd-cust1 - for cmd in cmds: - output = tgen.net[rname].cmd_raises(cmd.format(rname)) + ns = "{}-bfd-cust1".format(rname) + router.net.add_netns(ns) + router.net.set_intf_netns(rname + "-eth0", ns, up=True) if rname == "r2": - for cmd in cmds2: - output = tgen.net[rname].cmd_raises(cmd.format(rname)) + router.net.set_intf_netns(rname + "-eth1", ns, up=True) + router.net.set_intf_netns(rname + "-eth2", ns, up=True) for rname, router in router_list.items(): router.load_config( @@ -133,24 +123,15 @@ def setup_module(mod): def teardown_module(_mod): "Teardown the pytest environment" tgen = get_topogen() - # move back rx-eth0 to default VRF - # delete rx-vrf - cmds = [ - "ip netns exec {0}-bfd-cust1 ip link set {0}-eth0 netns 1", - "ip netns delete {0}-bfd-cust1", - ] - cmds2 = [ - "ip netns exec {0}-bfd-cust1 ip link set {0}-eth1 netns 1", - "ip netns exec {0}-cust2 ip link set {0}-eth1 netns 1", - ] + # Move interfaces out of vrf namespace and delete the namespace router_list = tgen.routers() for rname, router in router_list.items(): if rname == "r2": - for cmd in cmds2: - tgen.net[rname].cmd(cmd.format(rname)) - for cmd in cmds: - tgen.net[rname].cmd(cmd.format(rname)) + router.net.reset_intf_netns(rname + "-eth2") + router.net.reset_intf_netns(rname + "-eth1") + router.net.reset_intf_netns(rname + "-eth0") + router.net.delete_netns("{}-bfd-cust1".format(rname)) tgen.stop_topology() diff --git a/tests/topotests/bgp_aggregate_address_origin/test_bgp_aggregate-address_origin.py b/tests/topotests/bgp_aggregate_address_origin/test_bgp_aggregate-address_origin.py index be07fab87b..4fa6828efc 100644 --- a/tests/topotests/bgp_aggregate_address_origin/test_bgp_aggregate-address_origin.py +++ b/tests/topotests/bgp_aggregate_address_origin/test_bgp_aggregate-address_origin.py @@ -45,7 +45,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_aggregate_address_route_map/test_bgp_aggregate-address_route-map.py b/tests/topotests/bgp_aggregate_address_route_map/test_bgp_aggregate-address_route-map.py index 484f40251f..f4b9889545 100644 --- a/tests/topotests/bgp_aggregate_address_route_map/test_bgp_aggregate-address_route-map.py +++ b/tests/topotests/bgp_aggregate_address_route_map/test_bgp_aggregate-address_route-map.py @@ -48,7 +48,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_aggregate_address_topo1/test_bgp_aggregate_address_topo1.py b/tests/topotests/bgp_aggregate_address_topo1/test_bgp_aggregate_address_topo1.py index 9f26978259..6566a860bc 100644 --- a/tests/topotests/bgp_aggregate_address_topo1/test_bgp_aggregate_address_topo1.py +++ b/tests/topotests/bgp_aggregate_address_topo1/test_bgp_aggregate_address_topo1.py @@ -40,7 +40,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_aggregator_zero/test_bgp_aggregator_zero.py b/tests/topotests/bgp_aggregator_zero/test_bgp_aggregator_zero.py index c4bbdce2c3..99c31a355b 100644 --- a/tests/topotests/bgp_aggregator_zero/test_bgp_aggregator_zero.py +++ b/tests/topotests/bgp_aggregator_zero/test_bgp_aggregator_zero.py @@ -38,7 +38,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py b/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py index 4d41c7a321..4c0142fd03 100644 --- a/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py +++ b/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py @@ -51,7 +51,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration @@ -251,9 +251,11 @@ def test_bgp_allowas_in_p0(request): protocol=protocol, expected=False, ) - assert result is not True, "Testcase {} : Failed \n" - "Expected behavior: routes should not present in rib \n" - "Error: {}".format(tc_name, result) + assert result is not True, ( + "Testcase {} : Failed \n".format(tc_name) + + "Expected behavior: routes should not present in rib \n" + + "Error: {}".format(result) + ) step("Configure allowas-in on R3 for R2.") step("We should see the prefix advertised from R1 in R3's BGP table.") @@ -396,9 +398,11 @@ def test_bgp_allowas_in_per_addr_family_p0(request): result = verify_rib( tgen, "ipv6", dut, static_route_ipv6, protocol=protocol, expected=False ) - assert result is not True, "Testcase {} : Failed \n" - "Expected behavior: routes are should not be present in ipv6 rib\n" - " Error: {}".format(tc_name, result) + assert result is not True, ( + "Testcase {} : Failed \n".format(tc_name) + + "Expected behavior: routes are should not be present in ipv6 rib\n" + + " Error: {}".format(result) + ) step("Repeat the same test for IPv6 AFI.") step("Configure allowas-in on R3 for R2 under IPv6 addr-family only") @@ -444,9 +448,11 @@ def test_bgp_allowas_in_per_addr_family_p0(request): result = verify_rib( tgen, "ipv4", dut, static_route_ipv4, protocol=protocol, expected=False ) - assert result is not True, "Testcase {} : Failed \n" - "Expected behavior: routes should not be present in ipv4 rib\n" - " Error: {}".format(tc_name, result) + assert result is not True, ( + "Testcase {} : Failed \n".format(tc_name) + + "Expected behavior: routes should not be present in ipv4 rib\n" + + " Error: {}".format(result) + ) result = verify_rib(tgen, "ipv6", dut, static_route_ipv6, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) @@ -598,9 +604,11 @@ def test_bgp_allowas_in_no_of_occurrences_p0(request): result = verify_rib( tgen, addr_type, dut, static_routes, protocol=protocol, expected=False ) - assert result is not True, "Testcase {} : Failed \n " - "Expected behavior: routes are should not be present in rib\n" - "Error: {}".format(tc_name, result) + assert result is not True, ( + "Testcase {} : Failed \n ".format(tc_name) + + "Expected behavior: routes are should not be present in rib\n" + + "Error: {}".format(result) + ) for addr_type in ADDR_TYPES: step('Configure "allowas-in 5" on R3 for R2.') diff --git a/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py b/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py index a736463927..046f3f80a3 100644 --- a/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py +++ b/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py @@ -43,7 +43,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_aspath_zero/test_bgp_aspath_zero.py b/tests/topotests/bgp_aspath_zero/test_bgp_aspath_zero.py index 903ab12a13..3c264a7da0 100644 --- a/tests/topotests/bgp_aspath_zero/test_bgp_aspath_zero.py +++ b/tests/topotests/bgp_aspath_zero/test_bgp_aspath_zero.py @@ -38,7 +38,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_auth/test_bgp_auth.py b/tests/topotests/bgp_auth/test_bgp_auth.py index b2cdef1c93..b13f3d6e23 100644 --- a/tests/topotests/bgp_auth/test_bgp_auth.py +++ b/tests/topotests/bgp_auth/test_bgp_auth.py @@ -63,7 +63,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import apply_raw_config diff --git a/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py b/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py index 3623e89dcb..e3f07166f9 100644 --- a/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py +++ b/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py @@ -55,41 +55,24 @@ sys.path.append(os.path.join(CWD, "../lib/")) # Required to instantiate the topology builder class. +from lib.bgp import (clear_bgp_and_verify, create_router_bgp, modify_as_number, + verify_as_numbers, verify_bgp_convergence, verify_bgp_rib, + verify_bgp_timers_and_functionality, verify_router_id) +from lib.common_config import (addKernelRoute, apply_raw_config, + check_address_types, create_prefix_lists, + create_route_maps, create_static_routes, + required_linux_kernel_version, + reset_config_on_routers, start_topology, step, + verify_admin_distance_for_static_routes, + verify_bgp_community, verify_fib_routes, + verify_rib, write_test_footer, + write_test_header) +from lib.micronet_compat import Topo # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo - -from lib.common_config import ( - step, - start_topology, - write_test_header, - write_test_footer, - reset_config_on_routers, - create_static_routes, - verify_rib, - verify_admin_distance_for_static_routes, - check_address_types, - apply_raw_config, - addKernelRoute, - verify_fib_routes, - create_prefix_lists, - create_route_maps, - verify_bgp_community, - required_linux_kernel_version, -) +from lib.topojson import build_config_from_json, build_topo_from_json from lib.topolog import logger -from lib.bgp import ( - verify_bgp_convergence, - create_router_bgp, - verify_router_id, - modify_as_number, - verify_as_numbers, - clear_bgp_and_verify, - verify_bgp_timers_and_functionality, - verify_bgp_rib, -) -from lib.topojson import build_topo_from_json, build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] @@ -1158,10 +1141,12 @@ def test_bgp_with_loopback_with_same_subnet_p1(request): dut = "r1" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_fib_routes(tgen, addr_type, dut, input_dict_r1) - assert result is not True, "Testcase {} : Failed \n" - "Expected behavior: routes should not present in fib \n" - "Error: {}".format(tc_name, result) + result = verify_fib_routes(tgen, addr_type, dut, input_dict_r1, expected=False) # pylint: disable=E1123 + assert result is not True, ( + "Testcase {} : Failed \n".format(tc_name) + + "Expected behavior: routes should not present in fib \n" + + "Error: {}".format(result) + ) step("Verify Ipv4 and Ipv6 network installed in r3 RIB but not in FIB") input_dict_r3 = { @@ -1175,10 +1160,12 @@ def test_bgp_with_loopback_with_same_subnet_p1(request): dut = "r3" protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_fib_routes(tgen, addr_type, dut, input_dict_r1) - assert result is not True, "Testcase {} : Failed \n" - "Expected behavior: routes should not present in fib \n" - "Error: {}".format(tc_name, result) + result = verify_fib_routes(tgen, addr_type, dut, input_dict_r1, expected=False) # pylint: disable=E1123 + assert result is not True, ( + "Testcase {} : Failed \n".format(tc_name) + + "Expected behavior: routes should not present in fib \n" + + "Error: {}".format(result) + ) write_test_footer(tc_name) diff --git a/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py b/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py index 6512e4d4c6..7e78722da3 100644 --- a/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py +++ b/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py @@ -37,7 +37,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import step pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_comm_list_delete/test_bgp_comm-list_delete.py b/tests/topotests/bgp_comm_list_delete/test_bgp_comm-list_delete.py index 81bf8da31a..2c1546a3bf 100644 --- a/tests/topotests/bgp_comm_list_delete/test_bgp_comm-list_delete.py +++ b/tests/topotests/bgp_comm_list_delete/test_bgp_comm-list_delete.py @@ -43,7 +43,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_communities_topo1/test_bgp_communities.py b/tests/topotests/bgp_communities_topo1/test_bgp_communities.py index 6d4a7d82e5..f52f539afb 100644 --- a/tests/topotests/bgp_communities_topo1/test_bgp_communities.py +++ b/tests/topotests/bgp_communities_topo1/test_bgp_communities.py @@ -38,7 +38,7 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration diff --git a/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py b/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py index 3415789068..24dc6bb487 100644 --- a/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py +++ b/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py @@ -40,7 +40,7 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration diff --git a/tests/topotests/bgp_community_alias/test_bgp-community-alias.py b/tests/topotests/bgp_community_alias/test_bgp-community-alias.py index 26933a7992..2ef30249e7 100644 --- a/tests/topotests/bgp_community_alias/test_bgp-community-alias.py +++ b/tests/topotests/bgp_community_alias/test_bgp-community-alias.py @@ -38,7 +38,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_community_change_update/test_bgp_community_change_update.py b/tests/topotests/bgp_community_change_update/test_bgp_community_change_update.py index 9f449d7979..eee9294df4 100644 --- a/tests/topotests/bgp_community_change_update/test_bgp_community_change_update.py +++ b/tests/topotests/bgp_community_change_update/test_bgp_community_change_update.py @@ -54,7 +54,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import step from time import sleep diff --git a/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py b/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py index 44f54c7b51..9e020ae86e 100644 --- a/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py +++ b/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py @@ -137,7 +137,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_default_afi_safi/test_bgp-default-afi-safi.py b/tests/topotests/bgp_default_afi_safi/test_bgp-default-afi-safi.py index 6ed7023044..a22cd94063 100644 --- a/tests/topotests/bgp_default_afi_safi/test_bgp-default-afi-safi.py +++ b/tests/topotests/bgp_default_afi_safi/test_bgp-default-afi-safi.py @@ -44,7 +44,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import step pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_default_route/test_bgp_default-originate.py b/tests/topotests/bgp_default_route/test_bgp_default-originate.py index 6fbdfbe78a..68d9c52f45 100644 --- a/tests/topotests/bgp_default_route/test_bgp_default-originate.py +++ b/tests/topotests/bgp_default_route/test_bgp_default-originate.py @@ -36,7 +36,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_default_route_route_map_match/test_bgp_default-originate_route-map_match.py b/tests/topotests/bgp_default_route_route_map_match/test_bgp_default-originate_route-map_match.py index e7e3512b17..11a26570f8 100644 --- a/tests/topotests/bgp_default_route_route_map_match/test_bgp_default-originate_route-map_match.py +++ b/tests/topotests/bgp_default_route_route_map_match/test_bgp_default-originate_route-map_match.py @@ -36,7 +36,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_default_route_route_map_match2/test_bgp_default-originate_route-map_match2.py b/tests/topotests/bgp_default_route_route_map_match2/test_bgp_default-originate_route-map_match2.py index 5852ac268b..f8c36f6324 100644 --- a/tests/topotests/bgp_default_route_route_map_match2/test_bgp_default-originate_route-map_match2.py +++ b/tests/topotests/bgp_default_route_route_map_match2/test_bgp_default-originate_route-map_match2.py @@ -38,7 +38,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import step pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py b/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py index e2fa89fccb..3735fcfb3c 100644 --- a/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py +++ b/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py @@ -37,7 +37,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py b/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py index be87dc61cf..05f14f3525 100644 --- a/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py +++ b/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py @@ -36,7 +36,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_distance_change/test_bgp_distance_change.py b/tests/topotests/bgp_distance_change/test_bgp_distance_change.py index bf26714087..2583db01e1 100644 --- a/tests/topotests/bgp_distance_change/test_bgp_distance_change.py +++ b/tests/topotests/bgp_distance_change/test_bgp_distance_change.py @@ -47,7 +47,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_dont_capability_negogiate/test_bgp_dont_capability_negotiate.py b/tests/topotests/bgp_dont_capability_negogiate/test_bgp_dont_capability_negotiate.py index 398fa57ba9..6025ad935c 100644 --- a/tests/topotests/bgp_dont_capability_negogiate/test_bgp_dont_capability_negotiate.py +++ b/tests/topotests/bgp_dont_capability_negogiate/test_bgp_dont_capability_negotiate.py @@ -39,25 +39,13 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) - - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + topodef = { "s1": ("r1", "r2") } + tgen = Topogen(topodef, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_ebgp_common_subnet_nexthop_unchanged/test_bgp-ebgp-common-subnet-nexthop-unchanged.py b/tests/topotests/bgp_ebgp_common_subnet_nexthop_unchanged/test_bgp-ebgp-common-subnet-nexthop-unchanged.py index 6db2697e75..9460d6bae9 100644 --- a/tests/topotests/bgp_ebgp_common_subnet_nexthop_unchanged/test_bgp-ebgp-common-subnet-nexthop-unchanged.py +++ b/tests/topotests/bgp_ebgp_common_subnet_nexthop_unchanged/test_bgp-ebgp-common-subnet-nexthop-unchanged.py @@ -49,7 +49,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py b/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py index 2731d37fb0..390c8b2901 100644 --- a/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py +++ b/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py @@ -55,7 +55,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py b/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py index 75506d1a51..dea2ffbd8f 100644 --- a/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py +++ b/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py @@ -43,7 +43,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py b/tests/topotests/bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py index fffcbbd0ef..7bc3d2912d 100644 --- a/tests/topotests/bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py +++ b/tests/topotests/bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py @@ -50,7 +50,7 @@ sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import ( start_topology, diff --git a/tests/topotests/bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py b/tests/topotests/bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py index 342a0a4b2f..15982dad55 100644 --- a/tests/topotests/bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py +++ b/tests/topotests/bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py @@ -50,7 +50,7 @@ sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import ( start_topology, diff --git a/tests/topotests/bgp_evpn_mh/test_evpn_mh.py b/tests/topotests/bgp_evpn_mh/test_evpn_mh.py index 7c2787d557..8cdf3529dd 100644 --- a/tests/topotests/bgp_evpn_mh/test_evpn_mh.py +++ b/tests/topotests/bgp_evpn_mh/test_evpn_mh.py @@ -47,15 +47,13 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib import topotest +# Required to instantiate the topology builder class. +from lib.micronet_compat import Topo from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -# Required to instantiate the topology builder class. -from mininet.topo import Topo - pytestmark = [pytest.mark.bgpd, pytest.mark.pimd] - ##################################################### ## ## Network Topology Definition diff --git a/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py b/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py index a411f13d2e..7a53173dca 100755 --- a/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py +++ b/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py @@ -75,7 +75,7 @@ from lib.common_config import ( ) # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] @@ -142,47 +142,58 @@ def setup_module(mod): tgen.start_topology() # Configure MAC address for hosts as these MACs are advertised with EVPN type-2 routes - for (name, host) in tgen.gears.items(): + for name in tgen.gears: if name not in HOSTS: continue + host = tgen.net[name] host_mac = "1a:2b:3c:4d:5e:6{}".format(HOST_SUFFIX[name]) - host.run("ip link set dev {}-eth0 down").format(name) - host.run("ip link set dev {0}-eth0 address {1}".format(name, host_mac)) - host.run("ip link set dev {}-eth0 up").format(name) + host.cmd_raises("ip link set dev {}-eth0 down".format(name)) + host.cmd_raises("ip link set dev {0}-eth0 address {1}".format(name, host_mac)) + host.cmd_raises("ip link set dev {}-eth0 up".format(name)) # Configure PE VxLAN and Bridge interfaces - for (name, pe) in tgen.gears.items(): + for name in tgen.gears: if name not in PES: continue + pe = tgen.net[name] + vtep_ip = "10.100.0.{}".format(PE_SUFFIX[name]) bridge_ip = "50.0.1.{}/24".format(PE_SUFFIX[name]) bridge_ipv6 = "50:0:1::{}/48".format(PE_SUFFIX[name]) - pe.run("ip link add vrf-blue type vrf table 10") - pe.run("ip link set dev vrf-blue up") - pe.run("ip link add vxlan100 type vxlan id 100 dstport 4789 local {}".format(vtep_ip)) - pe.run("ip link add name br100 type bridge stp_state 0") - pe.run("ip link set dev vxlan100 master br100") - pe.run("ip link set dev {}-eth1 master br100".format(name)) - pe.run("ip addr add {} dev br100".format(bridge_ip)) - pe.run("ip link set up dev br100") - pe.run("ip link set up dev vxlan100") - pe.run("ip link set up dev {}-eth1".format(name)) - pe.run("ip link set dev br100 master vrf-blue") - pe.run("ip -6 addr add {} dev br100".format(bridge_ipv6)) + pe.cmd_raises("ip link add vrf-blue type vrf table 10") + pe.cmd_raises("ip link set dev vrf-blue up") + pe.cmd_raises( + "ip link add vxlan100 type vxlan id 100 dstport 4789 local {}".format( + vtep_ip + ) + ) + pe.cmd_raises("ip link add name br100 type bridge stp_state 0") + pe.cmd_raises("ip link set dev vxlan100 master br100") + pe.cmd_raises("ip link set dev {}-eth1 master br100".format(name)) + pe.cmd_raises("ip addr add {} dev br100".format(bridge_ip)) + pe.cmd_raises("ip link set up dev br100") + pe.cmd_raises("ip link set up dev vxlan100") + pe.cmd_raises("ip link set up dev {}-eth1".format(name)) + pe.cmd_raises("ip link set dev br100 master vrf-blue") + pe.cmd_raises("ip -6 addr add {} dev br100".format(bridge_ipv6)) - pe.run("ip link add vxlan1000 type vxlan id 1000 dstport 4789 local {}".format(vtep_ip)) - pe.run("ip link add name br1000 type bridge stp_state 0") - pe.run("ip link set dev vxlan1000 master br100") - pe.run("ip link set up dev br1000") - pe.run("ip link set up dev vxlan1000") - pe.run("ip link set dev br1000 master vrf-blue") + pe.cmd_raises( + "ip link add vxlan1000 type vxlan id 1000 dstport 4789 local {}".format( + vtep_ip + ) + ) + pe.cmd_raises("ip link add name br1000 type bridge stp_state 0") + pe.cmd_raises("ip link set dev vxlan1000 master br100") + pe.cmd_raises("ip link set up dev br1000") + pe.cmd_raises("ip link set up dev vxlan1000") + pe.cmd_raises("ip link set dev br1000 master vrf-blue") - pe.run("sysctl -w net.ipv4.ip_forward=1") - pe.run("sysctl -w net.ipv6.conf.all.forwarding=1") - pe.run("sysctl -w net.ipv4.udp_l3mdev_accept={}".format(l3mdev_accept)) - pe.run("sysctl -w net.ipv4.tcp_l3mdev_accept={}".format(l3mdev_accept)) + pe.cmd_raises("sysctl -w net.ipv4.ip_forward=1") + pe.cmd_raises("sysctl -w net.ipv6.conf.all.forwarding=1") + pe.cmd_raises("sysctl -w net.ipv4.udp_l3mdev_accept={}".format(l3mdev_accept)) + pe.cmd_raises("sysctl -w net.ipv4.tcp_l3mdev_accept={}".format(l3mdev_accept)) # For all registred routers, load the zebra configuration file for (name, router) in tgen.routers().items(): @@ -353,9 +364,9 @@ def test_evpn_gateway_ip_flap_rt2(request): step("Shut down VxLAN interface at PE1 which results in withdraw of type-2 routes") - pe1 = tgen.gears['PE1'] + pe1 = tgen.net["PE1"] - pe1.run('ip link set dev vxlan100 down') + pe1.cmd_raises("ip link set dev vxlan100 down") result, assertmsg = evpn_gateway_ip_show_op_check("no_rt2") if result is not None: @@ -364,7 +375,7 @@ def test_evpn_gateway_ip_flap_rt2(request): step("Bring up VxLAN interface at PE1 and advertise type-2 routes again") - pe1.run('ip link set dev vxlan100 up') + pe1.cmd_raises("ip link set dev vxlan100 up") result, assertmsg = evpn_gateway_ip_show_op_check("base") if result is not None: diff --git a/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py b/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py index 59024f7b71..02e67b70c0 100644 --- a/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py +++ b/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py @@ -44,7 +44,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] @@ -97,12 +97,6 @@ def setup_module(mod): "ip link set dev loop101 master {}-vrf-101", "ip link set dev loop101 up", ] - cmds_netns = [ - "ip netns add {}-vrf-101", - "ip link add loop101 type dummy", - "ip link set dev loop101 netns {}-vrf-101", - "ip netns exec {}-vrf-101 ip link set dev loop101 up", - ] cmds_r2 = [ # config routing 101 "ip link add name bridge-101 up type bridge stp_state 0", @@ -113,40 +107,41 @@ def setup_module(mod): "ip link set vxlan-101 up type bridge_slave learning off flood off mcast_flood off", ] - cmds_r1_netns_method3 = [ - "ip link add name vxlan-{1} type vxlan id {1} dstport 4789 dev {0}-eth0 local 192.168.100.21", - "ip link set dev vxlan-{1} netns {0}-vrf-{1}", - "ip netns exec {0}-vrf-{1} ip li set dev lo up", - "ip netns exec {0}-vrf-{1} ip link add name bridge-{1} up type bridge stp_state 0", - "ip netns exec {0}-vrf-{1} ip link set dev vxlan-{1} master bridge-{1}", - "ip netns exec {0}-vrf-{1} ip link set bridge-{1} up", - "ip netns exec {0}-vrf-{1} ip link set vxlan-{1} up", - ] + # cmds_r1_netns_method3 = [ + # "ip link add name vxlan-{1} type vxlan id {1} dstport 4789 dev {0}-eth0 local 192.168.100.21", + # "ip link set dev vxlan-{1} netns {0}-vrf-{1}", + # "ip netns exec {0}-vrf-{1} ip li set dev lo up", + # "ip netns exec {0}-vrf-{1} ip link add name bridge-{1} up type bridge stp_state 0", + # "ip netns exec {0}-vrf-{1} ip link set dev vxlan-{1} master bridge-{1}", + # "ip netns exec {0}-vrf-{1} ip link set bridge-{1} up", + # "ip netns exec {0}-vrf-{1} ip link set vxlan-{1} up", + # ] router = tgen.gears["r1"] - for cmd in cmds_netns: - logger.info("cmd to r1: " + cmd) - output = router.run(cmd.format("r1")) - logger.info("result: " + output) + + ns = "r1-vrf-101" + tgen.net["r1"].add_netns(ns) + tgen.net["r1"].cmd_raises("ip link add loop101 type dummy") + tgen.net["r1"].set_intf_netns("loop101", ns, up=True) router = tgen.gears["r2"] for cmd in cmds_vrflite: logger.info("cmd to r2: " + cmd.format("r2")) - output = router.run(cmd.format("r2")) + output = router.cmd_raises(cmd.format("r2")) logger.info("result: " + output) for cmd in cmds_r2: logger.info("cmd to r2: " + cmd.format("r2")) - output = router.run(cmd.format("r2")) + output = router.cmd_raises(cmd.format("r2")) logger.info("result: " + output) - router = tgen.gears["r1"] - bridge_id = "101" - for cmd in cmds_r1_netns_method3: - logger.info("cmd to r1: " + cmd.format("r1", bridge_id)) - output = router.run(cmd.format("r1", bridge_id)) - logger.info("result: " + output) - router = tgen.gears["r1"] + tgen.net["r1"].cmd_raises("ip link add name vxlan-101 type vxlan id 101 dstport 4789 dev r1-eth0 local 192.168.100.21") + tgen.net["r1"].set_intf_netns("vxlan-101", "r1-vrf-101", up=True) + tgen.net["r1"].cmd_raises("ip -n r1-vrf-101 link set lo up") + tgen.net["r1"].cmd_raises("ip -n r1-vrf-101 link add name bridge-101 up type bridge stp_state 0") + tgen.net["r1"].cmd_raises("ip -n r1-vrf-101 link set dev vxlan-101 master bridge-101") + tgen.net["r1"].cmd_raises("ip -n r1-vrf-101 link set bridge-101 up") + tgen.net["r1"].cmd_raises("ip -n r1-vrf-101 link set vxlan-101 up") for rname, router in router_list.items(): if rname == "r1": @@ -170,12 +165,8 @@ def setup_module(mod): def teardown_module(_mod): "Teardown the pytest environment" tgen = get_topogen() - cmds_rx_netns = ["ip netns del {}-vrf-101"] - router = tgen.gears["r1"] - for cmd in cmds_rx_netns: - logger.info("cmd to r1: " + cmd.format("r1")) - output = router.run(cmd.format("r1")) + tgen.net["r1"].delete_netns("r1-vrf-101") tgen.stop_topology() diff --git a/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py b/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py index 763cf9c156..0380ac07d0 100755 --- a/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py +++ b/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py @@ -44,7 +44,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd] diff --git a/tests/topotests/bgp_features/test_bgp_features.py b/tests/topotests/bgp_features/test_bgp_features.py index d19b7722d0..54f61f92e5 100644 --- a/tests/topotests/bgp_features/test_bgp_features.py +++ b/tests/topotests/bgp_features/test_bgp_features.py @@ -45,7 +45,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd] diff --git a/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py b/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py index fdd84fcd40..6a12ed80d3 100644 --- a/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py +++ b/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py @@ -69,7 +69,7 @@ from lib.lutil import lUtil from lib.lutil import luCommand # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py b/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py index 330ae5e437..bd3f6209ae 100644 --- a/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py +++ b/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py @@ -106,7 +106,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo # Import topoJson from lib, to create topology and initial configuration from lib.topojson import build_topo_from_json, build_config_from_json diff --git a/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py b/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py index 83bf4fcc18..dd44cbf96d 100644 --- a/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py +++ b/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py @@ -102,7 +102,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo # Import topoJson from lib, to create topology and initial configuration from lib.topojson import build_topo_from_json, build_config_from_json diff --git a/tests/topotests/bgp_gshut/test_bgp_gshut.py b/tests/topotests/bgp_gshut/test_bgp_gshut.py index 77f86a0bb8..d32ba1c1f1 100644 --- a/tests/topotests/bgp_gshut/test_bgp_gshut.py +++ b/tests/topotests/bgp_gshut/test_bgp_gshut.py @@ -73,7 +73,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_gshut_topo1/test_ebgp_gshut_topo1.py b/tests/topotests/bgp_gshut_topo1/test_ebgp_gshut_topo1.py index fcfeaab613..2595b20996 100644 --- a/tests/topotests/bgp_gshut_topo1/test_ebgp_gshut_topo1.py +++ b/tests/topotests/bgp_gshut_topo1/test_ebgp_gshut_topo1.py @@ -42,7 +42,7 @@ sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from time import sleep from lib.common_config import ( diff --git a/tests/topotests/bgp_gshut_topo1/test_ibgp_gshut_topo1.py b/tests/topotests/bgp_gshut_topo1/test_ibgp_gshut_topo1.py index d83e9e25a1..3f3354dc80 100644 --- a/tests/topotests/bgp_gshut_topo1/test_ibgp_gshut_topo1.py +++ b/tests/topotests/bgp_gshut_topo1/test_ibgp_gshut_topo1.py @@ -42,7 +42,7 @@ sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from time import sleep from lib.common_config import ( diff --git a/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py b/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py index 0df2c9cb5a..dc587cd709 100644 --- a/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py +++ b/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py @@ -43,7 +43,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py b/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py index 752e37f5f8..6eaf8e07f9 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py @@ -85,7 +85,7 @@ from lib.topolog import logger from lib.ltemplate import ltemplateRtrCmd # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo import shutil @@ -146,10 +146,6 @@ def ltemplatePreRouterStartHook(): if tgen.hasmpls != True: logger.info("MPLS not available, skipping setup") return False - # check for normal init - if len(tgen.net) == 1: - logger.info("Topology not configured, skipping setup") - return False # configure r2 mpls interfaces intfs = ["lo", "r2-eth0", "r2-eth1", "r2-eth2"] for intf in intfs: diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py index c2f85c68c4..40009b9ba9 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py @@ -86,7 +86,7 @@ from lib.topolog import logger from lib.ltemplate import ltemplateRtrCmd # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo import shutil @@ -155,10 +155,6 @@ def ltemplatePreRouterStartHook(): if tgen.hasmpls != True: logger.info("MPLS not available, skipping setup") return False - # check for normal init - if len(tgen.net) == 1: - logger.info("Topology not configured, skipping setup") - return False # trace errors/unexpected output cc.resetCounts() # configure r2 mpls interfaces diff --git a/tests/topotests/bgp_large_community/bgp_large_community_topo_2.json b/tests/topotests/bgp_large_community/bgp_large_community_topo_2.json index 6f1ca90afb..36dee39a13 100644 --- a/tests/topotests/bgp_large_community/bgp_large_community_topo_2.json +++ b/tests/topotests/bgp_large_community/bgp_large_community_topo_2.json @@ -12,7 +12,7 @@ "lo_prefix": { "ipv4": "1.0.", "v4mask": 32, - "ipv6": "2001:DB8:F::", + "ipv6": "2001:db8:f::", "v6mask": 128 }, "routers": { diff --git a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py index 69eba23e0f..d138a689e2 100644 --- a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py +++ b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py @@ -54,7 +54,7 @@ from json import load as json_load # Required to instantiate the topology builder class. from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import ( start_topology, diff --git a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py index b033c7e5cd..c9115bf42b 100644 --- a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py +++ b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py @@ -74,7 +74,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # Import topogen and topotest helpers # Import topoJson from lib, to create topology and initial configuration from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import ( start_topology, diff --git a/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py b/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py index a9b4b6b031..4ad1dbcaa6 100644 --- a/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py +++ b/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py @@ -44,7 +44,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_listen_on_multiple_addresses/test_bgp_listen_on_multiple_addresses.py b/tests/topotests/bgp_listen_on_multiple_addresses/test_bgp_listen_on_multiple_addresses.py index a7959fe61b..fdbc5e553b 100755 --- a/tests/topotests/bgp_listen_on_multiple_addresses/test_bgp_listen_on_multiple_addresses.py +++ b/tests/topotests/bgp_listen_on_multiple_addresses/test_bgp_listen_on_multiple_addresses.py @@ -53,7 +53,7 @@ from lib.topojson import build_topo_from_json, build_config_from_json from lib.topojson import linux_intf_config_from_json from lib.common_config import start_topology from lib.topotest import router_json_cmp, run_and_expect -from mininet.topo import Topo +from lib.micronet_compat import Topo from functools import partial pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py b/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py index 7c5ed87dd0..ec4919650e 100644 --- a/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py +++ b/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py @@ -41,7 +41,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_lu_topo1/test_bgp_lu.py b/tests/topotests/bgp_lu_topo1/test_bgp_lu.py index d1745674f0..258ddb148d 100644 --- a/tests/topotests/bgp_lu_topo1/test_bgp_lu.py +++ b/tests/topotests/bgp_lu_topo1/test_bgp_lu.py @@ -43,7 +43,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py b/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py index 0fde32a68b..c800946840 100644 --- a/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py +++ b/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py @@ -45,7 +45,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py b/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py index 5c93910788..5b762bfe52 100644 --- a/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py +++ b/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py @@ -41,7 +41,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py b/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py index 84e10af5b3..9a20f7d451 100644 --- a/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py +++ b/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py @@ -114,7 +114,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topotest import iproute2_is_vrf_capable from lib.common_config import ( step, diff --git a/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py b/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py index 31569e69b4..7fd9fac6ef 100644 --- a/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py +++ b/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py @@ -70,7 +70,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topotest import iproute2_is_vrf_capable from lib.common_config import ( step, diff --git a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py index caaa810662..a949c5282c 100644 --- a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py +++ b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py @@ -70,17 +70,12 @@ import glob import json from time import sleep -from mininet.topo import Topo -from mininet.net import Mininet -from mininet.node import Node, OVSSwitch, Host -from mininet.log import setLogLevel, info -from mininet.cli import CLI -from mininet.link import Intf - from functools import partial sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lib import topotest +from lib.micronet_compat import Mininet +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] @@ -121,10 +116,10 @@ class NetworkTopo(Topo): # Setup Switches switch = {} # First switch is for a dummy interface (for local network) - switch[0] = self.addSwitch("sw0", cls=topotest.LegacySwitch) + switch[0] = self.addSwitch("sw0") self.addLink(switch[0], router[1], intfName2="r1-stub") # Second switch is for connection to all peering routers - switch[1] = self.addSwitch("sw1", cls=topotest.LegacySwitch) + switch[1] = self.addSwitch("sw1") self.addLink(switch[1], router[1], intfName2="r1-eth0") for j in range(1, 9): self.addLink(switch[1], peer[j], intfName2="peer%s-eth0" % j) @@ -353,8 +348,6 @@ def test_shutdown_check_memleak(): if __name__ == "__main__": - - setLogLevel("info") # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli # retval = pytest.main(["-s", "--tb=no"]) retval = pytest.main(["-s"]) diff --git a/tests/topotests/bgp_path_attributes_topo1/test_bgp_path_attributes.py b/tests/topotests/bgp_path_attributes_topo1/test_bgp_path_attributes.py index a591c2f3f4..0fc9b7e021 100644 --- a/tests/topotests/bgp_path_attributes_topo1/test_bgp_path_attributes.py +++ b/tests/topotests/bgp_path_attributes_topo1/test_bgp_path_attributes.py @@ -65,7 +65,7 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen diff --git a/tests/topotests/bgp_peer_group/test_bgp_peer-group.py b/tests/topotests/bgp_peer_group/test_bgp_peer-group.py index 21dc725793..70e49d5cd4 100644 --- a/tests/topotests/bgp_peer_group/test_bgp_peer-group.py +++ b/tests/topotests/bgp_peer_group/test_bgp_peer-group.py @@ -36,7 +36,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py b/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py index 743fcf7b3a..c5924c787c 100755 --- a/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py +++ b/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py @@ -71,7 +71,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_prefix_list_topo1/test_prefix_lists.py b/tests/topotests/bgp_prefix_list_topo1/test_prefix_lists.py index 10dee0f77b..287ff87bf8 100644 --- a/tests/topotests/bgp_prefix_list_topo1/test_prefix_lists.py +++ b/tests/topotests/bgp_prefix_list_topo1/test_prefix_lists.py @@ -55,7 +55,7 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration diff --git a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py index fffe135b77..72df2eab6b 100644 --- a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py +++ b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py @@ -39,7 +39,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_prefix_sid2/test_bgp_prefix_sid2.py b/tests/topotests/bgp_prefix_sid2/test_bgp_prefix_sid2.py index 703dcd7e2d..6da44faf57 100755 --- a/tests/topotests/bgp_prefix_sid2/test_bgp_prefix_sid2.py +++ b/tests/topotests/bgp_prefix_sid2/test_bgp_prefix_sid2.py @@ -39,7 +39,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py b/tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py index 2fe80c77f0..320c7eb78c 100644 --- a/tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py +++ b/tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py @@ -52,7 +52,7 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib import topotest -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration diff --git a/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py b/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py index c644d2104f..f13b068d96 100644 --- a/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py +++ b/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py @@ -48,7 +48,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_rfapi_basic_sanity/customize.py b/tests/topotests/bgp_rfapi_basic_sanity/customize.py index 2c85cf6e9d..9166c57dfc 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/customize.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/customize.py @@ -72,7 +72,7 @@ from lib.topolog import logger from lib.ltemplate import ltemplateRtrCmd # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo import shutil @@ -116,10 +116,6 @@ def ltemplatePreRouterStartHook(): cc = ltemplateRtrCmd() tgen = get_topogen() logger.info("pre router-start hook") - # check for normal init - if len(tgen.net) == 1: - logger.info("Topology not configured, skipping setup") - return False return True diff --git a/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py b/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py index ecf1ed521c..04a66d0e25 100644 --- a/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py +++ b/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py @@ -43,7 +43,7 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib import topotest -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration diff --git a/tests/topotests/bgp_route_map/test_route_map_topo1.py b/tests/topotests/bgp_route_map/test_route_map_topo1.py index 7de56849c8..17058d178b 100644 --- a/tests/topotests/bgp_route_map/test_route_map_topo1.py +++ b/tests/topotests/bgp_route_map/test_route_map_topo1.py @@ -36,7 +36,7 @@ sys.path.append(os.path.join(CWD, "../")) # Import topogen and topotest helpers from lib import topotest from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo # Required to instantiate the topology builder class. from lib.topojson import * diff --git a/tests/topotests/bgp_route_map/test_route_map_topo2.py b/tests/topotests/bgp_route_map/test_route_map_topo2.py index 230a89ace1..54b3340d68 100644 --- a/tests/topotests/bgp_route_map/test_route_map_topo2.py +++ b/tests/topotests/bgp_route_map/test_route_map_topo2.py @@ -118,7 +118,7 @@ sys.path.append(os.path.join(CWD, "../")) # Import topogen and topotest helpers from lib import topotest from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo # Required to instantiate the topology builder class. from lib.common_config import ( diff --git a/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py b/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py index 664c9dc91a..72c25a3c6f 100644 --- a/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py +++ b/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py @@ -47,7 +47,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py b/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py index dffe24f3a0..526e1202da 100644 --- a/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py +++ b/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py @@ -41,7 +41,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_set_local_preference_add_subtract/test_bgp_set_local-preference_add_subtract.py b/tests/topotests/bgp_set_local_preference_add_subtract/test_bgp_set_local-preference_add_subtract.py index b4af911d91..531e1814a5 100644 --- a/tests/topotests/bgp_set_local_preference_add_subtract/test_bgp_set_local-preference_add_subtract.py +++ b/tests/topotests/bgp_set_local_preference_add_subtract/test_bgp_set_local-preference_add_subtract.py @@ -42,7 +42,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/ce1/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/ce1/snmpd.conf index 36218d3538..4aff57acaf 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/ce1/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/ce1/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/ce2/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/ce2/snmpd.conf index 714585cb9b..29c2041d12 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/ce2/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/ce2/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/ce3/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/ce3/snmpd.conf index 36218d3538..4aff57acaf 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/ce3/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/ce3/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/ce4/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/ce4/snmpd.conf index 36218d3538..4aff57acaf 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/ce4/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/ce4/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/r1/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/r1/snmpd.conf index c903c1ad2e..2ada53ced9 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/r1/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/r1/snmpd.conf @@ -14,4 +14,7 @@ rouser frr master agentx -noRangeCheck yes \ No newline at end of file +noRangeCheck yes + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/r2/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/r2/snmpd.conf index 0cfebc7238..3db1ab7ace 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/r2/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/r2/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/r3/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/r3/snmpd.conf index b9eb00ea52..494df81ffb 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/r3/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/r3/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/r4/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/r4/snmpd.conf index ec35f9f9c9..f3809607e3 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/r4/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/r4/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/test_bgp_snmp_mplsvpn.py b/tests/topotests/bgp_snmp_mplsl3vpn/test_bgp_snmp_mplsvpn.py index b830e16b9a..37486f1d73 100755 --- a/tests/topotests/bgp_snmp_mplsl3vpn/test_bgp_snmp_mplsvpn.py +++ b/tests/topotests/bgp_snmp_mplsl3vpn/test_bgp_snmp_mplsvpn.py @@ -45,7 +45,7 @@ from lib.topolog import logger from lib.snmptest import SnmpTester # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.isisd, pytest.mark.snmp] @@ -255,7 +255,7 @@ def test_pe1_converge_evpn(): "Wait for protocol convergence" tgen = get_topogen() - r1 = tgen.net.get("r1") + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "10.1.1.1", "public", "2c") assertmsg = "BGP SNMP does not seem to be running" @@ -297,7 +297,7 @@ interfaces_down_test = { def test_r1_mplsvpn_scalars(): "check scalar values" tgen = get_topogen() - r1 = tgen.net.get("r1") + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "10.1.1.1", "public", "2c") for item in interfaces_up_test.keys(): @@ -310,12 +310,11 @@ def test_r1_mplsvpn_scalars(): def test_r1_mplsvpn_scalars_interface(): "check scalar interface changing values" tgen = get_topogen() - r1 = tgen.net.get("r1") - r1_cmd = tgen.gears["r1"] + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "10.1.1.1", "public", "2c") - r1_cmd.vtysh_cmd("conf t\ninterface r1-eth3\nshutdown") - r1_cmd.vtysh_cmd("conf t\ninterface r1-eth4\nshutdown") + r1.vtysh_cmd("conf t\ninterface r1-eth3\nshutdown") + r1.vtysh_cmd("conf t\ninterface r1-eth4\nshutdown") for item in interfaces_up_test.keys(): assertmsg = "{} should be {}: value {}".format( @@ -323,8 +322,8 @@ def test_r1_mplsvpn_scalars_interface(): ) assert r1_snmp.test_oid(item, interfaces_down_test[item]), assertmsg - r1_cmd.vtysh_cmd("conf t\ninterface r1-eth3\nno shutdown") - r1_cmd.vtysh_cmd("conf t\ninterface r1-eth4\nno shutdown") + r1.vtysh_cmd("conf t\ninterface r1-eth3\nno shutdown") + r1.vtysh_cmd("conf t\ninterface r1-eth4\nno shutdown") for item in interfaces_up_test.keys(): assertmsg = "{} should be {}: value {}".format( @@ -378,15 +377,14 @@ def test_r1_mplsvpn_IfTable(): "mplsL3VpnIf table values" tgen = get_topogen() - r1 = tgen.net.get("r1") - r1r = tgen.gears["r1"] + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "10.1.1.1", "public", "2c") # tgen.mininet_cli() - eth3_ifindex = router_interface_get_ifindex(r1r, "eth3") - eth4_ifindex = router_interface_get_ifindex(r1r, "eth4") - eth5_ifindex = router_interface_get_ifindex(r1r, "eth5") + eth3_ifindex = router_interface_get_ifindex(r1, "eth3") + eth4_ifindex = router_interface_get_ifindex(r1, "eth4") + eth5_ifindex = router_interface_get_ifindex(r1, "eth5") # get ifindex and make sure the oid is correct @@ -432,8 +430,7 @@ vrftable_test = { def test_r1_mplsvpn_VrfTable(): tgen = get_topogen() - r1 = tgen.net.get("r1") - r1r = tgen.gears["r1"] + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "10.1.1.1", "public", "2c") @@ -476,7 +473,7 @@ def test_r1_mplsvpn_VrfTable(): "mplsL3VpnVrfConfLastChanged.{}".format(snmp_str_to_oid("VRF-a")) ) ts_val_last_1 = get_timetick_val(ts_last) - r1r.vtysh_cmd("conf t\ninterface r1-eth3\nshutdown") + r1.vtysh_cmd("conf t\ninterface r1-eth3\nshutdown") active_int = r1_snmp.get( "mplsL3VpnVrfActiveInterfaces.{}".format(snmp_str_to_oid("VRF-a")) ) @@ -491,7 +488,7 @@ def test_r1_mplsvpn_VrfTable(): ts_val_last_2 = get_timetick_val(ts_last) assertmsg = "mplsL3VpnVrfConfLastChanged does not update on interface change" assert ts_val_last_2 > ts_val_last_1, assertmsg - r1r.vtysh_cmd("conf t\ninterface r1-eth3\nno shutdown") + r1.vtysh_cmd("conf t\ninterface r1-eth3\nno shutdown") # take Last changed time, fiddle with associated interfaces, ensure # time changes and active interfaces change @@ -533,8 +530,7 @@ rt_table_test = { def test_r1_mplsvpn_VrfRT_table(): tgen = get_topogen() - r1 = tgen.net.get("r1") - r1r = tgen.gears["r1"] + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "10.1.1.1", "public", "2c") @@ -554,8 +550,7 @@ def test_r1_mplsvpn_VrfRT_table(): def test_r1_mplsvpn_perf_table(): tgen = get_topogen() - r1 = tgen.net.get("r1") - r1r = tgen.gears["r1"] + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "10.1.1.1", "public", "2c") @@ -682,8 +677,7 @@ rte_table_test = { def test_r1_mplsvpn_rte_table(): tgen = get_topogen() - r1 = tgen.net.get("r1") - r1r = tgen.gears["r1"] + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "10.1.1.1", "public", "2c") @@ -734,12 +728,12 @@ def test_r1_mplsvpn_rte_table(): # generate ifindex row grabbing ifindices from vtysh if passed: ifindex_row = [ - router_interface_get_ifindex(r1r, "eth3"), - router_interface_get_ifindex(r1r, "eth4"), - router_interface_get_ifindex(r1r, "eth2"), - router_interface_get_ifindex(r1r, "eth3"), + router_interface_get_ifindex(r1, "eth3"), + router_interface_get_ifindex(r1, "eth4"), + router_interface_get_ifindex(r1, "eth2"), + router_interface_get_ifindex(r1, "eth3"), "0", - router_interface_get_ifindex(r1r, "eth4"), + router_interface_get_ifindex(r1, "eth4"), "0", ] if not r1_snmp.test_oid_walk( diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py index 3251484514..a50151ab23 100755 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py @@ -37,7 +37,7 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from lib.common_config import required_linux_kernel_version -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py b/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py index 476f6b556b..3e421ad5c1 100644 --- a/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py +++ b/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py @@ -38,7 +38,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_tcp_mss/test_bgp_tcp_mss.py b/tests/topotests/bgp_tcp_mss/test_bgp_tcp_mss.py index cb1d28cc06..7ca30daf42 100644 --- a/tests/topotests/bgp_tcp_mss/test_bgp_tcp_mss.py +++ b/tests/topotests/bgp_tcp_mss/test_bgp_tcp_mss.py @@ -49,7 +49,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_update_delay/test_bgp_update_delay.py b/tests/topotests/bgp_update_delay/test_bgp_update_delay.py index 2972a25f38..a936d44d1b 100644 --- a/tests/topotests/bgp_update_delay/test_bgp_update_delay.py +++ b/tests/topotests/bgp_update_delay/test_bgp_update_delay.py @@ -71,7 +71,7 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py index 1e371f2195..55b4f1581f 100644 --- a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py +++ b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py @@ -49,7 +49,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen from lib.topotest import version_cmp -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import ( start_topology, diff --git a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py index f701529b52..18f048129c 100644 --- a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py +++ b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py @@ -47,7 +47,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen from lib.topotest import version_cmp -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import ( start_topology, diff --git a/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py b/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py index 57ba87e887..b818816d9e 100644 --- a/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py +++ b/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py @@ -45,7 +45,7 @@ from lib.topolog import logger from lib.common_config import required_linux_kernel_version # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py b/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py index 60511aebde..9c4c78bf1a 100644 --- a/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py +++ b/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py @@ -42,7 +42,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] @@ -108,24 +108,11 @@ def setup_module(module): # create VRF r1-bgp-cust1 # move r1-eth0 to VRF r1-bgp-cust1 - cmds = [ - "if [ -e /var/run/netns/{0}-bgp-cust1 ] ; then ip netns del {0}-bgp-cust1 ; fi", - "ip netns add {0}-bgp-cust1", - "ip link set {0}-eth0 netns {0}-bgp-cust1 up", - ] - for cmd in cmds: - cmd = cmd.format("r1") - logger.info("cmd: " + cmd) - output = router.run(cmd.format("r1")) - if output != None and len(output) > 0: - logger.info( - 'Aborting due to unexpected output: cmd="{}" output=\n{}'.format( - cmd, output - ) - ) - return pytest.skip( - "Skipping BGP VRF NETNS Test. Unexpected output to command: " + cmd - ) + + ns = "{}-bgp-cust1".format("r1") + router.net.add_netns(ns) + router.net.set_intf_netns("r1-eth0", ns, up=True) + # run daemons router.load_config( TopoRouter.RD_ZEBRA, @@ -152,14 +139,10 @@ def setup_module(module): def teardown_module(module): tgen = get_topogen() - # move back r1-eth0 to default VRF - # delete VRF r1-bgp-cust1 - cmds = [ - "ip netns exec {0}-bgp-cust1 ip link set {0}-eth0 netns 1", - "ip netns delete {0}-bgp-cust1", - ] - for cmd in cmds: - tgen.net["r1"].cmd(cmd.format("r1")) + + # Move interfaces out of vrf namespace and delete the namespace + tgen.net["r1"].reset_intf_netns("r1-eth0") + tgen.net["r1"].delete_netns("r1-bgp-cust1") tgen.stop_topology() diff --git a/tests/topotests/bgp_vrf_route_leak_basic/test_bgp-vrf-route-leak-basic.py b/tests/topotests/bgp_vrf_route_leak_basic/test_bgp-vrf-route-leak-basic.py index fcec0c23af..7ab2c608b1 100644 --- a/tests/topotests/bgp_vrf_route_leak_basic/test_bgp-vrf-route-leak-basic.py +++ b/tests/topotests/bgp_vrf_route_leak_basic/test_bgp-vrf-route-leak-basic.py @@ -39,7 +39,7 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/config_timing/test_config_timing.py b/tests/topotests/config_timing/test_config_timing.py index db8baa860d..54dca32e17 100644 --- a/tests/topotests/config_timing/test_config_timing.py +++ b/tests/topotests/config_timing/test_config_timing.py @@ -45,7 +45,7 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.staticd] @@ -172,7 +172,7 @@ def test_static_timing(): do_config(prefix_count, bad_indices, base_delta, 2, True, ipv6, prefix_base[ipv6][0]) # Remove 1/2 of duplicate - do_config(prefix_count / 2, bad_indices, base_delta, 2, False, ipv6, prefix_base[ipv6][0]) + do_config(prefix_count // 2, bad_indices, base_delta, 2, False, ipv6, prefix_base[ipv6][0]) # Add all back in so 1/2 replicate 1/2 new do_config(prefix_count, bad_indices, base_delta, 2, True, ipv6, prefix_base[ipv6][0]) diff --git a/tests/topotests/eigrp_topo1/test_eigrp_topo1.py b/tests/topotests/eigrp_topo1/test_eigrp_topo1.py index 6993bc53e7..982d3f0fa3 100644 --- a/tests/topotests/eigrp_topo1/test_eigrp_topo1.py +++ b/tests/topotests/eigrp_topo1/test_eigrp_topo1.py @@ -46,7 +46,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo ##################################################### ## diff --git a/tests/topotests/evpn_pim_1/test_evpn_pim_topo1.py b/tests/topotests/evpn_pim_1/test_evpn_pim_topo1.py index b1f5daef1e..e549d1acb2 100644 --- a/tests/topotests/evpn_pim_1/test_evpn_pim_topo1.py +++ b/tests/topotests/evpn_pim_1/test_evpn_pim_topo1.py @@ -47,7 +47,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.bgpd] diff --git a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py index 09d66baa79..86253acc4d 100644 --- a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py +++ b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py @@ -51,7 +51,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # Import topogen and topotest helpers from lib.topotest import version_cmp from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import ( start_topology, @@ -99,7 +99,6 @@ except IOError: # Reading the data from JSON File for topology creation # Global variables TCPDUMP_FILE = "evpn_log.txt" -LOGDIR = "/tmp/topotests/" NETWORK1_1 = {"ipv4": "10.1.1.1/32", "ipv6": "10::1/128"} NETWORK1_2 = {"ipv4": "40.1.1.1/32", "ipv6": "40::1/128"} NETWORK1_3 = {"ipv4": "40.1.1.2/32", "ipv6": "40::2/128"} diff --git a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py index 521f2335b4..4f2aef17c0 100644 --- a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py +++ b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py @@ -55,7 +55,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # Import topogen and topotest helpers from lib.topotest import version_cmp from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import ( start_topology, diff --git a/tests/topotests/example_test/test_template.py b/tests/topotests/example_test/test_template.py index 0265dbe796..534dd998d9 100644 --- a/tests/topotests/example_test/test_template.py +++ b/tests/topotests/example_test/test_template.py @@ -41,7 +41,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo # TODO: select markers based on daemons used during test @@ -87,7 +87,7 @@ def setup_module(mod): "Sets up the pytest environment" # This function initiates the topology build with Topogen... tgen = Topogen(TemplateTopo, mod.__name__) - # ... and here it calls Mininet initialization functions. + # ... and here it calls initialization functions. tgen.start_topology() # This is a sample of configuration loading. @@ -113,15 +113,15 @@ def teardown_module(mod): tgen.stop_topology() -def test_call_mininet_cli(): - "Dummy test that just calls mininet CLI so we can interact with the build." +def test_call_cli(): + "Dummy test that just calls tgen.cli() so we can interact with the build." tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) - logger.info("calling mininet CLI") - tgen.mininet_cli() + # logger.info("calling CLI") + # tgen.cli() # Memory leak test template diff --git a/tests/topotests/example_topojson_test/test_topo_json_multiple_links/test_example_topojson_multiple_links.py b/tests/topotests/example_topojson_test/test_topo_json_multiple_links/test_example_topojson_multiple_links.py index 09ac9f2fa4..b088616374 100755 --- a/tests/topotests/example_topojson_test/test_topo_json_multiple_links/test_example_topojson_multiple_links.py +++ b/tests/topotests/example_topojson_test/test_topo_json_multiple_links/test_example_topojson_multiple_links.py @@ -40,7 +40,7 @@ sys.path.append(os.path.join(CWD, "../../")) from lib.topogen import Topogen, get_topogen # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo # Import topoJson from lib, to create topology and initial configuration from lib.common_config import ( diff --git a/tests/topotests/example_topojson_test/test_topo_json_single_link/test_example_topojson.py b/tests/topotests/example_topojson_test/test_topo_json_single_link/test_example_topojson.py index 26336d5de1..4b13dce7df 100755 --- a/tests/topotests/example_topojson_test/test_topo_json_single_link/test_example_topojson.py +++ b/tests/topotests/example_topojson_test/test_topo_json_single_link/test_example_topojson.py @@ -39,7 +39,7 @@ sys.path.append(os.path.join(CWD, "../../")) from lib.topogen import Topogen, get_topogen # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo # Import topoJson from lib, to create topology and initial configuration from lib.common_config import ( diff --git a/tests/topotests/example_topojson_test/test_topo_json_single_link_loopback/test_example_topojson.py b/tests/topotests/example_topojson_test/test_topo_json_single_link_loopback/test_example_topojson.py index 012b05d376..07d13cb711 100755 --- a/tests/topotests/example_topojson_test/test_topo_json_single_link_loopback/test_example_topojson.py +++ b/tests/topotests/example_topojson_test/test_topo_json_single_link_loopback/test_example_topojson.py @@ -41,7 +41,7 @@ sys.path.append(os.path.join(CWD, "../../")) from lib.topogen import Topogen, get_topogen # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo # Import topoJson from lib, to create topology and initial configuration from lib.common_config import ( diff --git a/tests/topotests/isis_lfa_topo1/test_isis_lfa_topo1.py b/tests/topotests/isis_lfa_topo1/test_isis_lfa_topo1.py index dcfcd11435..a253b11c07 100755 --- a/tests/topotests/isis_lfa_topo1/test_isis_lfa_topo1.py +++ b/tests/topotests/isis_lfa_topo1/test_isis_lfa_topo1.py @@ -71,7 +71,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.isisd] @@ -79,91 +79,87 @@ pytestmark = [pytest.mark.isisd] outputs = {} -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6", "rt7"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6", "rt7"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["rt1"], nodeif="eth-rt2") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt1") + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt3") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt2") + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["rt1"], nodeif="eth-rt3") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt1") + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["rt1"], nodeif="eth-rt4") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt1") + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["rt1"], nodeif="eth-rt5") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt1") + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["rt1"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt1") + switch = tgen.add_switch("s7") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt7") + switch.add_link(tgen.gears["rt7"], nodeif="eth-rt2") + switch = tgen.add_switch("s8") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt7") + switch.add_link(tgen.gears["rt7"], nodeif="eth-rt3") + switch = tgen.add_switch("s9") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt7") + switch.add_link(tgen.gears["rt7"], nodeif="eth-rt4") + switch = tgen.add_switch("s10") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt7") + switch.add_link(tgen.gears["rt7"], nodeif="eth-rt5") + switch = tgen.add_switch("s11") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt7") + switch.add_link(tgen.gears["rt7"], nodeif="eth-rt6") - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["rt1"], nodeif="eth-rt2") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt1") - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt3") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt2") - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["rt1"], nodeif="eth-rt3") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt1") - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["rt1"], nodeif="eth-rt4") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt1") - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["rt1"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt1") - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["rt1"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt1") - switch = tgen.add_switch("s7") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt7") - switch.add_link(tgen.gears["rt7"], nodeif="eth-rt2") - switch = tgen.add_switch("s8") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt7") - switch.add_link(tgen.gears["rt7"], nodeif="eth-rt3") - switch = tgen.add_switch("s9") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt7") - switch.add_link(tgen.gears["rt7"], nodeif="eth-rt4") - switch = tgen.add_switch("s10") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt7") - switch.add_link(tgen.gears["rt7"], nodeif="eth-rt5") - switch = tgen.add_switch("s11") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt7") - switch.add_link(tgen.gears["rt7"], nodeif="eth-rt6") + # + # Populate multi-dimensional dictionary containing all expected outputs + # + files = ["show_ipv6_route.ref", "show_yang_interface_isis_adjacencies.ref"] + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6", "rt7"]: + outputs[rname] = {} + for step in range(1, 13 + 1): + outputs[rname][step] = {} + for file in files: + if step == 1: + # Get snapshots relative to the expected initial network convergence + filename = "{}/{}/step{}/{}".format(CWD, rname, step, file) + outputs[rname][step][file] = open(filename).read() + else: + if rname != "rt1": + continue + if file == "show_yang_interface_isis_adjacencies.ref": + continue - # - # Populate multi-dimensional dictionary containing all expected outputs - # - files = ["show_ipv6_route.ref", "show_yang_interface_isis_adjacencies.ref"] - for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6", "rt7"]: - outputs[rname] = {} - for step in range(1, 13 + 1): - outputs[rname][step] = {} - for file in files: - if step == 1: - # Get snapshots relative to the expected initial network convergence - filename = "{}/{}/step{}/{}".format(CWD, rname, step, file) - outputs[rname][step][file] = open(filename).read() - else: - if rname != "rt1": - continue - if file == "show_yang_interface_isis_adjacencies.ref": - continue + # Get diff relative to the previous step + filename = "{}/{}/step{}/{}.diff".format(CWD, rname, step, file) - # Get diff relative to the previous step - filename = "{}/{}/step{}/{}.diff".format(CWD, rname, step, file) + # Create temporary files in order to apply the diff + f_in = tempfile.NamedTemporaryFile(mode="w") + f_in.write(outputs[rname][step - 1][file]) + f_in.flush() + f_out = tempfile.NamedTemporaryFile(mode="r") + os.system( + "patch -s -o %s %s %s" % (f_out.name, f_in.name, filename) + ) - # Create temporary files in order to apply the diff - f_in = tempfile.NamedTemporaryFile() - f_in.write(outputs[rname][step - 1][file]) - f_in.flush() - f_out = tempfile.NamedTemporaryFile() - os.system( - "patch -s -o %s %s %s" % (f_out.name, f_in.name, filename) - ) - - # Store the updated snapshot and remove the temporary files - outputs[rname][step][file] = open(f_out.name).read() - f_in.close() - f_out.close() + # Store the updated snapshot and remove the temporary files + outputs[rname][step][file] = open(f_out.name).read() + f_in.close() + f_out.close() def setup_module(mod): diff --git a/tests/topotests/isis_lsp_bits_topo1/test_isis_lsp_bits_topo1.py b/tests/topotests/isis_lsp_bits_topo1/test_isis_lsp_bits_topo1.py index 70dcff035f..df174e9531 100755 --- a/tests/topotests/isis_lsp_bits_topo1/test_isis_lsp_bits_topo1.py +++ b/tests/topotests/isis_lsp_bits_topo1/test_isis_lsp_bits_topo1.py @@ -82,7 +82,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.isisd] diff --git a/tests/topotests/isis_rlfa_topo1/test_isis_rlfa_topo1.py b/tests/topotests/isis_rlfa_topo1/test_isis_rlfa_topo1.py index ded1a4cc22..325638a478 100755 --- a/tests/topotests/isis_rlfa_topo1/test_isis_rlfa_topo1.py +++ b/tests/topotests/isis_rlfa_topo1/test_isis_rlfa_topo1.py @@ -80,7 +80,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.isisd, pytest.mark.ldpd] @@ -88,84 +88,80 @@ pytestmark = [pytest.mark.isisd, pytest.mark.ldpd] outputs = {} -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6", "rt7", "rt8"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6", "rt7", "rt8"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["rt1"], nodeif="eth-rt2") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt1") + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["rt1"], nodeif="eth-rt3") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt1") + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2") + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3") + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt7") + switch.add_link(tgen.gears["rt7"], nodeif="eth-rt5") + switch = tgen.add_switch("s7") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt8") + switch.add_link(tgen.gears["rt8"], nodeif="eth-rt6") + switch = tgen.add_switch("s8") + switch.add_link(tgen.gears["rt7"], nodeif="eth-rt8") + switch.add_link(tgen.gears["rt8"], nodeif="eth-rt7") - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["rt1"], nodeif="eth-rt2") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt1") - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["rt1"], nodeif="eth-rt3") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt1") - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2") - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3") - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt7") - switch.add_link(tgen.gears["rt7"], nodeif="eth-rt5") - switch = tgen.add_switch("s7") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt8") - switch.add_link(tgen.gears["rt8"], nodeif="eth-rt6") - switch = tgen.add_switch("s8") - switch.add_link(tgen.gears["rt7"], nodeif="eth-rt8") - switch.add_link(tgen.gears["rt8"], nodeif="eth-rt7") + # + # Populate multi-dimensional dictionary containing all expected outputs + # + files = [ + "show_ip_route.ref", + "show_ipv6_route.ref", + "show_yang_interface_isis_adjacencies.ref", + ] + for rname in ["rt1"]: + outputs[rname] = {} + for step in range(1, 10 + 1): + outputs[rname][step] = {} + for file in files: + if step == 1: + # Get snapshots relative to the expected initial network convergence + filename = "{}/{}/step{}/{}".format(CWD, rname, step, file) + outputs[rname][step][file] = open(filename).read() + else: + if file == "show_yang_interface_isis_adjacencies.ref": + continue - # - # Populate multi-dimensional dictionary containing all expected outputs - # - files = [ - "show_ip_route.ref", - "show_ipv6_route.ref", - "show_yang_interface_isis_adjacencies.ref", - ] - for rname in ["rt1"]: - outputs[rname] = {} - for step in range(1, 10 + 1): - outputs[rname][step] = {} - for file in files: - if step == 1: - # Get snapshots relative to the expected initial network convergence - filename = "{}/{}/step{}/{}".format(CWD, rname, step, file) - outputs[rname][step][file] = open(filename).read() - else: - if file == "show_yang_interface_isis_adjacencies.ref": - continue + # Get diff relative to the previous step + filename = "{}/{}/step{}/{}.diff".format(CWD, rname, step, file) - # Get diff relative to the previous step - filename = "{}/{}/step{}/{}.diff".format(CWD, rname, step, file) + # Create temporary files in order to apply the diff + f_in = tempfile.NamedTemporaryFile(mode="w") + f_in.write(outputs[rname][step - 1][file]) + f_in.flush() + f_out = tempfile.NamedTemporaryFile(mode="r") + os.system( + "patch -s -o %s %s %s" % (f_out.name, f_in.name, filename) + ) - # Create temporary files in order to apply the diff - f_in = tempfile.NamedTemporaryFile() - f_in.write(outputs[rname][step - 1][file]) - f_in.flush() - f_out = tempfile.NamedTemporaryFile() - os.system( - "patch -s -o %s %s %s" % (f_out.name, f_in.name, filename) - ) - - # Store the updated snapshot and remove the temporary files - outputs[rname][step][file] = open(f_out.name).read() - f_in.close() - f_out.close() + # Store the updated snapshot and remove the temporary files + outputs[rname][step][file] = open(f_out.name).read() + f_in.close() + f_out.close() def setup_module(mod): diff --git a/tests/topotests/isis_snmp/r1/snmpd.conf b/tests/topotests/isis_snmp/r1/snmpd.conf index b37911da36..3fd5e982e8 100644 --- a/tests/topotests/isis_snmp/r1/snmpd.conf +++ b/tests/topotests/isis_snmp/r1/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/isis_snmp/r2/snmpd.conf b/tests/topotests/isis_snmp/r2/snmpd.conf index 0f779b8b91..fc648057a5 100644 --- a/tests/topotests/isis_snmp/r2/snmpd.conf +++ b/tests/topotests/isis_snmp/r2/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/isis_snmp/r3/snmpd.conf b/tests/topotests/isis_snmp/r3/snmpd.conf index 3f3501a6fd..20af65e431 100644 --- a/tests/topotests/isis_snmp/r3/snmpd.conf +++ b/tests/topotests/isis_snmp/r3/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/isis_snmp/r4/snmpd.conf b/tests/topotests/isis_snmp/r4/snmpd.conf index e5e336d888..76e4b79069 100644 --- a/tests/topotests/isis_snmp/r4/snmpd.conf +++ b/tests/topotests/isis_snmp/r4/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/isis_snmp/r5/snmpd.conf b/tests/topotests/isis_snmp/r5/snmpd.conf index 5bebbdebd4..af59194bc9 100644 --- a/tests/topotests/isis_snmp/r5/snmpd.conf +++ b/tests/topotests/isis_snmp/r5/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/isis_snmp/test_isis_snmp.py b/tests/topotests/isis_snmp/test_isis_snmp.py index 2cd07299b0..c6fc698005 100755 --- a/tests/topotests/isis_snmp/test_isis_snmp.py +++ b/tests/topotests/isis_snmp/test_isis_snmp.py @@ -80,7 +80,7 @@ from lib.topolog import logger from lib.snmptest import SnmpTester # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.isisd, pytest.mark.ldpd, pytest.mark.snmp] @@ -219,7 +219,7 @@ def test_r1_scalar_snmp(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - r1 = tgen.net.get("r1") + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c") assert r1_snmp.test_oid("isisSysVersion", "one(1)") @@ -231,7 +231,7 @@ def test_r1_scalar_snmp(): assert r1_snmp.test_oid("isisSysMaxAge", "1200 seconds") assert r1_snmp.test_oid("isisSysProtSupported", "07 5 6 7") - r2 = tgen.net.get("r2") + r2 = tgen.gears["r2"] r2_snmp = SnmpTester(r2, "2.2.2.2", "public", "2c") assert r2_snmp.test_oid("isisSysVersion", "one(1)") @@ -260,9 +260,7 @@ circtable_test = { def test_r1_isisCircTable(): tgen = get_topogen() - r1 = tgen.net.get("r1") - r1r = tgen.gears["r1"] - + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c") oids = [] @@ -296,9 +294,7 @@ circleveltable_test = { def test_r1_isislevelCircTable(): tgen = get_topogen() - r1 = tgen.net.get("r1") - r1r = tgen.gears["r1"] - + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c") oids = [] @@ -335,8 +331,7 @@ adjtable_down_test = { def test_r1_isisAdjTable(): "check ISIS Adjacency Table" tgen = get_topogen() - r1 = tgen.net.get("r1") - r1_cmd = tgen.gears["r1"] + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c") oids = [] @@ -355,7 +350,7 @@ def test_r1_isisAdjTable(): # shutdown interface and one adjacency should be removed "check ISIS adjacency is removed when interface is shutdown" - r1_cmd.vtysh_cmd("conf t\ninterface r1-eth1\nshutdown") + r1.vtysh_cmd("conf t\ninterface r1-eth1\nshutdown") r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c") for item in adjtable_down_test.keys(): @@ -367,7 +362,7 @@ def test_r1_isisAdjTable(): ), assertmsg # no shutdown interface and adjacency should be restored - r1_cmd.vtysh_cmd("conf t\ninterface r1-eth1\nno shutdown") + r1.vtysh_cmd("conf t\ninterface r1-eth1\nno shutdown") # Memory leak test template diff --git a/tests/topotests/isis_sr_te_topo1/test_isis_sr_te_topo1.py b/tests/topotests/isis_sr_te_topo1/test_isis_sr_te_topo1.py index 6bbb570267..06d15afe6c 100755 --- a/tests/topotests/isis_sr_te_topo1/test_isis_sr_te_topo1.py +++ b/tests/topotests/isis_sr_te_topo1/test_isis_sr_te_topo1.py @@ -94,7 +94,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.isisd, pytest.mark.pathd] diff --git a/tests/topotests/isis_sr_topo1/test_isis_sr_topo1.py b/tests/topotests/isis_sr_topo1/test_isis_sr_topo1.py index c22bd65d2d..8aa187871c 100644 --- a/tests/topotests/isis_sr_topo1/test_isis_sr_topo1.py +++ b/tests/topotests/isis_sr_topo1/test_isis_sr_topo1.py @@ -82,7 +82,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.isisd] diff --git a/tests/topotests/isis_tilfa_topo1/test_isis_tilfa_topo1.py b/tests/topotests/isis_tilfa_topo1/test_isis_tilfa_topo1.py index 00cb623999..351bce99e5 100755 --- a/tests/topotests/isis_tilfa_topo1/test_isis_tilfa_topo1.py +++ b/tests/topotests/isis_tilfa_topo1/test_isis_tilfa_topo1.py @@ -83,7 +83,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.isisd] @@ -91,93 +91,89 @@ pytestmark = [pytest.mark.isisd] outputs = {} -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1") + switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1") + switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1") - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1") - switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1") - switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1") + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-1") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-1") - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-1") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-1") + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-2") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-2") - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-2") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-2") + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-1") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-1") - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-1") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-1") + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-2") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-2") - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-2") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-2") + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") + switch = tgen.add_switch("s7") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") - switch = tgen.add_switch("s7") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") + switch = tgen.add_switch("s8") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5") - switch = tgen.add_switch("s8") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5") + # + # Populate multi-dimensional dictionary containing all expected outputs + # + files = [ + "show_ip_route.ref", + "show_ipv6_route.ref", + "show_mpls_table.ref", + "show_yang_interface_isis_adjacencies.ref", + ] + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + outputs[rname] = {} + for step in range(1, 9 + 1): + outputs[rname][step] = {} + for file in files: + if step == 1: + # Get snapshots relative to the expected initial network convergence + filename = "{}/{}/step{}/{}".format(CWD, rname, step, file) + outputs[rname][step][file] = open(filename).read() + else: + if file == "show_yang_interface_isis_adjacencies.ref": + continue - # - # Populate multi-dimensional dictionary containing all expected outputs - # - files = [ - "show_ip_route.ref", - "show_ipv6_route.ref", - "show_mpls_table.ref", - "show_yang_interface_isis_adjacencies.ref", - ] - for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: - outputs[rname] = {} - for step in range(1, 9 + 1): - outputs[rname][step] = {} - for file in files: - if step == 1: - # Get snapshots relative to the expected initial network convergence - filename = "{}/{}/step{}/{}".format(CWD, rname, step, file) - outputs[rname][step][file] = open(filename).read() - else: - if file == "show_yang_interface_isis_adjacencies.ref": - continue + # Get diff relative to the previous step + filename = "{}/{}/step{}/{}.diff".format(CWD, rname, step, file) - # Get diff relative to the previous step - filename = "{}/{}/step{}/{}.diff".format(CWD, rname, step, file) + # Create temporary files in order to apply the diff + f_in = tempfile.NamedTemporaryFile(mode="w") + f_in.write(outputs[rname][step - 1][file]) + f_in.flush() + f_out = tempfile.NamedTemporaryFile(mode="r") + os.system( + "patch -s -o %s %s %s" % (f_out.name, f_in.name, filename) + ) - # Create temporary files in order to apply the diff - f_in = tempfile.NamedTemporaryFile() - f_in.write(outputs[rname][step - 1][file]) - f_in.flush() - f_out = tempfile.NamedTemporaryFile() - os.system( - "patch -s -o %s %s %s" % (f_out.name, f_in.name, filename) - ) - - # Store the updated snapshot and remove the temporary files - outputs[rname][step][file] = open(f_out.name).read() - f_in.close() - f_out.close() + # Store the updated snapshot and remove the temporary files + outputs[rname][step][file] = open(f_out.name).read() + f_in.close() + f_out.close() def setup_module(mod): diff --git a/tests/topotests/isis_topo1/test_isis_topo1.py b/tests/topotests/isis_topo1/test_isis_topo1.py index 083a8b1e8d..3927222553 100644 --- a/tests/topotests/isis_topo1/test_isis_topo1.py +++ b/tests/topotests/isis_topo1/test_isis_topo1.py @@ -43,7 +43,7 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.isisd] diff --git a/tests/topotests/isis_topo1_vrf/test_isis_topo1_vrf.py b/tests/topotests/isis_topo1_vrf/test_isis_topo1_vrf.py index ff1544e4a2..67c60c729f 100644 --- a/tests/topotests/isis_topo1_vrf/test_isis_topo1_vrf.py +++ b/tests/topotests/isis_topo1_vrf/test_isis_topo1_vrf.py @@ -43,7 +43,7 @@ from lib.topolog import logger from lib.topotest import iproute2_is_vrf_capable from lib.common_config import required_linux_kernel_version -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.isisd] diff --git a/tests/topotests/ldp_oc_acl_topo1/test_ldp_oc_acl_topo1.py b/tests/topotests/ldp_oc_acl_topo1/test_ldp_oc_acl_topo1.py index 9aa4024598..f26c56e54a 100644 --- a/tests/topotests/ldp_oc_acl_topo1/test_ldp_oc_acl_topo1.py +++ b/tests/topotests/ldp_oc_acl_topo1/test_ldp_oc_acl_topo1.py @@ -76,7 +76,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.ldpd, pytest.mark.ospfd] diff --git a/tests/topotests/ldp_oc_topo1/test_ldp_oc_topo1.py b/tests/topotests/ldp_oc_topo1/test_ldp_oc_topo1.py index aef22c395d..5208728a98 100644 --- a/tests/topotests/ldp_oc_topo1/test_ldp_oc_topo1.py +++ b/tests/topotests/ldp_oc_topo1/test_ldp_oc_topo1.py @@ -76,7 +76,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.ldpd, pytest.mark.ospfd] diff --git a/tests/topotests/ldp_snmp/r1/snmpd.conf b/tests/topotests/ldp_snmp/r1/snmpd.conf index b37911da36..3fd5e982e8 100644 --- a/tests/topotests/ldp_snmp/r1/snmpd.conf +++ b/tests/topotests/ldp_snmp/r1/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/ldp_snmp/r2/snmpd.conf b/tests/topotests/ldp_snmp/r2/snmpd.conf index 0f779b8b91..fc648057a5 100644 --- a/tests/topotests/ldp_snmp/r2/snmpd.conf +++ b/tests/topotests/ldp_snmp/r2/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr \ No newline at end of file diff --git a/tests/topotests/ldp_snmp/test_ldp_snmp_topo1.py b/tests/topotests/ldp_snmp/test_ldp_snmp_topo1.py index 8052316d73..f0473257c9 100644 --- a/tests/topotests/ldp_snmp/test_ldp_snmp_topo1.py +++ b/tests/topotests/ldp_snmp/test_ldp_snmp_topo1.py @@ -79,7 +79,7 @@ from lib.topolog import logger from lib.snmptest import SnmpTester # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.ldpd, pytest.mark.isisd, pytest.mark.snmp] @@ -241,7 +241,7 @@ def test_r1_ldp_lsr_objects(): "Test mplsLdpLsrObjects objects" tgen = get_topogen() - r1 = tgen.net.get("r1") + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c") assert r1_snmp.test_oid("mplsLdpLsrId", "01 01 01 01") @@ -252,7 +252,7 @@ def test_r1_ldp_entity_table(): "Test mplsLdpEntityTable" tgen = get_topogen() - r1 = tgen.net.get("r1") + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c") assert r1_snmp.test_oid_walk("mplsLdpEntityLdpId", ["1.1.1.1:0"]) @@ -286,7 +286,7 @@ def test_r1_ldp_entity_stats_table(): "Test mplsLdpEntityStatsTable" tgen = get_topogen() - r1 = tgen.net.get("r1") + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c") assert r1_snmp.test_oid_walk("mplsLdpEntityStatsSessionAttempts", ["0"]) @@ -312,7 +312,7 @@ def test_r1_ldp_peer_table(): "Test mplsLdpPeerTable" tgen = get_topogen() - r1 = tgen.net.get("r1") + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c") assert r1_snmp.test_oid_walk("mplsLdpPeerLdpId", ["2.2.2.2:0", "3.3.3.3:0"]) @@ -331,7 +331,7 @@ def test_r1_ldp_session_table(): "Test mplsLdpSessionTable" tgen = get_topogen() - r1 = tgen.net.get("r1") + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c") assert r1_snmp.test_oid_walk( @@ -354,7 +354,7 @@ def test_r1_ldp_session_stats_table(): "Test mplsLdpSessionStatsTable" tgen = get_topogen() - r1 = tgen.net.get("r1") + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c") assert r1_snmp.test_oid_walk("mplsLdpSessionStatsUnknownMesTypeErrors", ["0", "0"]) @@ -365,7 +365,7 @@ def test_r1_ldp_hello_adjacency_table(): "Test mplsLdpHelloAdjacencyTable" tgen = get_topogen() - r1 = tgen.net.get("r1") + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c") assert r1_snmp.test_oid_walk("mplsLdpHelloAdjacencyIndex", ["1", "2", "1"]) diff --git a/tests/topotests/ldp_sync_isis_topo1/test_ldp_sync_isis_topo1.py b/tests/topotests/ldp_sync_isis_topo1/test_ldp_sync_isis_topo1.py index 44b34c485f..3c26bd5ba2 100644 --- a/tests/topotests/ldp_sync_isis_topo1/test_ldp_sync_isis_topo1.py +++ b/tests/topotests/ldp_sync_isis_topo1/test_ldp_sync_isis_topo1.py @@ -78,7 +78,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.isisd, pytest.mark.ldpd] @@ -466,20 +466,20 @@ def parse_show_isis_ldp_sync(lines, rname): interface = {} interface_name = None - line = it.next() + line = next(it) if line.startswith(rname + "-eth"): interface_name = line - line = it.next() + line = next(it) if line.startswith(" LDP-IGP Synchronization enabled: "): interface["ldpIgpSyncEnabled"] = line.endswith("yes") - line = it.next() + line = next(it) if line.startswith(" holddown timer in seconds: "): interface["holdDownTimeInSec"] = int(line.split(": ")[-1]) - line = it.next() + line = next(it) if line.startswith(" State: "): interface["ldpIgpSyncState"] = line.split(": ")[-1] @@ -539,7 +539,7 @@ def parse_show_isis_interface_detail(lines, rname): while True: try: - line = it.next() + line = next(it) area_match = re.match(r"Area (.+):", line) if not area_match: @@ -548,7 +548,7 @@ def parse_show_isis_interface_detail(lines, rname): area_id = area_match.group(1) area = {} - line = it.next() + line = next(it) while line.startswith(" Interface: "): interface_name = re.split(":|,", line)[1].lstrip() @@ -557,7 +557,7 @@ def parse_show_isis_interface_detail(lines, rname): # Look for keyword: Level-1 or Level-2 while not line.startswith(" Level-"): - line = it.next() + line = next(it) while line.startswith(" Level-"): @@ -566,7 +566,7 @@ def parse_show_isis_interface_detail(lines, rname): level_name = line.split()[0] level["level"] = level_name - line = it.next() + line = next(it) if line.startswith(" Metric:"): level["metric"] = re.split(":|,", line)[1].lstrip() @@ -577,7 +577,7 @@ def parse_show_isis_interface_detail(lines, rname): while not line.startswith(" Level-") and not line.startswith( " Interface: " ): - line = it.next() + line = next(it) if line.startswith(" Level-"): continue diff --git a/tests/topotests/ldp_sync_ospf_topo1/test_ldp_sync_ospf_topo1.py b/tests/topotests/ldp_sync_ospf_topo1/test_ldp_sync_ospf_topo1.py index 57b45e5fdf..c5bd97edf3 100644 --- a/tests/topotests/ldp_sync_ospf_topo1/test_ldp_sync_ospf_topo1.py +++ b/tests/topotests/ldp_sync_ospf_topo1/test_ldp_sync_ospf_topo1.py @@ -77,7 +77,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.ldpd, pytest.mark.ospfd] diff --git a/tests/topotests/ldp_topo1/test_ldp_topo1.py b/tests/topotests/ldp_topo1/test_ldp_topo1.py index 06e7734094..c0f869f826 100644 --- a/tests/topotests/ldp_topo1/test_ldp_topo1.py +++ b/tests/topotests/ldp_topo1/test_ldp_topo1.py @@ -65,15 +65,10 @@ import sys import pytest from time import sleep -from mininet.topo import Topo -from mininet.net import Mininet -from mininet.node import Node, OVSSwitch, Host -from mininet.log import setLogLevel, info -from mininet.cli import CLI -from mininet.link import Intf - sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lib import topotest +from lib.micronet_compat import Topo +from lib.micronet_compat import Mininet fatal_error = "" @@ -99,7 +94,7 @@ class NetworkTopo(Topo): # Setup Switches, add Interfaces and Connections switch = {} # First switch - switch[0] = self.addSwitch("sw0", cls=topotest.LegacySwitch) + switch[0] = self.addSwitch("sw0") self.addLink( switch[0], router[1], @@ -115,7 +110,7 @@ class NetworkTopo(Topo): addr2="00:11:00:02:00:00", ) # Second switch - switch[1] = self.addSwitch("sw1", cls=topotest.LegacySwitch) + switch[1] = self.addSwitch("sw1") self.addLink( switch[1], router[2], @@ -138,7 +133,7 @@ class NetworkTopo(Topo): addr2="00:11:00:04:00:00", ) # Third switch - switch[2] = self.addSwitch("sw2", cls=topotest.LegacySwitch) + switch[2] = self.addSwitch("sw2") self.addLink( switch[2], router[2], @@ -885,7 +880,6 @@ def test_shutdown_check_memleak(): if __name__ == "__main__": - setLogLevel("info") # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli # retval = pytest.main(["-s", "--tb=no"]) retval = pytest.main(["-s"]) diff --git a/tests/topotests/ldp_vpls_topo1/test_ldp_vpls_topo1.py b/tests/topotests/ldp_vpls_topo1/test_ldp_vpls_topo1.py index 0ea7aca3eb..8dc8039c99 100644 --- a/tests/topotests/ldp_vpls_topo1/test_ldp_vpls_topo1.py +++ b/tests/topotests/ldp_vpls_topo1/test_ldp_vpls_topo1.py @@ -78,7 +78,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.ldpd, pytest.mark.ospfd] diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py index 56eca4be04..1ea033a12c 100644 --- a/tests/topotests/lib/ltemplate.py +++ b/tests/topotests/lib/ltemplate.py @@ -39,7 +39,7 @@ from lib.topolog import logger from lib.lutil import * # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo customize = None diff --git a/tests/topotests/lib/lutil.py b/tests/topotests/lib/lutil.py index f8f580632e..7248ce267f 100644 --- a/tests/topotests/lib/lutil.py +++ b/tests/topotests/lib/lutil.py @@ -26,7 +26,7 @@ import math import time from lib.topolog import logger from lib.topotest import json_cmp -from mininet.net import Mininet +from lib.micronet_compat import Mininet # L utility functions diff --git a/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py b/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py index 222fb28ade..a10477d283 100644 --- a/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py +++ b/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py @@ -40,11 +40,11 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib import topotest +# Required to instantiate the topology builder class. +from lib.micronet_compat import Topo from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -# Required to instantiate the topology builder class. -from mininet.topo import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd, pytest.mark.pimd] @@ -52,21 +52,28 @@ pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd, pytest.mark.pimd] # Test global variables: # They are used to handle communicating with external application. # -APP_SOCK_PATH = '/tmp/topotests/apps.sock' HELPER_APP_PATH = os.path.join(CWD, "../lib/mcast-tester.py") app_listener = None app_clients = {} +app_procs = [] + + +def get_app_sock_path(): + tgen = get_topogen() + return os.path.join(tgen.logdir, "apps.sock") + def listen_to_applications(): "Start listening socket to connect with applications." # Remove old socket. + app_sock_path = get_app_sock_path() try: - os.unlink(APP_SOCK_PATH) + os.unlink(app_sock_path) except OSError: pass sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0) - sock.bind(APP_SOCK_PATH) + sock.bind(app_sock_path) sock.listen(10) global app_listener app_listener = sock @@ -87,9 +94,11 @@ def close_applications(): # Close listening socket. app_listener.close() + app_sock_path = get_app_sock_path() + # Remove old socket. try: - os.unlink(APP_SOCK_PATH) + os.unlink(app_sock_path) except OSError: pass @@ -99,6 +108,10 @@ def close_applications(): continue app_clients["h1"]["fd"].close() + for p in app_procs: + p.terminate() + p.wait() + class MSDPMeshTopo1(Topo): "Test topology builder" @@ -120,12 +133,12 @@ class MSDPMeshTopo1(Topo): switch.add_link(tgen.gears["r3"]) # Create stub networks for multicast traffic. - tgen.add_host("h1", "192.168.10.2/24", "192.168.10.1") + tgen.add_host("h1", "192.168.10.2/24", "via 192.168.10.1") switch = tgen.add_switch("s3") switch.add_link(tgen.gears["r1"]) switch.add_link(tgen.gears["h1"]) - tgen.add_host("h2", "192.168.30.2/24", "192.168.30.1") + tgen.add_host("h2", "192.168.30.2/24", "via 192.168.30.1") switch = tgen.add_switch("s4") switch.add_link(tgen.gears["r3"]) switch.add_link(tgen.gears["h2"]) @@ -206,14 +219,6 @@ def test_wait_msdp_convergence(): logger.info("test MSDP convergence") - tgen.gears["h1"].run("{} --send='0.7' '{}' '{}' '{}' &".format( - HELPER_APP_PATH, APP_SOCK_PATH, '229.0.1.10', 'h1-eth0')) - accept_host("h1") - - tgen.gears["h2"].run("{} '{}' '{}' '{}' &".format( - HELPER_APP_PATH, APP_SOCK_PATH, '229.0.1.10', 'h2-eth0')) - accept_host("h2") - def expect_msdp_peer(router, peer, sa_count=0): "Expect MSDP peer connection to be established with SA amount." logger.info("waiting MSDP connection from peer {} on router {}".format(peer, router)) @@ -227,6 +232,22 @@ def test_wait_msdp_convergence(): assertmsg = '"{}" MSDP connection failure'.format(router) assert result is None, assertmsg + app_sock_path = get_app_sock_path() + + + python3_path = tgen.net.get_exec_path(["python3", "python"]) + ph_base = [python3_path, HELPER_APP_PATH, app_sock_path] + + ph1_cmd = ph_base + ["--send=0.7", "229.0.1.10", "h1-eth0"] + ph1 = tgen.gears["h1"].popen(ph1_cmd) + app_procs.append(ph1) + accept_host("h1") + + ph2_cmd = ph_base + ["229.0.1.10", "h2-eth0"] + ph2 = tgen.gears["h2"].popen(ph2_cmd) + app_procs.append(ph2) + accept_host("h2") + # R1 peers. expect_msdp_peer("r1", "10.254.254.2") expect_msdp_peer("r1", "10.254.254.3") diff --git a/tests/topotests/msdp_topo1/test_msdp_topo1.py b/tests/topotests/msdp_topo1/test_msdp_topo1.py index b860c04faa..796706a2e0 100755 --- a/tests/topotests/msdp_topo1/test_msdp_topo1.py +++ b/tests/topotests/msdp_topo1/test_msdp_topo1.py @@ -41,11 +41,11 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib import topotest +# Required to instantiate the topology builder class. +from lib.micronet_compat import Topo from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -# Required to instantiate the topology builder class. -from mininet.topo import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.pimd] @@ -53,22 +53,30 @@ pytestmark = [pytest.mark.bgpd, pytest.mark.pimd] # Test global variables: # They are used to handle communicating with external application. # -APP_SOCK_PATH = '/tmp/topotests/apps.sock' HELPER_APP_PATH = os.path.join(CWD, "../lib/mcast-tester.py") app_listener = None app_clients = {} +def get_app_sock_path(): + tgen = get_topogen() + return os.path.join(tgen.logdir, "apps.sock") + + def listen_to_applications(): "Start listening socket to connect with applications." + + app_sock_path = get_app_sock_path() # Remove old socket. try: - os.unlink(APP_SOCK_PATH) + os.unlink(app_sock_path) except OSError: pass sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0) - sock.bind(APP_SOCK_PATH) + # Do not block forever + sock.settimeout(10) + sock.bind(app_sock_path) sock.listen(10) global app_listener app_listener = sock @@ -91,9 +99,10 @@ def close_applications(): # Close listening socket. app_listener.close() + app_sock_path = get_app_sock_path() # Remove old socket. try: - os.unlink(APP_SOCK_PATH) + os.unlink(app_sock_path) except OSError: pass @@ -135,12 +144,12 @@ class MSDPTopo1(Topo): switch.add_link(tgen.gears["r4"]) # Create a host connected and direct at r4: - tgen.add_host("h1", "192.168.4.100/24", "192.168.4.1") + tgen.add_host("h1", "192.168.4.100/24", "via 192.168.4.1") switch.add_link(tgen.gears["h1"]) # Create a host connected and direct at r1: switch = tgen.add_switch("s6") - tgen.add_host("h2", "192.168.10.100/24", "192.168.10.1") + tgen.add_host("h2", "192.168.10.100/24", "via 192.168.10.1") switch.add_link(tgen.gears["r1"]) switch.add_link(tgen.gears["h2"]) @@ -219,21 +228,12 @@ def test_bgp_convergence(): expect_loopback_route("r4", "ip", "10.254.254.2/32", "bgp") expect_loopback_route("r4", "ip", "10.254.254.3/32", "bgp") - -def test_mroute_install(): +def _test_mroute_install(): "Test that multicast routes propagated and installed" tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) - tgen.gears["h1"].run("{} '{}' '{}' '{}' &".format( - HELPER_APP_PATH, APP_SOCK_PATH, '229.1.2.3', 'h1-eth0')) - accept_host("h1") - - tgen.gears["h2"].run("{} --send='0.7' '{}' '{}' '{}' &".format( - HELPER_APP_PATH, APP_SOCK_PATH, '229.1.2.3', 'h2-eth0')) - accept_host("h2") - # # Test R1 mroute # @@ -366,6 +366,40 @@ def test_mroute_install(): _, val = topotest.run_and_expect(test_func, None, count=55, wait=2) assert val is None, 'multicast route convergence failure' +def test_mroute_install(): + tgen = get_topogen() + # pytest.skip("FOO") + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + ph1 = ph2 = None + + app_sock_path = get_app_sock_path() + try: + logger.info("Starting helper1") + ph1 = tgen.gears["h1"].popen( + "{} '{}' '{}' '{}'".format( + HELPER_APP_PATH, app_sock_path, "229.1.2.3", "h1-eth0" + ) + ) + logger.info("Accepting helper1") + accept_host("h1") + + logger.info("Starting helper2") + ph2 = tgen.gears["h2"].popen( + "{} --send='0.7' '{}' '{}' '{}'".format( + HELPER_APP_PATH, app_sock_path, "229.1.2.3", "h2-eth0" + ) + ) + accept_host("h2") + + _test_mroute_install() + finally: + if ph1: + ph1.terminate() + ph1.wait() + ph2.terminate() + ph2.wait() def test_msdp(): """ diff --git a/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py b/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py index 827dde69ec..60a883b285 100644 --- a/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py +++ b/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py @@ -66,7 +66,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import ( start_topology, @@ -213,6 +213,9 @@ def teardown_module(): tgen = get_topogen() + # Kill any iperfs we left running. + kill_iperf(tgen) + # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -401,15 +404,15 @@ def test_BSR_higher_prefer_ip_p0(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - reset_config_on_routers(tgen) step("pre-configure BSM packet") step("Configure cisco-1 as BSR1 1.1.2.7") @@ -607,15 +610,15 @@ def test_BSR_CRP_with_blackhole_address_p1(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - reset_config_on_routers(tgen) step("pre-configure BSM packet") step("Configure cisco-1 as BSR1 1.1.2.7") @@ -782,15 +785,15 @@ def test_new_router_fwd_p0(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - reset_config_on_routers(tgen) result = pre_config_to_bsm( @@ -919,15 +922,15 @@ def test_int_bsm_config_p1(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - reset_config_on_routers(tgen) result = pre_config_to_bsm( @@ -1080,15 +1083,15 @@ def test_static_rp_override_p1(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - reset_config_on_routers(tgen) result = pre_config_to_bsm( @@ -1231,15 +1234,15 @@ def test_bsmp_stress_add_del_restart_p2(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - reset_config_on_routers(tgen) result = pre_config_to_bsm( @@ -1400,15 +1403,15 @@ def test_BSM_timeout_p0(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - result = pre_config_to_bsm( tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1" ) @@ -1557,15 +1560,15 @@ def test_iif_join_state_p0(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - reset_config_on_routers(tgen) result = pre_config_to_bsm( diff --git a/tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py b/tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py index 894326f19f..115d0bff0d 100644 --- a/tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py +++ b/tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py @@ -57,7 +57,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import ( start_topology, @@ -204,6 +204,9 @@ def teardown_module(): tgen = get_topogen() + # Kill any iperfs we left running. + kill_iperf(tgen) + # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -354,15 +357,15 @@ def test_starg_mroute_p0(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - reset_config_on_routers(tgen) result = pre_config_to_bsm( @@ -506,15 +509,15 @@ def test_overlapping_group_p0(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - reset_config_on_routers(tgen) result = pre_config_to_bsm( @@ -612,15 +615,15 @@ def test_RP_priority_p0(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - reset_config_on_routers(tgen) result = pre_config_to_bsm( @@ -861,15 +864,15 @@ def test_RP_hash_p0(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - reset_config_on_routers(tgen) result = pre_config_to_bsm( @@ -954,6 +957,10 @@ def test_BSM_fragmentation_p1(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) @@ -961,10 +968,6 @@ def test_BSM_fragmentation_p1(request): reset_config_on_routers(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - result = pre_config_to_bsm( tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1" ) @@ -1072,14 +1075,15 @@ def test_RP_with_all_ip_octet_p1(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) step("pre-configure BSM packet") result = pre_config_to_bsm( tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1" diff --git a/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py b/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py index 36a3103c9d..487ec924e9 100755 --- a/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py +++ b/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py @@ -69,7 +69,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import ( start_topology, @@ -133,8 +133,8 @@ TOPOLOGY = """ Description: i1, i2, i3. i4, i5, i6, i7, i8 - FRR running iperf to send IGMP join and traffic - l1 - LHR - f1 - FHR + l1 - LHR (last hop router) + f1 - FHR (first hop router) r2 - FRR router c1 - FRR router c2 - FRR router @@ -219,7 +219,7 @@ def setup_module(mod): pytest.skip(tgen.errors) # Creating configuration from JSON - build_config_from_json(tgen, topo) + build_config_from_json(tgen, tgen.json_topo) logger.info("Running setup_module() done") @@ -231,6 +231,9 @@ def teardown_module(): tgen = get_topogen() + # Kill any iperfs we left running. + kill_iperf(tgen) + # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -276,13 +279,8 @@ def config_to_send_igmp_join_and_traffic( result = addKernelRoute(tgen, iperf, iperf_intf, GROUP_RANGE) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - router_list = tgen.routers() - for router in router_list.keys(): - if router == iperf: - continue - - rnode = router_list[router] - rnode.run("echo 2 > /proc/sys/net/ipv4/conf/all/rp_filter") + rnode = tgen.gears[iperf] + rnode.run("echo 2 > /proc/sys/net/ipv4/conf/all/rp_filter") return True @@ -333,6 +331,7 @@ def test_multicast_data_traffic_static_RP_send_join_then_traffic_p0(request): """ tgen = get_topogen() + topo = tgen.json_topo tc_name = request.node.name write_test_header(tc_name) @@ -342,10 +341,6 @@ def test_multicast_data_traffic_static_RP_send_join_then_traffic_p0(request): step("Enable IGMP on FRR1 interface and send IGMP join (225.1.1.1)") intf_i1_l1 = topo["routers"]["i1"]["links"]["l1"]["interface"] - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i1", intf_i1_l1, GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("joinRx value before join sent") intf_r2_l1 = topo["routers"]["r2"]["links"]["l1"]["interface"] @@ -356,7 +351,7 @@ def test_multicast_data_traffic_static_RP_send_join_then_traffic_p0(request): ), "Testcase {} : Failed \n state_before is not dictionary \n " "Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "i1", IGMP_JOIN, join_interval=1) + result = iperfSendIGMPJoin(tgen, "i1", ["{}%{}".format(IGMP_JOIN, intf_i1_l1)], join_interval=1) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send the IGMP join first and then start the traffic") @@ -382,13 +377,7 @@ def test_multicast_data_traffic_static_RP_send_join_then_traffic_p0(request): assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to 225.1.1.1 receiver") - intf_i2_f1 = topo["routers"]["i2"]["links"]["f1"]["interface"] - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i2", intf_i2_f1, GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - - result = iperfSendTraffic(tgen, "i2", IGMP_JOIN, 32, 2500) + result = iperfSendTraffic(tgen, "i2", IGMP_JOIN, 32, 2500, bindToIntf="f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( @@ -456,19 +445,20 @@ def test_multicast_data_traffic_static_RP_send_traffic_then_join_p0(request): """ tgen = get_topogen() + topo = tgen.json_topo tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure RP on R2 (loopback interface) for the" " group range 225.0.0.0/8") input_dict = { @@ -580,19 +570,20 @@ def test_clear_pim_neighbors_and_mroute_p0(request): """ tgen = get_topogen() + topo = tgen.json_topo tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure static RP on c1 for group (225.1.1.1-5)") input_dict = { "c1": { @@ -673,19 +664,20 @@ def test_verify_mroute_when_same_receiver_in_FHR_LHR_and_RP_p0(request): """ tgen = get_topogen() + topo = tgen.json_topo tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure RP on R2 (loopback interface) for the" " group range 225.0.0.0/8") input_dict = { @@ -738,7 +730,7 @@ def test_verify_mroute_when_same_receiver_in_FHR_LHR_and_RP_p0(request): step("IGMP is received on FRR1 , FRR2 , FRR3, using " "'show ip igmp groups'") igmp_groups = {"l1": "l1-i1-eth1", "r2": "r2-i3-eth1", "f1": "f1-i8-eth2"} for dut, interface in igmp_groups.items(): - result = verify_igmp_groups(tgen, dut, interface, IGMP_JOIN) + result = verify_igmp_groups(tgen, dut, interface, IGMP_JOIN, retry_timeout=80) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("(*,G) present on all the node with correct OIL" " using 'show ip mroute'") @@ -768,19 +760,20 @@ def test_verify_mroute_when_same_receiver_joining_5_diff_sources_p0(request): """ tgen = get_topogen() + topo = tgen.json_topo tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure static RP for (226.1.1.1-5) and (232.1.1.1-5)" " in c1") _GROUP_RANGE = GROUP_RANGE_2 + GROUP_RANGE_3 @@ -1088,19 +1081,20 @@ def test_verify_mroute_when_frr_is_transit_router_p2(request): """ tgen = get_topogen() + topo = tgen.json_topo tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure static RP for (226.1.1.1-5) in c2") input_dict = { "c2": { @@ -1197,19 +1191,20 @@ def test_verify_mroute_when_RP_unreachable_p1(request): """ tgen = get_topogen() + topo = tgen.json_topo tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure RP on FRR2 (loopback interface) for " "the group range 225.0.0.0/8") input_dict = { @@ -1317,19 +1312,20 @@ def test_modify_igmp_query_timer_p0(request): """ tgen = get_topogen() + topo = tgen.json_topo tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Enable IGMP on FRR1 interface and send IGMP join (225.1.1.1)") result = config_to_send_igmp_join_and_traffic( tgen, topo, tc_name, "i1", "i1-l1-eth0", GROUP_RANGE, join=True @@ -1455,19 +1451,20 @@ def test_modify_igmp_max_query_response_timer_p0(request): """ tgen = get_topogen() + topo = tgen.json_topo tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Enable IGMP on FRR1 interface and send IGMP join (225.1.1.1)") result = config_to_send_igmp_join_and_traffic( tgen, topo, tc_name, "i1", "i1-l1-eth0", GROUP_RANGE, join=True @@ -1477,7 +1474,7 @@ def test_modify_igmp_max_query_response_timer_p0(request): result = iperfSendIGMPJoin(tgen, "i1", IGMP_JOIN, join_interval=1) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - step("Configure IGMP query response time to 10 sec on FRR1") + step("Configure IGMP query response time to 10 deci-sec on FRR1") input_dict_1 = { "l1": { "igmp": { diff --git a/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py b/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py index f30902c1b2..0b68942208 100755 --- a/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py +++ b/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py @@ -65,7 +65,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import ( start_topology, @@ -225,6 +225,9 @@ def teardown_module(): tgen = get_topogen() + # Kill any iperfs we left running. + kill_iperf(tgen) + # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -330,16 +333,16 @@ def test_verify_mroute_and_traffic_when_pimd_restarted_p2(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure static RP for (226.1.1.1-5) in c1") step("Configure static RP for (232.1.1.1-5) in c2") @@ -542,16 +545,16 @@ def test_verify_mroute_and_traffic_when_frr_restarted_p2(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure static RP for (226.1.1.1-5) in c1") step("Configure static RP for (232.1.1.1-5) in c2") @@ -753,16 +756,16 @@ def test_verify_SPT_switchover_when_RPT_and_SPT_path_is_different_p0(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure static RP for (226.1.1.1-5) and " "(232.1.1.1-5) in c2") _GROUP_RANGE = GROUP_RANGE_2 + GROUP_RANGE_3 @@ -915,16 +918,16 @@ def test_verify_mroute_after_shut_noshut_of_upstream_interface_p1(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure static RP for (226.1.1.1-5) in c1") step("Configure static RP for (232.1.1.1-5) in c2") @@ -1131,21 +1134,11 @@ def test_verify_mroute_after_shut_noshut_of_upstream_interface_p1(request): intf_l1_c1 = "l1-c1-eth0" shutdown_bringup_interface(tgen, dut, intf_l1_c1, False) - done_flag = False - for retry in range(1, 11): - result = verify_upstream_iif( - tgen, "l1", "Unknown", source, IGMP_JOIN_RANGE_2, expected=False - ) - if result is not True: - done_flag = True - else: - continue - if done_flag: - logger.info("Expected Behavior: {}".format(result)) - break - - assert done_flag is True, ( + result = verify_upstream_iif( + tgen, "l1", "Unknown", source, IGMP_JOIN_RANGE_2, expected=False + ) + assert result is not True, ( "Testcase {} : Failed Error: \n " "mroutes are still present, after waiting for 10 mins".format(tc_name) ) @@ -1198,16 +1191,16 @@ def test_verify_mroute_when_receiver_is_outside_frr_p0(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure static RP on c1 for group range " "(226.1.1.1-5) and (232.1.1.1-5)") _GROUP_RANGE = GROUP_RANGE_2 + GROUP_RANGE_3 @@ -1338,16 +1331,16 @@ def test_verify_mroute_when_FRR_is_FHR_and_LHR_p0(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure static RP for group range (226.1.1.1-5) and " "(232.1.1.1-5) on c1") _GROUP_RANGE = GROUP_RANGE_2 + GROUP_RANGE_3 _IGMP_JOIN_RANGE = IGMP_JOIN_RANGE_2 + IGMP_JOIN_RANGE_3 @@ -1484,31 +1477,18 @@ def test_verify_mroute_when_FRR_is_FHR_and_LHR_p0(request): {"dut": "f1", "src_address": "*", "iif": "f1-c2-eth0", "oil": "f1-i8-eth2"}, {"dut": "l1", "src_address": "*", "iif": "l1-c1-eth0", "oil": "l1-i1-eth1"}, ] - - done_flag = False - for retry in range(1, 11): - for data in input_dict: - result = verify_ip_mroutes( - tgen, - data["dut"], - data["src_address"], - _IGMP_JOIN_RANGE, - data["iif"], - data["oil"], - ) - - if result is True: - done_flag = True - else: - continue - - if done_flag: - break - - assert done_flag is True, ( - "Testcase {} : Failed Error: \n " - "mroutes are still present, after waiting for 10 mins".format(tc_name) - ) + for data in input_dict: + result = verify_ip_mroutes( + tgen, + data["dut"], + data["src_address"], + _IGMP_JOIN_RANGE, + data["iif"], + data["oil"], + ) + assert result is True, ( + "Testcase {} : Failed Error mroutes were flushed.".format(tc_name) + ) step( "After traffic stopped , verify (S,G) entries are flushed out" @@ -1520,31 +1500,19 @@ def test_verify_mroute_when_FRR_is_FHR_and_LHR_p0(request): {"dut": "f1", "src_address": source, "iif": "i2-f1-eth0", "oil": "f1-r2-eth3"}, ] - done_flag = False - for retry in range(1, 11): - for data in input_dict: - result = verify_ip_mroutes( - tgen, - data["dut"], - data["src_address"], - _IGMP_JOIN_RANGE, - data["iif"], - data["oil"], - expected=False, - ) - if result is not True: - done_flag = True - else: - continue - - if done_flag: - logger.info("Expected Behavior: {}".format(result)) - break - - assert done_flag is True, ( - "Testcase {} : Failed Error: \n " - "mroutes are still present, after waiting for 10 mins".format(tc_name) - ) + for data in input_dict: + result = verify_ip_mroutes( + tgen, + data["dut"], + data["src_address"], + _IGMP_JOIN_RANGE, + data["iif"], + data["oil"], + expected=False, + ) + assert result is not True, ( + "Testcase {} : Failed Error: \nmroutes are still present".format(tc_name) + ) write_test_footer(tc_name) @@ -1559,16 +1527,16 @@ def test_verify_mroute_when_5_different_receiver_joining_same_sources_p0(request tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure static RP for (226.1.1.1-5) in c1") step("Configure static RP for (232.1.1.1-5) in c2") @@ -1790,16 +1758,16 @@ def test_verify_oil_iif_for_mroute_after_shut_noshut_source_interface_p1(request tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure static RP for (226.1.1.1-5) in c1") step("Configure static RP for (232.1.1.1-5) in c2") diff --git a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py index 033c76081a..f3688e2f55 100755 --- a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py +++ b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py @@ -68,7 +68,6 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo from lib.common_config import ( start_topology, @@ -178,7 +177,6 @@ SAME_VLAN_IP_1 = {"ip": "10.1.1.1", "subnet": "255.255.255.0", "cidr": "24"} SAME_VLAN_IP_2 = {"ip": "10.1.1.2", "subnet": "255.255.255.0", "cidr": "24"} SAME_VLAN_IP_3 = {"ip": "10.1.1.3", "subnet": "255.255.255.0", "cidr": "24"} SAME_VLAN_IP_4 = {"ip": "10.1.1.4", "subnet": "255.255.255.0", "cidr": "24"} -TCPDUMP_FILE = "{}/{}".format(LOGDIR, "v2query.txt") class CreateTopo(Topo): @@ -242,6 +240,9 @@ def teardown_module(): tgen = get_topogen() + # Kill any iperfs we left running. + kill_iperf(tgen) + # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -351,31 +352,27 @@ def verify_state_incremented(state_before, state_after): * `state_after` : State dictionary for any particular instance """ - for router, state_data in state_before.items(): - for state, value in state_data.items(): - if state_before[router][state] >= state_after[router][state]: - errormsg = ( - "[DUT: %s]: state %s value has not" - " incremented, Initial value: %s, " - "Current value: %s [FAILED!!]" - % ( - router, - state, - state_before[router][state], - state_after[router][state], + for ttype, v1 in state_before.items(): + for intf, v2 in v1.items(): + for state, value in v2.items(): + if value >= state_after[ttype][intf][state]: + errormsg = ( + "[DUT: %s]: state %s value has not incremented, Initial value: %s, Current value: %s [FAILED!!]" % ( + intf, + state, + value, + state_after[ttype][intf][state], + ) ) - ) - return errormsg + return errormsg - logger.info( - "[DUT: %s]: State %s value is " - "incremented, Initial value: %s, Current value: %s" - " [PASSED!!]", - router, - state, - state_before[router][state], - state_after[router][state], - ) + logger.info( + "[DUT: %s]: State %s value is incremented, Initial value: %s, Current value: %s [PASSED!!]", + intf, + state, + value, + state_after[ttype][intf][state], + ) return True @@ -392,7 +389,7 @@ def find_v2_query_msg_in_tcpdump(tgen, router, message, count, cap_file): """ - filepath = os.path.join(LOGDIR, tgen.modname, router, cap_file) + filepath = os.path.join(tgen.logdir, router, cap_file) with open(filepath) as f: if len(re.findall("{}".format(message), f.read())) < count: errormsg = "[DUT: %s]: Verify Message: %s in tcpdump" " [FAILED!!]" % ( @@ -422,7 +419,7 @@ def find_tos_in_tcpdump(tgen, router, message, cap_file): """ - filepath = os.path.join(LOGDIR, tgen.modname, router, cap_file) + filepath = os.path.join(tgen.logdir, router, cap_file) with open(filepath) as f: if len(re.findall(message, f.read())) < 1: @@ -449,6 +446,10 @@ def test_verify_oil_when_join_prune_sent_scenario_1_p1(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) @@ -456,10 +457,6 @@ def test_verify_oil_when_join_prune_sent_scenario_1_p1(request): clear_ip_pim_interface_traffic(tgen, topo) check_router_status(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Enable the PIM on all the interfaces of FRR1, FRR2, FRR3") step( "Enable IGMP of FRR1 interface and send IGMP joins " @@ -824,6 +821,10 @@ def test_verify_oil_when_join_prune_sent_scenario_2_p1(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) @@ -831,10 +832,6 @@ def test_verify_oil_when_join_prune_sent_scenario_2_p1(request): clear_ip_pim_interface_traffic(tgen, topo) check_router_status(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Removing FRR3 to simulate topo " "FHR(FRR1)---LHR(FRR2)") intf_l1_c1 = topo["routers"]["l1"]["links"]["c1"]["interface"] @@ -1066,6 +1063,10 @@ def test_shut_noshut_source_interface_when_upstream_cleared_from_LHR_p1(request) tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) @@ -1073,10 +1074,6 @@ def test_shut_noshut_source_interface_when_upstream_cleared_from_LHR_p1(request) clear_ip_pim_interface_traffic(tgen, topo) check_router_status(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Enable the PIM on all the interfaces of FRR1, R2 and FRR3" " routers") step("Enable IGMP on FRR1 interface and send IGMP join " "(225.1.1.1-225.1.1.10)") @@ -1211,22 +1208,11 @@ def test_shut_noshut_source_interface_when_upstream_cleared_from_LHR_p1(request) " 'show ip pim upstream' 'show ip mroute' " ) - done_flag = False - for retry in range(1, 11): - result = verify_upstream_iif( - tgen, "l1", "Unknown", source_i2, IGMP_JOIN_RANGE_1, expected=False - ) - if result is not True: - done_flag = True - else: - continue - if done_flag: - logger.info("Expected Behavior: {}".format(result)) - break - - assert done_flag is True, ( - "Testcase {} : Failed Error: \n " - "mroutes are still present, after waiting for 10 mins".format(tc_name) + result = verify_upstream_iif( + tgen, "l1", "Unknown", source_i2, IGMP_JOIN_RANGE_1, expected=False + ) + assert result is not True, ( + "Testcase {} : Failed Error: \n mroutes are still present".format(tc_name) ) step("No shut the Source interface just after the upstream is expired" " from FRR1") @@ -1294,6 +1280,10 @@ def test_shut_noshut_receiver_interface_when_upstream_cleared_from_LHR_p1(reques tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) @@ -1301,10 +1291,6 @@ def test_shut_noshut_receiver_interface_when_upstream_cleared_from_LHR_p1(reques clear_ip_pim_interface_traffic(tgen, topo) check_router_status(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Enable the PIM on all the interfaces of FRR1, R2 and FRR3" " routers") step("Enable IGMP on FRR1 interface and send IGMP join " "(225.1.1.1-225.1.1.10)") @@ -1425,22 +1411,11 @@ def test_shut_noshut_receiver_interface_when_upstream_cleared_from_LHR_p1(reques " 'show ip pim upstream' 'show ip mroute' " ) - done_flag = False - for retry in range(1, 11): - result = verify_upstream_iif( - tgen, "l1", "Unknown", source_i2, IGMP_JOIN_RANGE_1, expected=False - ) - if result is not True: - done_flag = True - else: - continue - if done_flag: - logger.info("Expected Behavior: {}".format(result)) - break - - assert done_flag is True, ( - "Testcase {} : Failed Error: \n " - "mroutes are still present, after waiting for 10 mins".format(tc_name) + result = verify_upstream_iif( + tgen, "l1", "Unknown", source_i2, IGMP_JOIN_RANGE_1, expected=False + ) + assert result is not True, ( + "Testcase {} : Failed Error: \nmroutes are still present".format(tc_name) ) step("No shut the Source interface just after the upstream is expired" " from FRR1") @@ -1507,6 +1482,10 @@ def test_verify_remove_add_igmp_config_to_receiver_interface_p0(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) @@ -1514,10 +1493,6 @@ def test_verify_remove_add_igmp_config_to_receiver_interface_p0(request): clear_ip_pim_interface_traffic(tgen, topo) check_router_status(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Enable PIM on all routers") step("Enable IGMP on FRR1 interface and send IGMP join " "(225.1.1.1-225.1.1.10)") @@ -1883,6 +1858,10 @@ def test_verify_remove_add_igmp_commands_when_pim_configured_p0(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) @@ -1890,10 +1869,6 @@ def test_verify_remove_add_igmp_commands_when_pim_configured_p0(request): clear_ip_pim_interface_traffic(tgen, topo) check_router_status(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Enable PIM on all routers") step("Enable IGMP on FRR1 interface and send IGMP join " "(225.1.1.1-225.1.1.10)") @@ -2182,6 +2157,10 @@ def test_verify_remove_add_pim_commands_when_igmp_configured_p1(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) @@ -2189,10 +2168,6 @@ def test_verify_remove_add_pim_commands_when_igmp_configured_p1(request): clear_ip_pim_interface_traffic(tgen, topo) check_router_status(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure 'ip pim' on receiver interface on FRR1") step("Enable PIM on all routers") step("Enable IGMP on FRR1 interface and send IGMP join " "(225.1.1.1-225.1.1.10)") @@ -2377,6 +2352,10 @@ def test_pim_dr_priority_p0(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) @@ -2384,10 +2363,6 @@ def test_pim_dr_priority_p0(request): clear_ip_pim_interface_traffic(tgen, topo) check_router_status(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure 'ip pim' on receiver interface on FRR1") step("Enable PIM on all routers") step("Enable IGMP on FRR1 interface and send IGMP join " "(225.1.1.1-225.1.1.10)") @@ -2660,6 +2635,10 @@ def test_pim_hello_timer_p1(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) @@ -2667,10 +2646,6 @@ def test_pim_hello_timer_p1(request): clear_ip_pim_interface_traffic(tgen, topo) check_router_status(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step("Configure 'ip pim' on receiver interface on FRR1") step("Enable PIM on all routers") step("Enable IGMP on FRR1 interface and send IGMP join " "(225.1.1.1-225.1.1.10)") @@ -2780,6 +2755,10 @@ def test_mroute_after_removing_RP_sending_IGMP_prune_p2(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) @@ -2787,9 +2766,6 @@ def test_mroute_after_removing_RP_sending_IGMP_prune_p2(request): clear_ip_pim_interface_traffic(tgen, topo) check_router_status(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) step( "Remove cisco connected link to simulate topo " "LHR(FRR1(f1))----RP(cisco(f1)---FHR(FRR3(l1))" @@ -3097,6 +3073,10 @@ def test_prune_sent_to_LHR_and_FHR_when_PIMnbr_down_p2(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) @@ -3104,9 +3084,6 @@ def test_prune_sent_to_LHR_and_FHR_when_PIMnbr_down_p2(request): clear_ip_pim_interface_traffic(tgen, topo) check_router_status(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) step( "Remove cisco connected link to simulate topo " "LHR(FRR1(f1))----RP(cisco(f1)---FHR(FRR3(l1))" @@ -3738,6 +3715,10 @@ def test_mroute_flags_p1(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) @@ -3745,9 +3726,6 @@ def test_mroute_flags_p1(request): clear_ip_pim_interface_traffic(tgen, topo) check_router_status(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) step( "Remove cisco connected link to simulate topo " "LHR(FRR1(f1))----RP(cisco(f1)---FHR(FRR3(l1))" @@ -3900,6 +3878,10 @@ def test_verify_multicast_traffic_when_LHR_connected_to_RP_p1(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) @@ -3907,10 +3889,6 @@ def test_verify_multicast_traffic_when_LHR_connected_to_RP_p1(request): clear_ip_pim_interface_traffic(tgen, topo) check_router_status(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step( "Remove FRR3 to cisco connected link to simulate topo " "FHR(FRR3(l1))---LHR(FRR1(r2)----RP(FRR2(f1))" @@ -4362,6 +4340,10 @@ def test_verify_multicast_traffic_when_FHR_connected_to_RP_p1(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) @@ -4369,10 +4351,6 @@ def test_verify_multicast_traffic_when_FHR_connected_to_RP_p1(request): clear_ip_pim_interface_traffic(tgen, topo) check_router_status(tgen) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - step( "Remove FRR3 to FRR2 connected link to simulate topo " "FHR(FRR3)---LHR(FRR1)----RP(FFR2)" diff --git a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py index 1081b764ac..0b9c216c66 100755 --- a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py +++ b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py @@ -61,7 +61,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.common_config import ( start_topology, @@ -210,6 +210,9 @@ def teardown_module(): tgen = get_topogen() + # Kill any iperfs we left running. + kill_iperf(tgen) + # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -323,15 +326,16 @@ def test_mroute_when_RP_reachable_default_route_p2(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) step( "Remove c1-c2 connected link to simulate topo " "c1(FHR)---l1(RP)----r2---f1-----c2(LHR)" @@ -621,15 +625,16 @@ def test_mroute_with_RP_default_route_all_nodes_p2(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) step( "Remove c1-c2 connected link to simulate topo " "c1(LHR)---l1(RP)----r2---f1-----c2(FHR)" @@ -908,15 +913,16 @@ def test_PIM_hello_tx_rx_p1(request): tc_name = request.node.name write_test_header(tc_name) + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) - # Don"t run this test if we have any failure. - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) step( "Remove c1-c2 connected link to simulate topo " "c1(LHR)---l1(RP)----r2---f1-----c2(FHR)" diff --git a/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py b/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py index 7c2d13f395..ba8ea0be63 100755 --- a/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py +++ b/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py @@ -114,7 +114,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen from lib.topolog import logger @@ -268,6 +268,9 @@ def teardown_module(): tgen = get_topogen() + # Kill any iperfs we left running. + kill_iperf(tgen) + # Stop toplogy and Remove tmp files tgen.stop_topology() diff --git a/tests/topotests/nhrp_topo/test_nhrp_topo.py b/tests/topotests/nhrp_topo/test_nhrp_topo.py index f59e3ae1b9..081c63a185 100644 --- a/tests/topotests/nhrp_topo/test_nhrp_topo.py +++ b/tests/topotests/nhrp_topo/test_nhrp_topo.py @@ -43,7 +43,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.nhrpd] diff --git a/tests/topotests/ospf6_topo1/test_ospf6_topo1.py b/tests/topotests/ospf6_topo1/test_ospf6_topo1.py index 8a6544734a..4a4ae3d5b9 100644 --- a/tests/topotests/ospf6_topo1/test_ospf6_topo1.py +++ b/tests/topotests/ospf6_topo1/test_ospf6_topo1.py @@ -78,7 +78,7 @@ from time import sleep from functools import partial -from mininet.topo import Topo +from lib.micronet_compat import Topo # Save the Current Working Directory to find configuration files later. CWD = os.path.dirname(os.path.realpath(__file__)) diff --git a/tests/topotests/ospf6_topo1_vrf/test_ospf6_topo1_vrf.py b/tests/topotests/ospf6_topo1_vrf/test_ospf6_topo1_vrf.py index 61a80cc9ec..fc1a472a17 100755 --- a/tests/topotests/ospf6_topo1_vrf/test_ospf6_topo1_vrf.py +++ b/tests/topotests/ospf6_topo1_vrf/test_ospf6_topo1_vrf.py @@ -80,7 +80,7 @@ from time import sleep from functools import partial -from mininet.topo import Topo +from lib.micronet_compat import Topo # Save the Current Working Directory to find configuration files later. CWD = os.path.dirname(os.path.realpath(__file__)) diff --git a/tests/topotests/ospf6_topo2/test_ospf6_topo2.py b/tests/topotests/ospf6_topo2/test_ospf6_topo2.py index 8c5f1e6f60..e64000b077 100644 --- a/tests/topotests/ospf6_topo2/test_ospf6_topo2.py +++ b/tests/topotests/ospf6_topo2/test_ospf6_topo2.py @@ -42,7 +42,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.ospf6d] @@ -346,7 +346,7 @@ def test_nssa_lsa_type7(): def dont_expect_route(unexpected_route): "Specialized test function to expect route go missing" output = tgen.gears["r4"].vtysh_cmd("show ipv6 ospf6 route json", isjson=True) - if output["routes"].has_key(unexpected_route): + if unexpected_route in output["routes"]: return output["routes"][unexpected_route] return None diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_topo1.py b/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_topo1.py index a3f1bc76ff..392cca3a1b 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_topo1.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_topo1.py @@ -35,7 +35,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen import ipaddress from time import sleep diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_type7_lsa.py b/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_type7_lsa.py index db177360b4..3bd4f8b596 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_type7_lsa.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_type7_lsa.py @@ -35,7 +35,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen import ipaddress from time import sleep diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py b/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py index bdba8fd8e4..6d1b8d9e9d 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py @@ -38,7 +38,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_chaos.py b/tests/topotests/ospf_basic_functionality/test_ospf_chaos.py index c117fc6a72..d946cca892 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_chaos.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_chaos.py @@ -36,7 +36,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py index 5c57f8be25..4c5510ca6c 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py @@ -37,7 +37,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen from ipaddress import IPv4Address diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py index 96f781c150..eb1c3a914c 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py @@ -35,7 +35,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_lan.py b/tests/topotests/ospf_basic_functionality/test_ospf_lan.py index c89a663380..e7a002fb80 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_lan.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_lan.py @@ -38,7 +38,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py b/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py index 0af83548b9..5cb4bd33dd 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py @@ -49,7 +49,7 @@ from lib.common_config import ( ) from ipaddress import IPv4Address from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo import os import sys import time diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py b/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py index 0172f589c5..5533136457 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py @@ -37,7 +37,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen import ipaddress @@ -57,6 +57,7 @@ from lib.common_config import ( ) from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topotest import frr_unicode from lib.ospf import ( verify_ospf_neighbor, diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py b/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py index 066f53aa58..34abd0dc48 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py @@ -36,7 +36,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py b/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py index 0e2fef4a22..9f05f396ad 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py @@ -36,7 +36,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py b/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py index 0d0668a931..2773c01ff5 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py @@ -38,7 +38,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen import ipaddress diff --git a/tests/topotests/ospf_dual_stack/test_ospf_dual_stack.py b/tests/topotests/ospf_dual_stack/test_ospf_dual_stack.py index b5f535cd06..f4d98fddb8 100644 --- a/tests/topotests/ospf_dual_stack/test_ospf_dual_stack.py +++ b/tests/topotests/ospf_dual_stack/test_ospf_dual_stack.py @@ -10,7 +10,7 @@ CWD = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(CWD, "../")) sys.path.append(os.path.join(CWD, "../lib/")) -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen from lib.common_config import ( diff --git a/tests/topotests/ospf_gr_topo1/test_ospf_gr_topo1.py b/tests/topotests/ospf_gr_topo1/test_ospf_gr_topo1.py index 0507c2d516..3520cdf243 100755 --- a/tests/topotests/ospf_gr_topo1/test_ospf_gr_topo1.py +++ b/tests/topotests/ospf_gr_topo1/test_ospf_gr_topo1.py @@ -92,7 +92,7 @@ from lib.common_config import ( ) # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.ospfd] diff --git a/tests/topotests/ospf_sr_te_topo1/test_ospf_sr_te_topo1.py b/tests/topotests/ospf_sr_te_topo1/test_ospf_sr_te_topo1.py index 6c1122ab72..6146178d89 100755 --- a/tests/topotests/ospf_sr_te_topo1/test_ospf_sr_te_topo1.py +++ b/tests/topotests/ospf_sr_te_topo1/test_ospf_sr_te_topo1.py @@ -93,7 +93,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd, pytest.mark.pathd] diff --git a/tests/topotests/ospf_sr_topo1/test_ospf_sr_topo1.py b/tests/topotests/ospf_sr_topo1/test_ospf_sr_topo1.py index 8b7e3b7787..3f448d4bf3 100644 --- a/tests/topotests/ospf_sr_topo1/test_ospf_sr_topo1.py +++ b/tests/topotests/ospf_sr_topo1/test_ospf_sr_topo1.py @@ -82,7 +82,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.ospfd] diff --git a/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py b/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py index a22fbf458a..2975e5864e 100644 --- a/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py +++ b/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py @@ -48,7 +48,7 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.ospfd] diff --git a/tests/topotests/ospf_te_topo1/test_ospf_te_topo1.py b/tests/topotests/ospf_te_topo1/test_ospf_te_topo1.py index 32f9b3453e..1678287bb7 100644 --- a/tests/topotests/ospf_te_topo1/test_ospf_te_topo1.py +++ b/tests/topotests/ospf_te_topo1/test_ospf_te_topo1.py @@ -67,7 +67,7 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo # Import topogen and topotest helpers from lib import topotest @@ -83,7 +83,7 @@ pytestmark = [pytest.mark.ospfd] class OspfTeTopo(Topo): "Test topology builder" - def build(self): + def build(self, *args, **kwargs): "Build function" tgen = get_topogen(self) diff --git a/tests/topotests/ospf_tilfa_topo1/test_ospf_tilfa_topo1.py b/tests/topotests/ospf_tilfa_topo1/test_ospf_tilfa_topo1.py index b3da6e2a1a..956e2ab0a0 100644 --- a/tests/topotests/ospf_tilfa_topo1/test_ospf_tilfa_topo1.py +++ b/tests/topotests/ospf_tilfa_topo1/test_ospf_tilfa_topo1.py @@ -69,7 +69,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.ospfd] diff --git a/tests/topotests/ospf_topo1/test_ospf_topo1.py b/tests/topotests/ospf_topo1/test_ospf_topo1.py index 42634ce906..50992503ea 100644 --- a/tests/topotests/ospf_topo1/test_ospf_topo1.py +++ b/tests/topotests/ospf_topo1/test_ospf_topo1.py @@ -43,7 +43,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.ospfd] diff --git a/tests/topotests/ospf_topo1_vrf/test_ospf_topo1_vrf.py b/tests/topotests/ospf_topo1_vrf/test_ospf_topo1_vrf.py index 713a65a812..711f76c5c8 100644 --- a/tests/topotests/ospf_topo1_vrf/test_ospf_topo1_vrf.py +++ b/tests/topotests/ospf_topo1_vrf/test_ospf_topo1_vrf.py @@ -43,7 +43,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.ospfd] @@ -99,20 +99,12 @@ def setup_module(mod): logger.info("Testing with VRF Namespace support") - cmds = [ - "if [ -e /var/run/netns/{0}-ospf-cust1 ] ; then ip netns del {0}-ospf-cust1 ; fi", - "ip netns add {0}-ospf-cust1", - "ip link set dev {0}-eth0 netns {0}-ospf-cust1", - "ip netns exec {0}-ospf-cust1 ip link set {0}-eth0 up", - "ip link set dev {0}-eth1 netns {0}-ospf-cust1", - "ip netns exec {0}-ospf-cust1 ip link set {0}-eth1 up", - ] - for rname, router in router_list.items(): - - # create VRF rx-ospf-cust1 and link rx-eth0 to rx-ospf-cust1 - for cmd in cmds: - output = tgen.net[rname].cmd(cmd.format(rname)) + # create VRF rx-ospf-cust1 and link rx-eth{0,1} to rx-ospf-cust1 + ns = "{}-ospf-cust1".format(rname) + router.net.add_netns(ns) + router.net.set_intf_netns(rname + "-eth0", ns, up=True) + router.net.set_intf_netns(rname + "-eth1", ns, up=True) router.load_config( TopoRouter.RD_ZEBRA, @@ -134,18 +126,12 @@ def teardown_module(mod): "Teardown the pytest environment" tgen = get_topogen() - # move back rx-eth0 to default VRF - # delete rx-vrf - cmds = [ - "ip netns exec {0}-ospf-cust1 ip link set {0}-eth0 netns 1", - "ip netns exec {0}-ospf-cust1 ip link set {0}-eth1 netns 1", - "ip netns delete {0}-ospf-cust1", - ] - + # Move interfaces out of vrf namespace and delete the namespace router_list = tgen.routers() for rname, router in router_list.items(): - for cmd in cmds: - tgen.net[rname].cmd(cmd.format(rname)) + tgen.net[rname].reset_intf_netns(rname + "-eth0") + tgen.net[rname].reset_intf_netns(rname + "-eth1") + tgen.net[rname].delete_netns(rname + "-ospf-cust1") tgen.stop_topology() diff --git a/tests/topotests/ospf_topo2/test_ospf_topo2.py b/tests/topotests/ospf_topo2/test_ospf_topo2.py index 8b8d5d6e9f..38d424c906 100644 --- a/tests/topotests/ospf_topo2/test_ospf_topo2.py +++ b/tests/topotests/ospf_topo2/test_ospf_topo2.py @@ -44,7 +44,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.ospfd] @@ -95,10 +95,10 @@ def setup_module(mod): # the rp_filter. Setting it to '0' allows the OS to pass # up the mcast packet not destined for the local routers # network. - topotest.set_sysctl(tgen.net["r1"], "net.ipv4.conf.r1-eth1.rp_filter", 0) - topotest.set_sysctl(tgen.net["r1"], "net.ipv4.conf.all.rp_filter", 0) - topotest.set_sysctl(tgen.net["r2"], "net.ipv4.conf.r2-eth1.rp_filter", 0) - topotest.set_sysctl(tgen.net["r2"], "net.ipv4.conf.all.rp_filter", 0) + topotest.sysctl_assure(tgen.net["r1"], "net.ipv4.conf.r1-eth1.rp_filter", 0) + topotest.sysctl_assure(tgen.net["r1"], "net.ipv4.conf.all.rp_filter", 0) + topotest.sysctl_assure(tgen.net["r2"], "net.ipv4.conf.r2-eth1.rp_filter", 0) + topotest.sysctl_assure(tgen.net["r2"], "net.ipv4.conf.all.rp_filter", 0) # Initialize all routers. tgen.start_router() diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py index 6a4b60fbed..c76da39ca5 100644 --- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py +++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py @@ -38,7 +38,6 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo from lib.topogen import Topogen, get_topogen import ipaddress from time import sleep diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp.py index 50c5144b3f..6bfe4f199e 100644 --- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp.py +++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp.py @@ -38,7 +38,6 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo from lib.topogen import Topogen, get_topogen import ipaddress diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py index d8cf3bd02d..af1017c6bc 100644 --- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py +++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py @@ -38,7 +38,6 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo from lib.topogen import Topogen, get_topogen import ipaddress diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_rte_calc.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_rte_calc.py index 860f17ba67..d16cbb76fb 100644 --- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_rte_calc.py +++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_rte_calc.py @@ -37,7 +37,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen import ipaddress from lib.bgp import verify_bgp_convergence, create_router_bgp diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_single_area.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_single_area.py index 0c1c51c78a..22593babaa 100644 --- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_single_area.py +++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_single_area.py @@ -38,7 +38,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen import ipaddress diff --git a/tests/topotests/pbr_topo1/test_pbr_topo1.py b/tests/topotests/pbr_topo1/test_pbr_topo1.py index 1a024063b8..494e27a2ad 100644 --- a/tests/topotests/pbr_topo1/test_pbr_topo1.py +++ b/tests/topotests/pbr_topo1/test_pbr_topo1.py @@ -47,7 +47,7 @@ from lib.topolog import logger from lib.common_config import shutdown_bringup_interface # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.pbrd] diff --git a/tests/topotests/pim_acl/test_pim_acl.py b/tests/topotests/pim_acl/test_pim_acl.py index 77917a0239..0f172d3d9d 100755 --- a/tests/topotests/pim_acl/test_pim_acl.py +++ b/tests/topotests/pim_acl/test_pim_acl.py @@ -119,7 +119,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.pim import McastTesterHelper pytestmark = [pytest.mark.pimd, pytest.mark.ospfd] diff --git a/tests/topotests/pim_basic/test_pim.py b/tests/topotests/pim_basic/test_pim.py index 4debbeb851..e921b37b69 100644 --- a/tests/topotests/pim_basic/test_pim.py +++ b/tests/topotests/pim_basic/test_pim.py @@ -41,7 +41,7 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.pimd] @@ -208,22 +208,29 @@ def test_pim_igmp_report(): r1 = tgen.gears["r1"] # Let's send a igmp report from r2->r1 - CWD = os.path.dirname(os.path.realpath(__file__)) - r2.run("{}/mcast-rx.py 229.1.1.2 r2-eth0 &".format(CWD)) - - out = r1.vtysh_cmd("show ip pim upstream json", isjson=True) - expected = { - "229.1.1.2": { - "*": { - "sourceIgmp": 1, - "joinState": "Joined", - "regState": "RegNoInfo", - "sptBit": 0, + cmd = [ os.path.join(CWD, "mcast-rx.py"), "229.1.1.2", "r2-eth0" ] + p = r2.popen(cmd) + try: + expected = { + "229.1.1.2": { + "*": { + "sourceIgmp": 1, + "joinState": "Joined", + "regState": "RegNoInfo", + "sptBit": 0, + } } } - } - - assert topotest.json_cmp(out, expected) is None, "failed to converge pim" + test_func = partial( + topotest.router_json_cmp, r1, "show ip pim upstream json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=5, wait=.5) + assertmsg = '"{}" JSON output mismatches'.format(r1.name) + assert result is None, assertmsg + finally: + if p: + p.terminate() + p.wait() def test_memory_leak(): diff --git a/tests/topotests/pim_basic_topo2/test_pim_basic_topo2.py b/tests/topotests/pim_basic_topo2/test_pim_basic_topo2.py index 883125cfc7..2bed11c546 100644 --- a/tests/topotests/pim_basic_topo2/test_pim_basic_topo2.py +++ b/tests/topotests/pim_basic_topo2/test_pim_basic_topo2.py @@ -43,7 +43,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from mininet.topo import Topo +from lib.micronet_compat import Topo pytestmark = [pytest.mark.bfdd, pytest.mark.pimd] diff --git a/tests/topotests/rip_topo1/test_rip_topo1.py b/tests/topotests/rip_topo1/test_rip_topo1.py index 78672ac871..91b4278cd3 100644 --- a/tests/topotests/rip_topo1/test_rip_topo1.py +++ b/tests/topotests/rip_topo1/test_rip_topo1.py @@ -33,17 +33,13 @@ import sys import pytest from time import sleep -from mininet.topo import Topo -from mininet.net import Mininet -from mininet.node import Node, OVSSwitch, Host -from mininet.log import setLogLevel, info -from mininet.cli import CLI -from mininet.link import Intf from functools import partial sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lib import topotest +from lib.micronet_compat import Topo +from lib.micronet_compat import Mininet fatal_error = "" @@ -76,26 +72,26 @@ class NetworkTopo(Topo): # # On main router # First switch is for a dummy interface (for local network) - switch[1] = self.addSwitch("sw1", cls=topotest.LegacySwitch) + switch[1] = self.addSwitch("sw1") self.addLink(switch[1], router[1], intfName2="r1-eth0") # # Switches for RIP # switch 2 switch is for connection to RIP router - switch[2] = self.addSwitch("sw2", cls=topotest.LegacySwitch) + switch[2] = self.addSwitch("sw2") self.addLink(switch[2], router[1], intfName2="r1-eth1") self.addLink(switch[2], router[2], intfName2="r2-eth0") # switch 3 is between RIP routers - switch[3] = self.addSwitch("sw3", cls=topotest.LegacySwitch) + switch[3] = self.addSwitch("sw3") self.addLink(switch[3], router[2], intfName2="r2-eth1") self.addLink(switch[3], router[3], intfName2="r3-eth1") # switch 4 is stub on remote RIP router - switch[4] = self.addSwitch("sw4", cls=topotest.LegacySwitch) + switch[4] = self.addSwitch("sw4") self.addLink(switch[4], router[3], intfName2="r3-eth0") - switch[5] = self.addSwitch("sw5", cls=topotest.LegacySwitch) + switch[5] = self.addSwitch("sw5") self.addLink(switch[5], router[1], intfName2="r1-eth2") - switch[6] = self.addSwitch("sw6", cls=topotest.LegacySwitch) + switch[6] = self.addSwitch("sw6") self.addLink(switch[6], router[1], intfName2="r1-eth3") @@ -397,7 +393,6 @@ def test_shutdown_check_stderr(): if __name__ == "__main__": - setLogLevel("info") # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli # retval = pytest.main(["-s", "--tb=no"]) retval = pytest.main(["-s"]) diff --git a/tests/topotests/ripng_topo1/test_ripng_topo1.py b/tests/topotests/ripng_topo1/test_ripng_topo1.py index 4a5a59cd75..9b3f66111c 100644 --- a/tests/topotests/ripng_topo1/test_ripng_topo1.py +++ b/tests/topotests/ripng_topo1/test_ripng_topo1.py @@ -34,17 +34,12 @@ import pytest import unicodedata from time import sleep -from mininet.topo import Topo -from mininet.net import Mininet -from mininet.node import Node, OVSSwitch, Host -from mininet.log import setLogLevel, info -from mininet.cli import CLI -from mininet.link import Intf - from functools import partial sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lib import topotest +from lib.micronet_compat import Topo +from lib.micronet_compat import Mininet fatal_error = "" @@ -77,25 +72,25 @@ class NetworkTopo(Topo): # # On main router # First switch is for a dummy interface (for local network) - switch[1] = self.addSwitch("sw1", cls=topotest.LegacySwitch) + switch[1] = self.addSwitch("sw1") self.addLink(switch[1], router[1], intfName2="r1-eth0") # # Switches for RIPng # switch 2 switch is for connection to RIP router - switch[2] = self.addSwitch("sw2", cls=topotest.LegacySwitch) + switch[2] = self.addSwitch("sw2") self.addLink(switch[2], router[1], intfName2="r1-eth1") self.addLink(switch[2], router[2], intfName2="r2-eth0") # switch 3 is between RIP routers - switch[3] = self.addSwitch("sw3", cls=topotest.LegacySwitch) + switch[3] = self.addSwitch("sw3") self.addLink(switch[3], router[2], intfName2="r2-eth1") self.addLink(switch[3], router[3], intfName2="r3-eth1") # switch 4 is stub on remote RIP router - switch[4] = self.addSwitch("sw4", cls=topotest.LegacySwitch) + switch[4] = self.addSwitch("sw4") self.addLink(switch[4], router[3], intfName2="r3-eth0") - switch[5] = self.addSwitch("sw5", cls=topotest.LegacySwitch) + switch[5] = self.addSwitch("sw5") self.addLink(switch[5], router[1], intfName2="r1-eth2") - switch[6] = self.addSwitch("sw6", cls=topotest.LegacySwitch) + switch[6] = self.addSwitch("sw6") self.addLink(switch[6], router[1], intfName2="r1-eth3") @@ -443,7 +438,6 @@ def test_shutdown_check_memleak(): if __name__ == "__main__": - setLogLevel("info") # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli # retval = pytest.main(["-s", "--tb=no"]) retval = pytest.main(["-s"]) diff --git a/tests/topotests/route_scale/test_route_scale.py b/tests/topotests/route_scale/test_route_scale.py index 469ad42d64..d489967209 100644 --- a/tests/topotests/route_scale/test_route_scale.py +++ b/tests/topotests/route_scale/test_route_scale.py @@ -45,8 +45,6 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from lib.common_config import shutdown_bringup_interface -# Required to instantiate the topology builder class. -from mininet.topo import Topo pytestmark = [pytest.mark.sharpd] @@ -58,22 +56,17 @@ pytestmark = [pytest.mark.sharpd] ##################################################### -class NetworkTopo(Topo): - "Route Scale Topology" +def build(tgen): + "Build function" - def build(self, **_opts): - "Build function" + # Populate routers + for routern in range(1, 2): + tgen.add_router("r{}".format(routern)) - tgen = get_topogen(self) - - # Populate routers - for routern in range(1, 2): - tgen.add_router("r{}".format(routern)) - - # Populate switches - for switchn in range(1, 33): - switch = tgen.add_switch("sw{}".format(switchn)) - switch.add_link(tgen.gears["r1"]) + # Populate switches + for switchn in range(1, 33): + switch = tgen.add_switch("sw{}".format(switchn)) + switch.add_link(tgen.gears["r1"]) ##################################################### @@ -85,7 +78,7 @@ class NetworkTopo(Topo): def setup_module(module): "Setup topology" - tgen = Topogen(NetworkTopo, module.__name__) + tgen = Topogen(build, module.__name__) tgen.start_topology() router_list = tgen.routers() @@ -213,11 +206,11 @@ def test_route_install(): scale_setups.append(d) # Avoid top ecmp case for runs with < 4G memory - p = os.popen("free") - l = p.readlines()[1].split() - mem = int(l[1]) - if mem < 4000000: - logger.info("Limited memory available: {}, skipping x32 testcase".format(mem)) + output = tgen.net.cmd_raises("free") + m = re.search("Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)", output) + total_mem = int(m.group(2)) + if total_mem < 4000000: + logger.info("Limited memory available: {}, skipping x32 testcase".format(total_mem)) scale_setups = scale_setups[0:-1] # Run each step using the dicts we've built diff --git a/tests/topotests/simple_snmp_test/r1/snmpd.conf b/tests/topotests/simple_snmp_test/r1/snmpd.conf index b37911da36..740574cb8e 100644 --- a/tests/topotests/simple_snmp_test/r1/snmpd.conf +++ b/tests/topotests/simple_snmp_test/r1/snmpd.conf @@ -13,3 +13,6 @@ iquerySecName frr rouser frr master agentx + +agentXSocket /etc/frr/agentx +agentXPerms 777 755 root frr diff --git a/tests/topotests/simple_snmp_test/test_simple_snmp.py b/tests/topotests/simple_snmp_test/test_simple_snmp.py index bdb44816b6..c96bddf18d 100755 --- a/tests/topotests/simple_snmp_test/test_simple_snmp.py +++ b/tests/topotests/simple_snmp_test/test_simple_snmp.py @@ -43,39 +43,10 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from lib.snmptest import SnmpTester -# Required to instantiate the topology builder class. -from mininet.topo import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.isisd, pytest.mark.snmp] -class TemplateTopo(Topo): - "Test topology builder" - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # This function only purpose is to define allocation and relationship - # between routers, switches and hosts. - # - # - # Create routers - tgen.add_router("r1") - - # r1-eth0 - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - - # r1-eth1 - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r1"]) - - # r1-eth2 - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r1"]) - - def setup_module(mod): "Sets up the pytest environment" @@ -84,7 +55,12 @@ def setup_module(mod): error_msg = "SNMP not installed - skipping" pytest.skip(error_msg) # This function initiates the topology build with Topogen... - tgen = Topogen(TemplateTopo, mod.__name__) + topodef = { + "s1": "r1", + "s2": "r1", + "s3": "r1" + } + tgen = Topogen(topodef, mod.__name__) # ... and here it calls Mininet initialization functions. tgen.start_topology() @@ -142,7 +118,7 @@ def test_r1_bgp_version(): pytest.skip(tgen.errors) # tgen.mininet_cli() - r1 = tgen.net.get("r1") + r1 = tgen.gears["r1"] r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c") assert r1_snmp.test_oid("bgpVersin", None) assert r1_snmp.test_oid("bgpVersion", "10") diff --git a/tests/topotests/srv6_locator/test_srv6_locator.py b/tests/topotests/srv6_locator/test_srv6_locator.py index 04b0d8db97..7b571a0a86 100755 --- a/tests/topotests/srv6_locator/test_srv6_locator.py +++ b/tests/topotests/srv6_locator/test_srv6_locator.py @@ -41,7 +41,6 @@ sys.path.append(os.path.join(CWD, '../')) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.sharpd] @@ -54,16 +53,11 @@ def open_json_file(filename): assert False, "Could not read file {}".format(filename) -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) - tgen.add_router('r1') def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen({None: "r1"}, mod.__name__) tgen.start_topology() - router_list = tgen.routers() for rname, router in tgen.routers().items(): router.run("/bin/bash {}/{}/setup.sh".format(CWD, rname)) router.load_config(TopoRouter.RD_ZEBRA, os.path.join(CWD, '{}/zebra.conf'.format(rname))) diff --git a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo1_ebgp.py b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo1_ebgp.py index a16c4ae297..7b9b61fd91 100644 --- a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo1_ebgp.py +++ b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo1_ebgp.py @@ -44,7 +44,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topotest import version_cmp # Import topoJson from lib, to create topology and initial configuration diff --git a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py index 2c44ec2351..c0edfef5d7 100644 --- a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py +++ b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py @@ -52,7 +52,7 @@ sys.path.append(os.path.join(CWD, "../")) sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration diff --git a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo3_ebgp.py b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo3_ebgp.py index 8525e3655c..f088fd618e 100644 --- a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo3_ebgp.py +++ b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo3_ebgp.py @@ -45,7 +45,7 @@ sys.path.append(os.path.join(CWD, "../")) sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen from lib.common_config import ( diff --git a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo4_ebgp.py b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo4_ebgp.py index 626de6b422..217f8467dd 100644 --- a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo4_ebgp.py +++ b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo4_ebgp.py @@ -44,7 +44,7 @@ sys.path.append(os.path.join(CWD, "../")) sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen from lib.topotest import version_cmp diff --git a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo1_ibgp.py b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo1_ibgp.py index 4e23a72423..ea888c1376 100644 --- a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo1_ibgp.py +++ b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo1_ibgp.py @@ -43,7 +43,7 @@ sys.path.append(os.path.join(CWD, "../")) sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen from lib.topotest import version_cmp diff --git a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo2_ibgp.py b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo2_ibgp.py index 85b9e8b543..b58543cc91 100644 --- a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo2_ibgp.py +++ b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo2_ibgp.py @@ -52,7 +52,7 @@ sys.path.append(os.path.join(CWD, "../")) sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration diff --git a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo3_ibgp.py b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo3_ibgp.py index c84c88ac35..8e769ea66f 100644 --- a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo3_ibgp.py +++ b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo3_ibgp.py @@ -47,7 +47,7 @@ sys.path.append(os.path.join(CWD, "../")) sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen from lib.topotest import version_cmp diff --git a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py index a82ee64538..eb828ea035 100644 --- a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py +++ b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py @@ -43,7 +43,7 @@ sys.path.append(os.path.join(CWD, "../")) sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo +from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen from lib.common_config import ( diff --git a/tests/topotests/zebra_netlink/test_zebra_netlink.py b/tests/topotests/zebra_netlink/test_zebra_netlink.py index cf08ee9639..8c258a9dae 100644 --- a/tests/topotests/zebra_netlink/test_zebra_netlink.py +++ b/tests/topotests/zebra_netlink/test_zebra_netlink.py @@ -44,33 +44,10 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from lib.common_config import shutdown_bringup_interface -# Required to instantiate the topology builder class. -from mininet.topo import Topo pytestmark = [pytest.mark.sharpd] -##################################################### -## -## Network Topology Definition -## -##################################################### - - -class ZebraTopo(Topo): - "Test topology builder" - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - tgen.add_router("r1") - - # Create a empty network for router 1 - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - - ##################################################### ## ## Tests starting @@ -80,7 +57,9 @@ class ZebraTopo(Topo): def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(ZebraTopo, mod.__name__) + + topodef = { "s1": ("r1") } + tgen = Topogen(topodef, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/zebra_opaque/test_zebra_opaque.py b/tests/topotests/zebra_opaque/test_zebra_opaque.py index 2339b0f5b0..05911a9de3 100644 --- a/tests/topotests/zebra_opaque/test_zebra_opaque.py +++ b/tests/topotests/zebra_opaque/test_zebra_opaque.py @@ -36,25 +36,15 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) - - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + topodef = { + "s1": ("r1", "r2") + } + tgen = Topogen(topodef, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/zebra_rib/test_zebra_rib.py b/tests/topotests/zebra_rib/test_zebra_rib.py index 778a710ee3..cc12189fd2 100644 --- a/tests/topotests/zebra_rib/test_zebra_rib.py +++ b/tests/topotests/zebra_rib/test_zebra_rib.py @@ -43,36 +43,17 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from time import sleep -# Required to instantiate the topology builder class. -from mininet.topo import Topo pytestmark = [pytest.mark.sharpd] -class ZebraTopo(Topo): - "Test topology builder" - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - tgen.add_router("r1") - - # Create a empty network for router 1 - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r1"]) - def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(ZebraTopo, mod.__name__) + topodef = { + "s1": ("r1", "r1", "r1", "r1", "r1", "r1", "r1", "r1") + } + tgen = Topogen(topodef, mod.__name__) tgen.start_topology() router_list = tgen.routers() 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 a83c6d6ec0..6ac6569fa1 100755 --- a/tests/topotests/zebra_seg6_route/test_zebra_seg6_route.py +++ b/tests/topotests/zebra_seg6_route/test_zebra_seg6_route.py @@ -41,7 +41,6 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from lib.common_config import shutdown_bringup_interface -from mininet.topo import Topo pytestmark = [pytest.mark.sharpd] @@ -54,14 +53,8 @@ def open_json_file(filename): assert False, "Could not read file {}".format(filename) -class TemplateTopo(Topo): - def build(self, **_opts): - tgen = get_topogen(self) - tgen.add_router("r1") - - def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen({None: "r1"}, mod.__name__) tgen.start_topology() router_list = tgen.routers() for rname, router in tgen.routers().items(): 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 6cdb77b94b..3311fbe0b7 100755 --- a/tests/topotests/zebra_seg6local_route/test_zebra_seg6local_route.py +++ b/tests/topotests/zebra_seg6local_route/test_zebra_seg6local_route.py @@ -41,7 +41,6 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from lib.common_config import shutdown_bringup_interface -from mininet.topo import Topo pytestmark = [pytest.mark.sharpd] @@ -54,14 +53,8 @@ def open_json_file(filename): assert False, "Could not read file {}".format(filename) -class TemplateTopo(Topo): - def build(self, **_opts): - tgen = get_topogen(self) - tgen.add_router("r1") - - def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen({None: "r1"}, mod.__name__) tgen.start_topology() router_list = tgen.routers() for rname, router in tgen.routers().items(): From 351bc82cac3a0f693f81ce17e2c1033764a9501b Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Tue, 20 Jul 2021 14:06:19 +0000 Subject: [PATCH 06/25] tests: micronet: update defaults for results+logging Signed-off-by: Christian Hopps --- tests/topotests/pytest.ini | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/topotests/pytest.ini b/tests/topotests/pytest.ini index 885c249b31..33c5635eb2 100644 --- a/tests/topotests/pytest.ini +++ b/tests/topotests/pytest.ini @@ -1,7 +1,34 @@ # Skip pytests example directory [pytest] + +# We always turn this on inside conftest.py, default shown +# addopts = --junitxml=/topotests.xml + +log_level = DEBUG +log_format = %(asctime)s,%(msecs)03d %(levelname)s: %(name)s: %(message)s +log_date_format = %Y-%m-%d %H:%M:%S + +# If verbose is specifyied log_cli will be set to 1, it can also be specified +# here or on the CLI. +# log_cli = 1 +log_cli_level = INFO +log_cli_format = %(asctime)s,%(msecs)03d %(levelname)s: %(name)s: %(message)s +log_cli_date_format = %Y-%m-%d %H:%M:%S + +# By default this is palced in /exec.log +# log_file = /exec.log +log_file_level = DEBUG +log_file_format = %(asctime)s,%(msecs)03d %(levelname)s: %(name)s: %(message)s +log_file_date_format = %Y-%m-%d %H:%M:%S + +junit_logging = all +junit_log_passing_tests = true + norecursedirs = .git example_test example_topojson_test lib docker +# Directory to store test results and run logs in, default shown +# rundir = /tmp/topotests + # Markers # # Please consult the documentation and discuss with TSC members before applying @@ -54,4 +81,4 @@ markers = # memleak_path = /tmp/memleak_ # Output files will be named after the testname: # /tmp/memleak_test_ospf_topo1.txt -#memleak_path = +memleak_path = /tmp/memleak_ From 77f3acb45e81c7c454e343cb41dafc59316c729a Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Sun, 18 Jul 2021 15:59:40 +0000 Subject: [PATCH 07/25] doc: minor update based on mininet removal Signed-off-by: Christian Hopps --- doc/developer/building-frr-for-ubuntu1804.rst | 4 +- doc/developer/building-frr-for-ubuntu2004.rst | 4 +- doc/developer/topotests-jsontopo.rst | 31 +- doc/developer/topotests.rst | 475 +++++++++++------- 4 files changed, 313 insertions(+), 201 deletions(-) diff --git a/doc/developer/building-frr-for-ubuntu1804.rst b/doc/developer/building-frr-for-ubuntu1804.rst index 39a17fc01c..3e8c6c0d0b 100644 --- a/doc/developer/building-frr-for-ubuntu1804.rst +++ b/doc/developer/building-frr-for-ubuntu1804.rst @@ -12,8 +12,8 @@ Installing Dependencies sudo apt update sudo apt-get install \ git autoconf automake libtool make libreadline-dev texinfo \ - pkg-config libpam0g-dev libjson-c-dev bison flex python3-pytest \ - libc-ares-dev python3-dev python-ipaddress python3-sphinx \ + pkg-config libpam0g-dev libjson-c-dev bison flex \ + libc-ares-dev python3-dev python3-sphinx \ install-info build-essential libsnmp-dev perl libcap-dev \ libelf-dev diff --git a/doc/developer/building-frr-for-ubuntu2004.rst b/doc/developer/building-frr-for-ubuntu2004.rst index 92ddead4a5..28e7ca6518 100644 --- a/doc/developer/building-frr-for-ubuntu2004.rst +++ b/doc/developer/building-frr-for-ubuntu2004.rst @@ -12,8 +12,8 @@ Installing Dependencies sudo apt update sudo apt-get install \ git autoconf automake libtool make libreadline-dev texinfo \ - pkg-config libpam0g-dev libjson-c-dev bison flex python3-pytest \ - libc-ares-dev python3-dev python-ipaddress python3-sphinx \ + pkg-config libpam0g-dev libjson-c-dev bison flex \ + libc-ares-dev python3-dev python3-sphinx \ install-info build-essential libsnmp-dev perl \ libcap-dev python2 libelf-dev diff --git a/doc/developer/topotests-jsontopo.rst b/doc/developer/topotests-jsontopo.rst index 07f1f05114..866f27337f 100644 --- a/doc/developer/topotests-jsontopo.rst +++ b/doc/developer/topotests-jsontopo.rst @@ -373,23 +373,18 @@ Building topology and configurations Topology and initial configuration will be created in setup_module(). Following is the sample code:: - class TemplateTopo(Topo): - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + json_file = "{}/my_test_name.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + + # json topo object is now available in tgen.json_topo # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers start_topology(tgen) # Creating configuration from JSON - build_config_from_json(tgen, topo) + build_config_from_json(tgen) def teardown_module(mod): tgen = get_topogen() @@ -412,10 +407,12 @@ configurations are like, static routes, prefixlists and route maps etc configs, these configs can be used by any other protocols as it is. BGP config will be specific to BGP protocol testing. -* JSON file is passed to API build_config_from_json(), which looks for - configuration tags in JSON file. -* If tag is found in JSON, configuration is created as per input and written - to file frr_json.conf +* json file is passed to API Topogen() which saves the JSON object in + `self.json_topo` +* The Topogen object is then passed to API build_config_from_json(), which looks + for configuration tags in new JSON object. +* If tag is found in the JSON object, configuration is created as per input and + written to file frr_json.conf * Once JSON parsing is over, frr_json.conf is loaded onto respective router. Config loading is done using 'vtysh -f '. Initial config at this point is also saved frr_json_initial.conf. This file can be used to reset @@ -428,10 +425,10 @@ Writing Tests """"""""""""" Test topologies should always be bootstrapped from the -example-test/test_example.py, because it contains important boilerplate code -that can't be avoided, like: +example_test/test_template_json.py, because it contains important boilerplate +code that can't be avoided, like: -imports: os, sys, pytest, topotest/topogen and mininet topology class +imports: os, sys, pytest, and topotest/topogen. The global variable CWD (Current Working directory): which is most likely going to be used to reference the routers configuration file location diff --git a/doc/developer/topotests.rst b/doc/developer/topotests.rst index 18317cd33c..4a8f7bd27d 100644 --- a/doc/developer/topotests.rst +++ b/doc/developer/topotests.rst @@ -3,32 +3,37 @@ Topotests ========= -Topotests is a suite of topology tests for FRR built on top of Mininet. +Topotests is a suite of topology tests for FRR built on top of micronet. Installation and Setup ---------------------- -Only tested with Ubuntu 16.04 and Ubuntu 18.04 (which uses Mininet 2.2.x). +Topotests run under python3. Additionally, for ExaBGP (which is used in some of +the BGP tests) an older python2 version must be installed. + +Tested with Ubuntu 20.04 and Ubuntu 18.04 and Debian 11. Instructions are the same for all setups (i.e. ExaBGP is only used for BGP tests). -Installing Mininet Infrastructure -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Installing Topotest Requirements +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code:: shell - apt-get install mininet - apt-get install python-pip - apt-get install iproute - apt-get install iperf - pip install ipaddr - pip install "pytest<5" - pip install "scapy>=2.4.2" - pip install exabgp==3.4.17 (Newer 4.0 version of exabgp is not yet - supported) + apt-get install iproute2 + apt-get install net-tools + apt-get install python3-pip + python3 -m pip install wheel + python3 -m pip install 'pytest>=6.2.4' + python3 -m pip install 'pytest-xdist>=2.3.0' + python3 -m pip install 'scapy>=2.4.5' + python3 -m pip install xmltodict + # Use python2 pip to install older ExaBGP + python2 -m pip install 'exabgp<4.0.0' useradd -d /var/run/exabgp/ -s /bin/false exabgp + Enable Coredumps """""""""""""""" @@ -125,20 +130,125 @@ And create ``frr`` user and ``frrvty`` group as follows: Executing Tests --------------- -Execute all tests with output to console -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Execute all tests in distributed test mode +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code:: shell - py.test -s -v --tb=no + py.test -s -v -nauto --dist=loadfile The above command must be executed from inside the topotests directory. All test\_\* scripts in subdirectories are detected and executed (unless -disabled in ``pytest.ini`` file). +disabled in ``pytest.ini`` file). Pytest will execute up to N tests in parallel +where N is based on the number of cores on the host. + +Analyze Test Results (``analyze.py``) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +By default router and execution logs are saved in ``/tmp/topotests`` and an XML +results file is saved in ``/tmp/topotests.xml``. An analysis tool ``analyze.py`` +is provided to archive and analyze these results after the run completes. + +After the test run completes one should pick an archive directory to store the +results in and pass this value to ``analyze.py``. On first execution the results +are copied to that directory from ``/tmp``, and subsequent runs use that +directory for analyzing the results. Below is an example of this which also +shows the default behavior which is to display all failed and errored tests in +the run. + +.. code:: shell + + ~/frr/tests/topotests# ./analyze.py -Ar run-save + bgp_multiview_topo1/test_bgp_multiview_topo1.py::test_bgp_converge + ospf_basic_functionality/test_ospf_lan.py::test_ospf_lan_tc1_p0 + bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py::test_BGP_GR_10_p2 + bgp_multiview_topo1/test_bgp_multiview_topo1.py::test_bgp_routingTable + +Here we see that 4 tests have failed. We an dig deeper by displaying the +captured logs and errors. First let's redisplay the results enumerated by adding +the ``-E`` flag + +.. code:: shell + + ~/frr/tests/topotests# ./analyze.py -Ar run-save -E + 0 bgp_multiview_topo1/test_bgp_multiview_topo1.py::test_bgp_converge + 1 ospf_basic_functionality/test_ospf_lan.py::test_ospf_lan_tc1_p0 + 2 bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py::test_BGP_GR_10_p2 + 3 bgp_multiview_topo1/test_bgp_multiview_topo1.py::test_bgp_routingTable + +Now to look at the error message for a failed test we use ``-T N`` where N is +the number of the test we are interested in along with ``--errmsg`` option. + +.. code:: shell + + ~/frr/tests/topotests# ./analyze.py -Ar run-save -T0 --errmsg + bgp_multiview_topo1/test_bgp_multiview_topo1.py::test_bgp_converge: AssertionError: BGP did not converge: + + IPv4 Unicast Summary (VIEW 1): + BGP router identifier 172.30.1.1, local AS number 100 vrf-id -1 + BGP table version 1 + RIB entries 1, using 184 bytes of memory + Peers 3, using 2169 KiB of memory + + Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc + 172.16.1.1 4 65001 0 0 0 0 0 never Connect 0 N/A + 172.16.1.2 4 65002 0 0 0 0 0 never Connect 0 N/A + 172.16.1.5 4 65005 0 0 0 0 0 never Connect 0 N/A + + Total number of neighbors 3 + + assert False + +Now to look at the full text of the error for a failed test we use ``-T N`` +where N is the number of the test we are interested in along with ``--errtext`` +option. + +.. code:: shell + + ~/frr/tests/topotests# ./analyze.py -Ar run-save -T0 --errtext + bgp_multiview_topo1/test_bgp_multiview_topo1.py::test_bgp_converge: def test_bgp_converge(): + "Check for BGP converged on all peers and BGP views" + + global fatal_error + global net + [...] + else: + # Bail out with error if a router fails to converge + bgpStatus = net["r%s" % i].cmd('vtysh -c "show ip bgp view %s summary"' % view) + > assert False, "BGP did not converge:\n%s" % bgpStatus + E AssertionError: BGP did not converge: + E + E IPv4 Unicast Summary (VIEW 1): + E BGP router identifier 172.30.1.1, local AS number 100 vrf-id -1 + [...] + E Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc + E 172.16.1.1 4 65001 0 0 0 0 0 never Connect 0 N/A + E 172.16.1.2 4 65002 0 0 0 0 0 never Connect 0 N/A + [...] + +To look at the full capture for a test including the stdout and stderr which +includes full debug logs, just use the ``-T N`` option without the ``--errmsg`` +or ``--errtext`` options. + +.. code:: shell + + ~/frr/tests/topotests# ./analyze.py -Ar run-save -T0 + @classname: bgp_multiview_topo1.test_bgp_multiview_topo1 + @name: test_bgp_converge + @time: 141.401 + @message: AssertionError: BGP did not converge: + [...] + system-out: --------------------------------- Captured Log --------------------------------- + 2021-08-09 02:55:06,581 DEBUG: lib.micronet_compat.topo: Topo(unnamed): Creating + 2021-08-09 02:55:06,581 DEBUG: lib.micronet_compat.topo: Topo(unnamed): addHost r1 + [...] + 2021-08-09 02:57:16,932 DEBUG: topolog.r1: LinuxNamespace(r1): cmd_status("['/bin/bash', '-c', 'vtysh -c "show ip bgp view 1 summary" 2> /dev/null | grep ^[0-9] | grep -vP " 11\\s+(\\d+)"']", kwargs: {'encoding': 'utf-8', 'stdout': -1, 'stderr': -2, 'shell': False}) + 2021-08-09 02:57:22,290 DEBUG: topolog.r1: LinuxNamespace(r1): cmd_status("['/bin/bash', '-c', 'vtysh -c "show ip bgp view 1 summary" 2> /dev/null | grep ^[0-9] | grep -vP " 11\\s+(\\d+)"']", kwargs: {'encoding': 'utf-8', 'stdout': -1, 'stderr': -2, 'shell': False}) + 2021-08-09 02:57:27,636 DEBUG: topolog.r1: LinuxNamespace(r1): cmd_status("['/bin/bash', '-c', 'vtysh -c "show ip bgp view 1 summary"']", kwargs: {'encoding': 'utf-8', 'stdout': -1, 'stderr': -2, 'shell': False}) + --------------------------------- Captured Out --------------------------------- + system-err: --------------------------------- Captured Err --------------------------------- -``--tb=no`` disables the python traceback which might be irrelevant unless the -test script itself is debugged. Execute single test ^^^^^^^^^^^^^^^^^^^ @@ -161,9 +271,6 @@ Test will set exit code which can be used with ``git bisect``. For the simulated topology, see the description in the python file. -If you need to clear the mininet setup between tests (if it isn't cleanly -shutdown), then use the ``mn -c`` command to clean up the environment. - StdErr log from daemos after exit ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -235,18 +342,64 @@ and create ``frr`` user and ``frrvty`` group as shown above. Debugging Topotest Failures ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -For the below debugging options which launch programs, if the topotest is run -within screen_ or tmux_, ``gdb``, the shell or ``vtysh`` will be launched using -that windowing program, otherwise mininet's ``xterm`` functionality will be used -to launch the given program. +Install and run tests inside ``tmux`` or ``byobu`` for best results. -If you wish to force the use of ``xterm`` rather than ``tmux`` or ``screen``, or -wish to use ``gnome-terminal`` instead of ``xterm``, set the environment -variable ``FRR_TOPO_TERMINAL`` to either ``xterm`` or ``gnome-terminal``. +``XTerm`` is also fully supported. GNU ``screen`` can be used in most +situations; however, it does not work as well with launching ``vtysh`` or shell +on error. + +For the below debugging options which launch programs or CLIs, topotest should +be run within ``tmux`` (or ``screen``)_, as ``gdb``, the shell or ``vtysh`` will +be launched using that windowing program, otherwise ``xterm`` will be attempted +to launch the given programs. .. _screen: https://www.gnu.org/software/screen/ .. _tmux: https://github.com/tmux/tmux/wiki +Spawning Debugging CLI, ``vtysh`` or Shells on Routers on Test Failure +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +One can have a debugging CLI invoked on test failures by specifying the +``--cli-on-error`` CLI option as shown in the example below. + +.. code:: shell + + pytest --cli-on-error all-protocol-startup + +The debugging CLI can run shell or vtysh commands on any combination of routers +It can also open shells or vtysh in their own windows for any combination of +routers. This is usually the most useful option when debugging failures. Here is +the help command from within a CLI launched on error: + +.. code:: shell + + test_bgp_multiview_topo1/test_bgp_routingTable> help + + Commands: + help :: this help + sh [hosts] :: execute on + term [hosts] :: open shell terminals for hosts + vtysh [hosts] :: open vtysh terminals for hosts + [hosts] :: execute vtysh-command on hosts + + test_bgp_multiview_topo1/test_bgp_routingTable> r1 show int br + ------ Host: r1 ------ + Interface Status VRF Addresses + --------- ------ --- --------- + erspan0 down default + gre0 down default + gretap0 down default + lo up default + r1-eth0 up default 172.16.1.254/24 + r1-stub up default 172.20.0.1/28 + + ---------------------- + test_bgp_multiview_topo1/test_bgp_routingTable> + +Additionally, one can have ``vtysh`` or a shell launched on all routers when a +test fails. To launch the given process on each router after a test failure +specify one of ``--shell-on-error`` or ``--vtysh-on-error``. + Spawning ``vtysh`` or Shells on Routers """"""""""""""""""""""""""""""""""""""" @@ -255,8 +408,8 @@ a test. This is enabled by specifying 1 of 2 CLI arguments ``--shell`` or ``--vtysh``. Both of these options can be set to a single router value, multiple comma-seperated values, or ``all``. -When either of these options are specified topotest will pause after each test -to allow for inspection of the router state. +When either of these options are specified topotest will pause after setup and +each test to allow for inspection of the router state. Here's an example of launching ``vtysh`` on routers ``rt1`` and ``rt2``. @@ -264,29 +417,6 @@ Here's an example of launching ``vtysh`` on routers ``rt1`` and ``rt2``. pytest --vtysh=rt1,rt2 all-protocol-startup -Spawning Mininet CLI, ``vtysh`` or Shells on Routers on Test Failure -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -Similar to the previous section one can have ``vtysh`` or a shell launched on -routers, but in this case only when a test fails. To launch the given process on -each router after a test failure specify one of ``--shell-on-error`` or -``--vtysh-on-error``. - - -Here's an example of having ``vtysh`` launched on test failure. - -.. code:: shell - - pytest --vtysh-on-error all-protocol-startup - - -Additionally, one can have the mininet CLI invoked on test failures by -specifying the ``--mininet-on-error`` CLI option as shown in the example below. - -.. code:: shell - - pytest --mininet-on-error all-protocol-startup - Debugging with GDB """""""""""""""""" @@ -424,7 +554,7 @@ top level directory of topotest: $ # Change to the top level directory of topotests. $ cd path/to/topotests - $ # Tests must be run as root, since Mininet requires it. + $ # Tests must be run as root, since micronet requires it. $ sudo pytest In order to run a specific test, you can use the following command: @@ -493,15 +623,16 @@ Some things to keep in mind: - Avoid including unstable data in your test: don't rely on link-local addresses or ifindex values, for example, because these can change from run to run. -- Using sleep is almost never appropriate to wait for some convergence - event as the sole item done. As an example: if the test resets the peers - in BGP, the test should look for the peers reconverging instead of just - sleeping an arbitrary amount of time and continuing on. It is ok to - use sleep in a tight loop with appropriate show commands to ensure that - the protocol reaches the desired state. This should be bounded by - appropriate timeouts for the protocol in question though. See - verify_bgp_convergence as a good example of this. If you are having - troubles figuring out what to look for, please do not be afraid to ask. +- Using sleep is almost never appropriate. As an example: if the test resets the + peers in BGP, the test should look for the peers re-converging instead of just + sleeping an arbitrary amount of time and continuing on. See + `verify_bgp_convergence` as a good example of this. In particular look at it's + use of the `@retry` decorator. If you are having troubles figuring out what to + look for, please do not be afraid to ask. +- Don't duplicate effort. There exists many protocol utility functions that can + be found in their eponymous module under `tests/topotests/lib/` (e.g., + `ospf.py`) + Topotest File Hierarchy @@ -661,25 +792,32 @@ Here is the template topology described in the previous section in python code: .. code:: py - class TemplateTopo(Topo): - "Test topology builder" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + topodef = { + "s1": "r1" + "s2": ("r1", "r2") + } - # Create 2 routers - for routern in range(1, 3): - tgen.add_router('r{}'.format(routern)) +If more specialized topology definitions, or router initialization arguments are +required a build function can be used instead of a dictionary: - # Create a switch with just one router connected to it to simulate a - # empty network. - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) +.. code:: py - # Create a connection between r1 and r2 - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r2']) + def build_topo(tgen): + "Build function" + + # Create 2 routers + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) + + # Create a switch with just one router connected to it to simulate a + # empty network. + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + + # Create a connection between r1 and r2 + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - Run the topology @@ -701,8 +839,8 @@ Parameters explanation: .. option:: -s - Actives input/output capture. This is required by mininet in order to show - the interactive shell. + Actives input/output capture. If this is not specified a new window will be + opened for the interactive CLI, otherwise it will be activated inline. .. option:: --topology-only @@ -713,110 +851,84 @@ output: .. code:: shell - === test session starts === - platform linux2 -- Python 2.7.12, pytest-3.1.2, py-1.4.34, pluggy-0.4.0 - rootdir: /media/sf_src/topotests, inifile: pytest.ini - collected 3 items + frr/tests/topotests# sudo pytest -s --topology-only ospf_topo1/test_ospf_topo1.py + ============================= test session starts ============================== + platform linux -- Python 3.9.2, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 + rootdir: /home/chopps/w/frr/tests/topotests, configfile: pytest.ini + plugins: forked-1.3.0, xdist-2.3.0 + collected 11 items - ospf-topo1/test_ospf_topo1.py *** Starting controller + [...] + unet> - *** Starting 6 switches - switch1 switch2 switch3 switch4 switch5 switch6 ... - r2: frr zebra started - r2: frr ospfd started - r3: frr zebra started - r3: frr ospfd started - r1: frr zebra started - r1: frr ospfd started - r4: frr zebra started - r4: frr ospfd started - *** Starting CLI: - mininet> - -The last line shows us that we are now using the Mininet CLI (Command Line +The last line shows us that we are now using the CLI (Command Line Interface), from here you can call your router ``vtysh`` or even bash. +Here's the help text: + +.. code:: shell + unet> help + + Commands: + help :: this help + sh [hosts] :: execute on + term [hosts] :: open shell terminals for hosts + vtysh [hosts] :: open vtysh terminals for hosts + [hosts] :: execute vtysh-command on hosts + +.. code:: shell + Here are some commands example: .. code:: shell - mininet> r1 ping 10.0.3.1 - PING 10.0.3.1 (10.0.3.1) 56(84) bytes of data. - 64 bytes from 10.0.3.1: icmp_seq=1 ttl=64 time=0.576 ms - 64 bytes from 10.0.3.1: icmp_seq=2 ttl=64 time=0.083 ms - 64 bytes from 10.0.3.1: icmp_seq=3 ttl=64 time=0.088 ms - ^C - --- 10.0.3.1 ping statistics --- - 3 packets transmitted, 3 received, 0% packet loss, time 1998ms - rtt min/avg/max/mdev = 0.083/0.249/0.576/0.231 ms + unet> sh r1 ping 10.0.3.1 + PING 10.0.3.1 (10.0.3.1) 56(84) bytes of data. + 64 bytes from 10.0.3.1: icmp_seq=1 ttl=64 time=0.576 ms + 64 bytes from 10.0.3.1: icmp_seq=2 ttl=64 time=0.083 ms + 64 bytes from 10.0.3.1: icmp_seq=3 ttl=64 time=0.088 ms + ^C + --- 10.0.3.1 ping statistics --- + 3 packets transmitted, 3 received, 0% packet loss, time 1998ms + rtt min/avg/max/mdev = 0.083/0.249/0.576/0.231 ms + unet> r1 show run + Building configuration... + Current configuration: + ! + frr version 8.1-dev-my-manual-build + frr defaults traditional + hostname r1 + log file /tmp/topotests/ospf_topo1.test_ospf_topo1/r1/zebra.log + [...] + end - mininet> r1 ping 10.0.3.3 - PING 10.0.3.3 (10.0.3.3) 56(84) bytes of data. - 64 bytes from 10.0.3.3: icmp_seq=1 ttl=64 time=2.87 ms - 64 bytes from 10.0.3.3: icmp_seq=2 ttl=64 time=0.080 ms - 64 bytes from 10.0.3.3: icmp_seq=3 ttl=64 time=0.091 ms - ^C - --- 10.0.3.3 ping statistics --- - 3 packets transmitted, 3 received, 0% packet loss, time 2003ms - rtt min/avg/max/mdev = 0.080/1.014/2.872/1.313 ms - - - - mininet> r3 vtysh - - Hello, this is FRRouting (version 3.1-devrzalamena-build). - Copyright 1996-2005 Kunihiro Ishiguro, et al. - - frr-1# show running-config - Building configuration... - - Current configuration: - ! - frr version 3.1-devrzalamena-build - frr defaults traditional - hostname r3 - no service integrated-vtysh-config - ! - log file zebra.log - ! - log file ospfd.log - ! - interface r3-eth0 - ip address 10.0.3.1/24 - ! - interface r3-eth1 - ip address 10.0.10.1/24 - ! - interface r3-eth2 - ip address 172.16.0.2/24 - ! - router ospf - ospf router-id 10.0.255.3 - redistribute kernel - redistribute connected - redistribute static - network 10.0.3.0/24 area 0 - network 10.0.10.0/24 area 0 - network 172.16.0.0/24 area 1 - ! - line vty - ! - end - frr-1# + unet> show daemons + ------ Host: r1 ------ + zebra ospfd ospf6d staticd + ------- End: r1 ------ + ------ Host: r2 ------ + zebra ospfd ospf6d staticd + ------- End: r2 ------ + ------ Host: r3 ------ + zebra ospfd ospf6d staticd + ------- End: r3 ------ + ------ Host: r4 ------ + zebra ospfd ospf6d staticd + ------- End: r4 ------ After you successfully configured your topology, you can obtain the configuration files (per-daemon) using the following commands: .. code:: shell - mininet> r3 vtysh -d ospfd + unet> sh r3 vtysh -d ospfd Hello, this is FRRouting (version 3.1-devrzalamena-build). Copyright 1996-2005 Kunihiro Ishiguro, et al. - frr-1# show running-config + r1# show running-config Building configuration... Current configuration: @@ -839,7 +951,7 @@ configuration files (per-daemon) using the following commands: line vty ! end - frr-1# + r1# Writing Tests """"""""""""" @@ -848,15 +960,12 @@ Test topologies should always be bootstrapped from :file:`tests/topotests/example-test/test_template.py` because it contains important boilerplate code that can't be avoided, like: -- imports: os, sys, pytest, topotest/topogen and mininet topology class -- The global variable CWD (Current Working directory): which is most likely - going to be used to reference the routers configuration file location - Example: .. code:: py # For all registered routers, load the zebra configuration file + CWD = os.path.dirname(os.path.realpath(__file__)) for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, @@ -865,21 +974,28 @@ Example: # os.path.join() joins the CWD string with arguments adding the necessary # slashes ('/'). Arguments must not begin with '/'. -- The topology class that inherits from Mininet Topo class: +- The topology definition or build function .. code:: py - class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) + topodef = { + "s1": ("r1", "r2"), + "s2": ("r2", "r3") + } + + def build_topo(tgen): # topology build code + ... - pytest ``setup_module()`` and ``teardown_module()`` to start the topology .. code:: py - def setup_module(_m): - tgen = Topogen(TemplateTopo) + def setup_module(module): + tgen = Topogen(topodef, module.__name__) + # or + tgen = Topogen(build_topo, module.__name__) + tgen.start_topology('debug') def teardown_module(_m): @@ -1042,11 +1158,10 @@ Example of pdb usage: (Pdb) router1 = tgen.gears[router] (Pdb) router1.vtysh_cmd('show ip ospf route') '============ OSPF network routing table ============\r\nN 10.0.1.0/24 [10] area: 0.0.0.0\r\n directly attached to r1-eth0\r\nN 10.0.2.0/24 [20] area: 0.0.0.0\r\n via 10.0.3.3, r1-eth1\r\nN 10.0.3.0/24 [10] area: 0.0.0.0\r\n directly attached to r1-eth1\r\nN 10.0.10.0/24 [20] area: 0.0.0.0\r\n via 10.0.3.1, r1-eth1\r\nN IA 172.16.0.0/24 [20] area: 0.0.0.0\r\n via 10.0.3.1, r1-eth1\r\nN IA 172.16.1.0/24 [30] area: 0.0.0.0\r\n via 10.0.3.1, r1-eth1\r\n\r\n============ OSPF router routing table =============\r\nR 10.0.255.2 [10] area: 0.0.0.0, ASBR\r\n via 10.0.3.3, r1-eth1\r\nR 10.0.255.3 [10] area: 0.0.0.0, ABR, ASBR\r\n via 10.0.3.1, r1-eth1\r\nR 10.0.255.4 IA [20] area: 0.0.0.0, ASBR\r\n via 10.0.3.1, r1-eth1\r\n\r\n============ OSPF external routing table ===========\r\n\r\n\r\n' - (Pdb) tgen.mininet_cli() - *** Starting CLI: - mininet> + (Pdb) tgen.cli() + unet> -To enable more debug messages in other Topogen subsystems (like Mininet), more +To enable more debug messages in other Topogen subsystems, more logging messages can be displayed by modifying the test configuration file ``pytest.ini``: From a3cecfb608d0ca7b6f94828f7adb9d03a77250df Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Fri, 6 Aug 2021 04:04:58 -0400 Subject: [PATCH 08/25] docker: update with micronet changes Signed-off-by: Christian Hopps --- docker/ubuntu18-ci/Dockerfile | 16 +++++++++------- docker/ubuntu20-ci/Dockerfile | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/docker/ubuntu18-ci/Dockerfile b/docker/ubuntu18-ci/Dockerfile index 766f06dfc2..07a5a2f7e0 100644 --- a/docker/ubuntu18-ci/Dockerfile +++ b/docker/ubuntu18-ci/Dockerfile @@ -6,16 +6,18 @@ ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn RUN apt update && \ apt-get install -y \ git autoconf automake libtool make libreadline-dev texinfo \ - pkg-config libpam0g-dev libjson-c-dev bison flex python3-pytest \ - libc-ares-dev python3-dev python-ipaddress python3-sphinx \ + pkg-config libpam0g-dev libjson-c-dev bison flex python3-pip \ + libc-ares-dev python3-dev python3-sphinx \ install-info build-essential libsnmp-dev perl libcap-dev \ libelf-dev \ sudo gdb iputils-ping time \ - mininet python-pip iproute2 iperf && \ - pip install ipaddr && \ - pip install "pytest<5" && \ - pip install "scapy>=2.4.2" && \ - pip install exabgp==3.4.17 + python-pip net-tools iproute2 && \ + python3 -m pip install wheel && \ + python3 -m pip install pytest && \ + python3 -m pip install pytest-xdist && \ + python3 -m pip install "scapy>=2.4.2" && \ + python3 -m pip install xmltodict && \ + python2 -m pip install 'exabgp<4.0.0' RUN groupadd -r -g 92 frr && \ groupadd -r -g 85 frrvty && \ diff --git a/docker/ubuntu20-ci/Dockerfile b/docker/ubuntu20-ci/Dockerfile index b5df98f23e..032db8b8ed 100644 --- a/docker/ubuntu20-ci/Dockerfile +++ b/docker/ubuntu20-ci/Dockerfile @@ -6,21 +6,23 @@ ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn RUN apt update && \ apt-get install -y \ git autoconf automake libtool make libreadline-dev texinfo \ - pkg-config libpam0g-dev libjson-c-dev bison flex python3-pytest \ - libc-ares-dev python3-dev python-ipaddress python3-sphinx \ + pkg-config libpam0g-dev libjson-c-dev bison flex python3-pip \ + libc-ares-dev python3-dev python3-sphinx \ install-info build-essential libsnmp-dev perl \ libcap-dev python2 libelf-dev \ sudo gdb curl iputils-ping time \ libgrpc++-dev libgrpc-dev protobuf-compiler-grpc \ lua5.3 liblua5.3-dev \ - mininet iproute2 iperf && \ + net-tools iproute2 && \ curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output /tmp/get-pip.py && \ python2 /tmp/get-pip.py && \ rm -f /tmp/get-pip.py && \ - pip2 install ipaddr && \ - pip2 install "pytest<5" && \ - pip2 install "scapy>=2.4.2" && \ - pip2 install exabgp==3.4.17 + python3 -m pip install wheel && \ + python3 -m pip install pytest && \ + python3 -m pip install pytest-xdist && \ + python3 -m pip install "scapy>=2.4.2" && \ + python3 -m pip install xmltodict && \ + python2 -m pip install 'exabgp<4.0.0' RUN groupadd -r -g 92 frr && \ groupadd -r -g 85 frrvty && \ From c8e5983d8efa12eea0e91512802a84d46dd899e9 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Wed, 21 Jul 2021 13:33:50 +0000 Subject: [PATCH 09/25] tests: fix pylint infra errors Signed-off-by: Christian Hopps --- tests/topotests/lib/bgp.py | 4 +--- tests/topotests/lib/bgprib.py | 2 +- tests/topotests/lib/common_config.py | 3 +-- tests/topotests/lib/ospf.py | 6 ++---- tests/topotests/lib/topojson.py | 5 ++--- tests/topotests/lib/topotest.py | 6 ++++++ 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/topotests/lib/bgp.py b/tests/topotests/lib/bgp.py index 051b2eb978..753b24e529 100644 --- a/tests/topotests/lib/bgp.py +++ b/tests/topotests/lib/bgp.py @@ -25,8 +25,6 @@ import traceback from copy import deepcopy from time import sleep -import ipaddr - # Import common_config to use commomnly used APIs from lib.common_config import ( create_common_configurations, @@ -2268,7 +2266,7 @@ def verify_bgp_attributes( """ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): if router != dut: continue diff --git a/tests/topotests/lib/bgprib.py b/tests/topotests/lib/bgprib.py index abab9600a1..a216e3588e 100644 --- a/tests/topotests/lib/bgprib.py +++ b/tests/topotests/lib/bgprib.py @@ -34,7 +34,7 @@ # ribRequireUnicastRoutes('r1','ipv4','','Customer routes in default',want_unicast_routes) # -from lutil import luCommand, luResult, LUtil +from lib.lutil import luCommand, luResult, LUtil import json import re diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index df0fd83631..99a3a4a87d 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -765,8 +765,7 @@ def get_frr_ipv6_linklocal(tgen, router, intf=None, vrf=None): ll_per_if_count = 0 # Interface ip - m1 = re_search('inet6 (fe80[:a-fA-F0-9]+[\/0-9]+)', - line) + m1 = re_search('inet6 (fe80[:a-fA-F0-9]+/[0-9]+)', line) if m1: local = m1.group(1) ll_per_if_count += 1 diff --git a/tests/topotests/lib/ospf.py b/tests/topotests/lib/ospf.py index ba926bf30e..d6f1b0e004 100644 --- a/tests/topotests/lib/ospf.py +++ b/tests/topotests/lib/ospf.py @@ -25,8 +25,6 @@ from copy import deepcopy from ipaddress import IPv6Address from time import sleep -import ipaddr - # Import common_config to use commomnly used APIs from lib.common_config import ( create_common_configurations, @@ -1147,7 +1145,7 @@ def verify_ospf_rib( nh_found = False for st_rt in ip_list: - st_rt = str(ipaddr.IPNetwork(frr_unicode(st_rt))) + st_rt = str(ipaddress.ip_network(frr_unicode(st_rt))) _addr_type = validate_ip_address(st_rt) if _addr_type != "ipv4": @@ -1720,7 +1718,7 @@ def verify_ospf6_rib(tgen, dut, input_dict, next_hop=None, additional_nexthops_in_required_nhs = [] found_hops = [] for routerInput in input_dict.keys(): - for router, rnode in router_list.iteritems(): + for router, rnode in router_list.items(): if router != dut: continue diff --git a/tests/topotests/lib/topojson.py b/tests/topotests/lib/topojson.py index 710a7b0cc6..1b00f83ab2 100644 --- a/tests/topotests/lib/topojson.py +++ b/tests/topotests/lib/topojson.py @@ -25,7 +25,6 @@ from collections import OrderedDict from copy import deepcopy from re import search as re_search -import ipaddr import pytest from lib.bgp import create_router_bgp @@ -94,7 +93,7 @@ def build_topo_from_json(tgen, topo): # Physical Interfaces if "links" in topo["routers"][curRouter]: for destRouterLink, data in sorted( - topo["routers"][curRouter]["links"].iteritems() + topo["routers"][curRouter]["links"].items() ): currRouter_lo_json = topo["routers"][curRouter]["links"][destRouterLink] # Loopback interfaces @@ -275,7 +274,7 @@ def build_topo_from_json(tgen, topo): ] = "{}/{}".format( ipv6Next, topo["link_ip_start"]["v6mask"] ) - ipv6Next = ipaddr.IPv6Address(int(ipv6Next) + ipv6Step) + ipv6Next = ipaddress.IPv6Address(int(ipv6Next) + ipv6Step) logger.debug( "Generated link data for router: %s\n%s", diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index 611230064f..76a9430fa5 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -44,8 +44,10 @@ from lib.topolog import logger if sys.version_info[0] > 2: import configparser + from collections.abc import Mapping else: import ConfigParser as configparser + from collections import Mapping from lib import micronet from lib.micronet_compat import Node @@ -2071,3 +2073,7 @@ def frr_unicode(s): return s else: return unicode(s) # pylint: disable=E0602 + + +def is_mapping(o): + return isinstance(o, Mapping) From d7d21c3a190f7754afe4d5b969501756a3739e48 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Thu, 29 Jul 2021 11:07:01 +0000 Subject: [PATCH 10/25] tests: fix pylint test errors Signed-off-by: Christian Hopps --- .../test_bgp_basic_functionality.py | 2 + .../test_bgp_communities.py | 54 +++++--- .../test_bgp_communities_topo2.py | 18 +-- .../bgp_ecmp_topo1/test_bgp_ecmp_topo1.py | 1 + .../scripts/notification_check.py | 2 +- .../scripts/scale_down.py | 2 +- .../bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py | 2 +- .../test_bgp_l3vpn_to_bgp_vrf.py | 30 ----- .../scripts/adjacencies.py | 2 + .../test_bgp_aggregation.py | 117 +++++++++++------- .../bgp_route_map/test_route_map_topo2.py | 80 ++++++++---- .../test_bgp_vrf_dynamic_route_leak_topo1.py | 3 +- .../test_bgp_vrf_dynamic_route_leak_topo2.py | 2 +- .../test_evpn_type5_chaos_topo1.py | 29 +++-- .../test_evpn_type5_topo1.py | 48 +++---- .../isis_lfa_topo1/test_isis_lfa_topo1.py | 2 +- .../isis_rlfa_topo1/test_isis_rlfa_topo1.py | 2 +- tests/topotests/isis_snmp/test_isis_snmp.py | 2 +- .../isis_sr_te_topo1/test_isis_sr_te_topo1.py | 2 +- tests/topotests/isis_topo1/test_isis_topo1.py | 3 +- .../isis_topo1_vrf/test_isis_topo1_vrf.py | 3 +- tests/topotests/ldp_topo1/test_ldp_topo1.py | 2 +- .../test_mcast_pim_bsmp_01.py | 13 +- .../test_multicast_pim_sm_topo1.py | 41 +++--- .../test_multicast_pim_sm_topo4.py | 30 +++-- .../test_multicast_pim_static_rp.py | 6 +- tests/topotests/nhrp_topo/test_nhrp_topo.py | 8 +- .../ospf6_topo1_vrf/test_ospf6_topo1_vrf.py | 4 +- .../test_ospf_p2mp.py | 4 +- tests/topotests/pim_acl/test_pim_acl.py | 3 +- tests/topotests/pim_igmp_vrf/test_pim_vrf.py | 3 + 31 files changed, 300 insertions(+), 220 deletions(-) diff --git a/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py b/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py index e3f07166f9..b9ad57f8bc 100644 --- a/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py +++ b/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py @@ -40,6 +40,8 @@ Test steps - Verify routes not installed in zebra when /32 routes received with loopback BGP session subnet """ +# XXX clean up in later commit to avoid conflict on rebase +# pylint: disable=C0413 import os import sys diff --git a/tests/topotests/bgp_communities_topo1/test_bgp_communities.py b/tests/topotests/bgp_communities_topo1/test_bgp_communities.py index f52f539afb..df579bc012 100644 --- a/tests/topotests/bgp_communities_topo1/test_bgp_communities.py +++ b/tests/topotests/bgp_communities_topo1/test_bgp_communities.py @@ -340,14 +340,18 @@ def test_bgp_no_advertise_community_p0(request): ) result = verify_bgp_rib(tgen, addr_type, dut, input_dict, expected=False) - assert result is not True, "Testcase {} : Failed \n " - " Routes still present in R3 router. Error: {}".format(tc_name, result) + assert result is not True, "Testcase {} : Failed \n ".format( + tc_name + ) + " Routes still present in R3 router. Error: {}".format(result) result = verify_rib( tgen, addr_type, dut, input_dict, protocol=protocol, expected=False ) - assert result is not True, "Testcase {} : Failed \n " - " Routes still present in R3 router. Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \n Routes still present in R3 router. Error: {}".format( + tc_name, result + ) step("Remove and Add no advertise community") # Configure neighbor for route map @@ -392,12 +396,18 @@ def test_bgp_no_advertise_community_p0(request): ) result = verify_bgp_rib(tgen, addr_type, dut, input_dict) - assert result is True, "Testcase {} : Failed \n " - " Routes still present in R3 router. Error: {}".format(tc_name, result) + assert ( + result is True + ), "Testcase {} : Failed \n Routes still present in R3 router. Error: {}".format( + tc_name, result + ) result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, "Testcase {} : Failed \n " - " Routes still present in R3 router. Error: {}".format(tc_name, result) + assert ( + result is True + ), "Testcase {} : Failed \n Routes still present in R3 router. Error: {}".format( + tc_name, result + ) step("Repeat above steps when IBGP nbr configured between R1, R2 & R2, R3") topo1 = deepcopy(topo) @@ -579,12 +589,18 @@ def test_bgp_no_advertise_community_p0(request): ) result = verify_bgp_rib(tgen, addr_type, dut, input_dict) - assert result is True, "Testcase {} : Failed \n " - " Routes still present in R3 router. Error: {}".format(tc_name, result) + assert ( + result is True + ), "Testcase {} : Failed \n Routes still present in R3 router. Error: {}".format( + tc_name, result + ) result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, "Testcase {} : Failed \n " - " Routes still present in R3 router. Error: {}".format(tc_name, result) + assert ( + result is True + ), "Testcase {} : Failed \n Routes still present in R3 router. Error: {}".format( + tc_name, result + ) step("Remove and Add no advertise community") # Configure neighbor for route map @@ -629,12 +645,18 @@ def test_bgp_no_advertise_community_p0(request): ) result = verify_bgp_rib(tgen, addr_type, dut, input_dict) - assert result is True, "Testcase {} : Failed \n " - " Routes still present in R3 router. Error: {}".format(tc_name, result) + assert ( + result is True + ), "Testcase {} : Failed \n Routes still present in R3 router. Error: {}".format( + tc_name, result + ) result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, "Testcase {} : Failed \n " - " Routes still present in R3 router. Error: {}".format(tc_name, result) + assert ( + result is True + ), "Testcase {} : Failed \n Routes still present in R3 router. Error: {}".format( + tc_name, result + ) write_test_footer(tc_name) diff --git a/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py b/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py index 24dc6bb487..d18e65bd66 100644 --- a/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py +++ b/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py @@ -292,7 +292,7 @@ def test_bgp_no_export_local_as_and_internet_communities_p0(request): input_dict_4, next_hop=topo["routers"]["r1"]["links"]["r2"][addr_type].split("/")[0], ) - assert result is True, "Testcase : Failed \n Error: {}".format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) @@ -311,7 +311,7 @@ def test_bgp_no_export_local_as_and_internet_communities_p0(request): 0 ], ) - assert result is True, "Testcase : Failed \n Error: {}".format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) else: @@ -330,7 +330,7 @@ def test_bgp_no_export_local_as_and_internet_communities_p0(request): ], expected=False, ) - assert result is not True, "Testcase : Failed \n Error: {}".format( + assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) @@ -358,7 +358,9 @@ def test_bgp_no_export_local_as_and_internet_communities_p0(request): } } result = create_router_bgp(tgen, topo, input_dict_2) - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) step("Configure redistribute static") input_dict_2 = { @@ -376,7 +378,9 @@ def test_bgp_no_export_local_as_and_internet_communities_p0(request): } } result = create_router_bgp(tgen, topo, input_dict_2) - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) step( "Verify that these prefixes, originated on R1, are now" @@ -402,7 +406,7 @@ def test_bgp_no_export_local_as_and_internet_communities_p0(request): input_dict_4, next_hop=topo["routers"]["r1"]["links"]["r2"][addr_type].split("/")[0], ) - assert result is True, "Testcase : Failed \n Error: {}".format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) @@ -413,7 +417,7 @@ def test_bgp_no_export_local_as_and_internet_communities_p0(request): input_dict_4, next_hop=topo["routers"]["r1"]["links"]["r3"][addr_type].split("/")[0], ) - assert result is True, "Testcase : Failed \n Error: {}".format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) diff --git a/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py b/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py index dea2ffbd8f..841a766197 100644 --- a/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py +++ b/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py @@ -119,6 +119,7 @@ def setup_module(module): def teardown_module(module): + del module tgen = get_topogen() tgen.stop_topology() diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/notification_check.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/notification_check.py index dd2e24722f..73cd08fbe3 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/notification_check.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/notification_check.py @@ -1,4 +1,4 @@ -from lib.lutil import luCommand +from lib.lutil import luCommand, luLast rtrs = ["ce1", "ce2", "ce3", "r1", "r2", "r3", "r4"] for rtr in rtrs: diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py index 6ce81baf11..36be926227 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py @@ -1,4 +1,4 @@ -from lib.lutil import luCommand +from lib.lutil import luCommand, luLast ret = luCommand( "ce1", diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py index 04ca03973d..9f100b7c30 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py @@ -1,4 +1,4 @@ -from lib.lutil import luCommand +from lib.lutil import luCommand, luLast num = 50000 b = int(num / (256 * 256)) diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/test_bgp_l3vpn_to_bgp_vrf.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/test_bgp_l3vpn_to_bgp_vrf.py index 8bb700235c..3844b5ef81 100755 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/test_bgp_l3vpn_to_bgp_vrf.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/test_bgp_l3vpn_to_bgp_vrf.py @@ -93,16 +93,6 @@ def test_check_linux_mpls(): ltemplateTest("scripts/check_linux_mpls.py", False, CliOnFail, CheckFunc) -def test_notification_check(): - CliOnFail = None - # For debugging, uncomment the next line - # CliOnFail = 'tgen.mininet_cli' - CheckFunc = "ltemplateVersionCheck('4.1', iproute2='4.9')" - # uncomment next line to start cli *before* script is run - # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' - ltemplateTest("scripts/notification_check.py", False, CliOnFail, CheckFunc) - - def test_check_scale_up(): CliOnFail = None # For debugging, uncomment the next line @@ -113,16 +103,6 @@ def test_check_scale_up(): ltemplateTest("scripts/scale_up.py", False, CliOnFail, CheckFunc) -def test_notification_check(): - CliOnFail = None - # For debugging, uncomment the next line - # CliOnFail = 'tgen.mininet_cli' - CheckFunc = "ltemplateVersionCheck('4.1', iproute2='4.9')" - # uncomment next line to start cli *before* script is run - # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' - ltemplateTest("scripts/notification_check.py", False, CliOnFail, CheckFunc) - - def test_check_scale_down(): CliOnFail = None # For debugging, uncomment the next line @@ -133,16 +113,6 @@ def test_check_scale_down(): ltemplateTest("scripts/scale_down.py", False, CliOnFail, CheckFunc) -def test_notification_check(): - CliOnFail = None - # For debugging, uncomment the next line - # CliOnFail = 'tgen.mininet_cli' - CheckFunc = "ltemplateVersionCheck('4.1', iproute2='4.9')" - # uncomment next line to start cli *before* script is run - # CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')' - ltemplateTest("scripts/notification_check.py", False, CliOnFail, CheckFunc) - - def SKIP_test_cleanup_all(): CliOnFail = None # For debugging, uncomment the next line diff --git a/tests/topotests/bgp_rfapi_basic_sanity/scripts/adjacencies.py b/tests/topotests/bgp_rfapi_basic_sanity/scripts/adjacencies.py index 6ad3e735ee..9878cdc877 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/scripts/adjacencies.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/scripts/adjacencies.py @@ -1,3 +1,5 @@ +from lib.lutil import luCommand + luCommand( "r1", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60 ) diff --git a/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py b/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py index 04a66d0e25..8297085ffe 100644 --- a/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py +++ b/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py @@ -242,7 +242,9 @@ def test_route_summarisation_with_summary_only_p1(request): step("Configuring {} static routes on router R1 ".format(addr_type)) result = create_static_routes(tgen, input_static) - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) step( "Configuring redistribute static for {} address-family on router R1 ".format( @@ -273,7 +275,9 @@ def test_route_summarisation_with_summary_only_p1(request): } result = verify_rib(tgen, addr_type, "r3", input_static) - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) step("Advertise some prefixes using network command") step( @@ -358,7 +362,9 @@ def test_route_summarisation_with_summary_only_p1(request): } result = verify_rib(tgen, addr_type, "r3", input_advertise) - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) step("Configure aggregate-address to summarise all the advertised routes.") @@ -413,22 +419,28 @@ def test_route_summarisation_with_summary_only_p1(request): } result = verify_rib(tgen, addr_type, "r3", input_static_agg, protocol="bgp") - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) result = verify_rib( tgen, addr_type, "r3", input_static, protocol="bgp", expected=False ) assert ( result is not True - ), "Testcase : Failed \n " "Routes are still present \n Error: {}".format( + ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format( tc_name, result ) result = verify_rib(tgen, addr_type, "r1", input_static_agg, protocol="bgp") - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) result = verify_rib(tgen, addr_type, "r1", input_static) - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) for action, value in zip(["removed", "add"], [True, False]): @@ -454,7 +466,7 @@ def test_route_summarisation_with_summary_only_p1(request): } result = create_static_routes(tgen, input_static) - assert result is True, "Testcase : Failed \n Error: {}".format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) @@ -481,18 +493,19 @@ def test_route_summarisation_with_summary_only_p1(request): result = verify_rib( tgen, addr_type, "r1", input_static_1, expected=False ) - assert result is not True, ( - "Testcase : Failed \n " - "Routes are still present \n Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \n Routes are still present \n Error: {}".format( + tc_name, result ) else: result = verify_rib(tgen, addr_type, "r1", input_static_1) - assert result is True, "Testcase : Failed \n Error: {}".format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) result = verify_rib(tgen, addr_type, "r3", input_static_2, protocol="bgp") - assert result is True, "Testcase : Failed \n Error: {}".format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) @@ -579,17 +592,17 @@ def test_route_summarisation_with_summary_only_p1(request): tgen, addr_type, "r1", input_advertise_1, expected=False ) assert result is not True, ( - "Testcase : Failed \n " + "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(tc_name, result) ) else: result = verify_bgp_rib(tgen, addr_type, "r1", input_advertise_1) - assert result is True, "Testcase : Failed \n Error: {}".format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) result = verify_rib(tgen, addr_type, "r3", input_advertise_2) - assert result is True, "Testcase : Failed \n Error: {}".format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) @@ -608,7 +621,9 @@ def test_route_summarisation_with_summary_only_p1(request): } result = create_static_routes(tgen, input_static) - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) for addr_type in ADDR_TYPES: input_advertise = { @@ -645,7 +660,9 @@ def test_route_summarisation_with_summary_only_p1(request): input_static = {"r1": {"static_routes": [{"network": AGGREGATE_NW[addr_type]}]}} result = verify_rib(tgen, addr_type, "r3", input_static, protocol="bgp") - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) input_advertise_2 = { "r1": { @@ -669,7 +686,9 @@ def test_route_summarisation_with_summary_only_p1(request): } result = verify_rib(tgen, addr_type, "r3", input_advertise_2, protocol="bgp") - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) for action, value in zip(["Delete", "Re-add"], [True, False]): step("{} aggregation command from R1.".format(action)) @@ -715,30 +734,28 @@ def test_route_summarisation_with_summary_only_p1(request): result = verify_rib( tgen, addr_type, "r1", input_static_agg, expected=False ) - assert result is not True, ( - "Testcase : Failed \n " - "Aggregated route is still present \n Error: {}".format( - tc_name, result - ) + assert ( + result is not True + ), "Testcase {} : Failed \n Aggregated route is still present \n Error: {}".format( + tc_name, result ) result = verify_rib( tgen, addr_type, "r3", input_static_agg, expected=False ) - assert result is not True, ( - "Testcase : Failed \n " - "Aggregated route is still present \n Error: {}".format( - tc_name, result - ) + assert ( + result is not True + ), "Testcase {} : Failed \n Aggregated route is still present \n Error: {}".format( + tc_name, result ) else: result = verify_rib(tgen, addr_type, "r1", input_static_agg) - assert result is True, "Testcase : Failed \n Error: {}".format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) result = verify_rib(tgen, addr_type, "r3", input_static_agg) - assert result is True, "Testcase : Failed \n Error: {}".format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) @@ -793,7 +810,9 @@ def test_route_summarisation_with_as_set_p1(request): step("Configuring {} static routes on router R1 ".format(addr_type)) result = create_static_routes(tgen, input_static) - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) step( "Configuring redistribute static for {} address-family on router R1 ".format( @@ -826,7 +845,9 @@ def test_route_summarisation_with_as_set_p1(request): } result = verify_rib(tgen, addr_type, "r3", input_static) - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) step( "Configure a route-map to attach a unique community attribute value " @@ -977,7 +998,9 @@ def test_route_summarisation_with_as_set_p1(request): } result = create_static_routes(tgen, input_static) - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) step( "Verify on R3 that whenever we remove the static routes, we still" @@ -1017,7 +1040,9 @@ def test_route_summarisation_with_as_set_p1(request): } result = create_static_routes(tgen, input_static) - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) for addr_type in ADDR_TYPES: for ( @@ -1134,30 +1159,28 @@ def test_route_summarisation_with_as_set_p1(request): result = verify_rib( tgen, addr_type, "r1", input_static_agg, expected=False ) - assert result is not True, ( - "Testcase : Failed \n " - "Aggregated route is still present \n Error: {}".format( - tc_name, result - ) + assert ( + result is not True + ), "Testcase {} : Failed \n Aggregated route is still present \n Error: {}".format( + tc_name, result ) result = verify_rib( tgen, addr_type, "r3", input_static_agg, expected=False ) - assert result is not True, ( - "Testcase : Failed \n " - "Aggregated route is still present \n Error: {}".format( - tc_name, result - ) + assert ( + result is not True + ), "Testcase {} : Failed \n Aggregated route is still present \n Error: {}".format( + tc_name, result ) else: result = verify_rib(tgen, addr_type, "r1", input_static_agg) - assert result is True, "Testcase : Failed \n Error: {}".format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) result = verify_rib(tgen, addr_type, "r3", input_static_agg) - assert result is True, "Testcase : Failed \n Error: {}".format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) diff --git a/tests/topotests/bgp_route_map/test_route_map_topo2.py b/tests/topotests/bgp_route_map/test_route_map_topo2.py index 54b3340d68..d4b145e817 100644 --- a/tests/topotests/bgp_route_map/test_route_map_topo2.py +++ b/tests/topotests/bgp_route_map/test_route_map_topo2.py @@ -74,12 +74,10 @@ TC_59: TC_60 Create route map to deny outbound prefixes with filter match tag, and set criteria -""" ################################# # TOPOLOGY ################################# -""" +-------+ +--------- | R2 | @@ -1049,8 +1047,11 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): result = verify_rib( tgen, addr_type, dut, input_dict, protocol=protocol, expected=False ) - assert result is not True, "Testcase {} : Failed \n" - "routes are not present \n Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \nroutes are not present \n Error: {}".format( + tc_name, result + ) logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes @@ -1060,9 +1061,11 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): result = verify_rib( tgen, addr_type, dut, input_dict, protocol=protocol, expected=False ) - assert result is not True, "Testcase {} : Failed \n" - "Expected behaviour: routes are not present \n " - "Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \nExpected behaviour: routes are not present \n Error: {}".format( + tc_name, result + ) write_test_footer(tc_name) @@ -1315,8 +1318,11 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): result = verify_rib( tgen, addr_type, dut, input_dict, protocol=protocol, expected=False ) - assert result is not True, "Testcase {} : Failed \n" - "routes are not present \n Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \nroutes are not present \n Error: {}".format( + tc_name, result + ) logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes @@ -1326,8 +1332,11 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): result = verify_rib( tgen, addr_type, dut, input_dict, protocol=protocol, expected=False ) - assert result is not True, "Testcase {} : Failed \n" - "routes are not present \n Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \nroutes are not present \n Error: {}".format( + tc_name, result + ) logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -2155,8 +2164,11 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): result = verify_rib( tgen, addr_type, dut, input_dict, protocol=protocol, expected=False ) - assert result is not True, "Testcase {} : Failed \n Error" - "Routes are still present: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \n Error Routes are still present: {}".format( + tc_name, result + ) logger.info("Expected behaviour: {}".format(result)) # Remove applied rmap from neighbor @@ -2566,8 +2578,11 @@ def test_rmap_without_match_and_set_clause_p0(): result = verify_rib( tgen, addr_type, dut, input_dict, protocol=protocol, expected=False ) - assert result is not True, "Testcase {} : Failed \n" - "routes are not present \n Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \nroutes are not present \n Error: {}".format( + tc_name, result + ) logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -2811,8 +2826,11 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): input_dict_3_addr_type[addr_type], expected=False, ) - assert result is not True, "Testcase {} : Failed \n" - "Attributes are not set \n Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \nAttributes are not set \n Error: {}".format( + tc_name, result + ) logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes @@ -2842,8 +2860,11 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): input_dict_3_addr_type[addr_type], expected=False, ) - assert result is not True, "Testcase {} : Failed \n" - "Attributes are not set \n Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \nAttributes are not set \n Error: {}".format( + tc_name, result + ) logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -3648,8 +3669,11 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): result = verify_rib( tgen, addr_type, dut, input_dict, protocol=protocol, expected=False ) - assert result is not True, "Testcase {} : Failed \n" - "routes are not present \n Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \nroutes are not present \n Error: {}".format( + tc_name, result + ) logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes @@ -3659,8 +3683,11 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): result = verify_rib( tgen, addr_type, dut, input_dict, protocol=protocol, expected=False ) - assert result is not True, "Testcase {} : Failed \n" - "routes are not present \n Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \nroutes are not present \n Error: {}".format( + tc_name, result + ) logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -3961,8 +3988,11 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): result = verify_rib( tgen, addr_type, dut, input_dict, protocol=protocol, expected=False ) - assert result is not True, "Testcase {} : Failed \n" - "routes are denied \n Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \nroutes are denied \n Error: {}".format( + tc_name, result + ) logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) diff --git a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py index 55b4f1581f..63e724cc5c 100644 --- a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py +++ b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py @@ -223,7 +223,6 @@ def disable_route_map_to_prefer_global_next_hop(tgen, topo): """ - tc_name = request.node.name logger.info("Remove prefer-global rmap applied on neighbors") input_dict = { "r1": { @@ -487,7 +486,7 @@ def disable_route_map_to_prefer_global_next_hop(tgen, topo): } result = create_router_bgp(tgen, topo, input_dict) - assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase :Failed \n Error: {}".format(result) return True diff --git a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py index 18f048129c..1241a37cf7 100644 --- a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py +++ b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py @@ -915,7 +915,7 @@ def test_modify_route_map_match_set_clauses_p1(request): rmap_name="rmap_IMP_{}".format(addr_type), input_dict=input_rmap, ) - assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Change community-list to match a different value then " "100:100.") diff --git a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py index 86253acc4d..d72b28e84c 100644 --- a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py +++ b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py @@ -251,9 +251,7 @@ def prerequisite_config_for_test_suite(tgen): } result = configure_vxlan(tgen, vxlan_input) - assert result is True, "Testcase {} :Failed \n Error: {}".format( - tc_name, result - ) + assert result is True, "Testcase :Failed \n Error: {}".format(result) step("Configure bridge interface") brctl_input = { @@ -269,9 +267,7 @@ def prerequisite_config_for_test_suite(tgen): } } result = configure_brctl(tgen, topo, brctl_input) - assert result is True, "Testcase {} :Failed \n Error: {}".format( - tc_name, result - ) + assert result is True, "Testcase :Failed \n Error: {}".format(result) step("Configure default routes") add_default_routes(tgen) @@ -340,7 +336,7 @@ def add_default_routes(tgen): } result = create_static_routes(tgen, default_routes) - assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase :Failed \n Error: {}".format(result) def test_verify_overlay_index_p1(request): @@ -865,8 +861,9 @@ def test_RT_verification_auto_p0(request): } result = verify_rib(tgen, addr_type, "d2", input_routes, expected=False) - assert result is not True, "Testcase {} :Failed \n " - "Routes are still present: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} :Failed \n Routes are still present: {}".format(tc_name, result) logger.info("Expected Behavior: {}".format(result)) step( @@ -1000,8 +997,11 @@ def test_RT_verification_auto_p0(request): result = verify_attributes_for_evpn_routes( tgen, topo, "d2", input_routes_1, rt="auto", rt_peer="e1", expected=False ) - assert result is not True, "Testcase {} :Failed \n " - "Malfaromed Auto-RT value accepted: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} :Failed \n Malfaromed Auto-RT value accepted: {}".format( + tc_name, result + ) logger.info("Expected Behavior: {}".format(result)) step("Configure VNI number more than boundary limit (16777215)") @@ -1032,8 +1032,11 @@ def test_RT_verification_auto_p0(request): result = verify_attributes_for_evpn_routes( tgen, topo, "d2", input_routes_1, rt="auto", rt_peer="e1", expected=False ) - assert result is not True, "Testcase {} :Failed \n " - "Malfaromed Auto-RT value accepted: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} :Failed \n Malfaromed Auto-RT value accepted: {}".format( + tc_name, result + ) logger.info("Expected Behavior: {}".format(result)) step("Un-configure VNI number more than boundary limit (16777215)") diff --git a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py index 4f2aef17c0..fda39be91d 100644 --- a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py +++ b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py @@ -254,9 +254,7 @@ def prerequisite_config_for_test_suite(tgen): } result = configure_vxlan(tgen, vxlan_input) - assert result is True, "Testcase {} on {} :Failed \n Error: {}".format( - tc_name, dut, result - ) + assert result is True, "Testcase :Failed \n Error: {}".format(result) step("Configure bridge interface") brctl_input = { @@ -272,9 +270,7 @@ def prerequisite_config_for_test_suite(tgen): } } result = configure_brctl(tgen, topo, brctl_input) - assert result is True, "Testcase {} on {} :Failed \n Error: {}".format( - tc_name, dut, result - ) + assert result is True, "Testcase :Failed \n Error: {}".format(result) step("Configure default routes") add_default_routes(tgen) @@ -343,7 +339,7 @@ def add_default_routes(tgen): } result = create_static_routes(tgen, default_routes) - assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + assert result is True, "Testcase :Failed \n Error: {}".format(result) def test_RD_verification_manual_and_auto_p0(request): @@ -1348,15 +1344,17 @@ def test_evpn_routes_from_VNFs_p1(request): for addr_type in ADDR_TYPES: input_routes = {key: topo["routers"][key] for key in ["r1"]} result = verify_rib(tgen, addr_type, "d2", input_routes, expected=False) - assert result is not True, "Testcase {} :Failed \n " - "Routes are still present: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase :Failed \n Routes are still present: {}".format(result) logger.info("Expected Behavior: {}".format(result)) for addr_type in ADDR_TYPES: input_routes = {key: topo["routers"][key] for key in ["r1"]} result = verify_rib(tgen, addr_type, "r3", input_routes, expected=False) - assert result is not True, "Testcase {} :Failed \n " - "Routes are still present: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} :Failed \n Routes are still present: {}".format(tc_name, result) logger.info("Expected Behavior: {}".format(result)) step("Re-advertise IP prefixes from VFN(R1).") @@ -1431,13 +1429,15 @@ def test_evpn_routes_from_VNFs_p1(request): } result = verify_rib(tgen, addr_type, "d2", input_routes, expected=False) - assert result is not True, "Testcase {} :Failed \n " - "Routes are still present: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} :Failed \n Routes are still present: {}".format(tc_name, result) logger.info("Expected Behavior: {}".format(result)) result = verify_rib(tgen, addr_type, "r4", input_routes, expected=False) - assert result is not True, "Testcase {} :Failed \n " - "Routes are still present: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} :Failed \n Routes are still present: {}".format(tc_name, result) logger.info("Expected Behavior: {}".format(result)) step("Add vrf BLUE on router Edge-1 again.") @@ -1532,13 +1532,15 @@ def test_evpn_routes_from_VNFs_p1(request): } result = verify_rib(tgen, addr_type, "d2", input_routes, expected=False) - assert result is not True, "Testcase {} :Failed \n " - "Routes are still present: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} :Failed \n Routes are still present: {}".format(tc_name, result) logger.info("Expected Behavior: {}".format(result)) result = verify_rib(tgen, addr_type, "r4", input_routes, expected=False) - assert result is not True, "Testcase {} :Failed \n " - "Routes are still present: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} :Failed \n Routes are still present: {}".format(tc_name, result) logger.info("Expected Behavior: {}".format(result)) step("Advertise IPv6 address-family in EVPN advertisements " "for VRF GREEN.") @@ -1990,7 +1992,7 @@ def test_bgp_attributes_for_evpn_address_family_p1(request, attribute): input_dict_1 = { "e1": { "route_maps": { - "rmap_d1".format(addr_type): [ + "rmap_d1": [ { "action": "permit", "set": { @@ -2001,7 +2003,7 @@ def test_bgp_attributes_for_evpn_address_family_p1(request, attribute): }, } ], - "rmap_d2".format(addr_type): [ + "rmap_d2": [ { "action": "permit", "set": { @@ -2016,10 +2018,10 @@ def test_bgp_attributes_for_evpn_address_family_p1(request, attribute): input_dict_1 = { "e1": { "route_maps": { - "rmap_d1".format(addr_type): [ + "rmap_d1": [ {"action": "permit", "set": {attribute: 120}} ], - "rmap_d2".format(addr_type): [ + "rmap_d2": [ {"action": "permit", "set": {attribute: 150}} ], } diff --git a/tests/topotests/isis_lfa_topo1/test_isis_lfa_topo1.py b/tests/topotests/isis_lfa_topo1/test_isis_lfa_topo1.py index a253b11c07..5555b1dca0 100755 --- a/tests/topotests/isis_lfa_topo1/test_isis_lfa_topo1.py +++ b/tests/topotests/isis_lfa_topo1/test_isis_lfa_topo1.py @@ -170,7 +170,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registered routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/isis_rlfa_topo1/test_isis_rlfa_topo1.py b/tests/topotests/isis_rlfa_topo1/test_isis_rlfa_topo1.py index 325638a478..e2cb080eb7 100755 --- a/tests/topotests/isis_rlfa_topo1/test_isis_rlfa_topo1.py +++ b/tests/topotests/isis_rlfa_topo1/test_isis_rlfa_topo1.py @@ -172,7 +172,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registered routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/isis_snmp/test_isis_snmp.py b/tests/topotests/isis_snmp/test_isis_snmp.py index c6fc698005..6ca5928fd9 100755 --- a/tests/topotests/isis_snmp/test_isis_snmp.py +++ b/tests/topotests/isis_snmp/test_isis_snmp.py @@ -142,7 +142,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registered routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/isis_sr_te_topo1/test_isis_sr_te_topo1.py b/tests/topotests/isis_sr_te_topo1/test_isis_sr_te_topo1.py index 06d15afe6c..260457b672 100755 --- a/tests/topotests/isis_sr_te_topo1/test_isis_sr_te_topo1.py +++ b/tests/topotests/isis_sr_te_topo1/test_isis_sr_te_topo1.py @@ -167,7 +167,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registered routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/isis_topo1/test_isis_topo1.py b/tests/topotests/isis_topo1/test_isis_topo1.py index 3927222553..29021c5623 100644 --- a/tests/topotests/isis_topo1/test_isis_topo1.py +++ b/tests/topotests/isis_topo1/test_isis_topo1.py @@ -26,7 +26,6 @@ test_isis_topo1.py: Test ISIS topology. """ -import collections import functools import json import os @@ -263,7 +262,7 @@ def dict_merge(dct, merge_dct): if ( k in dct and isinstance(dct[k], dict) - and isinstance(merge_dct[k], collections.Mapping) + and topotest.is_mapping(merge_dct[k]) ): dict_merge(dct[k], merge_dct[k]) else: diff --git a/tests/topotests/isis_topo1_vrf/test_isis_topo1_vrf.py b/tests/topotests/isis_topo1_vrf/test_isis_topo1_vrf.py index 67c60c729f..9c15ee3423 100644 --- a/tests/topotests/isis_topo1_vrf/test_isis_topo1_vrf.py +++ b/tests/topotests/isis_topo1_vrf/test_isis_topo1_vrf.py @@ -24,7 +24,6 @@ test_isis_topo1_vrf.py: Test ISIS vrf topology. """ -import collections import functools import json import os @@ -291,7 +290,7 @@ def dict_merge(dct, merge_dct): if ( k in dct and isinstance(dct[k], dict) - and isinstance(merge_dct[k], collections.Mapping) + and topotest.is_mapping(merge_dct[k]) ): dict_merge(dct[k], merge_dct[k]) else: diff --git a/tests/topotests/ldp_topo1/test_ldp_topo1.py b/tests/topotests/ldp_topo1/test_ldp_topo1.py index c0f869f826..62b763ce70 100644 --- a/tests/topotests/ldp_topo1/test_ldp_topo1.py +++ b/tests/topotests/ldp_topo1/test_ldp_topo1.py @@ -337,7 +337,7 @@ def test_mpls_ldp_neighbor_establish(): else: # Bail out with error if a router fails to converge fatal_error = "MPLS LDP neighbors did not establish" - assert False, "MPLS LDP neighbors did not establish" % ospfStatus + assert False, "MPLS LDP neighbors did not establish" print("MPLS LDP neighbors established.") diff --git a/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py b/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py index 60a883b285..5cd5cd1553 100644 --- a/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py +++ b/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py @@ -687,8 +687,9 @@ def test_BSR_CRP_with_blackhole_address_p1(request): state_before = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( state_before, dict - ), "Testcase{} : Failed \n state_before is not dictionary \n " - "Error: {}".format(tc_name, result) + ), "Testcase{} : Failed \n state_before is not dictionary \n Error: {}".format( + tc_name, result + ) step("Sending BSR after Configure black hole address for BSR and candidate RP") step("Send BSR packet from b1 to FHR") @@ -711,8 +712,9 @@ def test_BSR_CRP_with_blackhole_address_p1(request): state_after = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( state_after, dict - ), "Testcase{} : Failed \n state_before is not dictionary \n " - "Error: {}".format(tc_name, result) + ), "Testcase{} : Failed \n state_before is not dictionary \n Error: {}".format( + tc_name, result + ) result = verify_state_incremented(state_before, state_after) assert result is not True, "Testcase{} : Failed Error: {}".format(tc_name, result) @@ -1329,8 +1331,7 @@ def test_bsmp_stress_add_del_restart_p2(request): assert ( rp_add1 == rp2[group] ), "Testcase {} :Failed \n Error : rp expected {} rp received {}".format( - tc_name, - rp_add1, + tc_name, rp_add1, rp2[group] ) # Verify if that rp is installed diff --git a/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py b/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py index 487ec924e9..d808a60c05 100755 --- a/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py +++ b/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py @@ -348,8 +348,9 @@ def test_multicast_data_traffic_static_RP_send_join_then_traffic_p0(request): state_before = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( state_before, dict - ), "Testcase {} : Failed \n state_before is not dictionary \n " - "Error: {}".format(tc_name, result) + ), "Testcase {} : Failed \n state_before is not dictionary \n Error: {}".format( + tc_name, state_before + ) result = iperfSendIGMPJoin(tgen, "i1", ["{}%{}".format(IGMP_JOIN, intf_i1_l1)], join_interval=1) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -419,8 +420,9 @@ def test_multicast_data_traffic_static_RP_send_join_then_traffic_p0(request): state_after = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( state_after, dict - ), "Testcase {} : Failed \n state_before is not dictionary \n " - "Error: {}".format(tc_name, result) + ), "Testcase {} : Failed \n state_before is not dictionary \n Error: {}".format( + tc_name, result + ) step( "l1 sent PIM (*,G) join to r2 verify using" @@ -501,8 +503,9 @@ def test_multicast_data_traffic_static_RP_send_traffic_then_join_p0(request): state_before = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( state_before, dict - ), "Testcase {} : Failed \n state_before is not dictionary \n " - "Error: {}".format(tc_name, result) + ), "Testcase {} : Failed \n state_before is not dictionary \n Error: {}".format( + tc_name, result + ) result = iperfSendIGMPJoin(tgen, "i1", IGMP_JOIN, join_interval=1) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -544,8 +547,9 @@ def test_multicast_data_traffic_static_RP_send_traffic_then_join_p0(request): state_after = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( state_after, dict - ), "Testcase {} : Failed \n state_before is not dictionary \n " - "Error: {}".format(tc_name, result) + ), "Testcase {} : Failed \n state_before is not dictionary \n Error: {}".format( + tc_name, result + ) step( "l1 sent PIM (*,G) join to r2 verify using" @@ -951,8 +955,11 @@ def test_verify_mroute_when_same_receiver_joining_5_diff_sources_p0(request): data["oil"], expected=False, ) - assert result is not True, "Testcase {} : Failed \n mroutes are" - " still present \n Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \n mroutes are still present \n Error: {}".format( + tc_name, result + ) logger.info("Expected Behavior: {}".format(result)) step( @@ -1178,8 +1185,11 @@ def test_verify_mroute_when_frr_is_transit_router_p2(request): result = verify_ip_mroutes( tgen, "c1", "*", IGMP_JOIN, "c1-c2-eth1", "c1-l1-eth0", expected=False ) - assert result is not True, "Testcase {} : Failed \n mroutes are" - " still present \n Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \n mroutes are still present \n Error: {}".format( + tc_name, result + ) logger.info("Expected Behavior: {}".format(result)) write_test_footer(tc_name) @@ -1291,8 +1301,11 @@ def test_verify_mroute_when_RP_unreachable_p1(request): result = verify_ip_mroutes( tgen, "f1", "*", IGMP_JOIN, "f1-r2-eth3", "f1-i8-eth2", expected=False ) - assert result is not True, "Testcase {} : Failed \n mroutes are" - " still present \n Error: {}".format(tc_name, result) + assert ( + result is not True + ), "Testcase {} : Failed \n mroutes are still present \n Error: {}".format( + tc_name, result + ) logger.info("Expected Behavior: {}".format(result)) step("IGMP groups are present verify using 'show ip igmp group'") diff --git a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py index 0b9c216c66..d2bddc43b7 100755 --- a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py +++ b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py @@ -1046,8 +1046,9 @@ def test_PIM_hello_tx_rx_p1(request): c1_state_before = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( c1_state_before, dict - ), "Testcase{} : Failed \n state_before is not dictionary \n " - "Error: {}".format(tc_name, result) + ), "Testcase{} : Failed \n state_before is not dictionary \n Error: {}".format( + tc_name, result + ) step("Flap PIM nbr while doing interface c1-l1 interface shut from f1 side") shutdown_bringup_interface(tgen, "c1", intf_c1_l1, False) @@ -1062,8 +1063,9 @@ def test_PIM_hello_tx_rx_p1(request): c1_state_after = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( c1_state_after, dict - ), "Testcase{} : Failed \n state_before is not dictionary \n " - "Error: {}".format(tc_name, result) + ), "Testcase{} : Failed \n state_before is not dictionary \n Error: {}".format( + tc_name, result + ) step("verify stats not increamented on c1") result = verify_state_incremented(c1_state_before, c1_state_after) @@ -1081,8 +1083,9 @@ def test_PIM_hello_tx_rx_p1(request): l1_state_before = verify_pim_interface_traffic(tgen, l1_state_dict) assert isinstance( l1_state_before, dict - ), "Testcase{} : Failed \n state_before is not dictionary \n " - "Error: {}".format(tc_name, result) + ), "Testcase{} : Failed \n state_before is not dictionary \n Error: {}".format( + tc_name, result + ) step("Flap PIM nbr while doing interface r2-c1 shut from r2 side") shutdown_bringup_interface(tgen, "l1", intf_l1_c1, False) @@ -1097,8 +1100,9 @@ def test_PIM_hello_tx_rx_p1(request): l1_state_after = verify_pim_interface_traffic(tgen, l1_state_dict) assert isinstance( l1_state_after, dict - ), "Testcase{} : Failed \n state_before is not dictionary \n " - "Error: {}".format(tc_name, result) + ), "Testcase{} : Failed \n state_before is not dictionary \n Error: {}".format( + tc_name, result + ) step("verify stats not increamented on l1") result = verify_state_incremented(l1_state_before, l1_state_after) @@ -1122,8 +1126,9 @@ def test_PIM_hello_tx_rx_p1(request): c1_state_before = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( c1_state_before, dict - ), "Testcase{} : Failed \n state_before is not dictionary \n " - "Error: {}".format(tc_name, result) + ), "Testcase{} : Failed \n state_before is not dictionary \n Error: {}".format( + tc_name, result + ) step("Flap c1-r2 pim nbr while changing ip address from c1 side") c1_l1_ip_subnet = topo["routers"]["c1"]["links"]["l1"]["ipv4"] @@ -1145,8 +1150,9 @@ def test_PIM_hello_tx_rx_p1(request): c1_state_after = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( c1_state_after, dict - ), "Testcase{} : Failed \n state_before is not dictionary \n " - "Error: {}".format(tc_name, result) + ), "Testcase{} : Failed \n state_before is not dictionary \n Error: {}".format( + tc_name, result + ) step("verify stats not increamented on c1") result = verify_state_incremented(c1_state_before, c1_state_after) diff --git a/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py b/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py index ba8ea0be63..b57c5b16da 100755 --- a/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py +++ b/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py @@ -759,7 +759,7 @@ def test_not_reachable_static_RP_p0(request): assert isinstance( state_before, dict ), "Testcase{} : Failed \n state_before is not dictionary \n " "Error: {}".format( - tc_name, result + tc_name, state_before ) step("Enable IGMP on r1 interface and send IGMP " "join (225.1.1.1) to r1") @@ -1088,7 +1088,7 @@ def test_reachable_static_RP_after_join_p0(request): assert isinstance( state_before, dict ), "Testcase{} : Failed \n state_before is not dictionary \n " "Error: {}".format( - tc_name, result + tc_name, state_before ) step("r1: Make RP un-reachable") @@ -1277,7 +1277,7 @@ def test_send_join_on_higher_preffered_rp_p1(request): assert isinstance( state_before, dict ), "Testcase{} : Failed \n state_before is not dictionary \n " "Error: {}".format( - tc_name, result + tc_name, state_before ) step("r0 : Send IGMP join for 225.1.1.1") diff --git a/tests/topotests/nhrp_topo/test_nhrp_topo.py b/tests/topotests/nhrp_topo/test_nhrp_topo.py index 081c63a185..6d3cc3a552 100644 --- a/tests/topotests/nhrp_topo/test_nhrp_topo.py +++ b/tests/topotests/nhrp_topo/test_nhrp_topo.py @@ -105,7 +105,7 @@ def setup_module(mod): router_list = tgen.routers() _populate_iface() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, '{}/zebra.conf'.format(rname)), @@ -142,7 +142,7 @@ def test_protocols_convergence(): logger.info("Checking NHRP cache and IPv4 routes for convergence") router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): if rname == 'r3': continue @@ -163,7 +163,7 @@ def test_protocols_convergence(): assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): if rname == 'r3': continue @@ -184,7 +184,7 @@ def test_protocols_convergence(): assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): if rname == 'r3': continue logger.info('Dump neighbor information on {}-gre0'.format(rname)) diff --git a/tests/topotests/ospf6_topo1_vrf/test_ospf6_topo1_vrf.py b/tests/topotests/ospf6_topo1_vrf/test_ospf6_topo1_vrf.py index fc1a472a17..28e89dfa52 100755 --- a/tests/topotests/ospf6_topo1_vrf/test_ospf6_topo1_vrf.py +++ b/tests/topotests/ospf6_topo1_vrf/test_ospf6_topo1_vrf.py @@ -287,7 +287,7 @@ def test_ospfv3_routingTable(): # For debugging, uncomment the next line # tgen.mininet_cli() # Verify OSPFv3 Routing Table - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): logger.info('Waiting for router "%s" convergence', router) # Load expected results from the command @@ -418,7 +418,7 @@ def test_ospfv3_routingTable_write_multiplier(): r1.vtysh_cmd("clear ipv6 ospf interface r1-sw5") # Verify OSPFv3 Routing Table - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): logger.info('Waiting for router "%s" convergence', router) # Load expected results from the command diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py b/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py index 5533136457..0c2619d2f6 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py @@ -229,7 +229,7 @@ def test_ospf_p2mp_tc1_p0(request): topo_modify_change_ip = deepcopy(topo) intf_ip = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] = str( - IPv4Address(unicode(intf_ip.split("/")[0])) + 3 + IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 3 ) + "/{}".format(intf_ip.split("/")[1]) build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False) @@ -280,7 +280,7 @@ def test_ospf_p2mp_tc1_p0(request): topo_modify_change_ip = deepcopy(topo) intf_ip = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] = str( - IPv4Address(unicode(intf_ip.split("/")[0])) + 3 + IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 3 ) + "/{}".format(int(intf_ip.split("/")[1]) + 1) build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False) diff --git a/tests/topotests/pim_acl/test_pim_acl.py b/tests/topotests/pim_acl/test_pim_acl.py index 0f172d3d9d..4414713d8e 100755 --- a/tests/topotests/pim_acl/test_pim_acl.py +++ b/tests/topotests/pim_acl/test_pim_acl.py @@ -69,7 +69,8 @@ test_pim_acl.py: Test PIM with RP selection using ACLs # shutdown topology # - +# XXX clean up in later commit to avoid conflict on rebase +# pylint: disable=C0413 TOPOLOGY = """ +----------+ | Host H2 | diff --git a/tests/topotests/pim_igmp_vrf/test_pim_vrf.py b/tests/topotests/pim_igmp_vrf/test_pim_vrf.py index cb207cb810..a0f9e87b2a 100755 --- a/tests/topotests/pim_igmp_vrf/test_pim_vrf.py +++ b/tests/topotests/pim_igmp_vrf/test_pim_vrf.py @@ -26,6 +26,9 @@ test_pim_vrf.py: Test PIM with VRFs. """ +# XXX clean up in later commit to avoid conflict on rebase +# pylint: disable=C0413 + # Tests PIM with VRF # # R1 is split into 2 VRF: Blue and Red, the others are normal From e82b531df94b9fd7bc456df8a1b7c58f2770eff9 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Thu, 29 Jul 2021 09:38:55 +0000 Subject: [PATCH 11/25] tests: remove legacy Topo class (fixes many pylint errors) Signed-off-by: Christian Hopps --- .../test_all_protocol_startup.py | 86 +++--- tests/topotests/bfd_topo2/test_bfd_topo2.py | 23 -- .../bfd_vrf_topo1/test_bfd_vrf_topo1.py | 34 +-- .../test_bgp_aggregate-address_origin.py | 17 +- .../test_bgp_aggregate-address_route-map.py | 17 +- .../test_bgp_aggregate_address_topo1.py | 28 +- .../test_bgp_aggregator_zero.py | 21 +- .../bgp_as_allow_in/test_bgp_as_allow_in.py | 18 +- .../test_bgp_as_wide_bgp_identifier.py | 19 +- .../bgp_aspath_zero/test_bgp_aspath_zero.py | 21 +- tests/topotests/bgp_auth/test_bgp_auth.py | 96 +++--- .../test_bgp_basic_functionality.py | 27 +- .../test_bgp_blackhole_community.py | 29 +- .../test_bgp_comm-list_delete.py | 17 +- .../test_bgp_communities.py | 28 +- .../test_bgp_communities_topo2.py | 28 +- .../test_bgp-community-alias.py | 16 +- .../test_bgp_community_change_update.py | 75 +++-- .../test_bgp_conditional_advertisement.py | 25 +- .../test_bgp-default-afi-safi.py | 20 +- .../test_bgp_default-originate.py | 17 +- ...t_bgp_default-originate_route-map_match.py | 17 +- ..._bgp_default-originate_route-map_match2.py | 17 +- ...p_default-originate_route-map_match_set.py | 17 +- ...est_bgp_default-originate_route-map_set.py | 17 +- .../bgp_disable_addpath_rx/r1/bgpd.conf | 2 + .../bgp_disable_addpath_rx/r2/bgpd.conf | 4 + .../bgp_disable_addpath_rx/r3/bgpd.conf | 2 + .../bgp_disable_addpath_rx/r4/bgpd.conf | 2 + .../test_disable_addpath_rx.py | 28 +- .../test_bgp_distance_change.py | 17 +- ...gp-ebgp-common-subnet-nexthop-unchanged.py | 18 +- .../test_bgp_ebgp_requires_policy.py | 34 +-- .../bgp_ecmp_topo1/test_bgp_ecmp_topo1.py | 40 ++- .../bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py | 28 +- .../bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py | 28 +- .../bgp_ecmp_topo3/test_ibgp_ecmp_topo3.py | 56 +--- tests/topotests/bgp_evpn_mh/test_evpn_mh.py | 173 ++++++----- .../test_bgp_evpn_overlay_index_gateway.py | 36 +-- tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py | 27 +- .../test_bgp_evpn_vxlan.py | 62 ++-- .../bgp_features/test_bgp_features.py | 66 +++-- .../bgp_flowspec/test_bgp_flowspec_topo.py | 28 +- .../test_bgp_gr_functionality_topo1.py | 36 +-- .../test_bgp_gr_functionality_topo2.py | 35 +-- tests/topotests/bgp_gshut/test_bgp_gshut.py | 35 +-- .../bgp_gshut_topo1/test_ebgp_gshut_topo1.py | 36 +-- .../bgp_gshut_topo1/test_ibgp_gshut_topo1.py | 35 +-- .../test_rfc5549_ebgp_ibgp_nbr.py | 28 +- .../test_rfc5549_ebgp_nbr.py | 28 +- .../test_rfc5549_ebgp_unnumbered_nbr.py | 28 +- .../test_rfc5549_ibgp_nbr.py | 28 +- .../test_rfc5549_ibgp_unnumbered_nbr.py | 28 +- .../bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py | 22 +- .../bgp_l3vpn_to_bgp_direct/customize.py | 70 +++-- .../bgp_l3vpn_to_bgp_vrf/customize.py | 82 +++--- .../test_bgp_large_community_topo_1.py | 28 +- .../test_bgp_large_community_topo_2.py | 30 +- .../bgp_link_bw_ip/test_bgp_linkbw_ip.py | 85 +++--- .../test_bgp_listen_on_multiple_addresses.py | 23 +- .../test_bgp_local_as_private_remove.py | 23 +- tests/topotests/bgp_lu_topo1/test_bgp_lu.py | 42 ++- .../test_bgp_maximum_prefix_invalid_update.py | 17 +- .../test_bgp_maximum_prefix_out.py | 17 +- .../test_bgp_minimum_holdtime.py | 17 +- .../test_bgp_multi_vrf_topo1.py | 30 +- .../test_bgp_multi_vrf_topo2.py | 28 +- .../test_bgp_multiview_topo1.py | 278 ++++++++---------- .../test_bgp_path_attributes.py | 30 +- .../bgp_peer_group/test_bgp_peer-group.py | 19 +- .../test_bgp_peer-type_multipath-relax.py | 38 ++- .../test_prefix_lists.py | 30 +- .../bgp_prefix_sid/test_bgp_prefix_sid.py | 30 +- .../bgp_prefix_sid2/test_bgp_prefix_sid2.py | 22 +- ...test_bgp_recursive_route_ebgp_multi_hop.py | 28 +- .../test_bgp_reject_as_sets.py | 23 +- .../bgp_rfapi_basic_sanity/customize.py | 48 ++- .../test_bgp_rmap_extcommunity_none.py | 18 +- .../test_bgp_aggregation.py | 30 +- .../bgp_route_map/test_route_map_topo1.py | 28 +- .../bgp_route_map/test_route_map_topo2.py | 31 +- .../bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py | 59 ++-- .../test_bgp_sender-as-path-loop-detection.py | 23 +- ...t_bgp_set_local-preference_add_subtract.py | 19 +- .../test_bgp_snmp_mplsvpn.py | 114 ++++--- .../test_bgp_srv6l3vpn_to_bgp_vrf.py | 36 ++- .../bgp_suppress_fib/test_bgp_suppress_fib.py | 23 +- .../topotests/bgp_tcp_mss/test_bgp_tcp_mss.py | 17 +- .../bgp_update_delay/test_bgp_update_delay.py | 36 ++- .../test_bgp_vrf_dynamic_route_leak_topo1.py | 31 +- .../test_bgp_vrf_dynamic_route_leak_topo2.py | 18 +- .../test_bgp_vrf_lite_ipv6_rtadv.py | 22 +- .../bgp_vrf_netns/test_bgp_vrf_netns_topo.py | 30 +- .../test_bgp-vrf-route-leak-basic.py | 13 +- .../config_timing/test_config_timing.py | 12 +- .../topotests/eigrp_topo1/test_eigrp_topo1.py | 47 ++- .../evpn_pim_1/test_evpn_pim_topo1.py | 57 ++-- .../test_evpn_type5_chaos_topo1.py | 31 +- .../test_evpn_type5_topo1.py | 17 +- tests/topotests/example_test/test_template.py | 59 ++-- .../test_example_topojson_multiple_links.py | 32 +- .../test_example_topojson.py | 32 +- .../test_example_topojson.py | 32 +- .../isis_lfa_topo1/test_isis_lfa_topo1.py | 2 +- .../test_isis_lsp_bits_topo1.py | 64 ++-- .../isis_rlfa_topo1/test_isis_rlfa_topo1.py | 2 +- tests/topotests/isis_snmp/test_isis_snmp.py | 62 ++-- .../isis_sr_te_topo1/test_isis_sr_te_topo1.py | 82 +++--- .../isis_sr_topo1/test_isis_sr_topo1.py | 76 +++-- .../isis_tilfa_topo1/test_isis_tilfa_topo1.py | 2 +- tests/topotests/isis_topo1/test_isis_topo1.py | 62 ++-- .../isis_topo1_vrf/test_isis_topo1_vrf.py | 62 ++-- .../ldp_oc_acl_topo1/test_ldp_oc_acl_topo1.py | 46 ++- .../ldp_oc_topo1/test_ldp_oc_topo1.py | 46 ++- .../topotests/ldp_snmp/test_ldp_snmp_topo1.py | 62 ++-- .../test_ldp_sync_isis_topo1.py | 62 ++-- .../test_ldp_sync_ospf_topo1.py | 62 ++-- tests/topotests/ldp_topo1/test_ldp_topo1.py | 130 +++----- .../ldp_vpls_topo1/test_ldp_vpls_topo1.py | 62 ++-- tests/topotests/lib/ltemplate.py | 2 +- .../msdp_mesh_topo1/test_msdp_mesh_topo1.py | 46 ++- tests/topotests/msdp_topo1/test_msdp_topo1.py | 60 ++-- .../test_mcast_pim_bsmp_01.py | 30 +- .../test_mcast_pim_bsmp_02.py | 27 +- .../test_multicast_pim_sm_topo1.py | 33 +-- .../test_multicast_pim_sm_topo2.py | 30 +- .../test_multicast_pim_sm_topo3.py | 30 +- .../test_multicast_pim_sm_topo4.py | 28 +- .../test_multicast_pim_static_rp.py | 20 +- tests/topotests/nhrp_topo/test_nhrp_topo.py | 35 +-- .../topotests/ospf6_topo1/test_ospf6_topo1.py | 75 ++--- .../ospf6_topo1_vrf/test_ospf6_topo1_vrf.py | 74 ++--- .../topotests/ospf6_topo2/test_ospf6_topo2.py | 34 +-- .../test_ospf_asbr_summary_topo1.py | 28 +- .../test_ospf_asbr_summary_type7_lsa.py | 28 +- .../test_ospf_authentication.py | 28 +- .../test_ospf_chaos.py | 29 +- .../test_ospf_ecmp.py | 29 +- .../test_ospf_ecmp_lan.py | 29 +- .../ospf_basic_functionality/test_ospf_lan.py | 28 +- .../test_ospf_nssa.py | 28 +- .../test_ospf_p2mp.py | 30 +- .../test_ospf_routemaps.py | 28 +- .../test_ospf_rte_calc.py | 29 +- .../test_ospf_single_area.py | 28 +- .../ospf_dual_stack/test_ospf_dual_stack.py | 24 +- .../ospf_gr_helper/test_ospf_gr_helper.py | 31 +- .../ospf_gr_topo1/test_ospf_gr_topo1.py | 70 ++--- .../ospf_sr_te_topo1/test_ospf_sr_te_topo1.py | 82 +++--- .../ospf_sr_topo1/test_ospf_sr_topo1.py | 76 +++-- .../ospf_suppress_fa/test_ospf_suppress_fa.py | 32 +- .../ospf_te_topo1/test_ospf_te_topo1.py | 52 ++-- .../ospf_tilfa_topo1/test_ospf_tilfa_topo1.py | 56 ++-- tests/topotests/ospf_topo1/test_ospf_topo1.py | 58 ++-- .../ospf_topo1_vrf/test_ospf_topo1_vrf.py | 44 ++- tests/topotests/ospf_topo2/test_ospf_topo2.py | 36 ++- .../test_ospfv3_asbr_summary_topo1.py | 28 +- .../test_ospfv3_ecmp.py | 29 +- .../test_ospfv3_routemaps.py | 28 +- .../test_ospfv3_rte_calc.py | 29 +- .../test_ospfv3_single_area.py | 29 +- tests/topotests/pbr_topo1/test_pbr_topo1.py | 24 +- tests/topotests/pim_basic/test_pim.py | 64 ++-- .../pim_basic_topo2/test_pim_basic_topo2.py | 34 +-- tests/topotests/rip_topo1/test_rip_topo1.py | 102 +++---- .../topotests/ripng_topo1/test_ripng_topo1.py | 101 +++---- .../test_static_routes_topo1_ebgp.py | 32 +- .../test_static_routes_topo2_ebgp.py | 28 +- .../test_static_routes_topo3_ebgp.py | 29 +- .../test_static_routes_topo4_ebgp.py | 30 +- .../test_static_routes_topo1_ibgp.py | 29 +- .../test_static_routes_topo2_ibgp.py | 28 +- .../test_static_routes_topo3_ibgp.py | 29 +- .../test_static_routes_topo4_ibgp.py | 28 +- 174 files changed, 2392 insertions(+), 4245 deletions(-) diff --git a/tests/topotests/all_protocol_startup/test_all_protocol_startup.py b/tests/topotests/all_protocol_startup/test_all_protocol_startup.py index 41597c449e..52526e0c73 100644 --- a/tests/topotests/all_protocol_startup/test_all_protocol_startup.py +++ b/tests/topotests/all_protocol_startup/test_all_protocol_startup.py @@ -34,8 +34,6 @@ import pytest import glob from time import sleep -from lib.micronet_compat import Mininet, Topo - from functools import partial pytestmark = [ @@ -50,6 +48,7 @@ pytestmark = [ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lib import topotest +from lib.topogen import Topogen, get_topogen fatal_error = "" @@ -61,24 +60,10 @@ fatal_error = "" ##################################################### -class NetworkTopo(Topo): - "All Protocol Startup Test" - - def build(self, **_opts): - - # Setup Routers - router = {} - # - # Setup Main Router - router[1] = topotest.addRouter(self, "r1") - # - - # Setup Switches - switch = {} - # - for i in range(0, 10): - switch[i] = self.addSwitch("sw%s" % i) - self.addLink(switch[i], router[1], intfName2="r1-eth%s" % i) +def build_topo(tgen): + router = tgen.add_router("r1") + for i in range(0, 10): + tgen.add_switch("sw%d" % i).add_link(router) ##################################################### @@ -89,21 +74,16 @@ class NetworkTopo(Topo): def setup_module(module): - global topo, net global fatal_error print("\n\n** %s: Setup Topology" % module.__name__) print("******************************************\n") - print("Cleanup old Mininet runs") - os.system("sudo mn -c > /dev/null 2>&1") - os.system("sudo rm /tmp/r* > /dev/null 2>&1") - thisDir = os.path.dirname(os.path.realpath(__file__)) - topo = NetworkTopo() + tgen = Topogen(build_topo, module.__name__) + tgen.start_topology() - net = Mininet(controller=None, topo=topo) - net.start() + net = tgen.net if net["r1"].get_routertype() != "frr": fatal_error = "Test is only implemented for FRR" @@ -133,25 +113,22 @@ def setup_module(module): net["r%s" % i].loadConf("nhrpd", "%s/r%s/nhrpd.conf" % (thisDir, i)) net["r%s" % i].loadConf("babeld", "%s/r%s/babeld.conf" % (thisDir, i)) net["r%s" % i].loadConf("pbrd", "%s/r%s/pbrd.conf" % (thisDir, i)) - net["r%s" % i].startRouter() + tgen.gears["r%s" % i].start() # For debugging after starting FRR daemons, uncomment the next line # CLI(net) def teardown_module(module): - global net - print("\n\n** %s: Shutdown Topology" % module.__name__) print("******************************************\n") - - # End - Shutdown network - net.stop() + tgen = get_topogen() + tgen.stop_topology() def test_router_running(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -172,7 +149,7 @@ def test_router_running(): def test_error_messages_vtysh(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -228,7 +205,7 @@ def test_error_messages_vtysh(): def test_error_messages_daemons(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -319,7 +296,7 @@ def test_error_messages_daemons(): def test_converge_protocols(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -408,6 +385,7 @@ def test_converge_protocols(): def route_get_nhg_id(route_str): + net = get_topogen().net output = net["r1"].cmd('vtysh -c "show ip route %s nexthop-group"' % route_str) match = re.search(r"Nexthop Group ID: (\d+)", output) assert match is not None, ( @@ -419,6 +397,7 @@ def route_get_nhg_id(route_str): def verify_nexthop_group(nhg_id, recursive=False, ecmp=0): + net = get_topogen().net # Verify NHG is valid/installed output = net["r1"].cmd('vtysh -c "show nexthop-group rib %d"' % nhg_id) @@ -457,7 +436,7 @@ def verify_route_nexthop_group(route_str, recursive=False, ecmp=0): def test_nexthop_groups(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -606,7 +585,7 @@ def test_nexthop_groups(): def test_rip_status(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -666,7 +645,7 @@ def test_rip_status(): def test_ripng_status(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -733,7 +712,7 @@ def test_ripng_status(): def test_ospfv2_interfaces(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -818,7 +797,7 @@ def test_ospfv2_interfaces(): def test_isis_interfaces(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -884,7 +863,7 @@ def test_isis_interfaces(): def test_bgp_summary(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1045,7 +1024,7 @@ def test_bgp_summary(): def test_bgp_ipv6_summary(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1140,6 +1119,7 @@ def test_bgp_ipv6_summary(): def test_nht(): + net = get_topogen().net print("\n\n**** Test that nexthop tracking is at least nominally working ****\n") thisDir = os.path.dirname(os.path.realpath(__file__)) @@ -1188,7 +1168,7 @@ def test_nht(): def test_bgp_ipv4(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1258,7 +1238,7 @@ def test_bgp_ipv4(): def test_bgp_ipv6(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1327,7 +1307,7 @@ def test_bgp_ipv6(): def test_route_map(): global fatal_error - global net + net = get_topogen().net if fatal_error != "": pytest.skip(fatal_error) @@ -1370,7 +1350,7 @@ def test_route_map(): def test_nexthop_groups_with_route_maps(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1467,7 +1447,7 @@ def test_nexthop_groups_with_route_maps(): def test_nexthop_group_replace(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1500,7 +1480,7 @@ def test_nexthop_group_replace(): def test_mpls_interfaces(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1569,7 +1549,7 @@ def test_mpls_interfaces(): def test_shutdown_check_stderr(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -1632,7 +1612,7 @@ def test_shutdown_check_stderr(): def test_shutdown_check_memleak(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": diff --git a/tests/topotests/bfd_topo2/test_bfd_topo2.py b/tests/topotests/bfd_topo2/test_bfd_topo2.py index 00431ea1ff..57ce0cdf09 100644 --- a/tests/topotests/bfd_topo2/test_bfd_topo2.py +++ b/tests/topotests/bfd_topo2/test_bfd_topo2.py @@ -46,28 +46,6 @@ from lib.topolog import logger pytestmark = [pytest.mark.bfdd, pytest.mark.bgpd, pytest.mark.ospfd] -def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # Create 4 routers. - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) - - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r4"]) - - - def setup_module(mod): "Sets up the pytest environment" topodef = { @@ -76,7 +54,6 @@ def setup_module(mod): "s3": ("r2", "r4"), } tgen = Topogen(topodef, mod.__name__) - # tgen = Topogen(build, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py b/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py index 125cc183c5..06b20c4430 100644 --- a/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py +++ b/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py @@ -49,33 +49,27 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bfdd, pytest.mark.bgpd] -class BFDTopo(Topo): - "Test topology builder" +def build_topo(tgen): + # Create 4 routers + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - # Create 4 routers - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) - - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r4"]) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r4"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(BFDTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_aggregate_address_origin/test_bgp_aggregate-address_origin.py b/tests/topotests/bgp_aggregate_address_origin/test_bgp_aggregate-address_origin.py index 4fa6828efc..517154987e 100644 --- a/tests/topotests/bgp_aggregate_address_origin/test_bgp_aggregate-address_origin.py +++ b/tests/topotests/bgp_aggregate_address_origin/test_bgp_aggregate-address_origin.py @@ -50,20 +50,17 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_aggregate_address_route_map/test_bgp_aggregate-address_route-map.py b/tests/topotests/bgp_aggregate_address_route_map/test_bgp_aggregate-address_route-map.py index f4b9889545..74c9e83ce0 100644 --- a/tests/topotests/bgp_aggregate_address_route_map/test_bgp_aggregate-address_route-map.py +++ b/tests/topotests/bgp_aggregate_address_route_map/test_bgp_aggregate-address_route-map.py @@ -53,20 +53,17 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_aggregate_address_topo1/test_bgp_aggregate_address_topo1.py b/tests/topotests/bgp_aggregate_address_topo1/test_bgp_aggregate_address_topo1.py index 6566a860bc..4e82a61e11 100644 --- a/tests/topotests/bgp_aggregate_address_topo1/test_bgp_aggregate_address_topo1.py +++ b/tests/topotests/bgp_aggregate_address_topo1/test_bgp_aggregate_address_topo1.py @@ -45,27 +45,25 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class BgpAggregateAddressTopo1(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) - r1 = tgen.add_router("r1") - r2 = tgen.add_router("r2") - peer1 = tgen.add_exabgp_peer( - "peer1", ip="10.0.0.2", defaultRoute="via 10.0.0.1" - ) +def build_topo(tgen): + r1 = tgen.add_router("r1") + r2 = tgen.add_router("r2") + peer1 = tgen.add_exabgp_peer( + "peer1", ip="10.0.0.2", defaultRoute="via 10.0.0.1" + ) - switch = tgen.add_switch("s1") - switch.add_link(r1) - switch.add_link(peer1) + switch = tgen.add_switch("s1") + switch.add_link(r1) + switch.add_link(peer1) - switch = tgen.add_switch("s2") - switch.add_link(r1) - switch.add_link(r2) + switch = tgen.add_switch("s2") + switch.add_link(r1) + switch.add_link(r2) def setup_module(mod): - tgen = Topogen(BgpAggregateAddressTopo1, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router = tgen.gears["r1"] diff --git a/tests/topotests/bgp_aggregator_zero/test_bgp_aggregator_zero.py b/tests/topotests/bgp_aggregator_zero/test_bgp_aggregator_zero.py index 99c31a355b..76eafbce4e 100644 --- a/tests/topotests/bgp_aggregator_zero/test_bgp_aggregator_zero.py +++ b/tests/topotests/bgp_aggregator_zero/test_bgp_aggregator_zero.py @@ -43,22 +43,19 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class BgpAggregatorAsnZero(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + r1 = tgen.add_router("r1") + peer1 = tgen.add_exabgp_peer( + "peer1", ip="10.0.0.2", defaultRoute="via 10.0.0.1" + ) - r1 = tgen.add_router("r1") - peer1 = tgen.add_exabgp_peer( - "peer1", ip="10.0.0.2", defaultRoute="via 10.0.0.1" - ) - - switch = tgen.add_switch("s1") - switch.add_link(r1) - switch.add_link(peer1) + switch = tgen.add_switch("s1") + switch.add_link(r1) + switch.add_link(peer1) def setup_module(mod): - tgen = Topogen(BgpAggregatorAsnZero, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router = tgen.gears["r1"] diff --git a/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py b/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py index 4c0142fd03..5613b75d7a 100644 --- a/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py +++ b/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py @@ -94,19 +94,11 @@ NETWORK = {"ipv4": "2.2.2.2/32", "ipv6": "22:22::2/128"} NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"} -class BGPALLOWASIN(Topo): - """ - Test BGPALLOWASIN - topology 1 +def build_topo(tgen): + """Build function""" - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) + # Building topology from json file + build_topo_from_json(tgen, topo) def setup_module(mod): @@ -128,7 +120,7 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(BGPALLOWASIN, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py b/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py index 046f3f80a3..2f7a9cc587 100644 --- a/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py +++ b/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py @@ -48,21 +48,18 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 4): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 4): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_aspath_zero/test_bgp_aspath_zero.py b/tests/topotests/bgp_aspath_zero/test_bgp_aspath_zero.py index 3c264a7da0..875ff38d83 100644 --- a/tests/topotests/bgp_aspath_zero/test_bgp_aspath_zero.py +++ b/tests/topotests/bgp_aspath_zero/test_bgp_aspath_zero.py @@ -43,22 +43,19 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class BgpAggregatorAsnZero(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + r1 = tgen.add_router("r1") + peer1 = tgen.add_exabgp_peer( + "peer1", ip="10.0.0.2", defaultRoute="via 10.0.0.1" + ) - r1 = tgen.add_router("r1") - peer1 = tgen.add_exabgp_peer( - "peer1", ip="10.0.0.2", defaultRoute="via 10.0.0.1" - ) - - switch = tgen.add_switch("s1") - switch.add_link(r1) - switch.add_link(peer1) + switch = tgen.add_switch("s1") + switch.add_link(r1) + switch.add_link(peer1) def setup_module(mod): - tgen = Topogen(BgpAggregatorAsnZero, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router = tgen.gears["r1"] diff --git a/tests/topotests/bgp_auth/test_bgp_auth.py b/tests/topotests/bgp_auth/test_bgp_auth.py index b13f3d6e23..48ba0cca58 100644 --- a/tests/topotests/bgp_auth/test_bgp_auth.py +++ b/tests/topotests/bgp_auth/test_bgp_auth.py @@ -74,76 +74,64 @@ pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd] class InvalidCLIError(Exception): """Raise when the CLI command is wrong""" - pass +def build_topo(tgen): + # Create routers + tgen.add_router("R1") + tgen.add_router("R2") + tgen.add_router("R3") -class TemplateTopo(Topo): - "Test topology builder" + # R1-R2 1 + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["R1"]) + switch.add_link(tgen.gears["R2"]) - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # R1-R3 1 + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["R1"]) + switch.add_link(tgen.gears["R3"]) - # This function only purpose is to define allocation and relationship - # between routers, switches and hosts. - # - # - # Create routers - tgen.add_router("R1") - tgen.add_router("R2") - tgen.add_router("R3") + # R2-R3 1 + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["R2"]) + switch.add_link(tgen.gears["R3"]) - # R1-R2 1 - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["R1"]) - switch.add_link(tgen.gears["R2"]) + # R1-R2 2 + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["R1"]) + switch.add_link(tgen.gears["R2"]) - # R1-R3 1 - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["R1"]) - switch.add_link(tgen.gears["R3"]) + # R1-R3 2 + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["R1"]) + switch.add_link(tgen.gears["R3"]) - # R2-R3 1 - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["R2"]) - switch.add_link(tgen.gears["R3"]) + # R2-R3 2 + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["R2"]) + switch.add_link(tgen.gears["R3"]) - # R1-R2 2 - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["R1"]) - switch.add_link(tgen.gears["R2"]) + # R1-R2 3 + switch = tgen.add_switch("s7") + switch.add_link(tgen.gears["R1"]) + switch.add_link(tgen.gears["R2"]) - # R1-R3 2 - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["R1"]) - switch.add_link(tgen.gears["R3"]) + # R1-R3 2 + switch = tgen.add_switch("s8") + switch.add_link(tgen.gears["R1"]) + switch.add_link(tgen.gears["R3"]) - # R2-R3 2 - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["R2"]) - switch.add_link(tgen.gears["R3"]) - - # R1-R2 3 - switch = tgen.add_switch("s7") - switch.add_link(tgen.gears["R1"]) - switch.add_link(tgen.gears["R2"]) - - # R1-R3 2 - switch = tgen.add_switch("s8") - switch.add_link(tgen.gears["R1"]) - switch.add_link(tgen.gears["R3"]) - - # R2-R3 2 - switch = tgen.add_switch("s9") - switch.add_link(tgen.gears["R2"]) - switch.add_link(tgen.gears["R3"]) + # R2-R3 2 + switch = tgen.add_switch("s9") + switch.add_link(tgen.gears["R2"]) + switch.add_link(tgen.gears["R3"]) def setup_module(mod): "Sets up the pytest environment" # This function initiates the topology build with Topogen... - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) # ... and here it calls Mininet initialization functions. tgen.start_topology() diff --git a/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py b/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py index b9ad57f8bc..ee241b653a 100644 --- a/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py +++ b/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py @@ -79,13 +79,6 @@ from lib.topolog import logger pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology creation -jsonFile = "{}/bgp_basic_functionality.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) # Global Variable KEEPALIVETIMER = 2 @@ -104,21 +97,6 @@ NETWORK = { } -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -138,7 +116,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/bgp_basic_functionality.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py b/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py index 7e78722da3..aaa65004f1 100644 --- a/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py +++ b/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py @@ -43,28 +43,25 @@ from lib.common_config import step pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) - - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r4"]) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r4"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_comm_list_delete/test_bgp_comm-list_delete.py b/tests/topotests/bgp_comm_list_delete/test_bgp_comm-list_delete.py index 2c1546a3bf..2524756168 100644 --- a/tests/topotests/bgp_comm_list_delete/test_bgp_comm-list_delete.py +++ b/tests/topotests/bgp_comm_list_delete/test_bgp_comm-list_delete.py @@ -48,20 +48,17 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_communities_topo1/test_bgp_communities.py b/tests/topotests/bgp_communities_topo1/test_bgp_communities.py index df579bc012..be0d87d22e 100644 --- a/tests/topotests/bgp_communities_topo1/test_bgp_communities.py +++ b/tests/topotests/bgp_communities_topo1/test_bgp_communities.py @@ -69,14 +69,6 @@ from copy import deepcopy pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology creation -jsonFile = "{}/bgp_communities.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - # Global variables BGP_CONVERGENCE = False ADDR_TYPES = check_address_types() @@ -84,21 +76,6 @@ NETWORK = {"ipv4": "2.2.2.2/32", "ipv6": "22:22::2/128"} NEXT_HOP_IP = {} -class BGPCOMMUNITIES(Topo): - """ - Test BGPCOMMUNITIES - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -118,7 +95,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(BGPCOMMUNITIES, mod.__name__) + json_file = "{}/bgp_communities.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py b/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py index d18e65bd66..80bcae6312 100644 --- a/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py +++ b/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py @@ -73,14 +73,6 @@ from copy import deepcopy pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology creation -jsonFile = "{}/bgp_communities_topo2.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - # Global variables BGP_CONVERGENCE = False ADDR_TYPES = check_address_types() @@ -90,21 +82,6 @@ NETWORK = { } -class BGPCOMMUNITIES(Topo): - """ - Test BGPCOMMUNITIES - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -124,7 +101,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(BGPCOMMUNITIES, mod.__name__) + json_file = "{}/bgp_communities_topo2.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_community_alias/test_bgp-community-alias.py b/tests/topotests/bgp_community_alias/test_bgp-community-alias.py index 2ef30249e7..cc81660298 100644 --- a/tests/topotests/bgp_community_alias/test_bgp-community-alias.py +++ b/tests/topotests/bgp_community_alias/test_bgp-community-alias.py @@ -43,20 +43,18 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_community_change_update/test_bgp_community_change_update.py b/tests/topotests/bgp_community_change_update/test_bgp_community_change_update.py index eee9294df4..472a0b9557 100644 --- a/tests/topotests/bgp_community_change_update/test_bgp_community_change_update.py +++ b/tests/topotests/bgp_community_change_update/test_bgp_community_change_update.py @@ -62,55 +62,52 @@ from time import sleep pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + tgen.add_router("z1") + tgen.add_router("y1") + tgen.add_router("y2") + tgen.add_router("y3") + tgen.add_router("x1") + tgen.add_router("c1") - tgen.add_router("z1") - tgen.add_router("y1") - tgen.add_router("y2") - tgen.add_router("y3") - tgen.add_router("x1") - tgen.add_router("c1") + # 10.0.1.0/30 + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["c1"]) + switch.add_link(tgen.gears["x1"]) - # 10.0.1.0/30 - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["c1"]) - switch.add_link(tgen.gears["x1"]) + # 10.0.2.0/30 + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["x1"]) + switch.add_link(tgen.gears["y1"]) - # 10.0.2.0/30 - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["x1"]) - switch.add_link(tgen.gears["y1"]) + # 10.0.3.0/30 + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["y1"]) + switch.add_link(tgen.gears["y2"]) - # 10.0.3.0/30 - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["y1"]) - switch.add_link(tgen.gears["y2"]) + # 10.0.4.0/30 + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["y1"]) + switch.add_link(tgen.gears["y3"]) - # 10.0.4.0/30 - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["y1"]) - switch.add_link(tgen.gears["y3"]) + # 10.0.5.0/30 + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["y2"]) + switch.add_link(tgen.gears["y3"]) - # 10.0.5.0/30 - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["y2"]) - switch.add_link(tgen.gears["y3"]) + # 10.0.6.0/30 + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["y2"]) + switch.add_link(tgen.gears["z1"]) - # 10.0.6.0/30 - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["y2"]) - switch.add_link(tgen.gears["z1"]) - - # 10.0.7.0/30 - switch = tgen.add_switch("s7") - switch.add_link(tgen.gears["y3"]) - switch.add_link(tgen.gears["z1"]) + # 10.0.7.0/30 + switch = tgen.add_switch("s7") + switch.add_link(tgen.gears["y3"]) + switch.add_link(tgen.gears["z1"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py b/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py index 9e020ae86e..02fcd5445a 100644 --- a/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py +++ b/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py @@ -142,21 +142,18 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class BgpConditionalAdvertisementTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + r1 = tgen.add_router("r1") + r2 = tgen.add_router("r2") + r3 = tgen.add_router("r3") - r1 = tgen.add_router("r1") - r2 = tgen.add_router("r2") - r3 = tgen.add_router("r3") + switch = tgen.add_switch("s1") + switch.add_link(r1) + switch.add_link(r2) - switch = tgen.add_switch("s1") - switch.add_link(r1) - switch.add_link(r2) - - switch = tgen.add_switch("s2") - switch.add_link(r2) - switch.add_link(r3) + switch = tgen.add_switch("s2") + switch.add_link(r2) + switch.add_link(r3) def setup_module(mod): @@ -166,7 +163,7 @@ def setup_module(mod): logger.info("Running setup_module to create topology") - tgen = Topogen(BgpConditionalAdvertisementTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_default_afi_safi/test_bgp-default-afi-safi.py b/tests/topotests/bgp_default_afi_safi/test_bgp-default-afi-safi.py index a22cd94063..4bcf2ebb46 100644 --- a/tests/topotests/bgp_default_afi_safi/test_bgp-default-afi-safi.py +++ b/tests/topotests/bgp_default_afi_safi/test_bgp-default-afi-safi.py @@ -50,22 +50,20 @@ from lib.common_config import step pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) +def build_topo(tgen): + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) - switch.add_link(tgen.gears["r4"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_default_route/test_bgp_default-originate.py b/tests/topotests/bgp_default_route/test_bgp_default-originate.py index 68d9c52f45..9da8d0a491 100644 --- a/tests/topotests/bgp_default_route/test_bgp_default-originate.py +++ b/tests/topotests/bgp_default_route/test_bgp_default-originate.py @@ -41,20 +41,17 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_default_route_route_map_match/test_bgp_default-originate_route-map_match.py b/tests/topotests/bgp_default_route_route_map_match/test_bgp_default-originate_route-map_match.py index 11a26570f8..e6298dd782 100644 --- a/tests/topotests/bgp_default_route_route_map_match/test_bgp_default-originate_route-map_match.py +++ b/tests/topotests/bgp_default_route_route_map_match/test_bgp_default-originate_route-map_match.py @@ -41,20 +41,17 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_default_route_route_map_match2/test_bgp_default-originate_route-map_match2.py b/tests/topotests/bgp_default_route_route_map_match2/test_bgp_default-originate_route-map_match2.py index f8c36f6324..8f23cf25b5 100644 --- a/tests/topotests/bgp_default_route_route_map_match2/test_bgp_default-originate_route-map_match2.py +++ b/tests/topotests/bgp_default_route_route_map_match2/test_bgp_default-originate_route-map_match2.py @@ -44,20 +44,17 @@ from lib.common_config import step pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py b/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py index 3735fcfb3c..728819525a 100644 --- a/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py +++ b/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py @@ -43,20 +43,17 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py b/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py index 05f14f3525..4be98c08f6 100644 --- a/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py +++ b/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py @@ -41,20 +41,17 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_disable_addpath_rx/r1/bgpd.conf b/tests/topotests/bgp_disable_addpath_rx/r1/bgpd.conf index 1f3352131b..af1353e0e0 100644 --- a/tests/topotests/bgp_disable_addpath_rx/r1/bgpd.conf +++ b/tests/topotests/bgp_disable_addpath_rx/r1/bgpd.conf @@ -1,7 +1,9 @@ ! router bgp 65001 + timers 3 10 no bgp ebgp-requires-policy neighbor 192.168.1.2 remote-as external + neighbor 192.168.1.2 timers connect 5 address-family ipv4 unicast neighbor 192.168.1.2 disable-addpath-rx exit-address-family diff --git a/tests/topotests/bgp_disable_addpath_rx/r2/bgpd.conf b/tests/topotests/bgp_disable_addpath_rx/r2/bgpd.conf index 92d95003e9..db68e554d4 100644 --- a/tests/topotests/bgp_disable_addpath_rx/r2/bgpd.conf +++ b/tests/topotests/bgp_disable_addpath_rx/r2/bgpd.conf @@ -1,8 +1,12 @@ router bgp 65002 + timers 3 10 no bgp ebgp-requires-policy neighbor 192.168.1.1 remote-as external + neighbor 192.168.1.1 timers connect 5 neighbor 192.168.2.3 remote-as external + neighbor 192.168.2.3 timers connect 5 neighbor 192.168.2.4 remote-as external + neighbor 192.168.2.4 timers connect 5 address-family ipv4 unicast neighbor 192.168.1.1 addpath-tx-all-paths exit-address-family diff --git a/tests/topotests/bgp_disable_addpath_rx/r3/bgpd.conf b/tests/topotests/bgp_disable_addpath_rx/r3/bgpd.conf index f5731a1089..3ac6a08e47 100644 --- a/tests/topotests/bgp_disable_addpath_rx/r3/bgpd.conf +++ b/tests/topotests/bgp_disable_addpath_rx/r3/bgpd.conf @@ -1,6 +1,8 @@ router bgp 65003 + timers 3 10 no bgp ebgp-requires-policy neighbor 192.168.2.2 remote-as external + neighbor 192.168.2.2 timers connect 5 address-family ipv4 unicast redistribute connected exit-address-family diff --git a/tests/topotests/bgp_disable_addpath_rx/r4/bgpd.conf b/tests/topotests/bgp_disable_addpath_rx/r4/bgpd.conf index 527b8d3486..8ab405fbd8 100644 --- a/tests/topotests/bgp_disable_addpath_rx/r4/bgpd.conf +++ b/tests/topotests/bgp_disable_addpath_rx/r4/bgpd.conf @@ -1,6 +1,8 @@ router bgp 65004 + timers 3 10 no bgp ebgp-requires-policy neighbor 192.168.2.2 remote-as external + neighbor 192.168.2.2 timers connect 5 address-family ipv4 unicast redistribute connected exit-address-family diff --git a/tests/topotests/bgp_disable_addpath_rx/test_disable_addpath_rx.py b/tests/topotests/bgp_disable_addpath_rx/test_disable_addpath_rx.py index 2126d62262..ed88d5df22 100644 --- a/tests/topotests/bgp_disable_addpath_rx/test_disable_addpath_rx.py +++ b/tests/topotests/bgp_disable_addpath_rx/test_disable_addpath_rx.py @@ -25,7 +25,6 @@ Test if AddPath RX direction is not negotiated via AddPath capability. import os import sys import json -import time import pytest import functools @@ -35,32 +34,27 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from mininet.topo import Topo from lib.common_config import step pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) - switch.add_link(tgen.gears["r4"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_distance_change/test_bgp_distance_change.py b/tests/topotests/bgp_distance_change/test_bgp_distance_change.py index 2583db01e1..9af237986f 100644 --- a/tests/topotests/bgp_distance_change/test_bgp_distance_change.py +++ b/tests/topotests/bgp_distance_change/test_bgp_distance_change.py @@ -52,20 +52,17 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_ebgp_common_subnet_nexthop_unchanged/test_bgp-ebgp-common-subnet-nexthop-unchanged.py b/tests/topotests/bgp_ebgp_common_subnet_nexthop_unchanged/test_bgp-ebgp-common-subnet-nexthop-unchanged.py index 9460d6bae9..c0886de856 100644 --- a/tests/topotests/bgp_ebgp_common_subnet_nexthop_unchanged/test_bgp-ebgp-common-subnet-nexthop-unchanged.py +++ b/tests/topotests/bgp_ebgp_common_subnet_nexthop_unchanged/test_bgp-ebgp-common-subnet-nexthop-unchanged.py @@ -54,21 +54,19 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) - for routern in range(1, 4): - tgen.add_router("r{}".format(routern)) +def build_topo(tgen): + for routern in range(1, 4): + tgen.add_router("r{}".format(routern)) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py b/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py index 390c8b2901..4f33e81248 100644 --- a/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py +++ b/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py @@ -60,31 +60,29 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) - for routern in range(1, 7): - tgen.add_router("r{}".format(routern)) +def build_topo(tgen): + for routern in range(1, 7): + tgen.add_router("r{}".format(routern)) - # Scenario 1. - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + # Scenario 1. + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - # Scenario 2. - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r3"]) - switch.add_link(tgen.gears["r4"]) + # Scenario 2. + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) - # Scenario 3. - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r5"]) - switch.add_link(tgen.gears["r6"]) + # Scenario 3. + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r5"]) + switch.add_link(tgen.gears["r6"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py b/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py index 841a766197..66714fd2f3 100644 --- a/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py +++ b/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py @@ -58,32 +58,26 @@ total_ebgp_peers = 20 ##################################################### -class BGPECMPTopo1(Topo): - "BGP ECMP Topology 1" +def build_topo(tgen): + router = tgen.add_router("r1") - def build(self, **_opts): - tgen = get_topogen(self) + # Setup Switches - 1 switch per 5 peering routers + for swNum in range(1, (total_ebgp_peers + 4) // 5 + 1): + switch = tgen.add_switch("s{}".format(swNum)) + switch.add_link(router) - # Create the BGP router - router = tgen.add_router("r1") + # Add 'total_ebgp_peers' number of eBGP ExaBGP neighbors + for peerNum in range(1, total_ebgp_peers + 1): + swNum = (peerNum - 1) // 5 + 1 - # Setup Switches - 1 switch per 5 peering routers - for swNum in range(1, (total_ebgp_peers + 4) / 5 + 1): - switch = tgen.add_switch("s{}".format(swNum)) - switch.add_link(router) + peer_ip = "10.0.{}.{}".format(swNum, peerNum + 100) + peer_route = "via 10.0.{}.1".format(swNum) + peer = tgen.add_exabgp_peer( + "peer{}".format(peerNum), ip=peer_ip, defaultRoute=peer_route + ) - # Add 'total_ebgp_peers' number of eBGP ExaBGP neighbors - for peerNum in range(1, total_ebgp_peers + 1): - swNum = (peerNum - 1) / 5 + 1 - - peer_ip = "10.0.{}.{}".format(swNum, peerNum + 100) - peer_route = "via 10.0.{}.1".format(swNum) - peer = tgen.add_exabgp_peer( - "peer{}".format(peerNum), ip=peer_ip, defaultRoute=peer_route - ) - - switch = tgen.gears["s{}".format(swNum)] - switch.add_link(peer) + switch = tgen.gears["s{}".format(swNum)] + switch.add_link(peer) ##################################################### @@ -94,7 +88,7 @@ class BGPECMPTopo1(Topo): def setup_module(module): - tgen = Topogen(BGPECMPTopo1, module.__name__) + tgen = Topogen(build_topo, module.__name__) tgen.start_topology() # Starting Routers diff --git a/tests/topotests/bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py b/tests/topotests/bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py index 7bc3d2912d..a82ed8ec8c 100644 --- a/tests/topotests/bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py +++ b/tests/topotests/bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py @@ -71,14 +71,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology and configuration creation -jsonFile = "{}/ebgp_ecmp_topo2.json".format(CWD) - -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) # Global variables NEXT_HOPS = {"ipv4": [], "ipv6": []} @@ -89,21 +81,6 @@ NEXT_HOP_IP = {"ipv4": "10.0.0.1", "ipv6": "fd00::1"} BGP_CONVERGENCE = False -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment. @@ -125,7 +102,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ebgp_ecmp_topo2.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers diff --git a/tests/topotests/bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py b/tests/topotests/bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py index 15982dad55..561ba0edf7 100644 --- a/tests/topotests/bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py +++ b/tests/topotests/bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py @@ -71,14 +71,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology and configuration creation -jsonFile = "{}/ibgp_ecmp_topo2.json".format(CWD) - -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) # Global variables NEXT_HOPS = {"ipv4": [], "ipv6": []} @@ -89,21 +81,6 @@ NEXT_HOP_IP = {"ipv4": "10.0.0.1", "ipv6": "fd00::1"} BGP_CONVERGENCE = False -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment. @@ -125,7 +102,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ibgp_ecmp_topo2.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers diff --git a/tests/topotests/bgp_ecmp_topo3/test_ibgp_ecmp_topo3.py b/tests/topotests/bgp_ecmp_topo3/test_ibgp_ecmp_topo3.py index 5f3ac4e716..66ebe5b58e 100644 --- a/tests/topotests/bgp_ecmp_topo3/test_ibgp_ecmp_topo3.py +++ b/tests/topotests/bgp_ecmp_topo3/test_ibgp_ecmp_topo3.py @@ -40,7 +40,7 @@ sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo +from lib import topojson from lib.common_config import ( start_topology, @@ -63,15 +63,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology and configuration creation -jsonFile = "{}/ibgp_ecmp_topo3.json".format(CWD) - -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - # Global variables NEXT_HOPS = {"ipv4": [], "ipv6": []} NETWORK = {"ipv4": "192.168.1.10/32", "ipv6": "fd00:0:0:1::10/128"} @@ -79,45 +70,20 @@ NEXT_HOP_IP = {"ipv4": "10.0.0.1", "ipv6": "fd00::1"} BGP_CONVERGENCE = False -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment. * `mod`: module name """ - global NEXT_HOPS, INTF_LIST_R3, INTF_LIST_R2, TEST_STATIC global ADDR_TYPES testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) - logger.info("Running setup_module to create topology") - - # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) - - # Starting topology, create tmp files which are loaded to routers - # to start deamons and then start routers - start_topology(tgen) - - # Creating configuration from JSON - build_config_from_json(tgen, topo) + tgen = topojson.setup_module_from_json(mod.__file__) + topo = tgen.json_topo # Don't run this test if we have any failure. if tgen.routers_have_failure(): @@ -136,18 +102,7 @@ def setup_module(mod): def teardown_module(): - """ - Teardown the pytest environment. - - * `mod`: module name - """ - - logger.info("Running teardown_module to delete topology") - - tgen = get_topogen() - - # Stop toplogy and Remove tmp files - tgen.stop_topology() + get_topogen().stop_topology() def static_or_nw(tgen, topo, tc_name, test_type, dut): @@ -221,12 +176,11 @@ def static_or_nw(tgen, topo, tc_name, test_type, dut): @pytest.mark.parametrize("test_type", ["redist_static"]) -def test_ecmp_fast_convergence(request, test_type): +def test_ecmp_fast_convergence(request, test_type, tgen, topo): """This test is to verify bgp fast-convergence cli functionality""" tc_name = request.node.name write_test_header(tc_name) - tgen = get_topogen() # Verifying RIB routes dut = "r3" diff --git a/tests/topotests/bgp_evpn_mh/test_evpn_mh.py b/tests/topotests/bgp_evpn_mh/test_evpn_mh.py index 8cdf3529dd..bad4da116a 100644 --- a/tests/topotests/bgp_evpn_mh/test_evpn_mh.py +++ b/tests/topotests/bgp_evpn_mh/test_evpn_mh.py @@ -62,7 +62,7 @@ pytestmark = [pytest.mark.bgpd, pytest.mark.pimd] ##################################################### -class NetworkTopo(Topo): +def build_topo(tgen): """ EVPN Multihoming Topology - 1. Two level CLOS @@ -71,110 +71,105 @@ class NetworkTopo(Topo): 4. Two dual attached hosts per-rack - hostdx1, hostdx2 """ - def build(self, **_opts): - "Build function" + tgen.add_router("spine1") + tgen.add_router("spine2") + tgen.add_router("torm11") + tgen.add_router("torm12") + tgen.add_router("torm21") + tgen.add_router("torm22") + tgen.add_router("hostd11") + tgen.add_router("hostd12") + tgen.add_router("hostd21") + tgen.add_router("hostd22") - tgen = get_topogen(self) + # On main router + # First switch is for a dummy interface (for local network) - tgen.add_router("spine1") - tgen.add_router("spine2") - tgen.add_router("torm11") - tgen.add_router("torm12") - tgen.add_router("torm21") - tgen.add_router("torm22") - tgen.add_router("hostd11") - tgen.add_router("hostd12") - tgen.add_router("hostd21") - tgen.add_router("hostd22") + ##################### spine1 ######################## + # spine1-eth0 is connected to torm11-eth0 + switch = tgen.add_switch("sw1") + switch.add_link(tgen.gears["spine1"]) + switch.add_link(tgen.gears["torm11"]) - # On main router - # First switch is for a dummy interface (for local network) + # spine1-eth1 is connected to torm12-eth0 + switch = tgen.add_switch("sw2") + switch.add_link(tgen.gears["spine1"]) + switch.add_link(tgen.gears["torm12"]) - ##################### spine1 ######################## - # spine1-eth0 is connected to torm11-eth0 - switch = tgen.add_switch("sw1") - switch.add_link(tgen.gears["spine1"]) - switch.add_link(tgen.gears["torm11"]) + # spine1-eth2 is connected to torm21-eth0 + switch = tgen.add_switch("sw3") + switch.add_link(tgen.gears["spine1"]) + switch.add_link(tgen.gears["torm21"]) - # spine1-eth1 is connected to torm12-eth0 - switch = tgen.add_switch("sw2") - switch.add_link(tgen.gears["spine1"]) - switch.add_link(tgen.gears["torm12"]) + # spine1-eth3 is connected to torm22-eth0 + switch = tgen.add_switch("sw4") + switch.add_link(tgen.gears["spine1"]) + switch.add_link(tgen.gears["torm22"]) - # spine1-eth2 is connected to torm21-eth0 - switch = tgen.add_switch("sw3") - switch.add_link(tgen.gears["spine1"]) - switch.add_link(tgen.gears["torm21"]) + ##################### spine2 ######################## + # spine2-eth0 is connected to torm11-eth1 + switch = tgen.add_switch("sw5") + switch.add_link(tgen.gears["spine2"]) + switch.add_link(tgen.gears["torm11"]) - # spine1-eth3 is connected to torm22-eth0 - switch = tgen.add_switch("sw4") - switch.add_link(tgen.gears["spine1"]) - switch.add_link(tgen.gears["torm22"]) + # spine2-eth1 is connected to torm12-eth1 + switch = tgen.add_switch("sw6") + switch.add_link(tgen.gears["spine2"]) + switch.add_link(tgen.gears["torm12"]) - ##################### spine2 ######################## - # spine2-eth0 is connected to torm11-eth1 - switch = tgen.add_switch("sw5") - switch.add_link(tgen.gears["spine2"]) - switch.add_link(tgen.gears["torm11"]) + # spine2-eth2 is connected to torm21-eth1 + switch = tgen.add_switch("sw7") + switch.add_link(tgen.gears["spine2"]) + switch.add_link(tgen.gears["torm21"]) - # spine2-eth1 is connected to torm12-eth1 - switch = tgen.add_switch("sw6") - switch.add_link(tgen.gears["spine2"]) - switch.add_link(tgen.gears["torm12"]) + # spine2-eth3 is connected to torm22-eth1 + switch = tgen.add_switch("sw8") + switch.add_link(tgen.gears["spine2"]) + switch.add_link(tgen.gears["torm22"]) - # spine2-eth2 is connected to torm21-eth1 - switch = tgen.add_switch("sw7") - switch.add_link(tgen.gears["spine2"]) - switch.add_link(tgen.gears["torm21"]) + ##################### torm11 ######################## + # torm11-eth2 is connected to hostd11-eth0 + switch = tgen.add_switch("sw9") + switch.add_link(tgen.gears["torm11"]) + switch.add_link(tgen.gears["hostd11"]) - # spine2-eth3 is connected to torm22-eth1 - switch = tgen.add_switch("sw8") - switch.add_link(tgen.gears["spine2"]) - switch.add_link(tgen.gears["torm22"]) + # torm11-eth3 is connected to hostd12-eth0 + switch = tgen.add_switch("sw10") + switch.add_link(tgen.gears["torm11"]) + switch.add_link(tgen.gears["hostd12"]) - ##################### torm11 ######################## - # torm11-eth2 is connected to hostd11-eth0 - switch = tgen.add_switch("sw9") - switch.add_link(tgen.gears["torm11"]) - switch.add_link(tgen.gears["hostd11"]) + ##################### torm12 ######################## + # torm12-eth2 is connected to hostd11-eth1 + switch = tgen.add_switch("sw11") + switch.add_link(tgen.gears["torm12"]) + switch.add_link(tgen.gears["hostd11"]) - # torm11-eth3 is connected to hostd12-eth0 - switch = tgen.add_switch("sw10") - switch.add_link(tgen.gears["torm11"]) - switch.add_link(tgen.gears["hostd12"]) + # torm12-eth3 is connected to hostd12-eth1 + switch = tgen.add_switch("sw12") + switch.add_link(tgen.gears["torm12"]) + switch.add_link(tgen.gears["hostd12"]) - ##################### torm12 ######################## - # torm12-eth2 is connected to hostd11-eth1 - switch = tgen.add_switch("sw11") - switch.add_link(tgen.gears["torm12"]) - switch.add_link(tgen.gears["hostd11"]) + ##################### torm21 ######################## + # torm21-eth2 is connected to hostd21-eth0 + switch = tgen.add_switch("sw13") + switch.add_link(tgen.gears["torm21"]) + switch.add_link(tgen.gears["hostd21"]) - # torm12-eth3 is connected to hostd12-eth1 - switch = tgen.add_switch("sw12") - switch.add_link(tgen.gears["torm12"]) - switch.add_link(tgen.gears["hostd12"]) + # torm21-eth3 is connected to hostd22-eth0 + switch = tgen.add_switch("sw14") + switch.add_link(tgen.gears["torm21"]) + switch.add_link(tgen.gears["hostd22"]) - ##################### torm21 ######################## - # torm21-eth2 is connected to hostd21-eth0 - switch = tgen.add_switch("sw13") - switch.add_link(tgen.gears["torm21"]) - switch.add_link(tgen.gears["hostd21"]) + ##################### torm22 ######################## + # torm22-eth2 is connected to hostd21-eth1 + switch = tgen.add_switch("sw15") + switch.add_link(tgen.gears["torm22"]) + switch.add_link(tgen.gears["hostd21"]) - # torm21-eth3 is connected to hostd22-eth0 - switch = tgen.add_switch("sw14") - switch.add_link(tgen.gears["torm21"]) - switch.add_link(tgen.gears["hostd22"]) - - ##################### torm22 ######################## - # torm22-eth2 is connected to hostd21-eth1 - switch = tgen.add_switch("sw15") - switch.add_link(tgen.gears["torm22"]) - switch.add_link(tgen.gears["hostd21"]) - - # torm22-eth3 is connected to hostd22-eth1 - switch = tgen.add_switch("sw16") - switch.add_link(tgen.gears["torm22"]) - switch.add_link(tgen.gears["hostd22"]) + # torm22-eth3 is connected to hostd22-eth1 + switch = tgen.add_switch("sw16") + switch.add_link(tgen.gears["torm22"]) + switch.add_link(tgen.gears["hostd22"]) ##################################################### @@ -371,7 +366,7 @@ def config_hosts(tgen, hosts): def setup_module(module): "Setup topology" - tgen = Topogen(NetworkTopo, module.__name__) + tgen = Topogen(build_topo, module.__name__) tgen.start_topology() krel = platform.release() diff --git a/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py b/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py index 7a53173dca..20459adbdb 100755 --- a/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py +++ b/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py @@ -88,29 +88,23 @@ HOST_SUFFIX = {'host1': '1', 'host2': '2'} TRIGGERS = ["base", "no_rt5", "no_rt2"] -class TemplateTopo(Topo): - """Test topology builder""" +def build_topo(tgen): + # This function only purpose is to define allocation and relationship + # between routers and add links. - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) + # Create routers + for pe in PES: + tgen.add_router(pe) + for host in HOSTS: + tgen.add_router(host) - # This function only purpose is to define allocation and relationship - # between routers and add links. + krel = platform.release() + logger.info('Kernel version ' + krel) - # Create routers - for pe in PES: - tgen.add_router(pe) - for host in HOSTS: - tgen.add_router(host) - - krel = platform.release() - logger.info('Kernel version ' + krel) - - #Add links - tgen.add_link(tgen.gears['PE1'], tgen.gears['PE2'], 'PE1-eth0', 'PE2-eth0') - tgen.add_link(tgen.gears['PE1'], tgen.gears['host1'], 'PE1-eth1', 'host1-eth0') - tgen.add_link(tgen.gears['PE2'], tgen.gears['host2'], 'PE2-eth1', 'host2-eth0') + #Add links + tgen.add_link(tgen.gears['PE1'], tgen.gears['PE2'], 'PE1-eth0', 'PE2-eth0') + tgen.add_link(tgen.gears['PE1'], tgen.gears['host1'], 'PE1-eth1', 'host1-eth0') + tgen.add_link(tgen.gears['PE2'], tgen.gears['host2'], 'PE2-eth1', 'host2-eth0') def setup_module(mod): @@ -123,7 +117,7 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) # ... and here it calls Mininet initialization functions. kernelv = platform.release() diff --git a/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py b/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py index 02e67b70c0..98411938c4 100644 --- a/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py +++ b/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py @@ -48,31 +48,28 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class BGPEVPNTopo(Topo): - "Test topology builder" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) +def build_topo(tgen): + "Build function" - tgen.add_router("r1") - tgen.add_router("r2") + tgen.add_router("r1") + tgen.add_router("r2") - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r1"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r1"]) - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(BGPEVPNTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py b/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py index 0380ac07d0..d300561e1f 100755 --- a/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py +++ b/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py @@ -49,49 +49,45 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd] -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # This function only purpose is to define allocation and relationship + # between routers, switches and hosts. + # + # + # Create routers + tgen.add_router("P1") + tgen.add_router("PE1") + tgen.add_router("PE2") + tgen.add_router("host1") + tgen.add_router("host2") - # This function only purpose is to define allocation and relationship - # between routers, switches and hosts. - # - # - # Create routers - tgen.add_router("P1") - tgen.add_router("PE1") - tgen.add_router("PE2") - tgen.add_router("host1") - tgen.add_router("host2") + # Host1-PE1 + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["host1"]) + switch.add_link(tgen.gears["PE1"]) - # Host1-PE1 - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["host1"]) - switch.add_link(tgen.gears["PE1"]) + # PE1-P1 + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["PE1"]) + switch.add_link(tgen.gears["P1"]) - # PE1-P1 - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["PE1"]) - switch.add_link(tgen.gears["P1"]) + # P1-PE2 + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["P1"]) + switch.add_link(tgen.gears["PE2"]) - # P1-PE2 - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["P1"]) - switch.add_link(tgen.gears["PE2"]) - - # PE2-host2 - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["PE2"]) - switch.add_link(tgen.gears["host2"]) + # PE2-host2 + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["PE2"]) + switch.add_link(tgen.gears["host2"]) def setup_module(mod): "Sets up the pytest environment" # This function initiates the topology build with Topogen... - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) # ... and here it calls Mininet initialization functions. tgen.start_topology() diff --git a/tests/topotests/bgp_features/test_bgp_features.py b/tests/topotests/bgp_features/test_bgp_features.py index 54f61f92e5..f2e09fb010 100644 --- a/tests/topotests/bgp_features/test_bgp_features.py +++ b/tests/topotests/bgp_features/test_bgp_features.py @@ -56,40 +56,48 @@ pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd] ##################################################### -class BGPFeaturesTopo1(Topo): - "BGP Features Topology 1" +def build_topo(tgen): + for rtrNum in range(1, 6): + tgen.add_router("r{}".format(rtrNum)) - def build(self, **_opts): - tgen = get_topogen(self) + # create ExaBGP peers + for peer_num in range(1, 5): + tgen.add_exabgp_peer( + "peer{}".format(peer_num), + ip="192.168.101.{}".format(peer_num + 2), + defaultRoute="via 192.168.101.1", + ) - # Create the routers - for rtrNum in range(1, 6): - tgen.add_router("r{}".format(rtrNum)) + # Setup Switches and connections + for swNum in range(1, 11): + tgen.add_switch("sw{}".format(swNum)) - # Setup Switches and connections - for swNum in range(1, 11): - tgen.add_switch("sw{}".format(swNum)) + # Add connections to stub switches + tgen.gears["r1"].add_link(tgen.gears["sw6"]) + tgen.gears["r2"].add_link(tgen.gears["sw7"]) + tgen.gears["r3"].add_link(tgen.gears["sw8"]) + tgen.gears["r4"].add_link(tgen.gears["sw9"]) + tgen.gears["r5"].add_link(tgen.gears["sw10"]) - # Add connections to stub switches - tgen.gears["r1"].add_link(tgen.gears["sw6"]) - tgen.gears["r2"].add_link(tgen.gears["sw7"]) - tgen.gears["r3"].add_link(tgen.gears["sw8"]) - tgen.gears["r4"].add_link(tgen.gears["sw9"]) - tgen.gears["r5"].add_link(tgen.gears["sw10"]) + # Add connections to R1-R2-R3 core + tgen.gears["r1"].add_link(tgen.gears["sw1"]) + tgen.gears["r1"].add_link(tgen.gears["sw3"]) + tgen.gears["r2"].add_link(tgen.gears["sw1"]) + tgen.gears["r2"].add_link(tgen.gears["sw2"]) + tgen.gears["r3"].add_link(tgen.gears["sw2"]) + tgen.gears["r3"].add_link(tgen.gears["sw3"]) - # Add connections to R1-R2-R3 core - tgen.gears["r1"].add_link(tgen.gears["sw1"]) - tgen.gears["r1"].add_link(tgen.gears["sw3"]) - tgen.gears["r2"].add_link(tgen.gears["sw1"]) - tgen.gears["r2"].add_link(tgen.gears["sw2"]) - tgen.gears["r3"].add_link(tgen.gears["sw2"]) - tgen.gears["r3"].add_link(tgen.gears["sw3"]) + # Add connections to external R4/R5 Routers + tgen.gears["r1"].add_link(tgen.gears["sw4"]) + tgen.gears["r4"].add_link(tgen.gears["sw4"]) + tgen.gears["r2"].add_link(tgen.gears["sw5"]) + tgen.gears["r5"].add_link(tgen.gears["sw5"]) - # Add connections to external R4/R5 Routers - tgen.gears["r1"].add_link(tgen.gears["sw4"]) - tgen.gears["r4"].add_link(tgen.gears["sw4"]) - tgen.gears["r2"].add_link(tgen.gears["sw5"]) - tgen.gears["r5"].add_link(tgen.gears["sw5"]) + # Add ExaBGP peers to sw4 + tgen.gears["peer1"].add_link(tgen.gears["sw4"]) + tgen.gears["peer2"].add_link(tgen.gears["sw4"]) + tgen.gears["peer3"].add_link(tgen.gears["sw4"]) + tgen.gears["peer4"].add_link(tgen.gears["sw4"]) ##################################################### @@ -100,7 +108,7 @@ class BGPFeaturesTopo1(Topo): def setup_module(module): - tgen = Topogen(BGPFeaturesTopo1, module.__name__) + tgen = Topogen(build_topo, module.__name__) tgen.start_topology() # Starting Routers diff --git a/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py b/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py index 6a12ed80d3..05ea944ebf 100644 --- a/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py +++ b/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py @@ -82,24 +82,18 @@ pytestmark = [pytest.mark.bgpd] ##################################################### -class BGPFLOWSPECTopo1(Topo): - "BGP EBGP Flowspec Topology 1" +def build_topo(tgen): + tgen.add_router("r1") - def build(self, **_opts): - tgen = get_topogen(self) + # Setup Control Path Switch 1. r1-eth0 + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) - # Setup Routers - tgen.add_router("r1") - - # Setup Control Path Switch 1. r1-eth0 - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - - ## Add eBGP ExaBGP neighbors - peer_ip = "10.0.1.101" ## peer - peer_route = "via 10.0.1.1" ## router - peer = tgen.add_exabgp_peer("peer1", ip=peer_ip, defaultRoute=peer_route) - switch.add_link(peer) + ## Add eBGP ExaBGP neighbors + peer_ip = "10.0.1.101" ## peer + peer_route = "via 10.0.1.1" ## router + peer = tgen.add_exabgp_peer("peer1", ip=peer_ip, defaultRoute=peer_route) + switch.add_link(peer) ##################################################### @@ -110,7 +104,7 @@ class BGPFLOWSPECTopo1(Topo): def setup_module(module): - tgen = Topogen(BGPFLOWSPECTopo1, module.__name__) + tgen = Topogen(build_topo, module.__name__) tgen.start_topology() # check for zebra capability diff --git a/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py b/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py index bd3f6209ae..4ee3b97080 100644 --- a/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py +++ b/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py @@ -142,15 +142,6 @@ from lib.common_config import ( pytestmark = [pytest.mark.bgpd] -# Reading the data from JSON File for topology and configuration creation -jsonFile = "{}/bgp_gr_topojson_topo1.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - logger.info("Could not read file:", jsonFile) - - # Global variables NEXT_HOP_IP = {"ipv4": "192.168.1.10", "ipv6": "fd00:0:0:1::10"} NEXT_HOP_IP_1 = {"ipv4": "192.168.0.1", "ipv6": "fd00::1"} @@ -160,28 +151,6 @@ GR_RESTART_TIMER = 20 PREFERRED_NEXT_HOP = "link_local" -class GenerateTopo(Topo): - """ - Test topology builder - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # This function only purpose is to create topology - # as defined in input json file. - # - # Create topology (setup module) - # Creating 2 routers topology, r1, r2in IBGP - # Bring up topology - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -203,7 +172,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(GenerateTopo, mod.__name__) + json_file = "{}/bgp_gr_topojson_topo1.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py b/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py index dd44cbf96d..5fc361f8fe 100644 --- a/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py +++ b/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py @@ -141,14 +141,6 @@ from lib.common_config import ( pytestmark = [pytest.mark.bgpd] -# Reading the data from JSON File for topology and configuration creation -jsonFile = "{}/bgp_gr_topojson_topo2.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - logger.info("Could not read file:", jsonFile) - # Global variables BGP_CONVERGENCE = False GR_RESTART_TIMER = 5 @@ -159,28 +151,6 @@ NEXT_HOP_4 = ["192.168.1.1", "192.168.4.2"] NEXT_HOP_6 = ["fd00:0:0:1::1", "fd00:0:0:4::2"] -class GenerateTopo(Topo): - """ - Test topology builder - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # This function only purpose is to create topology - # as defined in input json file. - # - # Create topology (setup module) - # Creating 2 routers topology, r1, r2in IBGP - # Bring up topology - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -202,7 +172,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(GenerateTopo, mod.__name__) + json_file = "{}/bgp_gr_topojson_topo2.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_gshut/test_bgp_gshut.py b/tests/topotests/bgp_gshut/test_bgp_gshut.py index d32ba1c1f1..a08f74d6c4 100644 --- a/tests/topotests/bgp_gshut/test_bgp_gshut.py +++ b/tests/topotests/bgp_gshut/test_bgp_gshut.py @@ -78,28 +78,25 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 6): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 6): - tgen.add_router("r{}".format(routern)) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r4"]) - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r4"]) - - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r5"]) + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r5"]) def _run_cmd_and_check(router, cmd, results_file, retries=100, intvl=0.5): @@ -110,7 +107,7 @@ def _run_cmd_and_check(router, cmd, results_file, retries=100, intvl=0.5): def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_gshut_topo1/test_ebgp_gshut_topo1.py b/tests/topotests/bgp_gshut_topo1/test_ebgp_gshut_topo1.py index 2595b20996..2bddd9c77f 100644 --- a/tests/topotests/bgp_gshut_topo1/test_ebgp_gshut_topo1.py +++ b/tests/topotests/bgp_gshut_topo1/test_ebgp_gshut_topo1.py @@ -75,17 +75,10 @@ from lib.bgp import ( ) from lib.topojson import build_topo_from_json, build_config_from_json + pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology and configuration creation -jsonFile = "{}/ebgp_gshut_topo1.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - logger.info("Could not read file:", jsonFile) - # Global variables NETWORK = {"ipv4": "100.0.10.1/32", "ipv6": "1::1/128"} NEXT_HOP_IP_1 = {"ipv4": "10.0.2.1", "ipv6": "fd00:0:0:1::1"} @@ -94,28 +87,6 @@ PREFERRED_NEXT_HOP = "link_local" BGP_CONVERGENCE = False -class GenerateTopo(Topo): - """ - Test topology builder - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # This function only purpose is to create topology - # as defined in input json file. - # - # Create topology (setup module) - # Creating 2 routers topology, r1, r2in IBGP - # Bring up topology - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -137,7 +108,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(GenerateTopo, mod.__name__) + json_file = "{}/ebgp_gshut_topo1.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_gshut_topo1/test_ibgp_gshut_topo1.py b/tests/topotests/bgp_gshut_topo1/test_ibgp_gshut_topo1.py index 3f3354dc80..90d285f0f2 100644 --- a/tests/topotests/bgp_gshut_topo1/test_ibgp_gshut_topo1.py +++ b/tests/topotests/bgp_gshut_topo1/test_ibgp_gshut_topo1.py @@ -78,14 +78,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology and configuration creation -jsonFile = "{}/ibgp_gshut_topo1.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - logger.info("Could not read file:", jsonFile) - # Global variables NETWORK = {"ipv4": "100.0.10.1/32", "ipv6": "1::1/128"} NEXT_HOP_IP_1 = {"ipv4": "10.0.3.1", "ipv6": "fd00:0:0:3::1"} @@ -94,28 +86,6 @@ PREFERRED_NEXT_HOP = "link_local" BGP_CONVERGENCE = False -class GenerateTopo(Topo): - """ - Test topology builder - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # This function only purpose is to create topology - # as defined in input json file. - # - # Create topology (setup module) - # Creating 2 routers topology, r1, r2in IBGP - # Bring up topology - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -137,7 +107,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(GenerateTopo, mod.__name__) + json_file = "{}/ibgp_gshut_topo1.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_ibgp_nbr.py b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_ibgp_nbr.py index 4f72cbb300..04945a94a5 100644 --- a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_ibgp_nbr.py +++ b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_ibgp_nbr.py @@ -39,7 +39,6 @@ sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo from lib.common_config import ( start_topology, @@ -66,13 +65,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/rfc5549_ebgp_ibgp_nbr.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) # Global variables NETWORK = { @@ -121,21 +113,6 @@ unchange is configure on EBGP peers """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """Set up the pytest environment.""" @@ -147,7 +124,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/rfc5549_ebgp_ibgp_nbr.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers diff --git a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_nbr.py b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_nbr.py index 12237fec61..f09da23bc4 100644 --- a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_nbr.py +++ b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_nbr.py @@ -40,7 +40,6 @@ sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo from lib.common_config import ( start_topology, @@ -71,13 +70,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/rfc5549_ebgp_nbr.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) # Global variables NETWORK = { @@ -137,21 +129,6 @@ TC32. Verify IPv4 route received with IPv6 nexthop can be advertised to """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """Set up the pytest environment.""" global topo, ADDR_TYPES @@ -163,7 +140,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/rfc5549_ebgp_nbr.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers diff --git a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_unnumbered_nbr.py b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_unnumbered_nbr.py index 2675f3a393..5966ffdedd 100644 --- a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_unnumbered_nbr.py +++ b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_unnumbered_nbr.py @@ -37,7 +37,6 @@ sys.path.append(os.path.join(CWD, "../")) sys.path.append(os.path.join(CWD, "../../")) from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo from lib.common_config import ( write_test_header, @@ -62,13 +61,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/rfc5549_ebgp_unnumbered_nbr.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) # Global variables NO_OF_RTES = 2 @@ -124,21 +116,6 @@ shut / no shut of nexthop and BGP peer interfaces """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """Set up the pytest environment.""" global topo, ADDR_TYPES @@ -150,7 +127,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/rfc5549_ebgp_unnumbered_nbr.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers diff --git a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_nbr.py b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_nbr.py index 871f6b128a..9b5e48e08f 100644 --- a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_nbr.py +++ b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_nbr.py @@ -39,7 +39,6 @@ sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo from lib.common_config import ( start_topology, @@ -67,13 +66,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/rfc5549_ibgp_nbr.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) # Global variables NETWORK = { @@ -121,21 +113,6 @@ TESTCASES = """ """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """Set up the pytest environment.""" @@ -147,7 +124,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/rfc5549_ibgp_nbr.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers diff --git a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_unnumbered_nbr.py b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_unnumbered_nbr.py index 5f4292b81e..5e804df232 100644 --- a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_unnumbered_nbr.py +++ b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_unnumbered_nbr.py @@ -38,7 +38,6 @@ sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from mininet.topo import Topo from lib.common_config import ( start_topology, @@ -58,13 +57,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/rfc5549_ibgp_unnumbered_nbr.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) # Global variables @@ -107,21 +99,6 @@ TESTCASES = """ """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """Set up the pytest environment.""" @@ -133,7 +110,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/rfc5549_ibgp_unnumbered_nbr.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers diff --git a/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py b/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py index dc587cd709..04cf0395d6 100644 --- a/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py +++ b/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py @@ -49,25 +49,21 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class BGPIPV6RTADVTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # Create 2 routers. + tgen.add_router("r1") + tgen.add_router("r2") - # Create 2 routers. - tgen.add_router("r1") - tgen.add_router("r2") - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(BGPIPV6RTADVTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py b/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py index 6eaf8e07f9..f344ee76b0 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py @@ -94,48 +94,44 @@ CWD = os.path.dirname(os.path.realpath(__file__)) TEST = os.path.basename(CWD) -class ThisTestTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # This function only purpose is to define allocation and relationship + # between routers, switches and hosts. + # + # Create P/PE routers + tgen.add_router("r1") + # check for mpls + if tgen.hasmpls != True: + logger.info("MPLS not available, tests will be skipped") + return + for routern in range(2, 5): + tgen.add_router("r{}".format(routern)) + # Create CE routers + for routern in range(1, 4): + tgen.add_router("ce{}".format(routern)) - # This function only purpose is to define allocation and relationship - # between routers, switches and hosts. - # - # Create P/PE routers - tgen.add_router("r1") - # check for mpls - if tgen.hasmpls != True: - logger.info("MPLS not available, tests will be skipped") - return - for routern in range(2, 5): - tgen.add_router("r{}".format(routern)) - # Create CE routers - for routern in range(1, 4): - tgen.add_router("ce{}".format(routern)) + # CE/PE links + tgen.add_link(tgen.gears["ce1"], tgen.gears["r1"], "ce1-eth0", "r1-eth4") + tgen.add_link(tgen.gears["ce2"], tgen.gears["r3"], "ce2-eth0", "r3-eth4") + tgen.add_link(tgen.gears["ce3"], tgen.gears["r4"], "ce3-eth0", "r4-eth4") - # CE/PE links - tgen.add_link(tgen.gears["ce1"], tgen.gears["r1"], "ce1-eth0", "r1-eth4") - tgen.add_link(tgen.gears["ce2"], tgen.gears["r3"], "ce2-eth0", "r3-eth4") - tgen.add_link(tgen.gears["ce3"], tgen.gears["r4"], "ce3-eth0", "r4-eth4") + # Create a switch with just one router connected to it to simulate a + # empty network. + switch = {} + switch[0] = tgen.add_switch("sw0") + switch[0].add_link(tgen.gears["r1"], nodeif="r1-eth0") + switch[0].add_link(tgen.gears["r2"], nodeif="r2-eth0") - # Create a switch with just one router connected to it to simulate a - # empty network. - switch = {} - switch[0] = tgen.add_switch("sw0") - switch[0].add_link(tgen.gears["r1"], nodeif="r1-eth0") - switch[0].add_link(tgen.gears["r2"], nodeif="r2-eth0") + switch[1] = tgen.add_switch("sw1") + switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth1") + switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth0") + switch[1].add_link(tgen.gears["r4"], nodeif="r4-eth0") - switch[1] = tgen.add_switch("sw1") - switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth1") - switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth0") - switch[1].add_link(tgen.gears["r4"], nodeif="r4-eth0") - - switch[1] = tgen.add_switch("sw2") - switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth2") - switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth1") + switch[1] = tgen.add_switch("sw2") + switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth2") + switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth1") def ltemplatePreRouterStartHook(): diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py index 40009b9ba9..91291d89e3 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py @@ -95,54 +95,50 @@ CWD = os.path.dirname(os.path.realpath(__file__)) TEST = os.path.basename(CWD) -class ThisTestTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # This function only purpose is to define allocation and relationship + # between routers, switches and hosts. + # + # Create P/PE routers + # check for mpls + tgen.add_router("r1") + if tgen.hasmpls != True: + logger.info("MPLS not available, tests will be skipped") + return + mach = platform.machine() + krel = platform.release() + if mach[:1] == "a" and topotest.version_cmp(krel, "4.11") < 0: + logger.info("Need Kernel version 4.11 to run on arm processor") + return + for routern in range(2, 5): + tgen.add_router("r{}".format(routern)) + # Create CE routers + for routern in range(1, 5): + tgen.add_router("ce{}".format(routern)) - # This function only purpose is to define allocation and relationship - # between routers, switches and hosts. - # - # Create P/PE routers - # check for mpls - tgen.add_router("r1") - if tgen.hasmpls != True: - logger.info("MPLS not available, tests will be skipped") - return - mach = platform.machine() - krel = platform.release() - if mach[:1] == "a" and topotest.version_cmp(krel, "4.11") < 0: - logger.info("Need Kernel version 4.11 to run on arm processor") - return - for routern in range(2, 5): - tgen.add_router("r{}".format(routern)) - # Create CE routers - for routern in range(1, 5): - tgen.add_router("ce{}".format(routern)) + # CE/PE links + tgen.add_link(tgen.gears["ce1"], tgen.gears["r1"], "ce1-eth0", "r1-eth4") + tgen.add_link(tgen.gears["ce2"], tgen.gears["r3"], "ce2-eth0", "r3-eth4") + tgen.add_link(tgen.gears["ce3"], tgen.gears["r4"], "ce3-eth0", "r4-eth4") + tgen.add_link(tgen.gears["ce4"], tgen.gears["r4"], "ce4-eth0", "r4-eth5") - # CE/PE links - tgen.add_link(tgen.gears["ce1"], tgen.gears["r1"], "ce1-eth0", "r1-eth4") - tgen.add_link(tgen.gears["ce2"], tgen.gears["r3"], "ce2-eth0", "r3-eth4") - tgen.add_link(tgen.gears["ce3"], tgen.gears["r4"], "ce3-eth0", "r4-eth4") - tgen.add_link(tgen.gears["ce4"], tgen.gears["r4"], "ce4-eth0", "r4-eth5") + # Create a switch with just one router connected to it to simulate a + # empty network. + switch = {} + switch[0] = tgen.add_switch("sw0") + switch[0].add_link(tgen.gears["r1"], nodeif="r1-eth0") + switch[0].add_link(tgen.gears["r2"], nodeif="r2-eth0") - # Create a switch with just one router connected to it to simulate a - # empty network. - switch = {} - switch[0] = tgen.add_switch("sw0") - switch[0].add_link(tgen.gears["r1"], nodeif="r1-eth0") - switch[0].add_link(tgen.gears["r2"], nodeif="r2-eth0") + switch[1] = tgen.add_switch("sw1") + switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth1") + switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth0") + switch[1].add_link(tgen.gears["r4"], nodeif="r4-eth0") - switch[1] = tgen.add_switch("sw1") - switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth1") - switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth0") - switch[1].add_link(tgen.gears["r4"], nodeif="r4-eth0") - - switch[1] = tgen.add_switch("sw2") - switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth2") - switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth1") + switch[1] = tgen.add_switch("sw2") + switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth2") + switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth1") def ltemplatePreRouterStartHook(): diff --git a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py index d138a689e2..fb472c4495 100644 --- a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py +++ b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py @@ -81,13 +81,6 @@ CWD = os_path.dirname(os_path.realpath(__file__)) sys.path.append(os_path.join(CWD, "../")) sys.path.append(os_path.join(CWD, "../lib/")) -# Reading the data from JSON File for topology and configuration creation -jsonFile = "{}/bgp_large_community_topo_1.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json_load(topoJson) -except IOError: - logger.info("Could not read file:", jsonFile) # Global variables bgp_convergence = False @@ -124,22 +117,6 @@ STANDARD_COMM = { } -class CreateTopo(Topo): - """ - Test topology builder - - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -159,7 +136,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/bgp_large_community_topo_1.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py index c9115bf42b..a94d20da36 100644 --- a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py +++ b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py @@ -97,39 +97,16 @@ from lib.topolog import logger from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify from lib.topojson import build_topo_from_json, build_config_from_json + pytestmark = [pytest.mark.bgpd] -# Reading the data from JSON File for topology and configuration creation -jsonFile = "{}/bgp_large_community_topo_2.json".format(CWD) - -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - # Global variables bgp_convergence = False NETWORKS = {"ipv4": ["200.50.2.0/32"], "ipv6": ["1::1/128"]} -class GenerateTopo(Topo): - """ - Test topology builder - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -149,7 +126,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(GenerateTopo, mod.__name__) + json_file = "{}/bgp_large_community_topo_2.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py b/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py index 4ad1dbcaa6..799b5f93f1 100644 --- a/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py +++ b/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py @@ -66,62 +66,57 @@ this scenario, the servers are also routers as they have to announce anycast IP (VIP) addresses via BGP. """ +def build_topo(tgen): + "Build function" -class BgpLinkBwTopo(Topo): - "Test topology builder" + # Create 10 routers - 1 super-spine, 2 spines, 3 leafs + # and 4 servers + routers = {} + for i in range(1, 11): + routers[i] = tgen.add_router("r{}".format(i)) - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # Create 13 "switches" - to interconnect the above routers + switches = {} + for i in range(1, 14): + switches[i] = tgen.add_switch("s{}".format(i)) - # Create 10 routers - 1 super-spine, 2 spines, 3 leafs - # and 4 servers - routers = {} - for i in range(1, 11): - routers[i] = tgen.add_router("r{}".format(i)) + # Interconnect R1 (super-spine) to R2 and R3 (the two spines) + switches[1].add_link(tgen.gears["r1"]) + switches[1].add_link(tgen.gears["r2"]) + switches[2].add_link(tgen.gears["r1"]) + switches[2].add_link(tgen.gears["r3"]) - # Create 13 "switches" - to interconnect the above routers - switches = {} - for i in range(1, 14): - switches[i] = tgen.add_switch("s{}".format(i)) + # Interconnect R2 (spine in pod-1) to R4 and R5 (the associated + # leaf switches) + switches[3].add_link(tgen.gears["r2"]) + switches[3].add_link(tgen.gears["r4"]) + switches[4].add_link(tgen.gears["r2"]) + switches[4].add_link(tgen.gears["r5"]) - # Interconnect R1 (super-spine) to R2 and R3 (the two spines) - switches[1].add_link(tgen.gears["r1"]) - switches[1].add_link(tgen.gears["r2"]) - switches[2].add_link(tgen.gears["r1"]) - switches[2].add_link(tgen.gears["r3"]) + # Interconnect R3 (spine in pod-2) to R6 (associated leaf) + switches[5].add_link(tgen.gears["r3"]) + switches[5].add_link(tgen.gears["r6"]) - # Interconnect R2 (spine in pod-1) to R4 and R5 (the associated - # leaf switches) - switches[3].add_link(tgen.gears["r2"]) - switches[3].add_link(tgen.gears["r4"]) - switches[4].add_link(tgen.gears["r2"]) - switches[4].add_link(tgen.gears["r5"]) + # Interconnect leaf switches to servers + switches[6].add_link(tgen.gears["r4"]) + switches[6].add_link(tgen.gears["r7"]) + switches[7].add_link(tgen.gears["r4"]) + switches[7].add_link(tgen.gears["r8"]) + switches[8].add_link(tgen.gears["r5"]) + switches[8].add_link(tgen.gears["r9"]) + switches[9].add_link(tgen.gears["r6"]) + switches[9].add_link(tgen.gears["r10"]) - # Interconnect R3 (spine in pod-2) to R6 (associated leaf) - switches[5].add_link(tgen.gears["r3"]) - switches[5].add_link(tgen.gears["r6"]) - - # Interconnect leaf switches to servers - switches[6].add_link(tgen.gears["r4"]) - switches[6].add_link(tgen.gears["r7"]) - switches[7].add_link(tgen.gears["r4"]) - switches[7].add_link(tgen.gears["r8"]) - switches[8].add_link(tgen.gears["r5"]) - switches[8].add_link(tgen.gears["r9"]) - switches[9].add_link(tgen.gears["r6"]) - switches[9].add_link(tgen.gears["r10"]) - - # Create empty networks for the servers - switches[10].add_link(tgen.gears["r7"]) - switches[11].add_link(tgen.gears["r8"]) - switches[12].add_link(tgen.gears["r9"]) - switches[13].add_link(tgen.gears["r10"]) + # Create empty networks for the servers + switches[10].add_link(tgen.gears["r7"]) + switches[11].add_link(tgen.gears["r8"]) + switches[12].add_link(tgen.gears["r9"]) + switches[13].add_link(tgen.gears["r10"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(BgpLinkBwTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_listen_on_multiple_addresses/test_bgp_listen_on_multiple_addresses.py b/tests/topotests/bgp_listen_on_multiple_addresses/test_bgp_listen_on_multiple_addresses.py index fdbc5e553b..bc4336b6f3 100755 --- a/tests/topotests/bgp_listen_on_multiple_addresses/test_bgp_listen_on_multiple_addresses.py +++ b/tests/topotests/bgp_listen_on_multiple_addresses/test_bgp_listen_on_multiple_addresses.py @@ -67,27 +67,12 @@ LISTEN_ADDRESSES = { } -# Reads data from JSON File for topology and configuration creation. -jsonFile = "{}/bgp_listen_on_multiple_addresses.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - - -class TemplateTopo(Topo): - "Topology builder." - - def build(self, *_args, **_opts): - "Defines the allocation and relationship between routers and switches." - tgen = get_topogen(self) - build_topo_from_json(tgen, topo) - - def setup_module(mod): "Sets up the test environment." - tgen = Topogen(TemplateTopo, mod.__name__) + json_file = "{}/bgp_listen_on_multiple_addresses.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # Adds extra parameters to bgpd so they listen for connections on specific # multiple addresses. diff --git a/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py b/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py index ec4919650e..f648e1791f 100644 --- a/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py +++ b/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py @@ -46,24 +46,21 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r3"]) - switch.add_link(tgen.gears["r4"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_lu_topo1/test_bgp_lu.py b/tests/topotests/bgp_lu_topo1/test_bgp_lu.py index 258ddb148d..6318044eaa 100644 --- a/tests/topotests/bgp_lu_topo1/test_bgp_lu.py +++ b/tests/topotests/bgp_lu_topo1/test_bgp_lu.py @@ -62,37 +62,33 @@ pytestmark = [pytest.mark.bgpd] # +-----+ +-----+ +-----+ -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # This function only purpose is to define allocation and relationship + # between routers, switches and hosts. + # + # + # Create routers + tgen.add_router("R1") + tgen.add_router("R2") + tgen.add_router("R3") - # This function only purpose is to define allocation and relationship - # between routers, switches and hosts. - # - # - # Create routers - tgen.add_router("R1") - tgen.add_router("R2") - tgen.add_router("R3") + # R1-R2 + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["R1"]) + switch.add_link(tgen.gears["R2"]) - # R1-R2 - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["R1"]) - switch.add_link(tgen.gears["R2"]) - - # R2-R3 - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["R2"]) - switch.add_link(tgen.gears["R3"]) + # R2-R3 + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["R2"]) + switch.add_link(tgen.gears["R3"]) def setup_module(mod): "Sets up the pytest environment" # This function initiates the topology build with Topogen... - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) # ... and here it calls Mininet initialization functions. tgen.start_topology() diff --git a/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py b/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py index c800946840..66fcd355ee 100644 --- a/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py +++ b/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py @@ -50,20 +50,17 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py b/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py index 5b762bfe52..07d1cb02b1 100644 --- a/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py +++ b/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py @@ -46,20 +46,17 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_minimum_holdtime/test_bgp_minimum_holdtime.py b/tests/topotests/bgp_minimum_holdtime/test_bgp_minimum_holdtime.py index c5afcdf112..5facdd26ea 100755 --- a/tests/topotests/bgp_minimum_holdtime/test_bgp_minimum_holdtime.py +++ b/tests/topotests/bgp_minimum_holdtime/test_bgp_minimum_holdtime.py @@ -41,20 +41,17 @@ from mininet.topo import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py b/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py index 9a20f7d451..ffa1c3fb61 100644 --- a/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py +++ b/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py @@ -145,15 +145,9 @@ from lib.bgp import ( ) from lib.topojson import build_topo_from_json, build_config_from_json -pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology creation -jsonFile = "{}/bgp_multi_vrf_topo1.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) +pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] + # Global variables NETWORK1_1 = {"ipv4": "1.1.1.1/32", "ipv6": "1::1/128"} @@ -185,21 +179,6 @@ LOOPBACK_2 = { } -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -222,7 +201,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/bgp_multi_vrf_topo1.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py b/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py index 7fd9fac6ef..609fdf3587 100644 --- a/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py +++ b/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py @@ -105,14 +105,6 @@ from lib.topojson import build_config_from_json, build_topo_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology creation -jsonFile = "{}/bgp_multi_vrf_topo2.json".format(CWD) - -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) # Global variables NETWORK1_1 = {"ipv4": "1.1.1.1/32", "ipv6": "1::1/128"} @@ -139,21 +131,6 @@ HOLDDOWNTIMER = 3 PREFERRED_NEXT_HOP = "link_local" -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -176,7 +153,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/bgp_multi_vrf_topo2.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py index a949c5282c..25240791ce 100644 --- a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py +++ b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py @@ -74,8 +74,7 @@ from functools import partial sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lib import topotest -from lib.micronet_compat import Mininet -from lib.micronet_compat import Topo +from lib.topogen import get_topogen, Topogen pytestmark = [pytest.mark.bgpd] @@ -91,38 +90,28 @@ fatal_error = "" ##################################################### -class NetworkTopo(Topo): - "BGP Multiview Topology 1" +def build_topo(tgen): + # Setup Routers + router = tgen.add_router("r1") - def build(self, **_opts): + # Setup Provider BGP peers + peer = {} + for i in range(1, 9): + peer[i] = tgen.add_exabgp_peer( + "peer%s" % i, + ip="172.16.1.%s/24" % i, + defaultRoute="via 172.16.1.254" + ) - exabgpPrivateDirs = ["/etc/exabgp", "/var/run/exabgp", "/var/log"] + # First switch is for a dummy interface (for local network) + switch = tgen.add_switch("sw0") + switch.add_link(router, nodeif="r1-stub") - # Setup Routers - router = {} - for i in range(1, 2): - router[i] = topotest.addRouter(self, "r%s" % i) - - # Setup Provider BGP peers - peer = {} - for i in range(1, 9): - peer[i] = self.addHost( - "peer%s" % i, - ip="172.16.1.%s/24" % i, - defaultRoute="via 172.16.1.254", - privateDirs=exabgpPrivateDirs, - ) - - # Setup Switches - switch = {} - # First switch is for a dummy interface (for local network) - switch[0] = self.addSwitch("sw0") - self.addLink(switch[0], router[1], intfName2="r1-stub") - # Second switch is for connection to all peering routers - switch[1] = self.addSwitch("sw1") - self.addLink(switch[1], router[1], intfName2="r1-eth0") - for j in range(1, 9): - self.addLink(switch[1], peer[j], intfName2="peer%s-eth0" % j) + # Second switch is for connection to all peering routers + switch = tgen.add_switch("sw1") + switch.add_link(router, nodeif="r1-eth0") + for j in range(1, 9): + switch.add_link(peer[j], nodeif="peer%s-eth0" % j) ##################################################### @@ -133,87 +122,43 @@ class NetworkTopo(Topo): def setup_module(module): - global topo, net - - print("\n\n** %s: Setup Topology" % module.__name__) - print("******************************************\n") - - print("Cleanup old Mininet runs") - os.system("sudo mn -c > /dev/null 2>&1") - thisDir = os.path.dirname(os.path.realpath(__file__)) - topo = NetworkTopo() - - net = Mininet(controller=None, topo=topo) - net.start() + tgen = Topogen(build_topo, module.__name__) + tgen.start_topology() # Starting Routers - for i in range(1, 2): - net["r%s" % i].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir, i)) - net["r%s" % i].loadConf("bgpd", "%s/r%s/bgpd.conf" % (thisDir, i)) - net["r%s" % i].startRouter() + router = tgen.net["r1"] + router.loadConf("zebra", "%s/r1/zebra.conf" % thisDir) + router.loadConf("bgpd", "%s/r1/bgpd.conf" % thisDir) + tgen.gears["r1"].start() # Starting PE Hosts and init ExaBGP on each of them - print("*** Starting BGP on all 8 Peers") - for i in range(1, 9): - net["peer%s" % i].cmd("cp %s/exabgp.env /etc/exabgp/exabgp.env" % thisDir) - net["peer%s" % i].cmd("cp %s/peer%s/* /etc/exabgp/" % (thisDir, i)) - net["peer%s" % i].cmd("chmod 644 /etc/exabgp/*") - net["peer%s" % i].cmd("chmod 755 /etc/exabgp/*.py") - net["peer%s" % i].cmd("chown -R exabgp:exabgp /etc/exabgp") - net["peer%s" % i].cmd("exabgp -e /etc/exabgp/exabgp.env /etc/exabgp/exabgp.cfg") - print("peer%s" % i), - print("") - - # For debugging after starting FRR daemons, uncomment the next line - # CLI(net) + peer_list = tgen.exabgp_peers() + for pname, peer in peer_list.items(): + peer_dir = os.path.join(thisDir, pname) + env_file = os.path.join(thisDir, "exabgp.env") + peer.start(peer_dir, env_file) def teardown_module(module): - global net - - print("\n\n** %s: Shutdown Topology" % module.__name__) - print("******************************************\n") - - # Shutdown - clean up everything - print("*** Killing BGP on Peer routers") - # Killing ExaBGP - for i in range(1, 9): - net["peer%s" % i].cmd("kill `cat /var/run/exabgp/exabgp.pid`") - - # End - Shutdown network - net.stop() + tgen = get_topogen() + tgen.stop_topology() def test_router_running(): - global fatal_error - global net + tgen = get_topogen() - # Skip if previous fatal error condition is raised - if fatal_error != "": - pytest.skip(fatal_error) - - print("\n\n** Check if FRR is running on each Router node") - print("******************************************\n") - - # Starting Routers - for i in range(1, 2): - fatal_error = net["r%s" % i].checkRouterRunning() - assert fatal_error == "", fatal_error - - # For debugging after starting FRR daemons, uncomment the next line - # CLI(net) + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) def test_bgp_converge(): "Check for BGP converged on all peers and BGP views" - global fatal_error - global net + tgen = get_topogen() - # Skip if previous fatal error condition is raised - if fatal_error != "": - pytest.skip(fatal_error) + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) # Wait for BGP to converge (All Neighbors in either Full or TwoWay State) @@ -224,7 +169,7 @@ def test_bgp_converge(): # Look for any node not yet converged for i in range(1, 2): for view in range(1, 4): - notConverged = net["r%s" % i].cmd( + notConverged = tgen.net["r%s" % i].cmd( 'vtysh -c "show ip bgp view %s summary" 2> /dev/null | grep ^[0-9] | grep -vP " 11\s+(\d+)"' % view ) @@ -242,7 +187,7 @@ def test_bgp_converge(): break else: # Bail out with error if a router fails to converge - bgpStatus = net["r%s" % i].cmd('vtysh -c "show ip bgp view %s summary"' % view) + bgpStatus = tgen.net["r%s" % i].cmd('vtysh -c "show ip bgp view %s summary"' % view) assert False, "BGP did not converge:\n%s" % bgpStatus # Wait for an extra 5s to announce all routes @@ -256,53 +201,92 @@ def test_bgp_converge(): # print("\nwaiting 15s for routes to populate") # sleep(15) - # Make sure that all daemons are running - for i in range(1, 2): - fatal_error = net["r%s" % i].checkRouterRunning() - assert fatal_error == "", fatal_error - - # For debugging after starting FRR daemons, uncomment the next line - # CLI(net) + tgen.routers_have_failure() def test_bgp_routingTable(): - global fatal_error - global net - # Skip if previous fatal error condition is raised - if fatal_error != "": - pytest.skip(fatal_error) + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + thisDir = os.path.dirname(os.path.realpath(__file__)) - print("Verifying BGP Routing Tables") - def router_json_cmp(router, cmd, data): - json_data = json.loads(router.cmd("vtysh -c \"{}\" 2> /dev/null".format(cmd))) - return topotest.json_cmp(json_data, data) - router = net["r1"] - for view in range(1, 4): - json_file = "{}/{}/view_{}.json".format(thisDir, router.name, view) - expected = json.loads(open(json_file).read()) - test_func = partial( - router_json_cmp, router, "show ip bgp view {} json".format(view), expected - ) - _, result = topotest.run_and_expect(test_func, None, count=5, wait=1) - assertmsg = "Routing Table verification failed for router {}, view {}".format( - router.name, view - ) - assert result is None, assertmsg - # Make sure that all daemons are running + + print("\n\n** Verifying BGP Routing Tables") + print("******************************************\n") + diffresult = {} for i in range(1, 2): - fatal_error = net["r%s" % i].checkRouterRunning() - assert fatal_error == "", fatal_error - # For debugging after starting FRR daemons, uncomment the next line - # CLI(net) + for view in range(1, 4): + success = 0 + # This glob pattern should work as long as number of views < 10 + for refTableFile in glob.glob( + "%s/r%s/show_ip_bgp_view_%s*.ref" % (thisDir, i, view) + ): + + if os.path.isfile(refTableFile): + # Read expected result from file + expected = open(refTableFile).read().rstrip() + # Fix newlines (make them all the same) + expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) + + # Actual output from router + actual = ( + tgen.net["r%s" % i] + .cmd('vtysh -c "show ip bgp view %s" 2> /dev/null' % view) + .rstrip() + ) + + # Fix inconsitent spaces between 0.99.24 and newer versions + actual = re.sub("0 0", "0 0", actual) + actual = re.sub( + r"([0-9]) 32768", r"\1 32768", actual + ) + # Remove summary line (changed recently) + actual = re.sub(r"Total number.*", "", actual) + actual = re.sub(r"Displayed.*", "", actual) + actual = actual.rstrip() + # Fix table version (ignore it) + actual = re.sub(r"(BGP table version is )[0-9]+", r"\1XXX", actual) + + # Fix newlines (make them all the same) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) + + # Generate Diff + diff = topotest.get_textdiff( + actual, + expected, + title1="actual BGP routing table", + title2="expected BGP routing table", + ) + + if diff: + diffresult[refTableFile] = diff + else: + success = 1 + print("template %s matched: r%s ok" % (refTableFile, i)) + break + + if not success: + resultstr = "No template matched.\n" + for f in diffresult.keys(): + resultstr += ( + "template %s: r%s failed Routing Table Check for view %s:\n%s\n" + % (f, i, view, diffresult[f]) + ) + raise AssertionError( + "Routing Table verification failed for router r%s, view %s:\n%s" + % (i, view, resultstr) + ) + + tgen.routers_have_failure() def test_shutdown_check_stderr(): - global fatal_error - global net + tgen = get_topogen() # Skip if previous fatal error condition is raised - if fatal_error != "": - pytest.skip(fatal_error) + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) if os.environ.get("TOPOTESTS_CHECK_STDERR") is None: print( @@ -315,36 +299,22 @@ def test_shutdown_check_stderr(): print("\n\n** Verifying unexpected STDERR output from daemons") print("******************************************\n") - net["r1"].stopRouter() + tgen.net["r1"].stopRouter() - log = net["r1"].getStdErr("bgpd") + log = tgen.net["r1"].getStdErr("bgpd") if log: print("\nBGPd StdErr Log:\n" + log) - log = net["r1"].getStdErr("zebra") + log = tgen.net["r1"].getStdErr("zebra") if log: print("\nZebra StdErr Log:\n" + log) def test_shutdown_check_memleak(): - global fatal_error - global net + tgen = get_topogen() + if not tgen.is_memleak_enabled(): + pytest.skip("Memory leak test/report is disabled") - # Skip if previous fatal error condition is raised - if fatal_error != "": - pytest.skip(fatal_error) - - if os.environ.get("TOPOTESTS_CHECK_MEMLEAK") is None: - print( - "SKIPPED final check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)\n" - ) - pytest.skip("Skipping test for memory leaks") - - thisDir = os.path.dirname(os.path.realpath(__file__)) - - net["r1"].stopRouter() - net["r1"].report_memory_leaks( - os.environ.get("TOPOTESTS_CHECK_MEMLEAK"), os.path.basename(__file__) - ) + tgen.report_memory_leaks() if __name__ == "__main__": diff --git a/tests/topotests/bgp_path_attributes_topo1/test_bgp_path_attributes.py b/tests/topotests/bgp_path_attributes_topo1/test_bgp_path_attributes.py index 0fc9b7e021..f34ecc30a0 100644 --- a/tests/topotests/bgp_path_attributes_topo1/test_bgp_path_attributes.py +++ b/tests/topotests/bgp_path_attributes_topo1/test_bgp_path_attributes.py @@ -94,37 +94,14 @@ from lib.bgp import ( ) from lib.topojson import build_topo_from_json, build_config_from_json + pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology creation -jsonFile = "{}/bgp_path_attributes.json".format(CWD) - -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - # Address read from env variables ADDR_TYPES = check_address_types() #### -class CreateTopo(Topo): - """ - Test CreateTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # Building topology and configuration from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -141,7 +118,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/bgp_path_attributes.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_peer_group/test_bgp_peer-group.py b/tests/topotests/bgp_peer_group/test_bgp_peer-group.py index 70e49d5cd4..172426b2c8 100644 --- a/tests/topotests/bgp_peer_group/test_bgp_peer-group.py +++ b/tests/topotests/bgp_peer_group/test_bgp_peer-group.py @@ -42,21 +42,18 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 4): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 4): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py b/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py index c5924c787c..4cd14367bf 100755 --- a/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py +++ b/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py @@ -76,32 +76,30 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -class PeerTypeRelaxTopo(Topo): - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) +def build_topo(tgen): + "Build function" - # Set up routers - tgen.add_router("r1") # DUT - tgen.add_router("r2") + # Set up routers + tgen.add_router("r1") # DUT + tgen.add_router("r2") - # Set up peers - for peern in range(1, 5): - peer = tgen.add_exabgp_peer( - "peer{}".format(peern), - ip="10.0.{}.2/24".format(peern), - defaultRoute="via 10.0.{}.1".format(peern), - ) - if peern == 2: - tgen.add_link(tgen.gears["r2"], peer) - else: - tgen.add_link(tgen.gears["r1"], peer) - tgen.add_link(tgen.gears["r1"], tgen.gears["r2"]) + # Set up peers + for peern in range(1, 5): + peer = tgen.add_exabgp_peer( + "peer{}".format(peern), + ip="10.0.{}.2/24".format(peern), + defaultRoute="via 10.0.{}.1".format(peern), + ) + if peern == 2: + tgen.add_link(tgen.gears["r2"], peer) + else: + tgen.add_link(tgen.gears["r1"], peer) + tgen.add_link(tgen.gears["r1"], tgen.gears["r2"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(PeerTypeRelaxTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() # For all registered routers, load the zebra configuration file diff --git a/tests/topotests/bgp_prefix_list_topo1/test_prefix_lists.py b/tests/topotests/bgp_prefix_list_topo1/test_prefix_lists.py index 287ff87bf8..f046f442e0 100644 --- a/tests/topotests/bgp_prefix_list_topo1/test_prefix_lists.py +++ b/tests/topotests/bgp_prefix_list_topo1/test_prefix_lists.py @@ -73,37 +73,14 @@ from lib.topolog import logger from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify from lib.topojson import build_topo_from_json, build_config_from_json + pytestmark = [pytest.mark.bgpd] -# Reading the data from JSON File for topology creation -jsonFile = "{}/prefix_lists.json".format(CWD) - -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - # Global variables bgp_convergence = False -class BGPPrefixListTopo(Topo): - """ - Test BGPPrefixListTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -118,7 +95,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(BGPPrefixListTopo, mod.__name__) + json_file = "{}/prefix_lists.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py index 72df2eab6b..8acf7feae1 100644 --- a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py +++ b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py @@ -44,26 +44,24 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, **_opts): - tgen = get_topogen(self) - router = tgen.add_router("r1") - switch = tgen.add_switch("s1") - switch.add_link(router) +def build_topo(tgen): + router = tgen.add_router("r1") + switch = tgen.add_switch("s1") + switch.add_link(router) - switch = tgen.gears["s1"] - peer1 = tgen.add_exabgp_peer( - "peer1", ip="10.0.0.101", defaultRoute="via 10.0.0.1" - ) - peer2 = tgen.add_exabgp_peer( - "peer2", ip="10.0.0.102", defaultRoute="via 10.0.0.1" - ) - switch.add_link(peer1) - switch.add_link(peer2) + switch = tgen.gears["s1"] + peer1 = tgen.add_exabgp_peer( + "peer1", ip="10.0.0.101", defaultRoute="via 10.0.0.1" + ) + peer2 = tgen.add_exabgp_peer( + "peer2", ip="10.0.0.102", defaultRoute="via 10.0.0.1" + ) + switch.add_link(peer1) + switch.add_link(peer2) def setup_module(module): - tgen = Topogen(TemplateTopo, module.__name__) + tgen = Topogen(build_topo, module.__name__) tgen.start_topology() router = tgen.gears["r1"] diff --git a/tests/topotests/bgp_prefix_sid2/test_bgp_prefix_sid2.py b/tests/topotests/bgp_prefix_sid2/test_bgp_prefix_sid2.py index 6da44faf57..5c85895ed2 100755 --- a/tests/topotests/bgp_prefix_sid2/test_bgp_prefix_sid2.py +++ b/tests/topotests/bgp_prefix_sid2/test_bgp_prefix_sid2.py @@ -44,22 +44,20 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, **_opts): - tgen = get_topogen(self) - router = tgen.add_router("r1") - switch = tgen.add_switch("s1") - switch.add_link(router) +def build_topo(tgen): + router = tgen.add_router("r1") + switch = tgen.add_switch("s1") + switch.add_link(router) - switch = tgen.gears["s1"] - peer1 = tgen.add_exabgp_peer( - "peer1", ip="10.0.0.101", defaultRoute="via 10.0.0.1" - ) - switch.add_link(peer1) + switch = tgen.gears["s1"] + peer1 = tgen.add_exabgp_peer( + "peer1", ip="10.0.0.101", defaultRoute="via 10.0.0.1" + ) + switch.add_link(peer1) def setup_module(module): - tgen = Topogen(TemplateTopo, module.__name__) + tgen = Topogen(build_topo, module.__name__) tgen.start_topology() router = tgen.gears["r1"] diff --git a/tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py b/tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py index 320c7eb78c..918c16e34a 100644 --- a/tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py +++ b/tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py @@ -89,14 +89,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology and configuration creation -jsonFile = "{}/bgp_recursive_route_ebgp_multi_hop.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - logger.info("Could not read file:", jsonFile) - # Global variables BGP_CONVERGENCE = False KEEP_ALIVE_TIMER = 2 @@ -124,21 +116,6 @@ Loopabck_IP = { } -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -153,7 +130,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/bgp_recursive_route_ebgp_multi_hop.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py b/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py index f13b068d96..271db0a7c9 100644 --- a/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py +++ b/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py @@ -53,24 +53,21 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 4): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 4): - tgen.add_router("r{}".format(routern)) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_rfapi_basic_sanity/customize.py b/tests/topotests/bgp_rfapi_basic_sanity/customize.py index 9166c57dfc..3cf53a184d 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/customize.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/customize.py @@ -81,35 +81,31 @@ CWD = os.path.dirname(os.path.realpath(__file__)) TEST = os.path.basename(CWD) -class ThisTestTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # This function only purpose is to define allocation and relationship + # between routers, switches and hosts. + # + # Create P/PE routers + tgen.add_router("r1") + for routern in range(2, 5): + tgen.add_router("r{}".format(routern)) + # Create a switch with just one router connected to it to simulate a + # empty network. + switch = {} + switch[0] = tgen.add_switch("sw0") + switch[0].add_link(tgen.gears["r1"], nodeif="r1-eth0") + switch[0].add_link(tgen.gears["r2"], nodeif="r2-eth0") - # This function only purpose is to define allocation and relationship - # between routers, switches and hosts. - # - # Create P/PE routers - tgen.add_router("r1") - for routern in range(2, 5): - tgen.add_router("r{}".format(routern)) - # Create a switch with just one router connected to it to simulate a - # empty network. - switch = {} - switch[0] = tgen.add_switch("sw0") - switch[0].add_link(tgen.gears["r1"], nodeif="r1-eth0") - switch[0].add_link(tgen.gears["r2"], nodeif="r2-eth0") + switch[1] = tgen.add_switch("sw1") + switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth1") + switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth0") + switch[1].add_link(tgen.gears["r4"], nodeif="r4-eth0") - switch[1] = tgen.add_switch("sw1") - switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth1") - switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth0") - switch[1].add_link(tgen.gears["r4"], nodeif="r4-eth0") - - switch[2] = tgen.add_switch("sw2") - switch[2].add_link(tgen.gears["r2"], nodeif="r2-eth2") - switch[2].add_link(tgen.gears["r3"], nodeif="r3-eth1") + switch[2] = tgen.add_switch("sw2") + switch[2].add_link(tgen.gears["r2"], nodeif="r2-eth2") + switch[2].add_link(tgen.gears["r3"], nodeif="r3-eth1") def ltemplatePreRouterStartHook(): diff --git a/tests/topotests/bgp_rmap_extcommunity_none/test_bgp_rmap_extcommunity_none.py b/tests/topotests/bgp_rmap_extcommunity_none/test_bgp_rmap_extcommunity_none.py index 3c11ba74c1..d2a602f9a2 100644 --- a/tests/topotests/bgp_rmap_extcommunity_none/test_bgp_rmap_extcommunity_none.py +++ b/tests/topotests/bgp_rmap_extcommunity_none/test_bgp_rmap_extcommunity_none.py @@ -41,25 +41,21 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from mininet.topo import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py b/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py index 8297085ffe..007e640f58 100644 --- a/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py +++ b/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py @@ -70,17 +70,9 @@ from lib.bgp import ( ) from lib.topojson import build_topo_from_json, build_config_from_json + pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] - -# Reading the data from JSON File for topology and configuration creation -jsonFile = "{}/bgp_aggregation.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - logger.info("Could not read file:", jsonFile) - # Global variables BGP_CONVERGENCE = False ADDR_TYPES = check_address_types() @@ -113,21 +105,6 @@ COMMUNITY = [ ] -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -142,7 +119,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/bgp_aggregation.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_route_map/test_route_map_topo1.py b/tests/topotests/bgp_route_map/test_route_map_topo1.py index 17058d178b..ba4456e717 100644 --- a/tests/topotests/bgp_route_map/test_route_map_topo1.py +++ b/tests/topotests/bgp_route_map/test_route_map_topo1.py @@ -115,13 +115,6 @@ TC_38: bgp_convergence = False BGP_CONVERGENCE = False ADDR_TYPES = check_address_types() -# Reading the data from JSON File for topology and configuration creation -jsonFile = "{}/bgp_route_map_topo1.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) # Global variables bgp_convergence = False @@ -131,22 +124,6 @@ NEXT_HOP = {"ipv4": "10.0.0.2", "ipv6": "fd00::2"} ADDR_TYPES = check_address_types() -class CreateTopo(Topo): - """ - Test topology builder - - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -161,7 +138,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/bgp_route_map_topo1.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_route_map/test_route_map_topo2.py b/tests/topotests/bgp_route_map/test_route_map_topo2.py index d4b145e817..ca05ba45d9 100644 --- a/tests/topotests/bgp_route_map/test_route_map_topo2.py +++ b/tests/topotests/bgp_route_map/test_route_map_topo2.py @@ -147,18 +147,9 @@ from lib.bgp import ( ) from lib.topojson import build_topo_from_json, build_config_from_json + pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] - -# Reading the data from JSON File for topology and configuration creation -jsonFile = "{}/bgp_route_map_topo2.json".format(CWD) - -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - # Global variables # Global variables bgp_convergence = False @@ -169,21 +160,6 @@ BGP_CONVERGENCE = False ADDR_TYPES = check_address_types() -class BGPRmapTopo(Topo): - """BGPRmapTopo. - - BGPRmap topology 1 - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology and configuration from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """setup_module. @@ -197,7 +173,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(BGPRmapTopo, mod.__name__) + json_file = "{}/bgp_route_map_topo2.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py b/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py index 72c25a3c6f..d40ea2ed85 100644 --- a/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py +++ b/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py @@ -49,48 +49,37 @@ from lib.topolog import logger # Required to instantiate the topology builder class. from lib.micronet_compat import Topo + pytestmark = [pytest.mark.bgpd] -##################################################### -## -## Network Topology Definition -## -##################################################### +def build_topo(tgen): + "Build function" + tgen.add_router("tor1") + tgen.add_router("tor2") + tgen.add_router("spine1") -class NetworkTopo(Topo): - "BGP_RR_IBGP Topology 1" + # First switch is for a dummy interface (for local network) + # on tor1 + # 192.168.1.0/24 + switch = tgen.add_switch("sw1") + switch.add_link(tgen.gears["tor1"]) - def build(self, **_opts): - "Build function" + # 192.168.2.0/24 - tor1 <-> spine1 connection + switch = tgen.add_switch("sw2") + switch.add_link(tgen.gears["tor1"]) + switch.add_link(tgen.gears["spine1"]) - tgen = get_topogen(self) + # 3rd switch is for a dummy interface (for local netwokr) + # 192.168.3.0/24 - tor2 + switch = tgen.add_switch("sw3") + switch.add_link(tgen.gears["tor2"]) - tgen.add_router("tor1") - tgen.add_router("tor2") - tgen.add_router("spine1") - - # First switch is for a dummy interface (for local network) - # on tor1 - # 192.168.1.0/24 - switch = tgen.add_switch("sw1") - switch.add_link(tgen.gears["tor1"]) - - # 192.168.2.0/24 - tor1 <-> spine1 connection - switch = tgen.add_switch("sw2") - switch.add_link(tgen.gears["tor1"]) - switch.add_link(tgen.gears["spine1"]) - - # 3rd switch is for a dummy interface (for local netwokr) - # 192.168.3.0/24 - tor2 - switch = tgen.add_switch("sw3") - switch.add_link(tgen.gears["tor2"]) - - # 192.168.4.0/24 - tor2 <-> spine1 connection - switch = tgen.add_switch("sw4") - switch.add_link(tgen.gears["tor2"]) - switch.add_link(tgen.gears["spine1"]) + # 192.168.4.0/24 - tor2 <-> spine1 connection + switch = tgen.add_switch("sw4") + switch.add_link(tgen.gears["tor2"]) + switch.add_link(tgen.gears["spine1"]) ##################################################### @@ -102,7 +91,7 @@ class NetworkTopo(Topo): def setup_module(module): "Setup topology" - tgen = Topogen(NetworkTopo, module.__name__) + tgen = Topogen(build_topo, module.__name__) tgen.start_topology() # This is a sample of configuration loading. diff --git a/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py b/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py index 526e1202da..9d3c3a7652 100644 --- a/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py +++ b/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py @@ -47,24 +47,21 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 4): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 4): - tgen.add_router("r{}".format(routern)) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_set_local_preference_add_subtract/test_bgp_set_local-preference_add_subtract.py b/tests/topotests/bgp_set_local_preference_add_subtract/test_bgp_set_local-preference_add_subtract.py index 531e1814a5..0ef5f61d97 100644 --- a/tests/topotests/bgp_set_local_preference_add_subtract/test_bgp_set_local-preference_add_subtract.py +++ b/tests/topotests/bgp_set_local_preference_add_subtract/test_bgp_set_local-preference_add_subtract.py @@ -47,21 +47,18 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 4): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 4): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/test_bgp_snmp_mplsvpn.py b/tests/topotests/bgp_snmp_mplsl3vpn/test_bgp_snmp_mplsvpn.py index 37486f1d73..7f58c65ab0 100755 --- a/tests/topotests/bgp_snmp_mplsl3vpn/test_bgp_snmp_mplsvpn.py +++ b/tests/topotests/bgp_snmp_mplsl3vpn/test_bgp_snmp_mplsvpn.py @@ -50,75 +50,71 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.isisd, pytest.mark.snmp] -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # This function only purpose is to define allocation and relationship + # between routers, switches and hosts. + # + # + # Create routers + tgen.add_router("r1") + tgen.add_router("r2") + tgen.add_router("r3") + tgen.add_router("r4") + tgen.add_router("ce1") + tgen.add_router("ce2") + tgen.add_router("ce3") + tgen.add_router("ce4") - # This function only purpose is to define allocation and relationship - # between routers, switches and hosts. - # - # - # Create routers - tgen.add_router("r1") - tgen.add_router("r2") - tgen.add_router("r3") - tgen.add_router("r4") - tgen.add_router("ce1") - tgen.add_router("ce2") - tgen.add_router("ce3") - tgen.add_router("ce4") + # r1-r2 + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - # r1-r2 - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + # r1-r3 + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r3"]) - # r1-r3 - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r3"]) + # r1-r4 + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r4"]) - # r1-r4 - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r4"]) + # r1-ce1 + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["ce1"]) - # r1-ce1 - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["ce1"]) + # r1-ce3 + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["ce3"]) - # r1-ce3 - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["ce3"]) + # r1-ce4 + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["ce4"]) - # r1-ce4 - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["ce4"]) + # r1-dangling + switch = tgen.add_switch("s7") + switch.add_link(tgen.gears["r1"]) - # r1-dangling - switch = tgen.add_switch("s7") - switch.add_link(tgen.gears["r1"]) + # r2-r3 + switch = tgen.add_switch("s8") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - # r2-r3 - switch = tgen.add_switch("s8") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + # r3-r4 + switch = tgen.add_switch("s9") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) - # r3-r4 - switch = tgen.add_switch("s9") - switch.add_link(tgen.gears["r3"]) - switch.add_link(tgen.gears["r4"]) - - # r4-ce2 - switch = tgen.add_switch("s10") - switch.add_link(tgen.gears["r4"]) - switch.add_link(tgen.gears["ce2"]) + # r4-ce2 + switch = tgen.add_switch("s10") + switch.add_link(tgen.gears["r4"]) + switch.add_link(tgen.gears["ce2"]) def setup_module(mod): @@ -131,7 +127,7 @@ def setup_module(mod): pytest.skip(error_msg) # This function initiates the topology build with Topogen... - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) # ... and here it calls Mininet initialization functions. tgen.start_topology() diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py index a50151ab23..60e419ab1c 100755 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py @@ -42,7 +42,7 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class Topology(Topo): +def build_topo(tgen): """ CE1 CE3 CE5 (eth0) (eth0) (eth0) @@ -79,24 +79,22 @@ class Topology(Topo): (eth0) (eth0) (eth0) CE2 CE4 CE6 """ - def build(self, *_args, **_opts): - tgen = get_topogen(self) - tgen.add_router("r1") - tgen.add_router("r2") - tgen.add_router("ce1") - tgen.add_router("ce2") - tgen.add_router("ce3") - tgen.add_router("ce4") - tgen.add_router("ce5") - tgen.add_router("ce6") + tgen.add_router("r1") + tgen.add_router("r2") + tgen.add_router("ce1") + tgen.add_router("ce2") + tgen.add_router("ce3") + tgen.add_router("ce4") + tgen.add_router("ce5") + tgen.add_router("ce6") - tgen.add_link(tgen.gears["r1"], tgen.gears["r2"], "eth0", "eth0") - tgen.add_link(tgen.gears["ce1"], tgen.gears["r1"], "eth0", "eth1") - tgen.add_link(tgen.gears["ce2"], tgen.gears["r2"], "eth0", "eth1") - tgen.add_link(tgen.gears["ce3"], tgen.gears["r1"], "eth0", "eth2") - tgen.add_link(tgen.gears["ce4"], tgen.gears["r2"], "eth0", "eth2") - tgen.add_link(tgen.gears["ce5"], tgen.gears["r1"], "eth0", "eth3") - tgen.add_link(tgen.gears["ce6"], tgen.gears["r2"], "eth0", "eth3") + tgen.add_link(tgen.gears["r1"], tgen.gears["r2"], "eth0", "eth0") + tgen.add_link(tgen.gears["ce1"], tgen.gears["r1"], "eth0", "eth1") + tgen.add_link(tgen.gears["ce2"], tgen.gears["r2"], "eth0", "eth1") + tgen.add_link(tgen.gears["ce3"], tgen.gears["r1"], "eth0", "eth2") + tgen.add_link(tgen.gears["ce4"], tgen.gears["r2"], "eth0", "eth2") + tgen.add_link(tgen.gears["ce5"], tgen.gears["r1"], "eth0", "eth3") + tgen.add_link(tgen.gears["ce6"], tgen.gears["r2"], "eth0", "eth3") def setup_module(mod): @@ -104,7 +102,7 @@ def setup_module(mod): if result is not True: pytest.skip("Kernel requirements are not met") - tgen = Topogen(Topology, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() for rname, router in tgen.routers().items(): diff --git a/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py b/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py index 3e421ad5c1..2c14ad9dee 100644 --- a/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py +++ b/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py @@ -43,24 +43,21 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 4): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 4): - tgen.add_router("r{}".format(routern)) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_tcp_mss/test_bgp_tcp_mss.py b/tests/topotests/bgp_tcp_mss/test_bgp_tcp_mss.py index 7ca30daf42..db90bbd5df 100644 --- a/tests/topotests/bgp_tcp_mss/test_bgp_tcp_mss.py +++ b/tests/topotests/bgp_tcp_mss/test_bgp_tcp_mss.py @@ -54,20 +54,17 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_update_delay/test_bgp_update_delay.py b/tests/topotests/bgp_update_delay/test_bgp_update_delay.py index a936d44d1b..31a887b6c3 100644 --- a/tests/topotests/bgp_update_delay/test_bgp_update_delay.py +++ b/tests/topotests/bgp_update_delay/test_bgp_update_delay.py @@ -76,32 +76,30 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class TemplateTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) +CWD = os.path.dirname(os.path.realpath(__file__)) +def build_topo(tgen): + for routern in range(1, 6): + tgen.add_router("r{}".format(routern)) - for routern in range(1, 6): - tgen.add_router("r{}".format(routern)) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r4"]) - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r4"]) - - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r5"]) + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r5"]) def setup_module(mod): - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py index 63e724cc5c..b2e2250a9c 100644 --- a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py +++ b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py @@ -81,17 +81,9 @@ from lib.bgp import ( ) from lib.topojson import build_topo_from_json, build_config_from_json + pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] - -# Reading the data from JSON File for topology creation -jsonFile = "{}/bgp_vrf_dynamic_route_leak_topo1.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - # Global variables NETWORK1_1 = {"ipv4": "11.11.11.1/32", "ipv6": "11:11::1/128"} NETWORK1_2 = {"ipv4": "11.11.11.11/32", "ipv6": "11:11::11/128"} @@ -125,21 +117,6 @@ LOOPBACK_2 = { PREFERRED_NEXT_HOP = "global" -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -147,7 +124,6 @@ def setup_module(mod): * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -155,7 +131,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/bgp_vrf_dynamic_route_leak_topo1.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py index 1241a37cf7..8e3e32fc8f 100644 --- a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py +++ b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py @@ -97,19 +97,11 @@ NETWORK3_4 = {"ipv4": "50.50.50.50/32", "ipv6": "50:50::50/128"} PREFERRED_NEXT_HOP = "global" -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 +def build_topo(tgen): + """Build function""" - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) + # Building topology from json file + build_topo_from_json(tgen, topo) def setup_module(mod): @@ -127,7 +119,7 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py b/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py index b818816d9e..5d6a5859cf 100644 --- a/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py +++ b/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py @@ -50,20 +50,16 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] -class BGPIPV6RTADVVRFTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # Create 2 routers. + tgen.add_router("r1") + tgen.add_router("r2") - # Create 2 routers. - tgen.add_router("r1") - tgen.add_router("r2") - - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): @@ -74,7 +70,7 @@ def setup_module(mod): if result is not True: pytest.skip("Kernel requirements are not met") - tgen = Topogen(BGPIPV6RTADVVRFTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py b/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py index 9c4c78bf1a..d0011f9df2 100644 --- a/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py +++ b/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py @@ -57,25 +57,19 @@ CustomizeVrfWithNetns = True ##################################################### -class BGPVRFNETNSTopo1(Topo): - "BGP EBGP VRF NETNS Topology 1" +def build_topo(tgen): + tgen.add_router("r1") - def build(self, **_opts): - tgen = get_topogen(self) + # Setup Switches + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) - # Setup Routers - tgen.add_router("r1") - - # Setup Switches - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - - # Add eBGP ExaBGP neighbors - peer_ip = "10.0.1.101" - peer_route = "via 10.0.1.1" - peer = tgen.add_exabgp_peer("peer1", ip=peer_ip, defaultRoute=peer_route) - switch = tgen.gears["s1"] - switch.add_link(peer) + # Add eBGP ExaBGP neighbors + peer_ip = "10.0.1.101" + peer_route = "via 10.0.1.1" + peer = tgen.add_exabgp_peer("peer1", ip=peer_ip, defaultRoute=peer_route) + switch = tgen.gears["s1"] + switch.add_link(peer) ##################################################### @@ -86,7 +80,7 @@ class BGPVRFNETNSTopo1(Topo): def setup_module(module): - tgen = Topogen(BGPVRFNETNSTopo1, module.__name__) + tgen = Topogen(build_topo, module.__name__) tgen.start_topology() # Get r1 reference diff --git a/tests/topotests/bgp_vrf_route_leak_basic/test_bgp-vrf-route-leak-basic.py b/tests/topotests/bgp_vrf_route_leak_basic/test_bgp-vrf-route-leak-basic.py index 7ab2c608b1..66a52841fb 100644 --- a/tests/topotests/bgp_vrf_route_leak_basic/test_bgp-vrf-route-leak-basic.py +++ b/tests/topotests/bgp_vrf_route_leak_basic/test_bgp-vrf-route-leak-basic.py @@ -41,21 +41,20 @@ from lib.topolog import logger from lib.micronet_compat import Topo + pytestmark = [pytest.mark.bgpd] -class BGPVRFTopo(Topo): - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) +def build_topo(tgen): + "Build function" - for routern in range(1, 2): - tgen.add_router("r{}".format(routern)) + for routern in range(1, 2): + tgen.add_router("r{}".format(routern)) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(BGPVRFTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() # For all registered routers, load the zebra configuration file diff --git a/tests/topotests/config_timing/test_config_timing.py b/tests/topotests/config_timing/test_config_timing.py index 54dca32e17..b68f52bbda 100644 --- a/tests/topotests/config_timing/test_config_timing.py +++ b/tests/topotests/config_timing/test_config_timing.py @@ -49,16 +49,14 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.staticd] -class TimingTopo(Topo): - def build(self, *_args, **_opts): - tgen = get_topogen(self) - tgen.add_router("r1") - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) +def build_topo(tgen): + tgen.add_router("r1") + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) def setup_module(mod): - tgen = Topogen(TimingTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/eigrp_topo1/test_eigrp_topo1.py b/tests/topotests/eigrp_topo1/test_eigrp_topo1.py index 982d3f0fa3..f97b1f2daa 100644 --- a/tests/topotests/eigrp_topo1/test_eigrp_topo1.py +++ b/tests/topotests/eigrp_topo1/test_eigrp_topo1.py @@ -55,36 +55,29 @@ from lib.micronet_compat import Topo ##################################################### -class NetworkTopo(Topo): - "EIGRP Topology 1" +def build_topo(tgen): + for routern in range(1, 4): + tgen.add_router("r{}".format(routern)) - def build(self, **_opts): - "Build function" + # On main router + # First switch is for a dummy interface (for local network) + switch = tgen.add_switch("sw1") + switch.add_link(tgen.gears["r1"]) - tgen = get_topogen(self) + # Switches for EIGRP + # switch 2 switch is for connection to EIGRP router + switch = tgen.add_switch("sw2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - for routern in range(1, 4): - tgen.add_router("r{}".format(routern)) + # switch 4 is stub on remote EIGRP router + switch = tgen.add_switch("sw4") + switch.add_link(tgen.gears["r3"]) - # On main router - # First switch is for a dummy interface (for local network) - switch = tgen.add_switch("sw1") - switch.add_link(tgen.gears["r1"]) - - # Switches for EIGRP - # switch 2 switch is for connection to EIGRP router - switch = tgen.add_switch("sw2") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - # switch 4 is stub on remote EIGRP router - switch = tgen.add_switch("sw4") - switch.add_link(tgen.gears["r3"]) - - # switch 3 is between EIGRP routers - switch = tgen.add_switch("sw3") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + # switch 3 is between EIGRP routers + switch = tgen.add_switch("sw3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) ##################################################### @@ -96,7 +89,7 @@ class NetworkTopo(Topo): def setup_module(module): "Setup topology" - tgen = Topogen(NetworkTopo, module.__name__) + tgen = Topogen(build_topo, module.__name__) tgen.start_topology() # This is a sample of configuration loading. diff --git a/tests/topotests/evpn_pim_1/test_evpn_pim_topo1.py b/tests/topotests/evpn_pim_1/test_evpn_pim_topo1.py index e549d1acb2..216494d4e6 100644 --- a/tests/topotests/evpn_pim_1/test_evpn_pim_topo1.py +++ b/tests/topotests/evpn_pim_1/test_evpn_pim_topo1.py @@ -59,41 +59,34 @@ pytestmark = [pytest.mark.bgpd, pytest.mark.bgpd] ##################################################### -class NetworkTopo(Topo): - "evpn-pim Topology 1" +def build_topo(tgen): + tgen.add_router("spine") + tgen.add_router("leaf1") + tgen.add_router("leaf2") + tgen.add_router("host1") + tgen.add_router("host2") - def build(self, **_opts): - "Build function" + # On main router + # First switch is for a dummy interface (for local network) + # spine-eth0 is connected to leaf1-eth0 + switch = tgen.add_switch("sw1") + switch.add_link(tgen.gears["spine"]) + switch.add_link(tgen.gears["leaf1"]) - tgen = get_topogen(self) + # spine-eth1 is connected to leaf2-eth0 + switch = tgen.add_switch("sw2") + switch.add_link(tgen.gears["spine"]) + switch.add_link(tgen.gears["leaf2"]) - tgen.add_router("spine") - tgen.add_router("leaf1") - tgen.add_router("leaf2") - tgen.add_router("host1") - tgen.add_router("host2") + # leaf1-eth1 is connected to host1-eth0 + switch = tgen.add_switch("sw3") + switch.add_link(tgen.gears["leaf1"]) + switch.add_link(tgen.gears["host1"]) - # On main router - # First switch is for a dummy interface (for local network) - # spine-eth0 is connected to leaf1-eth0 - switch = tgen.add_switch("sw1") - switch.add_link(tgen.gears["spine"]) - switch.add_link(tgen.gears["leaf1"]) - - # spine-eth1 is connected to leaf2-eth0 - switch = tgen.add_switch("sw2") - switch.add_link(tgen.gears["spine"]) - switch.add_link(tgen.gears["leaf2"]) - - # leaf1-eth1 is connected to host1-eth0 - switch = tgen.add_switch("sw3") - switch.add_link(tgen.gears["leaf1"]) - switch.add_link(tgen.gears["host1"]) - - # leaf2-eth1 is connected to host2-eth0 - switch = tgen.add_switch("sw4") - switch.add_link(tgen.gears["leaf2"]) - switch.add_link(tgen.gears["host2"]) + # leaf2-eth1 is connected to host2-eth0 + switch = tgen.add_switch("sw4") + switch.add_link(tgen.gears["leaf2"]) + switch.add_link(tgen.gears["host2"]) ##################################################### @@ -105,7 +98,7 @@ class NetworkTopo(Topo): def setup_module(module): "Setup topology" - tgen = Topogen(NetworkTopo, module.__name__) + tgen = Topogen(build_topo, module.__name__) tgen.start_topology() leaf1 = tgen.gears["leaf1"] diff --git a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py index d72b28e84c..83c415c0f3 100644 --- a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py +++ b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py @@ -85,17 +85,9 @@ from lib.bgp import ( ) from lib.topojson import build_topo_from_json, build_config_from_json + pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] - -# Reading the data from JSON File for topology creation -jsonFile = "{}/evpn_type5_chaos_topo1.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - # Reading the data from JSON File for topology creation # Global variables TCPDUMP_FILE = "evpn_log.txt" @@ -139,21 +131,6 @@ BRCTL = { } -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -161,7 +138,6 @@ def setup_module(mod): * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -169,7 +145,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/evpn_type5_chaos_topo1.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py index fda39be91d..3a101b4533 100644 --- a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py +++ b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py @@ -142,19 +142,8 @@ BRCTL = { } -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) +def build_topo(tgen): + build_topo_from_json(tgen, topo) def setup_module(mod): @@ -172,7 +161,7 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/example_test/test_template.py b/tests/topotests/example_test/test_template.py index 534dd998d9..7bd434d756 100644 --- a/tests/topotests/example_test/test_template.py +++ b/tests/topotests/example_test/test_template.py @@ -30,19 +30,10 @@ import os import sys import pytest -# Save the Current Working Directory to find configuration files. -CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, "../")) - -# pylint: disable=C0413 # Import topogen and topotest helpers -from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -# Required to instantiate the topology builder class. -from lib.micronet_compat import Topo - # TODO: select markers based on daemons used during test # pytest module level markers @@ -56,37 +47,40 @@ pytestmark = [ """ -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # Create 2 routers + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - # This function only purpose is to define allocation and relationship - # between routers, switches and hosts. - # - # Example - # - # Create 2 routers - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) + # Create a switch with just one router connected to it to simulate a + # empty network. + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) - # Create a switch with just one router connected to it to simulate a - # empty network. - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - - # Create a connection between r1 and r2 - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + # Create a connection between r1 and r2 + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): "Sets up the pytest environment" + + # This function initiates the topology build with Topogen... - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) + + # The basic topology above could also have be more easily specified using a + # dictionary, remove the build_topo function and use the following instead: + # + # topodef = { + # "s1": "r1" + # "s2": ("r1", "r2") + # } + # tgen = Topogen(topodef, mod.__name__) + # ... and here it calls initialization functions. tgen.start_topology() @@ -94,6 +88,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registred routers, load the zebra configuration file + # CWD = os.path.dirname(os.path.realpath(__file__)) for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, diff --git a/tests/topotests/example_topojson_test/test_topo_json_multiple_links/test_example_topojson_multiple_links.py b/tests/topotests/example_topojson_test/test_topo_json_multiple_links/test_example_topojson_multiple_links.py index b088616374..11b58301db 100755 --- a/tests/topotests/example_topojson_test/test_topo_json_multiple_links/test_example_topojson_multiple_links.py +++ b/tests/topotests/example_topojson_test/test_topo_json_multiple_links/test_example_topojson_multiple_links.py @@ -79,27 +79,19 @@ bgp_convergence = False input_dict = {} -class TemplateTopo(Topo): - """ - Test topology builder +def build_topo(tgen): + "Build function" - * `Topo`: Topology object - """ + # This function only purpose is to create topology + # as defined in input json file. + # + # Example + # + # Creating 2 routers having 2 links in between, + # one is used to establised BGP neighborship - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # This function only purpose is to create topology - # as defined in input json file. - # - # Example - # - # Creating 2 routers having 2 links in between, - # one is used to establised BGP neighborship - - # Building topology from json file - build_topo_from_json(tgen, topo) + # Building topology from json file + build_topo_from_json(tgen, topo) def setup_module(mod): @@ -116,7 +108,7 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/example_topojson_test/test_topo_json_single_link/test_example_topojson.py b/tests/topotests/example_topojson_test/test_topo_json_single_link/test_example_topojson.py index 4b13dce7df..82cc9bd94a 100755 --- a/tests/topotests/example_topojson_test/test_topo_json_single_link/test_example_topojson.py +++ b/tests/topotests/example_topojson_test/test_topo_json_single_link/test_example_topojson.py @@ -79,27 +79,19 @@ bgp_convergence = False input_dict = {} -class TemplateTopo(Topo): - """ - Test topology builder +def build_topo(tgen): + "Build function" - * `Topo`: Topology object - """ + # This function only purpose is to create topology + # as defined in input json file. + # + # Example + # + # Creating 2 routers having single links in between, + # which is used to establised BGP neighborship - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # This function only purpose is to create topology - # as defined in input json file. - # - # Example - # - # Creating 2 routers having single links in between, - # which is used to establised BGP neighborship - - # Building topology from json file - build_topo_from_json(tgen, topo) + # Building topology from json file + build_topo_from_json(tgen, topo) def setup_module(mod): @@ -116,7 +108,7 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/example_topojson_test/test_topo_json_single_link_loopback/test_example_topojson.py b/tests/topotests/example_topojson_test/test_topo_json_single_link_loopback/test_example_topojson.py index 07d13cb711..9ab9f77f0f 100755 --- a/tests/topotests/example_topojson_test/test_topo_json_single_link_loopback/test_example_topojson.py +++ b/tests/topotests/example_topojson_test/test_topo_json_single_link_loopback/test_example_topojson.py @@ -81,27 +81,19 @@ bgp_convergence = False input_dict = {} -class TemplateTopo(Topo): - """ - Test topology builder +def build_topo(tgen): + "Build function" - * `Topo`: Topology object - """ + # This function only purpose is to create topology + # as defined in input json file. + # + # Example + # + # Creating 2 routers having single links in between, + # which is used to establised BGP neighborship - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) - - # This function only purpose is to create topology - # as defined in input json file. - # - # Example - # - # Creating 2 routers having single links in between, - # which is used to establised BGP neighborship - - # Building topology from json file - build_topo_from_json(tgen, topo) + # Building topology from json file + build_topo_from_json(tgen, topo) def setup_module(mod): @@ -118,7 +110,7 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/isis_lfa_topo1/test_isis_lfa_topo1.py b/tests/topotests/isis_lfa_topo1/test_isis_lfa_topo1.py index 5555b1dca0..07391ec2b7 100755 --- a/tests/topotests/isis_lfa_topo1/test_isis_lfa_topo1.py +++ b/tests/topotests/isis_lfa_topo1/test_isis_lfa_topo1.py @@ -164,7 +164,7 @@ def build_topo(tgen): def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/isis_lsp_bits_topo1/test_isis_lsp_bits_topo1.py b/tests/topotests/isis_lsp_bits_topo1/test_isis_lsp_bits_topo1.py index df174e9531..b86a2cf316 100755 --- a/tests/topotests/isis_lsp_bits_topo1/test_isis_lsp_bits_topo1.py +++ b/tests/topotests/isis_lsp_bits_topo1/test_isis_lsp_bits_topo1.py @@ -91,51 +91,47 @@ pytestmark = [pytest.mark.isisd] outputs = {} -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1") + switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1") + switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1") - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1") - switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1") - switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1") + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2") - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2") + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3") - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3") + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") + switch = tgen.add_switch("s7") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") - switch = tgen.add_switch("s7") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") - - switch = tgen.add_switch("s8") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5") + switch = tgen.add_switch("s8") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5") def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/isis_rlfa_topo1/test_isis_rlfa_topo1.py b/tests/topotests/isis_rlfa_topo1/test_isis_rlfa_topo1.py index e2cb080eb7..39a03a3e99 100755 --- a/tests/topotests/isis_rlfa_topo1/test_isis_rlfa_topo1.py +++ b/tests/topotests/isis_rlfa_topo1/test_isis_rlfa_topo1.py @@ -166,7 +166,7 @@ def build_topo(tgen): def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/isis_snmp/test_isis_snmp.py b/tests/topotests/isis_snmp/test_isis_snmp.py index 6ca5928fd9..cb8705e5b0 100755 --- a/tests/topotests/isis_snmp/test_isis_snmp.py +++ b/tests/topotests/isis_snmp/test_isis_snmp.py @@ -85,45 +85,41 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.isisd, pytest.mark.ldpd, pytest.mark.snmp] -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["ce3", "r1", "r2", "r3", "r4", "r5"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["ce3", "r1", "r2", "r3", "r4", "r5"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r4"]) - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r4"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r5"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r5"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["ce3"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["ce3"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r4"]) + switch.add_link(tgen.gears["r5"]) - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r4"]) - switch.add_link(tgen.gears["r5"]) + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r3"]) - - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): @@ -135,7 +131,7 @@ def setup_module(mod): pytest.skip(error_msg) # This function initiates the topology build with Topogen... - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) # ... and here it calls Mininet initialization functions. tgen.start_topology() diff --git a/tests/topotests/isis_sr_te_topo1/test_isis_sr_te_topo1.py b/tests/topotests/isis_sr_te_topo1/test_isis_sr_te_topo1.py index 260457b672..c653d52865 100755 --- a/tests/topotests/isis_sr_te_topo1/test_isis_sr_te_topo1.py +++ b/tests/topotests/isis_sr_te_topo1/test_isis_sr_te_topo1.py @@ -99,64 +99,60 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.isisd, pytest.mark.pathd] -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6", "dst"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6", "dst"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1") + switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1") + switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1") - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1") - switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1") - switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1") + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-1") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-1") - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-1") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-1") + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-2") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-2") - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-2") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-2") + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-1") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-1") - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-1") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-1") + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-2") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-2") - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-2") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-2") + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") + switch = tgen.add_switch("s7") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") - switch = tgen.add_switch("s7") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") + switch = tgen.add_switch("s8") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5") - switch = tgen.add_switch("s8") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5") - - switch = tgen.add_switch("s9") - switch.add_link(tgen.gears["rt6"], nodeif="eth-dst") - switch.add_link(tgen.gears["dst"], nodeif="eth-rt6") + switch = tgen.add_switch("s9") + switch.add_link(tgen.gears["rt6"], nodeif="eth-dst") + switch.add_link(tgen.gears["dst"], nodeif="eth-rt6") def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) frrdir = tgen.config.get(tgen.CONFIG_SECTION, "frrdir") if not os.path.isfile(os.path.join(frrdir, "pathd")): diff --git a/tests/topotests/isis_sr_topo1/test_isis_sr_topo1.py b/tests/topotests/isis_sr_topo1/test_isis_sr_topo1.py index 8aa187871c..a8956bb57e 100644 --- a/tests/topotests/isis_sr_topo1/test_isis_sr_topo1.py +++ b/tests/topotests/isis_sr_topo1/test_isis_sr_topo1.py @@ -87,59 +87,55 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.isisd] -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1") + switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1") + switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1") - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1") - switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1") - switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1") + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-1") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-1") - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-1") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-1") + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-2") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-2") - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-2") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-2") + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-1") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-1") - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-1") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-1") + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-2") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-2") - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-2") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-2") + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") + switch = tgen.add_switch("s7") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") - switch = tgen.add_switch("s7") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") - - switch = tgen.add_switch("s8") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5") + switch = tgen.add_switch("s8") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5") def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/isis_tilfa_topo1/test_isis_tilfa_topo1.py b/tests/topotests/isis_tilfa_topo1/test_isis_tilfa_topo1.py index 351bce99e5..37ce253129 100755 --- a/tests/topotests/isis_tilfa_topo1/test_isis_tilfa_topo1.py +++ b/tests/topotests/isis_tilfa_topo1/test_isis_tilfa_topo1.py @@ -178,7 +178,7 @@ def build_topo(tgen): def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/isis_topo1/test_isis_topo1.py b/tests/topotests/isis_topo1/test_isis_topo1.py index 29021c5623..34bc3830ff 100644 --- a/tests/topotests/isis_topo1/test_isis_topo1.py +++ b/tests/topotests/isis_topo1/test_isis_topo1.py @@ -61,48 +61,44 @@ VERTEX_TYPE_LIST = [ ] -class ISISTopo1(Topo): - "Simple two layer ISIS topology" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # Add ISIS routers: + # r1 r2 + # | sw1 | sw2 + # r3 r4 + # | | + # sw3 sw4 + # \ / + # r5 + for routern in range(1, 6): + tgen.add_router("r{}".format(routern)) - # Add ISIS routers: - # r1 r2 - # | sw1 | sw2 - # r3 r4 - # | | - # sw3 sw4 - # \ / - # r5 - for routern in range(1, 6): - tgen.add_router("r{}".format(routern)) + # r1 <- sw1 -> r3 + sw = tgen.add_switch("sw1") + sw.add_link(tgen.gears["r1"]) + sw.add_link(tgen.gears["r3"]) - # r1 <- sw1 -> r3 - sw = tgen.add_switch("sw1") - sw.add_link(tgen.gears["r1"]) - sw.add_link(tgen.gears["r3"]) + # r2 <- sw2 -> r4 + sw = tgen.add_switch("sw2") + sw.add_link(tgen.gears["r2"]) + sw.add_link(tgen.gears["r4"]) - # r2 <- sw2 -> r4 - sw = tgen.add_switch("sw2") - sw.add_link(tgen.gears["r2"]) - sw.add_link(tgen.gears["r4"]) + # r3 <- sw3 -> r5 + sw = tgen.add_switch("sw3") + sw.add_link(tgen.gears["r3"]) + sw.add_link(tgen.gears["r5"]) - # r3 <- sw3 -> r5 - sw = tgen.add_switch("sw3") - sw.add_link(tgen.gears["r3"]) - sw.add_link(tgen.gears["r5"]) - - # r4 <- sw4 -> r5 - sw = tgen.add_switch("sw4") - sw.add_link(tgen.gears["r4"]) - sw.add_link(tgen.gears["r5"]) + # r4 <- sw4 -> r5 + sw = tgen.add_switch("sw4") + sw.add_link(tgen.gears["r4"]) + sw.add_link(tgen.gears["r5"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(ISISTopo1, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() # For all registered routers, load the zebra configuration file diff --git a/tests/topotests/isis_topo1_vrf/test_isis_topo1_vrf.py b/tests/topotests/isis_topo1_vrf/test_isis_topo1_vrf.py index 9c15ee3423..620fc333bc 100644 --- a/tests/topotests/isis_topo1_vrf/test_isis_topo1_vrf.py +++ b/tests/topotests/isis_topo1_vrf/test_isis_topo1_vrf.py @@ -61,48 +61,44 @@ VERTEX_TYPE_LIST = [ ] -class ISISTopo1(Topo): - "Simple two layer ISIS vrf topology" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # Add ISIS routers: + # r1 r2 + # | sw1 | sw2 + # r3 r4 + # | | + # sw3 sw4 + # \ / + # r5 + for routern in range(1, 6): + tgen.add_router("r{}".format(routern)) - # Add ISIS routers: - # r1 r2 - # | sw1 | sw2 - # r3 r4 - # | | - # sw3 sw4 - # \ / - # r5 - for routern in range(1, 6): - tgen.add_router("r{}".format(routern)) + # r1 <- sw1 -> r3 + sw = tgen.add_switch("sw1") + sw.add_link(tgen.gears["r1"]) + sw.add_link(tgen.gears["r3"]) - # r1 <- sw1 -> r3 - sw = tgen.add_switch("sw1") - sw.add_link(tgen.gears["r1"]) - sw.add_link(tgen.gears["r3"]) + # r2 <- sw2 -> r4 + sw = tgen.add_switch("sw2") + sw.add_link(tgen.gears["r2"]) + sw.add_link(tgen.gears["r4"]) - # r2 <- sw2 -> r4 - sw = tgen.add_switch("sw2") - sw.add_link(tgen.gears["r2"]) - sw.add_link(tgen.gears["r4"]) + # r3 <- sw3 -> r5 + sw = tgen.add_switch("sw3") + sw.add_link(tgen.gears["r3"]) + sw.add_link(tgen.gears["r5"]) - # r3 <- sw3 -> r5 - sw = tgen.add_switch("sw3") - sw.add_link(tgen.gears["r3"]) - sw.add_link(tgen.gears["r5"]) - - # r4 <- sw4 -> r5 - sw = tgen.add_switch("sw4") - sw.add_link(tgen.gears["r4"]) - sw.add_link(tgen.gears["r5"]) + # r4 <- sw4 -> r5 + sw = tgen.add_switch("sw4") + sw.add_link(tgen.gears["r4"]) + sw.add_link(tgen.gears["r5"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(ISISTopo1, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() logger.info("Testing with VRF Lite support") diff --git a/tests/topotests/ldp_oc_acl_topo1/test_ldp_oc_acl_topo1.py b/tests/topotests/ldp_oc_acl_topo1/test_ldp_oc_acl_topo1.py index f26c56e54a..42ba24f781 100644 --- a/tests/topotests/ldp_oc_acl_topo1/test_ldp_oc_acl_topo1.py +++ b/tests/topotests/ldp_oc_acl_topo1/test_ldp_oc_acl_topo1.py @@ -81,39 +81,35 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.ldpd, pytest.mark.ospfd] -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["r1", "r2", "r3", "r4"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["r1", "r2", "r3", "r4"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s0") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - # - # Define connections - # - switch = tgen.add_switch("s0") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) - switch.add_link(tgen.gears["r4"]) - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/ldp_oc_topo1/test_ldp_oc_topo1.py b/tests/topotests/ldp_oc_topo1/test_ldp_oc_topo1.py index 5208728a98..78e231b604 100644 --- a/tests/topotests/ldp_oc_topo1/test_ldp_oc_topo1.py +++ b/tests/topotests/ldp_oc_topo1/test_ldp_oc_topo1.py @@ -81,39 +81,35 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.ldpd, pytest.mark.ospfd] -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["r1", "r2", "r3", "r4"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["r1", "r2", "r3", "r4"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s0") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - # - # Define connections - # - switch = tgen.add_switch("s0") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) - switch.add_link(tgen.gears["r4"]) - - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/ldp_snmp/test_ldp_snmp_topo1.py b/tests/topotests/ldp_snmp/test_ldp_snmp_topo1.py index f0473257c9..a616335d7b 100644 --- a/tests/topotests/ldp_snmp/test_ldp_snmp_topo1.py +++ b/tests/topotests/ldp_snmp/test_ldp_snmp_topo1.py @@ -83,50 +83,46 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.ldpd, pytest.mark.isisd, pytest.mark.snmp] -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["ce1", "ce2", "ce3", "r1", "r2", "r3"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["ce1", "ce2", "ce3", "r1", "r2", "r3"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["ce1"]) + switch.add_link(tgen.gears["r1"]) - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["ce1"]) - switch.add_link(tgen.gears["r1"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["ce2"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["ce2"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["ce3"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["ce3"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r3"]) - - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/ldp_sync_isis_topo1/test_ldp_sync_isis_topo1.py b/tests/topotests/ldp_sync_isis_topo1/test_ldp_sync_isis_topo1.py index 3c26bd5ba2..37275ed9e6 100644 --- a/tests/topotests/ldp_sync_isis_topo1/test_ldp_sync_isis_topo1.py +++ b/tests/topotests/ldp_sync_isis_topo1/test_ldp_sync_isis_topo1.py @@ -83,50 +83,46 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.isisd, pytest.mark.ldpd] -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["ce1", "ce2", "ce3", "r1", "r2", "r3"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["ce1", "ce2", "ce3", "r1", "r2", "r3"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["ce1"]) + switch.add_link(tgen.gears["r1"]) - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["ce1"]) - switch.add_link(tgen.gears["r1"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["ce2"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["ce2"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["ce3"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["ce3"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r3"]) - - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/ldp_sync_ospf_topo1/test_ldp_sync_ospf_topo1.py b/tests/topotests/ldp_sync_ospf_topo1/test_ldp_sync_ospf_topo1.py index c5bd97edf3..5412fa600e 100644 --- a/tests/topotests/ldp_sync_ospf_topo1/test_ldp_sync_ospf_topo1.py +++ b/tests/topotests/ldp_sync_ospf_topo1/test_ldp_sync_ospf_topo1.py @@ -82,50 +82,46 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.ldpd, pytest.mark.ospfd] -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["ce1", "ce2", "ce3", "r1", "r2", "r3"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["ce1", "ce2", "ce3", "r1", "r2", "r3"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["ce1"]) + switch.add_link(tgen.gears["r1"]) - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["ce1"]) - switch.add_link(tgen.gears["r1"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["ce2"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["ce2"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["ce3"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["ce3"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r3"]) - - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/ldp_topo1/test_ldp_topo1.py b/tests/topotests/ldp_topo1/test_ldp_topo1.py index 62b763ce70..f6d28b66ae 100644 --- a/tests/topotests/ldp_topo1/test_ldp_topo1.py +++ b/tests/topotests/ldp_topo1/test_ldp_topo1.py @@ -68,7 +68,7 @@ from time import sleep sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lib import topotest from lib.micronet_compat import Topo -from lib.micronet_compat import Mininet +from lib.topogen import Topogen, get_topogen fatal_error = "" @@ -81,73 +81,25 @@ pytestmark = [pytest.mark.ldpd, pytest.mark.ospfd] ##################################################### -class NetworkTopo(Topo): - "LDP Test Topology 1" +def build_topo(tgen): - def build(self, **_opts): + # Setup Routers + for i in range(1, 5): + tgen.add_router("r%s" % i) - # Setup Routers - router = {} - for i in range(1, 5): - router[i] = topotest.addRouter(self, "r%s" % i) - - # Setup Switches, add Interfaces and Connections - switch = {} - # First switch - switch[0] = self.addSwitch("sw0") - self.addLink( - switch[0], - router[1], - intfName2="r1-eth0", - addr1="80:AA:00:00:00:00", - addr2="00:11:00:01:00:00", - ) - self.addLink( - switch[0], - router[2], - intfName2="r2-eth0", - addr1="80:AA:00:00:00:01", - addr2="00:11:00:02:00:00", - ) - # Second switch - switch[1] = self.addSwitch("sw1") - self.addLink( - switch[1], - router[2], - intfName2="r2-eth1", - addr1="80:AA:00:01:00:00", - addr2="00:11:00:02:00:01", - ) - self.addLink( - switch[1], - router[3], - intfName2="r3-eth0", - addr1="80:AA:00:01:00:01", - addr2="00:11:00:03:00:00", - ) - self.addLink( - switch[1], - router[4], - intfName2="r4-eth0", - addr1="80:AA:00:01:00:02", - addr2="00:11:00:04:00:00", - ) - # Third switch - switch[2] = self.addSwitch("sw2") - self.addLink( - switch[2], - router[2], - intfName2="r2-eth2", - addr1="80:AA:00:02:00:00", - addr2="00:11:00:02:00:02", - ) - self.addLink( - switch[2], - router[3], - intfName2="r3-eth1", - addr1="80:AA:00:02:00:01", - addr2="00:11:00:03:00:01", - ) + # First switch + switch = tgen.add_switch("sw0") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + # Second switch + switch = tgen.add_switch("sw1") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) + # Third switch + switch = tgen.add_switch("sw2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) ##################################################### @@ -158,48 +110,36 @@ class NetworkTopo(Topo): def setup_module(module): - global topo, net - global fatal_error - print("\n\n** %s: Setup Topology" % module.__name__) print("******************************************\n") - print("Cleanup old Mininet runs") - os.system("sudo mn -c > /dev/null 2>&1") - thisDir = os.path.dirname(os.path.realpath(__file__)) - topo = NetworkTopo() + tgen = Topogen(build_topo, module.__name__) + tgen.start_topology() - net = Mininet(controller=None, topo=topo) - net.start() + net = tgen.net # Starting Routers for i in range(1, 5): net["r%s" % i].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir, i)) net["r%s" % i].loadConf("ospfd", "%s/r%s/ospfd.conf" % (thisDir, i)) net["r%s" % i].loadConf("ldpd", "%s/r%s/ldpd.conf" % (thisDir, i)) - fatal_error = net["r%s" % i].startRouter() - - if fatal_error != "": - break + tgen.gears["r%s" % i].start() # For debugging after starting FRR daemons, uncomment the next line # CLI(net) def teardown_module(module): - global net - print("\n\n** %s: Shutdown Topology" % module.__name__) print("******************************************\n") - - # End - Shutdown network - net.stop() + tgen = get_topogen() + tgen.stop_topology() def test_router_running(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -220,7 +160,7 @@ def test_router_running(): def test_mpls_interfaces(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -286,7 +226,7 @@ def test_mpls_interfaces(): def test_mpls_ldp_neighbor_establish(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -354,7 +294,7 @@ def test_mpls_ldp_neighbor_establish(): def test_mpls_ldp_discovery(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -423,7 +363,7 @@ def test_mpls_ldp_discovery(): def test_mpls_ldp_neighbor(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -493,7 +433,7 @@ def test_mpls_ldp_neighbor(): def test_mpls_ldp_binding(): global fatal_error - global net + net = get_topogen().net # Skip this test for now until proper sorting of the output # is implemented @@ -585,7 +525,7 @@ def test_mpls_ldp_binding(): def test_zebra_ipv4_routingTable(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -662,7 +602,7 @@ def test_zebra_ipv4_routingTable(): def test_mpls_table(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -741,7 +681,7 @@ def test_mpls_table(): def test_linux_mpls_routes(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -825,7 +765,7 @@ def test_linux_mpls_routes(): def test_shutdown_check_stderr(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -857,7 +797,7 @@ def test_shutdown_check_stderr(): def test_shutdown_check_memleak(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": diff --git a/tests/topotests/ldp_vpls_topo1/test_ldp_vpls_topo1.py b/tests/topotests/ldp_vpls_topo1/test_ldp_vpls_topo1.py index 8dc8039c99..c77c96b173 100644 --- a/tests/topotests/ldp_vpls_topo1/test_ldp_vpls_topo1.py +++ b/tests/topotests/ldp_vpls_topo1/test_ldp_vpls_topo1.py @@ -83,50 +83,46 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.ldpd, pytest.mark.ospfd] -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["ce1", "ce2", "ce3", "r1", "r2", "r3"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["ce1", "ce2", "ce3", "r1", "r2", "r3"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["ce1"]) + switch.add_link(tgen.gears["r1"]) - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["ce1"]) - switch.add_link(tgen.gears["r1"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["ce2"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["ce2"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["ce3"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["ce3"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r3"]) - - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py index 1ea033a12c..ef2eb8cab0 100644 --- a/tests/topotests/lib/ltemplate.py +++ b/tests/topotests/lib/ltemplate.py @@ -72,7 +72,7 @@ class LTemplate: def setup_module(self, mod): "Sets up the pytest environment" # This function initiates the topology build with Topogen... - tgen = Topogen(customize.ThisTestTopo, mod.__name__) + tgen = Topogen(customize.build_topo, mod.__name__) # ... and here it calls Mininet initialization functions. tgen.start_topology() diff --git a/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py b/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py index a10477d283..121f4a7fdc 100644 --- a/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py +++ b/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py @@ -113,40 +113,36 @@ def close_applications(): p.wait() -class MSDPMeshTopo1(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # Create 3 routers + for routern in range(1, 4): + tgen.add_router("r{}".format(routern)) - # Create 3 routers - for routern in range(1, 4): - tgen.add_router("r{}".format(routern)) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + # Create stub networks for multicast traffic. + tgen.add_host("h1", "192.168.10.2/24", "via 192.168.10.1") + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["h1"]) - # Create stub networks for multicast traffic. - tgen.add_host("h1", "192.168.10.2/24", "via 192.168.10.1") - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["h1"]) - - tgen.add_host("h2", "192.168.30.2/24", "via 192.168.30.1") - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r3"]) - switch.add_link(tgen.gears["h2"]) + tgen.add_host("h2", "192.168.30.2/24", "via 192.168.30.1") + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["h2"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(MSDPMeshTopo1, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/msdp_topo1/test_msdp_topo1.py b/tests/topotests/msdp_topo1/test_msdp_topo1.py index 796706a2e0..8fad62db79 100755 --- a/tests/topotests/msdp_topo1/test_msdp_topo1.py +++ b/tests/topotests/msdp_topo1/test_msdp_topo1.py @@ -113,50 +113,46 @@ def close_applications(): app_clients[host]["fd"].close() -class MSDPTopo1(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # Create 4 routers + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) - # Create 4 routers - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r3"]) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r4"]) - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r4"]) + switch = tgen.add_switch("s4") + # switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) - switch = tgen.add_switch("s4") - #switch.add_link(tgen.gears["r3"]) - switch.add_link(tgen.gears["r4"]) + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r4"]) - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["r4"]) + # Create a host connected and direct at r4: + tgen.add_host("h1", "192.168.4.100/24", "via 192.168.4.1") + switch.add_link(tgen.gears["h1"]) - # Create a host connected and direct at r4: - tgen.add_host("h1", "192.168.4.100/24", "via 192.168.4.1") - switch.add_link(tgen.gears["h1"]) - - # Create a host connected and direct at r1: - switch = tgen.add_switch("s6") - tgen.add_host("h2", "192.168.10.100/24", "via 192.168.10.1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["h2"]) + # Create a host connected and direct at r1: + switch = tgen.add_switch("s6") + tgen.add_host("h2", "192.168.10.100/24", "via 192.168.10.1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["h2"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(MSDPTopo1, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py b/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py index 5cd5cd1553..df1cce654f 100644 --- a/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py +++ b/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py @@ -113,17 +113,9 @@ from lib.pim import ( from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json + pytestmark = [pytest.mark.pimd, pytest.mark.staticd] - -# Reading the data from JSON File for topology creation -jsonFile = "{}/mcast_pim_bsmp_01.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - TOPOLOGY = """ b1_____ @@ -151,21 +143,6 @@ BSR1_ADDR = "1.1.2.7/32" BSR2_ADDR = "10.2.1.1/32" -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -186,7 +163,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/mcast_pim_bsmp_01.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py b/tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py index 115d0bff0d..64c284f7f1 100644 --- a/tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py +++ b/tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py @@ -107,13 +107,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json pytestmark = [pytest.mark.pimd, pytest.mark.staticd] -# Reading the data from JSON File for topology creation -jsonFile = "{}/mcast_pim_bsmp_02.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) TOPOLOGY = """ @@ -142,21 +135,6 @@ BSR1_ADDR = "1.1.2.7/32" BSR2_ADDR = "10.2.1.1/32" -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -177,7 +155,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/mcast_pim_bsmp_02.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py b/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py index d808a60c05..9eb3d8cc58 100755 --- a/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py +++ b/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py @@ -108,17 +108,9 @@ from lib.pim import ( from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json + pytestmark = [pytest.mark.pimd] - -# Reading the data from JSON File for topology creation -jsonFile = "{}/multicast_pim_sm_topo1.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - TOPOLOGY = """ @@ -170,21 +162,6 @@ GROUP_RANGE_3 = [ IGMP_JOIN_RANGE_3 = ["227.1.1.1", "227.1.1.2", "227.1.1.3", "227.1.1.4", "227.1.1.5"] -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -204,11 +181,15 @@ def setup_module(mod): logger.info("Running setup_module to create topology") - tgen = Topogen(CreateTopo, mod.__name__) + testdir = os.path.dirname(os.path.realpath(__file__)) + json_file = "{}/multicast_pim_sm_topo1.json".format(testdir) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. - daemons = topo_daemons(tgen, topo) + daemons = topo_daemons(tgen, tgen.json_topo) # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers diff --git a/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py b/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py index 0b68942208..96886b0d95 100755 --- a/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py +++ b/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py @@ -102,17 +102,9 @@ from lib.pim import ( from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json + pytestmark = [pytest.mark.pimd] - -# Reading the data from JSON File for topology creation -jsonFile = "{}/multicast_pim_sm_topo2.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - TOPOLOGY = """ @@ -164,21 +156,6 @@ GROUP_RANGE_3 = [ IGMP_JOIN_RANGE_3 = ["227.1.1.1", "227.1.1.2", "227.1.1.3", "227.1.1.4", "227.1.1.5"] -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -198,7 +175,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/multicast_pim_sm_topo2.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py index f3688e2f55..7c04dba066 100755 --- a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py +++ b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py @@ -88,7 +88,6 @@ from lib.common_config import ( add_interfaces_to_vlan, tcpdump_capture_start, tcpdump_capture_stop, - LOGDIR, check_router_status, required_linux_kernel_version, topo_daemons, @@ -114,13 +113,8 @@ from lib.pim import ( from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json -# Reading the data from JSON File for topology creation -jsonFile = "{}/multicast_pim_sm_topo3.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) +CWD = os.path.dirname(os.path.realpath(__file__)) +pytestmark = pytest.mark.pimd TOPOLOGY = """ @@ -179,21 +173,6 @@ SAME_VLAN_IP_3 = {"ip": "10.1.1.3", "subnet": "255.255.255.0", "cidr": "24"} SAME_VLAN_IP_4 = {"ip": "10.1.1.4", "subnet": "255.255.255.0", "cidr": "24"} -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -213,7 +192,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/multicast_pim_sm_topo3.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py index d2bddc43b7..445dab8373 100755 --- a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py +++ b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py @@ -101,14 +101,6 @@ from lib.pim import ( from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json -# Reading the data from JSON File for topology creation -jsonFile = "{}/multicast_pim_sm_topo4.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - TOPOLOGY = """ @@ -149,21 +141,6 @@ NEW_ADDRESS_1_SUBNET = "192.168.20.1/24" NEW_ADDRESS_2_SUBNET = "192.168.20.2/24" -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -183,7 +160,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/multicast_pim_sm_topo4.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py b/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py index b57c5b16da..b1ffd37865 100755 --- a/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py +++ b/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py @@ -187,23 +187,11 @@ SOURCE_ADDRESS = "10.0.6.2" SOURCE = "Static" -class CreateTopo(Topo): - """ - Test BasicTopo - topology 1 +def build_topo(tgen): + """Build function""" - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, TOPO) - - def dumdum(self): - """ Dummy """ - print("%s", self.name) + # Building topology from json file + build_topo_from_json(tgen, TOPO) def setup_module(mod): diff --git a/tests/topotests/nhrp_topo/test_nhrp_topo.py b/tests/topotests/nhrp_topo/test_nhrp_topo.py index 6d3cc3a552..19be9a8ffb 100644 --- a/tests/topotests/nhrp_topo/test_nhrp_topo.py +++ b/tests/topotests/nhrp_topo/test_nhrp_topo.py @@ -48,26 +48,23 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.nhrpd] -class NHRPTopo(Topo): - "Test topology builder" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) +def build_topo(tgen): + "Build function" - # Create 3 routers. - for routern in range(1, 4): - tgen.add_router('r{}'.format(routern)) + # Create 3 routers. + for routern in range(1, 4): + tgen.add_router('r{}'.format(routern)) - switch = tgen.add_switch('s1') - switch.add_link(tgen.gears['r1']) - switch.add_link(tgen.gears['r3']) - switch = tgen.add_switch('s2') - switch.add_link(tgen.gears['r2']) - switch.add_link(tgen.gears['r3']) - switch = tgen.add_switch('s3') - switch.add_link(tgen.gears['r2']) - switch = tgen.add_switch('s4') - switch.add_link(tgen.gears['r1']) + switch = tgen.add_switch('s1') + switch.add_link(tgen.gears['r1']) + switch.add_link(tgen.gears['r3']) + switch = tgen.add_switch('s2') + switch.add_link(tgen.gears['r2']) + switch.add_link(tgen.gears['r3']) + switch = tgen.add_switch('s3') + switch.add_link(tgen.gears['r2']) + switch = tgen.add_switch('s4') + switch.add_link(tgen.gears['r1']) def _populate_iface(): @@ -99,7 +96,7 @@ def _populate_iface(): def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(NHRPTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/ospf6_topo1/test_ospf6_topo1.py b/tests/topotests/ospf6_topo1/test_ospf6_topo1.py index 4a4ae3d5b9..1bc994aaa5 100644 --- a/tests/topotests/ospf6_topo1/test_ospf6_topo1.py +++ b/tests/topotests/ospf6_topo1/test_ospf6_topo1.py @@ -91,59 +91,46 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger import platform + pytestmark = [pytest.mark.ospfd] -##################################################### -## -## Network Topology Definition -## -##################################################### +def build_topo(tgen): + # Create 4 routers + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) + # + # Wire up the switches and routers + # Note that we specify the link names so we match the config files + # -class NetworkTopo(Topo): - "OSPFv3 (IPv6) Test Topology 1" + # Create a empty network for router 1 + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"], nodeif="r1-stubnet") - def build(self, **_opts): - "Build function" + # Create a empty network for router 2 + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"], nodeif="r2-stubnet") - tgen = get_topogen(self) + # Create a empty network for router 3 + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r3"], nodeif="r3-stubnet") - # Create 4 routers - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) + # Create a empty network for router 4 + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r4"], nodeif="r4-stubnet") - # - # Wire up the switches and routers - # Note that we specify the link names so we match the config files - # + # Interconnect routers 1, 2, and 3 + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r1"], nodeif="r1-sw5") + switch.add_link(tgen.gears["r2"], nodeif="r2-sw5") + switch.add_link(tgen.gears["r3"], nodeif="r3-sw5") - # Create a empty network for router 1 - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"], nodeif="r1-stubnet") - - # Create a empty network for router 2 - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"], nodeif="r2-stubnet") - - # Create a empty network for router 3 - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r3"], nodeif="r3-stubnet") - - # Create a empty network for router 4 - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r4"], nodeif="r4-stubnet") - - # Interconnect routers 1, 2, and 3 - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["r1"], nodeif="r1-sw5") - switch.add_link(tgen.gears["r2"], nodeif="r2-sw5") - switch.add_link(tgen.gears["r3"], nodeif="r3-sw5") - - # Interconnect routers 3 and 4 - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["r3"], nodeif="r3-sw6") - switch.add_link(tgen.gears["r4"], nodeif="r4-sw6") + # Interconnect routers 3 and 4 + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r3"], nodeif="r3-sw6") + switch.add_link(tgen.gears["r4"], nodeif="r4-sw6") ##################################################### @@ -156,7 +143,7 @@ class NetworkTopo(Topo): def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(NetworkTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() logger.info("** %s: Setup Topology" % mod.__name__) diff --git a/tests/topotests/ospf6_topo1_vrf/test_ospf6_topo1_vrf.py b/tests/topotests/ospf6_topo1_vrf/test_ospf6_topo1_vrf.py index 28e89dfa52..174cecfef1 100755 --- a/tests/topotests/ospf6_topo1_vrf/test_ospf6_topo1_vrf.py +++ b/tests/topotests/ospf6_topo1_vrf/test_ospf6_topo1_vrf.py @@ -94,59 +94,49 @@ from lib.topolog import logger from lib.topotest import iproute2_is_vrf_capable from lib.common_config import required_linux_kernel_version + pytestmark = [pytest.mark.ospfd] -##################################################### -## -## Network Topology Definition -## -##################################################### +def build_topo(tgen): + "Build function" -class NetworkTopo(Topo): - "OSPFv3 (IPv6) Test Topology 1" + # Create 4 routers + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) - def build(self, **_opts): - "Build function" + # + # Wire up the switches and routers + # Note that we specify the link names so we match the config files + # - tgen = get_topogen(self) + # Create a empty network for router 1 + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"], nodeif="r1-stubnet") - # Create 4 routers - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) + # Create a empty network for router 2 + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"], nodeif="r2-stubnet") - # - # Wire up the switches and routers - # Note that we specify the link names so we match the config files - # + # Create a empty network for router 3 + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r3"], nodeif="r3-stubnet") - # Create a empty network for router 1 - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"], nodeif="r1-stubnet") + # Create a empty network for router 4 + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r4"], nodeif="r4-stubnet") - # Create a empty network for router 2 - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"], nodeif="r2-stubnet") + # Interconnect routers 1, 2, and 3 + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r1"], nodeif="r1-sw5") + switch.add_link(tgen.gears["r2"], nodeif="r2-sw5") + switch.add_link(tgen.gears["r3"], nodeif="r3-sw5") - # Create a empty network for router 3 - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r3"], nodeif="r3-stubnet") - - # Create a empty network for router 4 - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r4"], nodeif="r4-stubnet") - - # Interconnect routers 1, 2, and 3 - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["r1"], nodeif="r1-sw5") - switch.add_link(tgen.gears["r2"], nodeif="r2-sw5") - switch.add_link(tgen.gears["r3"], nodeif="r3-sw5") - - # Interconnect routers 3 and 4 - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["r3"], nodeif="r3-sw6") - switch.add_link(tgen.gears["r4"], nodeif="r4-sw6") + # Interconnect routers 3 and 4 + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r3"], nodeif="r3-sw6") + switch.add_link(tgen.gears["r4"], nodeif="r4-sw6") ##################################################### @@ -164,7 +154,7 @@ def setup_module(mod): if result is not True: pytest.skip("Kernel requirements are not met") - tgen = Topogen(NetworkTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() logger.info("** %s: Setup Topology" % mod.__name__) diff --git a/tests/topotests/ospf6_topo2/test_ospf6_topo2.py b/tests/topotests/ospf6_topo2/test_ospf6_topo2.py index e64000b077..c1ff243fdf 100644 --- a/tests/topotests/ospf6_topo2/test_ospf6_topo2.py +++ b/tests/topotests/ospf6_topo2/test_ospf6_topo2.py @@ -95,33 +95,29 @@ def expect_ospfv3_routes(router, routes, wait=5, detail=False): assert result is None, assertmsg -class OSPFv3Topo2(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # Create 4 routers + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) - # Create 4 routers - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) - - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r4"]) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r4"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(OSPFv3Topo2, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_topo1.py b/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_topo1.py index 392cca3a1b..dfcbf7bcbc 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_topo1.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_topo1.py @@ -75,13 +75,6 @@ pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospf_asbr_summary_topo1.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) NETWORK = { "ipv4": [ @@ -132,28 +125,12 @@ TESTCASES = """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -161,7 +138,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospf_asbr_summary_topo1.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_type7_lsa.py b/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_type7_lsa.py index 3bd4f8b596..a4a946f2e3 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_type7_lsa.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_type7_lsa.py @@ -75,13 +75,6 @@ pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospf_asbr_summary_type7_lsa.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) NETWORK = { "ipv4": [ @@ -135,28 +128,12 @@ TESTCASES = """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -164,7 +141,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospf_asbr_summary_type7_lsa.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py b/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py index 6d1b8d9e9d..0ddd7d517c 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py @@ -61,13 +61,6 @@ pytestmark = [pytest.mark.ospfd] # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospf_authentication.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) """ TOPOOLOGY = Please view in a fixed-width font such as Courier. @@ -92,28 +85,12 @@ TESTCASES = """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -121,7 +98,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospf_authentication.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_chaos.py b/tests/topotests/ospf_basic_functionality/test_ospf_chaos.py index d946cca892..eade677ca5 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_chaos.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_chaos.py @@ -98,29 +98,6 @@ TESTCASES = 3. Verify ospf functionality when staticd is restarted. """ -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospf_chaos.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - - -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - def setup_module(mod): """ @@ -128,7 +105,6 @@ def setup_module(mod): * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -136,7 +112,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospf_chaos.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py index 4c5510ca6c..6c8571fa9d 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py @@ -73,14 +73,6 @@ pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospf_ecmp.json".format(CWD) - -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) # Global variables NETWORK = { @@ -114,28 +106,12 @@ TESTCASES : """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -143,7 +119,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospf_ecmp.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py index eb1c3a914c..9ca46082d1 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py @@ -76,14 +76,6 @@ pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] # Global variables topo = None # Reading the data from JSON File for topology creation - -jsonFile = "{}/ospf_ecmp_lan.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - NETWORK = { "ipv4": [ "11.0.20.1/32", @@ -119,28 +111,12 @@ TESTCASES = """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -148,7 +124,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospf_ecmp_lan.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_lan.py b/tests/topotests/ospf_basic_functionality/test_ospf_lan.py index e7a002fb80..d85267a364 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_lan.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_lan.py @@ -76,13 +76,6 @@ pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospf_lan.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) NETWORK = { "ipv4": [ @@ -114,28 +107,12 @@ Testcases: """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -143,7 +120,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospf_lan.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py b/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py index 5cb4bd33dd..1c2b9a9dd1 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py @@ -68,13 +68,6 @@ pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospf_nssa.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) NETWORK = { "ipv4": [ "11.0.20.1/32", @@ -111,28 +104,12 @@ TESTCASES = """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -140,7 +117,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospf_nssa.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py b/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py index 0c2619d2f6..43e93e98c8 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py @@ -69,19 +69,12 @@ from lib.ospf import ( verify_ospf_database, ) -pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] +pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospf_p2mp.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) """ TOPOOLOGY = @@ -104,28 +97,12 @@ TESTCASES = """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -133,7 +110,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospf_p2mp.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py b/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py index 34abd0dc48..5620ce60a1 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py @@ -71,13 +71,6 @@ pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospf_routemaps.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) NETWORK = { "ipv4": [ @@ -124,28 +117,12 @@ TESTCASES = """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -153,7 +130,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospf_routemaps.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py b/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py index 9f05f396ad..d89864ac4d 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py @@ -75,14 +75,6 @@ topo = None # number of retries. nretry = 5 -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospf_rte_calc.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - NETWORK = { "ipv4": [ "11.0.20.1/32", @@ -115,28 +107,12 @@ TESTCASES = """ """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -144,7 +120,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospf_rte_calc.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py b/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py index 2773c01ff5..4bbc9099d7 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py @@ -73,13 +73,6 @@ pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospf_single_area.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) """ TOPOOLOGY = @@ -106,28 +99,12 @@ TESTCASES = """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -135,7 +112,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospf_single_area.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospf_dual_stack/test_ospf_dual_stack.py b/tests/topotests/ospf_dual_stack/test_ospf_dual_stack.py index f4d98fddb8..fda9892f29 100644 --- a/tests/topotests/ospf_dual_stack/test_ospf_dual_stack.py +++ b/tests/topotests/ospf_dual_stack/test_ospf_dual_stack.py @@ -48,29 +48,10 @@ pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/test_ospf_dual_stack.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - - -class CreateTopo(Topo): - """Test topology builder.""" - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) def setup_module(mod): """Sets up the pytest environment.""" - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -78,7 +59,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/test_ospf_dual_stack.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospf_gr_helper/test_ospf_gr_helper.py b/tests/topotests/ospf_gr_helper/test_ospf_gr_helper.py index 5363822134..6e3147bd0a 100644 --- a/tests/topotests/ospf_gr_helper/test_ospf_gr_helper.py +++ b/tests/topotests/ospf_gr_helper/test_ospf_gr_helper.py @@ -37,7 +37,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from mininet.topo import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration @@ -76,14 +75,6 @@ intf = None intf1 = None pkt = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospf_gr_helper.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - """ Topology: @@ -118,21 +109,6 @@ TC8. Verify helper functionality when dut is helping RR and new grace lsa """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -147,7 +123,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospf_gr_helper.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. @@ -169,7 +148,7 @@ def setup_module(mod): ospf_covergence ) - sw_name = topo["switches"].keys()[0] + sw_name = "s1" intf = topo["routers"]["r0"]["links"][sw_name]["interface"] intf1 = topo["routers"]["r1"]["links"][sw_name]["interface"] pkt = topo["routers"]["r1"]["opq_lsa_hex"] diff --git a/tests/topotests/ospf_gr_topo1/test_ospf_gr_topo1.py b/tests/topotests/ospf_gr_topo1/test_ospf_gr_topo1.py index 3520cdf243..0a6e1ea2f1 100755 --- a/tests/topotests/ospf_gr_topo1/test_ospf_gr_topo1.py +++ b/tests/topotests/ospf_gr_topo1/test_ospf_gr_topo1.py @@ -100,56 +100,50 @@ pytestmark = [pytest.mark.ospfd] outputs = {} -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + # + # Define FRR Routers + # + for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6", "rt7"]: + tgen.add_router(router) - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["rt1"], nodeif="eth-rt2") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt1") - # - # Define FRR Routers - # - for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6", "rt7"]: - tgen.add_router(router) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["rt1"], nodeif="stub1") - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["rt1"], nodeif="eth-rt2") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt1") + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt3") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt2") - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["rt1"], nodeif="stub1") + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt4") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt3") - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt3") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt2") + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt3") - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt4") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt3") + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt3") + switch = tgen.add_switch("s7") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt7") + switch.add_link(tgen.gears["rt7"], nodeif="eth-rt6") - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") - - switch = tgen.add_switch("s7") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt7") - switch.add_link(tgen.gears["rt7"], nodeif="eth-rt6") - - switch = tgen.add_switch("s8") - switch.add_link(tgen.gears["rt7"], nodeif="stub1") + switch = tgen.add_switch("s8") + switch.add_link(tgen.gears["rt7"], nodeif="stub1") def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/ospf_sr_te_topo1/test_ospf_sr_te_topo1.py b/tests/topotests/ospf_sr_te_topo1/test_ospf_sr_te_topo1.py index 6146178d89..cf89141114 100755 --- a/tests/topotests/ospf_sr_te_topo1/test_ospf_sr_te_topo1.py +++ b/tests/topotests/ospf_sr_te_topo1/test_ospf_sr_te_topo1.py @@ -98,64 +98,60 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd, pytest.mark.pathd] -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6", "dst"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6", "dst"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1") + switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1") + #switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1") - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1") - switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1") - #switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1") + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-1") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-1") - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-1") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-1") + #switch = tgen.add_switch("s3") + #switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-2") + #switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-2") - #switch = tgen.add_switch("s3") - #switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-2") - #switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-2") + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-1") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-1") - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-1") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-1") + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-2") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-2") - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-2") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-2") + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") + switch = tgen.add_switch("s7") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") - switch = tgen.add_switch("s7") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") + switch = tgen.add_switch("s8") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5") - switch = tgen.add_switch("s8") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5") - - switch = tgen.add_switch("s9") - switch.add_link(tgen.gears["rt6"], nodeif="eth-dst") - switch.add_link(tgen.gears["dst"], nodeif="eth-rt6") + switch = tgen.add_switch("s9") + switch.add_link(tgen.gears["rt6"], nodeif="eth-dst") + switch.add_link(tgen.gears["dst"], nodeif="eth-rt6") def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) frrdir = tgen.config.get(tgen.CONFIG_SECTION, "frrdir") if not os.path.isfile(os.path.join(frrdir, "pathd")): diff --git a/tests/topotests/ospf_sr_topo1/test_ospf_sr_topo1.py b/tests/topotests/ospf_sr_topo1/test_ospf_sr_topo1.py index 3f448d4bf3..60c87cbb52 100644 --- a/tests/topotests/ospf_sr_topo1/test_ospf_sr_topo1.py +++ b/tests/topotests/ospf_sr_topo1/test_ospf_sr_topo1.py @@ -87,59 +87,55 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.ospfd] -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1") + switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1") + switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1") - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1") - switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1") - switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1") + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-1") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-1") - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-1") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-1") + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-2") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-2") - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-2") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-2") + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-1") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-1") - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-1") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-1") + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-2") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-2") - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-2") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-2") + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") + switch = tgen.add_switch("s7") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") - switch = tgen.add_switch("s7") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") - - switch = tgen.add_switch("s8") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6") - switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5") + switch = tgen.add_switch("s8") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5") def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py b/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py index 2975e5864e..2dcdcba58b 100644 --- a/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py +++ b/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py @@ -53,33 +53,29 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.ospfd] -class NetworkTopo(Topo): - "OSPF topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # Create routers + for router in range(1, 4): + tgen.add_router("r{}".format(router)) - # Create routers - for router in range(1, 4): - tgen.add_router("r{}".format(router)) + # R1-R2 backbone area + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - # R1-R2 backbone area - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - - # R2-R3 NSSA area - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + # R2-R3 NSSA area + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(NetworkTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() # This is a sample of configuration loading. diff --git a/tests/topotests/ospf_te_topo1/test_ospf_te_topo1.py b/tests/topotests/ospf_te_topo1/test_ospf_te_topo1.py index 1678287bb7..a8bb2f6995 100644 --- a/tests/topotests/ospf_te_topo1/test_ospf_te_topo1.py +++ b/tests/topotests/ospf_te_topo1/test_ospf_te_topo1.py @@ -80,38 +80,34 @@ import pytest pytestmark = [pytest.mark.ospfd] -class OspfTeTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *args, **kwargs): - "Build function" - tgen = get_topogen(self) + # Create 4 routers + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) - # Create 4 routers - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) + # Interconect router 1 and 2 with 2 links + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - # Interconect router 1 and 2 with 2 links - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + # Interconect router 3 and 2 + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r2"]) - # Interconect router 3 and 2 - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r3"]) - switch.add_link(tgen.gears["r2"]) + # Interconect router 4 and 2 + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r4"]) + switch.add_link(tgen.gears["r2"]) - # Interconect router 4 and 2 - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r4"]) - switch.add_link(tgen.gears["r2"]) - - # Interconnect router 3 with next AS - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["r3"]) + # Interconnect router 3 with next AS + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r3"]) def setup_module(mod): @@ -119,7 +115,7 @@ def setup_module(mod): logger.info("\n\n---- Starting OSPF TE tests ----\n") - tgen = Topogen(OspfTeTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/ospf_tilfa_topo1/test_ospf_tilfa_topo1.py b/tests/topotests/ospf_tilfa_topo1/test_ospf_tilfa_topo1.py index 956e2ab0a0..97ccdbf370 100644 --- a/tests/topotests/ospf_tilfa_topo1/test_ospf_tilfa_topo1.py +++ b/tests/topotests/ospf_tilfa_topo1/test_ospf_tilfa_topo1.py @@ -74,46 +74,42 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.ospfd] -class TemplateTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # + # Define FRR Routers + # + for router in ["rt1", "rt2", "rt3", "rt4", "rt5"]: + tgen.add_router(router) - # - # Define FRR Routers - # - for router in ["rt1", "rt2", "rt3", "rt4", "rt5"]: - tgen.add_router(router) + # + # Define connections + # + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["rt1"], nodeif="eth-rt2") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt1") - # - # Define connections - # - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["rt1"], nodeif="eth-rt2") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt1") + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["rt1"], nodeif="eth-rt3") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt1") - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["rt1"], nodeif="eth-rt3") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt1") + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2") - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2") + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3") - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3") - - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") - switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(TemplateTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/ospf_topo1/test_ospf_topo1.py b/tests/topotests/ospf_topo1/test_ospf_topo1.py index 50992503ea..175b75f903 100644 --- a/tests/topotests/ospf_topo1/test_ospf_topo1.py +++ b/tests/topotests/ospf_topo1/test_ospf_topo1.py @@ -48,48 +48,44 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.ospfd] -class OSPFTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # Create 4 routers + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) - # Create 4 routers - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) + # Create a empty network for router 1 + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) - # Create a empty network for router 1 - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) + # Create a empty network for router 2 + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) - # Create a empty network for router 2 - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) + # Interconect router 1, 2 and 3 + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - # Interconect router 1, 2 and 3 - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) + # Create empty netowrk for router3 + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r3"]) - # Create empty netowrk for router3 - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r3"]) + # Interconect router 3 and 4 + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) - # Interconect router 3 and 4 - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["r3"]) - switch.add_link(tgen.gears["r4"]) - - # Create a empty network for router 4 - switch = tgen.add_switch("s6") - switch.add_link(tgen.gears["r4"]) + # Create a empty network for router 4 + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r4"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(OSPFTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() ospf6_config = "ospf6d.conf" diff --git a/tests/topotests/ospf_topo1_vrf/test_ospf_topo1_vrf.py b/tests/topotests/ospf_topo1_vrf/test_ospf_topo1_vrf.py index 711f76c5c8..c83c916689 100644 --- a/tests/topotests/ospf_topo1_vrf/test_ospf_topo1_vrf.py +++ b/tests/topotests/ospf_topo1_vrf/test_ospf_topo1_vrf.py @@ -48,39 +48,35 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.ospfd] -class OSPFTopo(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # Create 3 routers + for routern in range(1, 4): + tgen.add_router("r{}".format(routern)) - # Create 3 routers - for routern in range(1, 4): - tgen.add_router("r{}".format(routern)) + # Create a empty network for router 1 + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) - # Create a empty network for router 1 - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) + # Create a empty network for router 2 + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) - # Create a empty network for router 2 - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) + # Interconect router 1, 2 and 3 + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - # Interconect router 1, 2 and 3 - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) - - # Create empty netowrk for router3 - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r3"]) + # Create empty netowrk for router3 + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r3"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(OSPFTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/ospf_topo2/test_ospf_topo2.py b/tests/topotests/ospf_topo2/test_ospf_topo2.py index 38d424c906..696396d68a 100644 --- a/tests/topotests/ospf_topo2/test_ospf_topo2.py +++ b/tests/topotests/ospf_topo2/test_ospf_topo2.py @@ -49,34 +49,32 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.ospfd] -class OSPFTopo(Topo): - "Test topology builder" +CWD = os.path.dirname(os.path.realpath(__file__)) - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) +def build_topo(tgen): + "Build function" - # Create 4 routers - for routern in range(1, 3): - tgen.add_router("r{}".format(routern)) + # Create 4 routers + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) - # Create a empty network for router 1 - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) + # Create a empty network for router 1 + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) - # Create a empty network for router 2 - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) + # Create a empty network for router 2 + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) - # Interconect router 1, 2 - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + # Interconect router 1, 2 + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(OSPFTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py index c76da39ca5..f2158c36e8 100644 --- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py +++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py @@ -75,13 +75,6 @@ from lib.ospf import ( # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospfv3_asbr_summary_topo1.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) NETWORK = { "ipv4": [ @@ -149,28 +142,12 @@ TESTCASES = """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -178,7 +155,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospfv3_asbr_summary_topo1.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp.py index 6bfe4f199e..50f05a2eca 100644 --- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp.py +++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp.py @@ -78,14 +78,6 @@ pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospfv3_ecmp.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - NETWORK = { "ipv4": [ "11.0.20.1/32", @@ -118,28 +110,12 @@ TESTCASES : """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -147,7 +123,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospfv3_ecmp.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py index af1017c6bc..9d944f4d96 100644 --- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py +++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py @@ -78,13 +78,6 @@ pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospfv3_routemaps.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) NETWORK = { "ipv4": [ @@ -131,28 +124,12 @@ TESTCASES = """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -160,7 +137,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospfv3_routemaps.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_rte_calc.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_rte_calc.py index d16cbb76fb..f4dc8dc09a 100644 --- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_rte_calc.py +++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_rte_calc.py @@ -80,14 +80,6 @@ pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospfv3_rte_calc.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - NETWORK = { "ipv6": [ "11.0.20.1/32", @@ -119,28 +111,12 @@ TESTCASES = """ """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -148,7 +124,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospfv3_rte_calc.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_single_area.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_single_area.py index 22593babaa..969e9c45b1 100644 --- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_single_area.py +++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_single_area.py @@ -78,14 +78,6 @@ pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] # Global variables topo = None -# Reading the data from JSON File for topology creation -jsonFile = "{}/ospfv3_single_area.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - """ TOPOOLOGY = Please view in a fixed-width font such as Courier. @@ -111,28 +103,12 @@ TESTCASES = """ -class CreateTopo(Topo): - """ - Test topology builder. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -140,7 +116,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/ospfv3_single_area.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. diff --git a/tests/topotests/pbr_topo1/test_pbr_topo1.py b/tests/topotests/pbr_topo1/test_pbr_topo1.py index 494e27a2ad..304a2dd0c4 100644 --- a/tests/topotests/pbr_topo1/test_pbr_topo1.py +++ b/tests/topotests/pbr_topo1/test_pbr_topo1.py @@ -58,22 +58,18 @@ pytestmark = [pytest.mark.pbrd] ##################################################### -class NetworkTopo(Topo): - "PBR Topology 1" +def build_topo(tgen): + "Build function" - def build(self, **_opts): - "Build function" - tgen = get_topogen(self) + # Populate routers + for routern in range(1, 2): + tgen.add_router("r{}".format(routern)) - # Populate routers - for routern in range(1, 2): - tgen.add_router("r{}".format(routern)) - - # Populate switches - for switchn in range(1, 6): - switch = tgen.add_switch("sw{}".format(switchn)) - switch.add_link(tgen.gears["r1"]) + # Populate switches + for switchn in range(1, 6): + switch = tgen.add_switch("sw{}".format(switchn)) + switch.add_link(tgen.gears["r1"]) ##################################################### @@ -85,7 +81,7 @@ class NetworkTopo(Topo): def setup_module(module): "Setup topology" - tgen = Topogen(NetworkTopo, module.__name__) + tgen = Topogen(build_topo, module.__name__) tgen.start_topology() krel = platform.release() diff --git a/tests/topotests/pim_basic/test_pim.py b/tests/topotests/pim_basic/test_pim.py index e921b37b69..c346a77c08 100644 --- a/tests/topotests/pim_basic/test_pim.py +++ b/tests/topotests/pim_basic/test_pim.py @@ -46,48 +46,46 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.pimd] -class PIMTopo(Topo): - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) +def build_topo(tgen): + "Build function" - for routern in range(1, 4): - tgen.add_router("r{}".format(routern)) + for routern in range(1, 4): + tgen.add_router("r{}".format(routern)) - tgen.add_router("rp") + tgen.add_router("rp") - # rp ------ r1 -------- r2 - # \ - # --------- r3 - # r1 -> .1 - # r2 -> .2 - # rp -> .3 - # r3 -> .4 - # loopback network is 10.254.0.X/32 - # - # r1 <- sw1 -> r2 - # r1-eth0 <-> r2-eth0 - # 10.0.20.0/24 - sw = tgen.add_switch("sw1") - sw.add_link(tgen.gears["r1"]) - sw.add_link(tgen.gears["r2"]) + # rp ------ r1 -------- r2 + # \ + # --------- r3 + # r1 -> .1 + # r2 -> .2 + # rp -> .3 + # r3 -> .4 + # loopback network is 10.254.0.X/32 + # + # r1 <- sw1 -> r2 + # r1-eth0 <-> r2-eth0 + # 10.0.20.0/24 + sw = tgen.add_switch("sw1") + sw.add_link(tgen.gears["r1"]) + sw.add_link(tgen.gears["r2"]) - # r1 <- sw2 -> rp - # r1-eth1 <-> rp-eth0 - # 10.0.30.0/24 - sw = tgen.add_switch("sw2") - sw.add_link(tgen.gears["r1"]) - sw.add_link(tgen.gears["rp"]) + # r1 <- sw2 -> rp + # r1-eth1 <-> rp-eth0 + # 10.0.30.0/24 + sw = tgen.add_switch("sw2") + sw.add_link(tgen.gears["r1"]) + sw.add_link(tgen.gears["rp"]) - # 10.0.40.0/24 - sw = tgen.add_switch("sw3") - sw.add_link(tgen.gears["r1"]) - sw.add_link(tgen.gears["r3"]) + # 10.0.40.0/24 + sw = tgen.add_switch("sw3") + sw.add_link(tgen.gears["r1"]) + sw.add_link(tgen.gears["r3"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(PIMTopo, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() # For all registered routers, load the zebra configuration file diff --git a/tests/topotests/pim_basic_topo2/test_pim_basic_topo2.py b/tests/topotests/pim_basic_topo2/test_pim_basic_topo2.py index 2bed11c546..2352a9ab12 100644 --- a/tests/topotests/pim_basic_topo2/test_pim_basic_topo2.py +++ b/tests/topotests/pim_basic_topo2/test_pim_basic_topo2.py @@ -48,33 +48,29 @@ from lib.micronet_compat import Topo pytestmark = [pytest.mark.bfdd, pytest.mark.pimd] -class PimBasicTopo2(Topo): - "Test topology builder" +def build_topo(tgen): + "Build function" - def build(self, *_args, **_opts): - "Build function" - tgen = get_topogen(self) + # Create 4 routers + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) - # Create 4 routers - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r3"]) - - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r2"]) - switch.add_link(tgen.gears["r4"]) + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r4"]) def setup_module(mod): "Sets up the pytest environment" - tgen = Topogen(PimBasicTopo2, mod.__name__) + tgen = Topogen(build_topo, mod.__name__) tgen.start_topology() router_list = tgen.routers() diff --git a/tests/topotests/rip_topo1/test_rip_topo1.py b/tests/topotests/rip_topo1/test_rip_topo1.py index 91b4278cd3..8cf96777bf 100644 --- a/tests/topotests/rip_topo1/test_rip_topo1.py +++ b/tests/topotests/rip_topo1/test_rip_topo1.py @@ -38,8 +38,7 @@ from functools import partial sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lib import topotest -from lib.micronet_compat import Topo -from lib.micronet_compat import Mininet +from lib.topogen import Topogen, get_topogen fatal_error = "" @@ -52,47 +51,38 @@ pytestmark = [pytest.mark.ripd] ##################################################### -class NetworkTopo(Topo): - "RIP Topology 1" +def build_topo(tgen): + # Setup RIP Routers + for i in range(1, 4): + tgen.add_router("r%s" % i) - def build(self, **_opts): + # + # On main router + # First switch is for a dummy interface (for local network) + switch = tgen.add_switch("sw1") + switch.add_link(tgen.gears["r1"]) + # + # Switches for RIP - # Setup Routers - router = {} - # - # Setup Main Router - router[1] = topotest.addRouter(self, "r1") - # - # Setup RIP Routers - for i in range(2, 4): - router[i] = topotest.addRouter(self, "r%s" % i) - # - # Setup Switches - switch = {} - # - # On main router - # First switch is for a dummy interface (for local network) - switch[1] = self.addSwitch("sw1") - self.addLink(switch[1], router[1], intfName2="r1-eth0") - # - # Switches for RIP - # switch 2 switch is for connection to RIP router - switch[2] = self.addSwitch("sw2") - self.addLink(switch[2], router[1], intfName2="r1-eth1") - self.addLink(switch[2], router[2], intfName2="r2-eth0") - # switch 3 is between RIP routers - switch[3] = self.addSwitch("sw3") - self.addLink(switch[3], router[2], intfName2="r2-eth1") - self.addLink(switch[3], router[3], intfName2="r3-eth1") - # switch 4 is stub on remote RIP router - switch[4] = self.addSwitch("sw4") - self.addLink(switch[4], router[3], intfName2="r3-eth0") + # switch 2 switch is for connection to RIP router + switch = tgen.add_switch("sw2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) - switch[5] = self.addSwitch("sw5") - self.addLink(switch[5], router[1], intfName2="r1-eth2") + # switch 3 is between RIP routers + switch = tgen.add_switch("sw3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"], nodeif="r3-eth1") - switch[6] = self.addSwitch("sw6") - self.addLink(switch[6], router[1], intfName2="r1-eth3") + # switch 4 is stub on remote RIP router + switch = tgen.add_switch("sw4") + switch.add_link(tgen.gears["r3"], nodeif="r3-eth0") + + switch = tgen.add_switch("sw5") + switch.add_link(tgen.gears["r1"]) + + switch = tgen.add_switch("sw6") + switch.add_link(tgen.gears["r1"]) ##################################################### @@ -103,44 +93,36 @@ class NetworkTopo(Topo): def setup_module(module): - global topo, net - print("\n\n** %s: Setup Topology" % module.__name__) print("******************************************\n") - print("Cleanup old Mininet runs") - os.system("sudo mn -c > /dev/null 2>&1") - thisDir = os.path.dirname(os.path.realpath(__file__)) - topo = NetworkTopo() + tgen = Topogen(build_topo, module.__name__) + tgen.start_topology() - net = Mininet(controller=None, topo=topo) - net.start() + net = tgen.net # Starting Routers # for i in range(1, 4): net["r%s" % i].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir, i)) net["r%s" % i].loadConf("ripd", "%s/r%s/ripd.conf" % (thisDir, i)) - net["r%s" % i].startRouter() + tgen.gears["r%s" % i].start() # For debugging after starting FRR daemons, uncomment the next line # CLI(net) def teardown_module(module): - global net - print("\n\n** %s: Shutdown Topology" % module.__name__) print("******************************************\n") - - # End - Shutdown network - net.stop() + tgen = get_topogen() + tgen.stop_topology() def test_router_running(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -160,7 +142,7 @@ def test_router_running(): def test_converge_protocols(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -172,7 +154,7 @@ def test_converge_protocols(): print("******************************************\n") # Not really implemented yet - just sleep 11 secs for now - sleep(11) + sleep(21) # Make sure that all daemons are still running for i in range(1, 4): @@ -185,7 +167,7 @@ def test_converge_protocols(): def test_rip_status(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -246,7 +228,7 @@ def test_rip_status(): def test_rip_routes(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -301,7 +283,7 @@ def test_rip_routes(): def test_zebra_ipv4_routingTable(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -367,7 +349,7 @@ def test_zebra_ipv4_routingTable(): def test_shutdown_check_stderr(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": diff --git a/tests/topotests/ripng_topo1/test_ripng_topo1.py b/tests/topotests/ripng_topo1/test_ripng_topo1.py index 9b3f66111c..e2be3abcc3 100644 --- a/tests/topotests/ripng_topo1/test_ripng_topo1.py +++ b/tests/topotests/ripng_topo1/test_ripng_topo1.py @@ -38,8 +38,7 @@ from functools import partial sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lib import topotest -from lib.micronet_compat import Topo -from lib.micronet_compat import Mininet +from lib.topogen import Topogen, get_topogen fatal_error = "" @@ -52,46 +51,34 @@ pytestmark = [pytest.mark.ripd] ##################################################### -class NetworkTopo(Topo): - "RIPng Topology 1" +def build_topo(tgen): + # Setup RIPng Routers + for i in range(1, 4): + tgen.add_router("r%s" % i) - def build(self, **_opts): + # + # On main router + # First switch is for a dummy interface (for local network) + switch = tgen.add_switch("sw1") + switch.add_link(tgen.gears["r1"]) + # + # Switches for RIPng + # switch 2 switch is for connection to RIP router + switch = tgen.add_switch("sw2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + # switch 3 is between RIP routers + switch = tgen.add_switch("sw3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"], nodeif="r3-eth1") + # switch 4 is stub on remote RIP router + switch = tgen.add_switch("sw4") + switch.add_link(tgen.gears["r3"], nodeif="r3-eth0") - # Setup Routers - router = {} - # - # Setup Main Router - router[1] = topotest.addRouter(self, "r1") - # - # Setup RIPng Routers - for i in range(2, 4): - router[i] = topotest.addRouter(self, "r%s" % i) - - # Setup Switches - switch = {} - # - # On main router - # First switch is for a dummy interface (for local network) - switch[1] = self.addSwitch("sw1") - self.addLink(switch[1], router[1], intfName2="r1-eth0") - # - # Switches for RIPng - # switch 2 switch is for connection to RIP router - switch[2] = self.addSwitch("sw2") - self.addLink(switch[2], router[1], intfName2="r1-eth1") - self.addLink(switch[2], router[2], intfName2="r2-eth0") - # switch 3 is between RIP routers - switch[3] = self.addSwitch("sw3") - self.addLink(switch[3], router[2], intfName2="r2-eth1") - self.addLink(switch[3], router[3], intfName2="r3-eth1") - # switch 4 is stub on remote RIP router - switch[4] = self.addSwitch("sw4") - self.addLink(switch[4], router[3], intfName2="r3-eth0") - - switch[5] = self.addSwitch("sw5") - self.addLink(switch[5], router[1], intfName2="r1-eth2") - switch[6] = self.addSwitch("sw6") - self.addLink(switch[6], router[1], intfName2="r1-eth3") + switch = tgen.add_switch("sw5") + switch.add_link(tgen.gears["r1"]) + switch = tgen.add_switch("sw6") + switch.add_link(tgen.gears["r1"]) ##################################################### @@ -102,44 +89,36 @@ class NetworkTopo(Topo): def setup_module(module): - global topo, net - print("\n\n** %s: Setup Topology" % module.__name__) print("******************************************\n") - print("Cleanup old Mininet runs") - os.system("sudo mn -c > /dev/null 2>&1") - thisDir = os.path.dirname(os.path.realpath(__file__)) - topo = NetworkTopo() + tgen = Topogen(build_topo, module.__name__) + tgen.start_topology() - net = Mininet(controller=None, topo=topo) - net.start() + net = tgen.net # Starting Routers # for i in range(1, 4): net["r%s" % i].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir, i)) net["r%s" % i].loadConf("ripngd", "%s/r%s/ripngd.conf" % (thisDir, i)) - net["r%s" % i].startRouter() + tgen.gears["r%s" % i].start() # For debugging after starting FRR daemons, uncomment the next line # CLI(net) def teardown_module(module): - global net - print("\n\n** %s: Shutdown Topology" % module.__name__) print("******************************************\n") - - # End - Shutdown network - net.stop() + tgen = get_topogen() + tgen.stop_topology() def test_router_running(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -159,7 +138,7 @@ def test_router_running(): def test_converge_protocols(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -184,7 +163,7 @@ def test_converge_protocols(): def test_ripng_status(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -252,7 +231,7 @@ def test_ripng_status(): def test_ripng_routes(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -319,7 +298,7 @@ def test_ripng_routes(): def test_zebra_ipv6_routingTable(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -387,7 +366,7 @@ def test_zebra_ipv6_routingTable(): def test_shutdown_check_stderr(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": @@ -416,7 +395,7 @@ def test_shutdown_check_stderr(): def test_shutdown_check_memleak(): global fatal_error - global net + net = get_topogen().net # Skip if previous fatal error condition is raised if fatal_error != "": diff --git a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo1_ebgp.py b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo1_ebgp.py index 7b9b61fd91..3298be17ee 100644 --- a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo1_ebgp.py +++ b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo1_ebgp.py @@ -68,14 +68,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology creation -JSONFILE = "{}/static_routes_topo1_ebgp.json".format(CWD) -try: - with open(JSONFILE, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(JSONFILE) - # Global variables ADDR_TYPES = check_address_types() NETWORK = {"ipv4": ["11.0.20.1/32", "11.0.20.2/32"], "ipv6": ["2::1/128", "2::2/128"]} @@ -84,25 +76,6 @@ NETWORK2 = {"ipv4": "11.0.20.1/32", "ipv6": "2::1/128"} PREFIX1 = {"ipv4": "110.0.20.1/32", "ipv6": "20::1/128"} -class CreateTopo(Topo): - """ - Test CreateTopo - topology 1. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def dumdum(self): - """ Dummy """ - print("%s", self.name) - - def setup_module(mod): """ Sets up the pytest environment. @@ -117,7 +90,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/static_routes_topo1_ebgp.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py index c0edfef5d7..8c98a88bd5 100644 --- a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py +++ b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py @@ -75,13 +75,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology creation -jsonFile = "{}/static_routes_topo2_ebgp.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) # Global variables BGP_CONVERGENCE = False ADDR_TYPES = check_address_types() @@ -123,21 +116,6 @@ topo_diag = """ """ -class CreateTopo(Topo): - """ - Test CreateTopo - topology 1. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ @@ -145,7 +123,6 @@ def setup_module(mod): * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -153,7 +130,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/static_routes_topo2_ebgp.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo3_ebgp.py b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo3_ebgp.py index f088fd618e..703e295e5a 100644 --- a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo3_ebgp.py +++ b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo3_ebgp.py @@ -70,14 +70,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology creation -jsonFile = "{}/static_routes_topo3_ebgp.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - # Global variables BGP_CONVERGENCE = False ADDR_TYPES = check_address_types() @@ -108,21 +100,6 @@ NETWORK2 = {"ipv4": ["11.0.20.1/32"], "ipv6": ["2::1/128"]} NEXT_HOP_IP = [] -class CreateTopo(Topo): - """ - Test CreateTopo - topology 1. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ @@ -130,7 +107,6 @@ def setup_module(mod): * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -138,7 +114,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/static_routes_topo3_ebgp.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo4_ebgp.py b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo4_ebgp.py index 217f8467dd..bc85a752a4 100644 --- a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo4_ebgp.py +++ b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo4_ebgp.py @@ -72,17 +72,9 @@ from lib.bgp import ( ) from lib.topojson import build_topo_from_json, build_config_from_json + pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] - -# Reading the data from JSON File for topology creation -jsonFile = "{}/static_routes_topo4_ebgp.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - # Global variables BGP_CONVERGENCE = False ADDR_TYPES = check_address_types() @@ -92,21 +84,6 @@ NEXT_HOP_IP = {} pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -class CreateTopo(Topo): - """ - Test CreateTopo - topology 1. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Set up the pytest environment. @@ -120,7 +97,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/static_routes_topo4_ebgp.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo1_ibgp.py b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo1_ibgp.py index ea888c1376..b571e312dd 100644 --- a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo1_ibgp.py +++ b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo1_ibgp.py @@ -68,14 +68,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology creation -jsonFile = "{}/static_routes_topo1_ibgp.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - # Global variables BGP_CONVERGENCE = False ADDR_TYPES = check_address_types() @@ -85,21 +77,6 @@ NETWORK2 = {"ipv4": "11.0.20.1/32", "ipv6": "2::1/128"} PREFIX1 = {"ipv4": "110.0.20.1/32", "ipv6": "20::1/128"} -class CreateTopo(Topo): - """ - Test CreateTopo - topology 1. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ @@ -107,7 +84,6 @@ def setup_module(mod): * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -115,7 +91,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/static_routes_topo1_ibgp.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo2_ibgp.py b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo2_ibgp.py index b58543cc91..20697bf193 100644 --- a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo2_ibgp.py +++ b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo2_ibgp.py @@ -77,13 +77,6 @@ from lib.topotest import version_cmp pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology creation -jsonFile = "{}/static_routes_topo2_ibgp.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) # Global variables BGP_CONVERGENCE = False ADDR_TYPES = check_address_types() @@ -125,21 +118,6 @@ topo_diag = """ """ -class CreateTopo(Topo): - """ - Test CreateTopo - topology 1. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ @@ -147,7 +125,6 @@ def setup_module(mod): * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -155,7 +132,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/static_routes_topo2_ibgp.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo3_ibgp.py b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo3_ibgp.py index 8e769ea66f..ac7a807452 100644 --- a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo3_ibgp.py +++ b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo3_ibgp.py @@ -71,14 +71,6 @@ from lib.topojson import build_topo_from_json, build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -# Reading the data from JSON File for topology creation -jsonFile = "{}/static_routes_topo3_ibgp.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) - # Global variables BGP_CONVERGENCE = False ADDR_TYPES = check_address_types() @@ -109,21 +101,6 @@ NETWORK2 = {"ipv4": ["11.0.20.1/32"], "ipv6": ["2::1/128"]} NEXT_HOP_IP = [] -class CreateTopo(Topo): - """ - Test CreateTopo - topology 1. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ @@ -131,7 +108,6 @@ def setup_module(mod): * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -139,7 +115,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/static_routes_topo3_ibgp.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers diff --git a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py index eb828ea035..8dcdc8093c 100644 --- a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py +++ b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py @@ -70,13 +70,6 @@ from lib.bgp import ( from lib.topojson import build_topo_from_json, build_config_from_json from lib.topotest import version_cmp -# Reading the data from JSON File for topology creation -jsonFile = "{}/static_routes_topo4_ibgp.json".format(CWD) -try: - with open(jsonFile, "r") as topoJson: - topo = json.load(topoJson) -except IOError: - assert False, "Could not read file {}".format(jsonFile) # Global variables BGP_CONVERGENCE = False @@ -87,27 +80,11 @@ NEXT_HOP_IP = {} pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] -class CreateTopo(Topo): - """ - Test CreateTopo - topology 1. - - * `Topo`: Topology object - """ - - def build(self, *_args, **_opts): - """Build function.""" - tgen = get_topogen(self) - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Set up the pytest environment. * `mod`: module name """ - global topo testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -115,7 +92,10 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(CreateTopo, mod.__name__) + json_file = "{}/static_routes_topo4_ibgp.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # Starting topology, create tmp files which are loaded to routers From fe50239bc679cf9d4c64991f220bc214f96b18ec Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Tue, 10 Aug 2021 05:36:46 -0400 Subject: [PATCH 12/25] tests: remove legacy Topo class from infra Signed-off-by: Christian Hopps --- tests/topotests/lib/common_config.py | 1 - tests/topotests/lib/lutil.py | 1 - tests/topotests/lib/topogen.py | 17 ++++++----------- tests/topotests/lib/topojson.py | 18 +++++++++++++----- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index 99a3a4a87d..de3aa534a4 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -44,7 +44,6 @@ except ImportError: import configparser from io import StringIO -from lib.micronet_compat import Mininet from lib.topogen import TopoRouter, get_topogen from lib.topolog import get_logger, logger from lib.topotest import frr_unicode, interface_set_status, version_cmp diff --git a/tests/topotests/lib/lutil.py b/tests/topotests/lib/lutil.py index 7248ce267f..c49488ed9d 100644 --- a/tests/topotests/lib/lutil.py +++ b/tests/topotests/lib/lutil.py @@ -26,7 +26,6 @@ import math import time from lib.topolog import logger from lib.topotest import json_cmp -from lib.micronet_compat import Mininet # L utility functions diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index c0529c68e2..5c2ff1bf85 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -160,7 +160,6 @@ class Topogen(object): * `modname`: module name must be a unique name to identify logs later. """ self.config = None - self.topo = None self.net = None self.gears = {} self.routern = 1 @@ -220,14 +219,13 @@ class Topogen(object): # Allow anyone, but set the sticky bit to avoid file deletions os.chmod(self.logdir, 0o1777) - # Old twisty way of creating sub-classed topology object which has it's build - # method invoked which calls Topogen methods which then call Topo methods to - # create a topology within the Topo object, which is then used by + # Remove old twisty way of creating sub-classed topology object which has it's + # build method invoked which calls Topogen methods which then call Topo methods + # to create a topology within the Topo object, which is then used by # Mininet(Micronet) to build the actual topology. - if inspect.isclass(topodef): - self.topo = topodef() + assert not inspect.isclass(topodef) - self.net = Mininet(controller=None, topo=self.topo) + self.net = Mininet(controller=None) # New direct way: Either a dictionary defines the topology or a build function # is supplied, or a json filename all of which build the topology by calling @@ -390,10 +388,7 @@ class Topogen(object): node1.register_link(ifname1, node2, ifname2) node2.register_link(ifname2, node1, ifname1) - if self.net: - self.net.add_link(node1.name, node2.name, ifname1, ifname2) - else: - self.topo.addLink(node1.name, node2.name, intfName1=ifname1, intfName2=ifname2) + self.net.add_link(node1.name, node2.name, ifname1, ifname2) def get_gears(self, geartype): """ diff --git a/tests/topotests/lib/topojson.py b/tests/topotests/lib/topojson.py index 1b00f83ab2..d8e0e5d182 100644 --- a/tests/topotests/lib/topojson.py +++ b/tests/topotests/lib/topojson.py @@ -42,14 +42,16 @@ from lib.topolog import logger ROUTER_LIST = [] -def build_topo_from_json(tgen, topo): +def build_topo_from_json(tgen, topo=None): """ Reads configuration from JSON file. Adds routers, creates interface names dynamically and link routers as defined in JSON to create topology. Assigns IPs dynamically to all interfaces of each router. * `tgen`: Topogen object - * `topo`: json file data + * `topo`: json file data, or use tgen.json_topo if None """ + if topo is None: + topo = tgen.json_topo ROUTER_LIST = sorted( topo["routers"].keys(), key=lambda x: int(re_search(r"\d+", x).group(0)) @@ -285,8 +287,11 @@ def build_topo_from_json(tgen, topo): ) -def linux_intf_config_from_json(tgen, topo): +def linux_intf_config_from_json(tgen, topo=None): """Configure interfaces from linux based on topo.""" + if topo is None: + topo = tgen.json_topo + routers = topo["routers"] for rname in routers: router = tgen.net[rname] @@ -303,13 +308,13 @@ def linux_intf_config_from_json(tgen, topo): router.cmd_raises("ip -6 addr add {} dev {}".format(link["ipv6"], lname)) -def build_config_from_json(tgen, topo, save_bkup=True): +def build_config_from_json(tgen, topo=None, save_bkup=True): """ Reads initial configuraiton from JSON for each router, builds configuration and loads its to router. * `tgen`: Topogen object - * `topo`: json file data + * `topo`: json file data, or use tgen.json_topo if None """ func_dict = OrderedDict( @@ -328,6 +333,9 @@ def build_config_from_json(tgen, topo, save_bkup=True): ] ) + if topo is None: + topo = tgen.json_topo + data = topo["routers"] for func_type in func_dict.keys(): logger.info("Checking for {} configuration in input data".format(func_type)) From 86dc61d1b2796d0454c03919a0e99b863bb31dbb Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Tue, 10 Aug 2021 05:36:21 -0400 Subject: [PATCH 13/25] tests: remove legacy Topo class from micronet Signed-off-by: Christian Hopps --- tests/topotests/lib/micronet_compat.py | 119 +------------------------ 1 file changed, 2 insertions(+), 117 deletions(-) diff --git a/tests/topotests/lib/micronet_compat.py b/tests/topotests/lib/micronet_compat.py index fcf3610a38..ca061c8b26 100644 --- a/tests/topotests/lib/micronet_compat.py +++ b/tests/topotests/lib/micronet_compat.py @@ -161,102 +161,8 @@ class Node(LinuxNamespace): class Topo(object): # pylint: disable=R0205 - """ - Topology object passed to Micronet to build actual topology. - """ - def __init__(self, *args, **kwargs): - self.params = kwargs - self.name = kwargs["name"] if "name" in kwargs else "unnamed" - self.tgen = kwargs["tgen"] if "tgen" in kwargs else None - - self.logger = logging.getLogger(__name__ + ".topo") - - self.logger.debug("%s: Creating", self) - - self.nodes = {} - self.hosts = {} - self.switches = {} - self.links = {} - - # if "no_init_build" in kwargs and kwargs["no_init_build"]: - # return - - # This needs to move outside of here. Current tests count on it being called on init; - # however, b/c of this there is lots of twisty logic to support topogen based tests where - # the build routine must get get_topogen() so topogen can then set it's topogen.topo to the - # class it's in the process of instantiating (this one) b/c build will use topogen before - # the instantiation completes. - self.build(*args, **kwargs) - - def __str__(self): - return "Topo({})".format(self.name) - - def build(self, *args, **kwargs): - "Overriden by real class" - del args - del kwargs - raise NotImplementedError("Needs to be overriden") - - def addHost(self, name, **kwargs): - self.logger.debug("%s: addHost %s", self, name) - self.nodes[name] = dict(**kwargs) - self.hosts[name] = self.nodes[name] - return name - - addNode = addHost - - def addSwitch(self, name, **kwargs): - self.logger.debug("%s: addSwitch %s", self, name) - self.nodes[name] = dict(**kwargs) - if "cls" in self.nodes[name]: - self.logger.warning("Overriding Bridge class with micronet.Bridge") - del self.nodes[name]["cls"] - self.switches[name] = self.nodes[name] - return name - - def addLink(self, name1, name2, **kwargs): - """Link up switch and a router. - - possible kwargs: - - intfName1 :: switch-side interface name - sometimes missing - - intfName2 :: router-side interface name - - addr1 :: switch-side MAC used by test_ldp_topo1 only - - addr2 :: router-side MAC used by test_ldp_topo1 only - """ - if1 = ( - kwargs["intfName1"] - if "intfName1" in kwargs - else "{}-{}".format(name1, name2) - ) - if2 = ( - kwargs["intfName2"] - if "intfName2" in kwargs - else "{}-{}".format(name2, name1) - ) - - self.logger.debug("%s: addLink %s %s if1: %s if2: %s", self, name1, name2, if1, if2) - - if name1 in self.switches: - assert name2 in self.hosts - swname, rname = name1, name2 - elif name2 in self.switches: - assert name1 in self.hosts - swname, rname = name2, name1 - if1, if2 = if2, if1 - else: - # p2p link - assert name1 in self.hosts - assert name2 in self.hosts - swname, rname = name1, name2 - - if swname not in self.links: - self.links[swname] = {} - - if rname not in self.links[swname]: - self.links[swname][rname] = set() - - self.links[swname][rname].add((if1, if2)) + raise Exception("Remove Me") class Mininet(Micronet): @@ -266,7 +172,7 @@ class Mininet(Micronet): g_mnet_inst = None - def __init__(self, controller=None, topo=None): + def __init__(self, controller=None): """ Create a Micronet. """ @@ -290,27 +196,6 @@ class Mininet(Micronet): self.logger.debug("%s: Creating", self) - if topo and topo.hosts: - self.logger.debug("Adding hosts: %s", topo.hosts.keys()) - for name in topo.hosts: - self.add_host(name, **topo.hosts[name]) - - if topo and topo.switches: - self.logger.debug("Adding switches: %s", topo.switches.keys()) - for name in topo.switches: - self.add_switch(name, **topo.switches[name]) - - if topo and topo.links: - self.logger.debug("Adding links: ") - for swname in sorted(topo.links): - for rname in sorted(topo.links[swname]): - for link in topo.links[swname][rname]: - self.add_link(swname, rname, link[0], link[1]) - - if topo: - # Now that topology is built, configure hosts - self.configure_hosts() - def __str__(self): return "Mininet()" From a5124c49d37c7474ad720f387307ff62f680a297 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Fri, 30 Jul 2021 14:45:56 +0000 Subject: [PATCH 14/25] tests: add helper object for mcast-tester and iperf tool. Signed-off-by: Christian Hopps --- tests/topotests/lib/common_config.py | 411 ++++++++++++++------------- tests/topotests/lib/mcast-tester.py | 51 ++-- tests/topotests/lib/pim.py | 116 ++++++++ 3 files changed, 367 insertions(+), 211 deletions(-) diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index de3aa534a4..fc51b11141 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -44,6 +44,7 @@ except ImportError: import configparser from io import StringIO +from lib.micronet import comm_error from lib.topogen import TopoRouter, get_topogen from lib.topolog import get_logger, logger from lib.topotest import frr_unicode, interface_set_status, version_cmp @@ -4439,202 +4440,232 @@ def required_linux_kernel_version(required_version): return True -def iperfSendIGMPJoin(tgen, server, bindToAddress, l4Type="UDP", join_interval=1): - """ - Run iperf to send IGMP join and traffic +class HostApplicationHelper (object): + """Helper to track and cleanup per-host based test processes.""" - Parameters: - ----------- - * `tgen` : Topogen object - * `l4Type`: string, one of [ TCP, UDP ] - * `server`: iperf server, from where IGMP join would be sent - * `bindToAddress`: bind to , an interface or multicast - address - * `join_interval`: seconds between periodic bandwidth reports + def __init__(self, tgen=None, base_cmd=None): + self.base_cmd_str = "" + self.host_procs = {} + self.tgen = None + self.set_base_cmd(base_cmd if base_cmd else []) + if tgen is not None: + self.init(tgen) - returns: - -------- - errormsg or True - """ + def __enter__ (self): + self.init() + return self - logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) + def __exit__ (self ,type, value, traceback): + self.cleanup() - rnode = tgen.gears[server] + def __str__ (self): + return "HostApplicationHelper({})".format(self.base_cmd_str) - iperf_path = tgen.net.get_exec_path("iperf") - - if bindToAddress and not isinstance(bindToAddress, list): - bindToAddress = [ipaddress.IPv4Address(frr_unicode(bindToAddress))] - - for bindTo in bindToAddress: - iperf_args = [iperf_path, "-s"] - - # UDP/TCP - if l4Type == "UDP": - iperf_args.append("-u") - - iperf_args.append("-B") - iperf_args.append(str(bindTo)) - - # Join interval - if join_interval: - iperf_args.append("-i") - iperf_args.append(str(join_interval)) - - # Run iperf command to send IGMP join - logger.debug("[DUT: %s]: Running command: %s",server, iperf_args) - - p = rnode.popen(iperf_args, stderr=subprocess.STDOUT) - rc = p.poll() - if rc is not None: - output, _ = p.communicate() - if rc: - errormsg = "IGMP join is not sent for {}. Error: {}".format(bindTo, output) - logger.error("%s", output) - return errormsg - - if server not in g_iperf_server_procs: - g_iperf_server_procs[server] = [] - g_iperf_server_procs[server].append(p) - - logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name)) - return True - - -def iperfSendTraffic( - tgen, - client, - sentToAddress, - ttl, - time=0, - l4Type="UDP", - bindToIntf=None, -): - """ - Run iperf to send IGMP join and traffic - - Parameters: - ----------- - * `tgen` : Topogen object - * `l4Type`: string, one of [ TCP, UDP ] - * `client`: iperf client, from where iperf traffic would be sent - * `sentToAddress`: bind to , an interface or multicast - address - * `ttl`: time to live - * `time`: time in seconds to transmit for - * `bindToIntf`: Source interface ip address - - returns: - -------- - errormsg or True - """ - - logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - - rnode = tgen.gears[client] - - iperf_path = tgen.net.get_exec_path("iperf") - - if sentToAddress and not isinstance(sentToAddress, list): - sentToAddress = [ipaddress.IPv4Address(frr_unicode(sentToAddress))] - - for sendTo in sentToAddress: - iperf_args = [iperf_path, "-c", sendTo] - - # Bind to Interface IP - if bindToIntf: - ifaddr = frr_unicode(tgen.json_topo["routers"][client]["links"][bindToIntf]["ipv4"]) - ipaddr = ipaddress.IPv4Interface(ifaddr).ip - iperf_args.append("-B") - iperf_args.append(str(ipaddr)) - - # UDP/TCP - if l4Type == "UDP": - iperf_args.append("-u") - iperf_args.append("-b") - iperf_args.append("0.012m") - - # TTL - if ttl: - iperf_args.append("-T") - iperf_args.append(str(ttl)) - - # Time - if time: - iperf_args.append("-t") - iperf_args.append(str(time)) - - # Run iperf command to send multicast traffic - logger.debug("[DUT: {}]: Running command: {}".format(client, iperf_args)) - - p = rnode.popen(iperf_args, stderr=subprocess.STDOUT) - rc = p.poll() - if rc is not None: - output, _ = p.communicate() - if rc: - errormsg = "Multicast traffic is not sent for {}. Error {}".format( - sendTo, output - ) - logger.error(output) - return errormsg - - if client not in g_iperf_client_procs: - g_iperf_client_procs[client] = [] - g_iperf_client_procs[client].append(p) - - logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name)) - return True - - -def kill_iperf(tgen, dut=None, action=None): - """ - Killing iperf process if running for any router in topology - Parameters: - ----------- - * `tgen` : Topogen object - * `dut` : Any iperf hostname to send igmp prune - * `action`: to kill igmp join iperf action is remove_join - to kill traffic iperf action is remove_traffic - - Usage - ---- - kill_iperf(tgen, dut ="i6", action="remove_join") - - """ - - logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - logger.debug("Running iperfs: clients: %s servers: %s", g_iperf_client_procs, g_iperf_server_procs) - - if dut is not None: - nodes = [dut] - else: - nodes = sorted(tgen.gears.keys()) - - for name in nodes: - logger.debug("Checking for iperfs on %s", name) - if action == "remove_join": - procs = g_iperf_server_procs[name] if name in g_iperf_server_procs else [] - g_iperf_server_procs[name] = [] - elif action == "remove_traffic": - procs = g_iperf_client_procs[name] if name in g_iperf_client_procs else [] - g_iperf_client_procs[name] = [] + def set_base_cmd(self, base_cmd): + assert isinstance(base_cmd, list) or isinstance(base_cmd, tuple) + self.base_cmd = base_cmd + if base_cmd: + self.base_cmd_str = " ".join(base_cmd) else: - procs = [] - if name in g_iperf_server_procs: - procs.extend(g_iperf_server_procs[name]) - g_iperf_server_procs[name] = [] - if name in g_iperf_client_procs: - procs.extend(g_iperf_client_procs[name]) - g_iperf_client_procs[name] = [] - for p in procs: - logger.info("[DUT: {}]: Terminating iperf: [{}]".format(name, p.pid)) - # p.send_signal(signal.SIGHUP) - p.terminate() - for p in procs: - logger.info("[DUT: {}]: Waiting for iperf to terminate: [{}]".format(name, p.pid)) - p.wait() + self.base_cmd_str = "" - logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name)) + def init(self, tgen=None): + """Initialize the helper with tgen if needed. + + If overridden, need to handle multiple entries but one init. Will be called on + object creation if tgen is supplied. Will be called again on __enter__ so should + not re-init if already inited. + """ + if self.tgen: + assert tgen is None or self.tgen == tgen + else: + self.tgen = tgen + + def started_proc(self, host, p): + """Called after process started on host. + + Return value is passed to `stopping_proc` method.""" + logger.debug("%s: Doing nothing after starting process", self) + return False + + def stopping_proc(self, host, p, info): + """Called after process started on host.""" + logger.debug("%s: Doing nothing before stopping process", self) + + def _add_host_proc(self, host, p): + v = self.started_proc(host, p) + + if host not in self.host_procs: + self.host_procs[host] = [] + logger.debug("%s: %s: tracking process %s", self, host, p) + self.host_procs[host].append((p, v)) + + def stop_host(self, host): + """Stop the process on the host. + + Override to do additional cleanup.""" + if host in self.host_procs: + hlogger = self.tgen.net[host].logger + for p, v in self.host_procs[host]: + self.stopping_proc(host, p, v) + logger.debug("%s: %s: terminating process %s", self, host, p.pid) + hlogger.debug("%s: %s: terminating process %s", self, host, p.pid) + rc = p.poll() + if rc is not None: + logger.error("%s: %s: process early exit %s: %s", self, host, p.pid, comm_error(p)) + hlogger.error("%s: %s: process early exit %s: %s", self, host, p.pid, comm_error(p)) + else: + p.terminate() + p.wait() + logger.debug("%s: %s: terminated process %s: %s", self, host, p.pid, comm_error(p)) + hlogger.debug("%s: %s: terminated process %s: %s", self, host, p.pid, comm_error(p)) + + del self.host_procs[host] + + def stop_all_hosts(self): + hosts = set(self.host_procs) + for host in hosts: + self.stop_host(host) + + def cleanup(self): + self.stop_all_hosts() + + def run(self, host, cmd_args, **kwargs): + cmd = list(self.base_cmd) + cmd.extend(cmd_args) + p = self.tgen.gears[host].popen(cmd, **kwargs) + assert p.poll() is None + self._add_host_proc(host, p) + return p + + def check_procs(self): + """Check that all current processes are running, log errors if not. + + Returns: List of stopped processes.""" + procs = [] + + logger.debug("%s: checking procs on hosts %s", self, self.host_procs.keys()) + + for host in self.host_procs: + hlogger = self.tgen.net[host].logger + for p, _ in self.host_procs[host]: + logger.debug("%s: checking %s proc %s", self, host, p) + rc = p.poll() + if rc is None: + continue + logger.error("%s: %s proc exited: %s", self, host, comm_error(p), exc_info=True) + hlogger.error("%s: %s proc exited: %s", self, host, comm_error(p), exc_info=True) + procs.append(p) + return procs + + +class IPerfHelper(HostApplicationHelper): + + def __str__ (self): + return "IPerfHelper()" + + def run_join(self, host, join_addr, l4Type="UDP", join_interval=1, join_intf=None, join_towards=None): + """ + Use iperf to send IGMP join and listen to traffic + + Parameters: + ----------- + * `host`: iperf host from where IGMP join would be sent + * `l4Type`: string, one of [ TCP, UDP ] + * `join_addr`: multicast address (or addresses) to join to + * `join_interval`: seconds between periodic bandwidth reports + * `join_intf`: the interface to bind the join to + * `join_towards`: router whos interface to bind the join to + + returns: Success (bool) + """ + + iperf_path = self.tgen.net.get_exec_path("iperf") + + assert join_addr + if not isinstance(join_addr, list) and not isinstance(join_addr, tuple): + join_addr = [ipaddress.IPv4Address(frr_unicode(join_addr))] + + for bindTo in join_addr: + iperf_args = [iperf_path, "-s"] + + if l4Type == "UDP": + iperf_args.append("-u") + + iperf_args.append("-B") + if join_towards: + to_intf = frr_unicode(self.tgen.json_topo["routers"][host]["links"][join_towards]["interface"]) + iperf_args.append("{}%{}".format(str(bindTo), to_intf)) + elif join_intf: + iperf_args.append("{}%{}".format(str(bindTo), join_intf)) + else: + iperf_args.append(str(bindTo)) + + + if join_interval: + iperf_args.append("-i") + iperf_args.append(str(join_interval)) + + p = self.run(host, iperf_args) + if p.poll() is not None: + logger.error("IGMP join failed on %s: %s", bindTo, comm_error(p)) + return False + return True + + + def run_traffic(self, host, sentToAddress, ttl, time=0, l4Type="UDP", bind_towards=None): + """ + Run iperf to send IGMP join and traffic + + Parameters: + ----------- + * `host`: iperf host to send traffic from + * `l4Type`: string, one of [ TCP, UDP ] + * `sentToAddress`: multicast address to send traffic to + * `ttl`: time to live + * `time`: time in seconds to transmit for + * `bind_towards`: Router who's interface the source ip address is got from + + returns: Success (bool) + """ + + iperf_path = self.tgen.net.get_exec_path("iperf") + + if sentToAddress and not isinstance(sentToAddress, list): + sentToAddress = [ipaddress.IPv4Address(frr_unicode(sentToAddress))] + + for sendTo in sentToAddress: + iperf_args = [iperf_path, "-c", sendTo] + + # Bind to Interface IP + if bind_towards: + ifaddr = frr_unicode(self.tgen.json_topo["routers"][host]["links"][bind_towards]["ipv4"]) + ipaddr = ipaddress.IPv4Interface(ifaddr).ip + iperf_args.append("-B") + iperf_args.append(str(ipaddr)) + + # UDP/TCP + if l4Type == "UDP": + iperf_args.append("-u") + iperf_args.append("-b") + iperf_args.append("0.012m") + + # TTL + if ttl: + iperf_args.append("-T") + iperf_args.append(str(ttl)) + + # Time + if time: + iperf_args.append("-t") + iperf_args.append(str(time)) + + p = self.run(host, iperf_args) + if p.poll() is not None: + logger.error("mcast traffic send failed for %s: %s", sendTo, comm_error(p)) + return False + + return True def verify_ip_nht(tgen, input_dict): @@ -4675,7 +4706,7 @@ def verify_ip_nht(tgen, input_dict): rnode = router_list[router] nh_list = input_dict[router] - if validate_ip_address(next(iter(nh_list))) is "ipv6": + if validate_ip_address(next(iter(nh_list))) == "ipv6": show_ip_nht = run_frr_cmd(rnode, "show ipv6 nht") else: show_ip_nht = run_frr_cmd(rnode, "show ip nht") diff --git a/tests/topotests/lib/mcast-tester.py b/tests/topotests/lib/mcast-tester.py index 117bf79eb9..a594c4c88d 100755 --- a/tests/topotests/lib/mcast-tester.py +++ b/tests/topotests/lib/mcast-tester.py @@ -60,9 +60,9 @@ def multicast_join(sock, ifindex, group, port): # Main code. # parser = argparse.ArgumentParser(description="Multicast RX utility") -parser.add_argument('socket', help='Point to topotest UNIX socket') parser.add_argument('group', help='Multicast IP') parser.add_argument('interface', help='Interface name') +parser.add_argument('--socket', help='Point to topotest UNIX socket') parser.add_argument( '--send', help='Transmit instead of join with interval', @@ -84,14 +84,19 @@ if os.geteuid() != 0: sys.exit(1) # Wait for topotest to synchronize with us. -toposock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0) -while True: - try: - toposock.connect(args.socket) - break - except ConnectionRefusedError: - time.sleep(1) - continue +if not args.socket: + toposock = None +else: + toposock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0) + while True: + try: + toposock.connect(args.socket) + break + except ConnectionRefusedError: + time.sleep(1) + continue + # Set topotest socket non blocking so we can multiplex the main loop. + toposock.setblocking(False) msock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) if args.send > 0: @@ -105,26 +110,30 @@ if args.send > 0: socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, struct.pack("b", ttl)) # Block to ensure packet send. msock.setblocking(True) - # Set topotest socket non blocking so we can multiplex the main loop. - toposock.setblocking(False) else: multicast_join(msock, ifindex, args.group, port) +def should_exit(): + if not toposock: + # If we are sending then we have slept + if not args.send: + time.sleep(100) + return False + else: + try: + data = toposock.recv(1) + if data == b'': + print(' -> Connection closed') + return True + except BlockingIOError: + return False + counter = 0 -while True: +while not should_exit(): if args.send > 0: msock.sendto(b"test %d" % counter, (args.group, port)) counter += 1 time.sleep(args.send) - try: - data = toposock.recv(1) - if data == b'': - print(' -> Connection closed') - break - except BlockingIOError: - continue - msock.close() - sys.exit(0) diff --git a/tests/topotests/lib/pim.py b/tests/topotests/lib/pim.py index bb964df7dc..2cb4777a94 100644 --- a/tests/topotests/lib/pim.py +++ b/tests/topotests/lib/pim.py @@ -19,7 +19,9 @@ import datetime import os import re +import socket import sys +import tempfile import traceback from copy import deepcopy from time import sleep @@ -29,12 +31,16 @@ import pytest # Import common_config to use commomnly used APIs from lib.common_config import ( create_common_configurations, + HostApplicationHelper, + InvalidCLIError, create_common_configuration, InvalidCLIError, retry, run_frr_cmd, ) +from lib.micronet import comm_error, get_exec_path from lib.topolog import logger +from lib.topotest import frr_unicode #### CWD = os.path.dirname(os.path.realpath(__file__)) @@ -3412,3 +3418,113 @@ def verify_igmp_interface(tgen, topo, dut, igmp_iface, interface_ip, expected=Tr logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name)) return True + + +class McastTesterHelper (HostApplicationHelper): + + def __init__(self, tgen=None): + self.script_path = os.path.join(CWD, "mcast-tester.py") + self.host_conn = {} + self.listen_sock = None + + # # Get a temporary file for socket path + # (fd, sock_path) = tempfile.mkstemp("-mct.sock", "tmp" + str(os.getpid())) + # os.close(fd) + # os.remove(sock_path) + # self.app_sock_path = sock_path + + # # Listen on unix socket + # logger.debug("%s: listening on socket %s", self, self.app_sock_path) + # self.listen_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0) + # self.listen_sock.settimeout(10) + # self.listen_sock.bind(self.app_sock_path) + # self.listen_sock.listen(10) + + python3_path = get_exec_path(["python3", "python"]) + super(McastTesterHelper, self).__init__( + tgen, + # [python3_path, self.script_path, self.app_sock_path] + [python3_path, self.script_path] + ) + + def __str__ (self): + return "McastTesterHelper({})".format(self.script_path) + + def run_join(self, host, join_addrs, join_towards=None, join_intf=None): + """ + Join a UDP multicast group. + + One of join_towards or join_intf MUST be set. + + Parameters: + ----------- + * `host`: host from where IGMP join would be sent + * `join_addrs`: multicast address (or addresses) to join to + * `join_intf`: the interface to bind the join[s] to + * `join_towards`: router whos interface to bind the join[s] to + """ + if not isinstance(join_addrs, list) and not isinstance(join_addrs, tuple): + join_addrs = [join_addrs] + + if join_towards: + join_intf = frr_unicode(self.tgen.json_topo["routers"][host]["links"][join_towards]["interface"]) + else: + assert join_intf + + for join in join_addrs: + self.run(host, [join, join_intf]) + + return True + + def run_traffic(self, host, send_to_addrs, bind_towards=None, bind_intf=None): + """ + Send UDP multicast traffic. + + One of bind_towards or bind_intf MUST be set. + + Parameters: + ----------- + * `host`: host to send traffic from + * `send_to_addrs`: multicast address (or addresses) to send traffic to + * `bind_towards`: Router who's interface the source ip address is got from + """ + if bind_towards: + bind_intf = frr_unicode(self.tgen.json_topo["routers"][host]["links"][bind_towards]["interface"]) + else: + assert bind_intf + + if not isinstance(send_to_addrs, list) and not isinstance(send_to_addrs, tuple): + send_to_addrs = [send_to_addrs] + + for send_to in send_to_addrs: + self.run(host, ["--send=0.7", send_to, bind_intf]) + + return True + + # def cleanup(self): + # super(McastTesterHelper, self).cleanup() + + # if not self.listen_sock: + # return + + # logger.debug("%s: closing listen socket %s", self, self.app_sock_path) + # self.listen_sock.close() + # self.listen_sock = None + + # if os.path.exists(self.app_sock_path): + # os.remove(self.app_sock_path) + + # def started_proc(self, host, p): + # logger.debug("%s: %s: accepting on socket %s", self, host, self.app_sock_path) + # try: + # conn = self.listen_sock.accept() + # return conn + # except Exception as error: + # logger.error("%s: %s: accept on socket failed: %s", self, host, error) + # if p.poll() is not None: + # logger.error("%s: %s: helper app quit: %s", self, host, comm_error(p)) + # raise + + # def stopping_proc(self, host, p, conn): + # logger.debug("%s: %s: closing socket %s", self, host, conn) + # conn[0].close() From 1973df1d3970d5e24fe50ec17acacfd91c7c1be2 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Fri, 30 Jul 2021 14:46:11 +0000 Subject: [PATCH 15/25] tests: use new helper object for mcast-tester and iperf - Decrease igmp query interval to fix pim test run times Signed-off-by: Christian Hopps --- .../msdp_mesh_topo1/test_msdp_mesh_topo1.py | 91 +-------- tests/topotests/msdp_topo1/test_msdp_topo1.py | 102 +-------- .../test_mcast_pim_bsmp_01.py | 44 ++-- .../test_mcast_pim_bsmp_02.py | 38 ++-- .../test_multicast_pim_sm_topo1.py | 169 +++++++-------- .../test_multicast_pim_sm_topo2.py | 111 +++++----- .../test_multicast_pim_sm_topo3.py | 119 +++++------ .../test_multicast_pim_sm_topo4.py | 29 +-- .../test_multicast_pim_static_rp.py | 102 ++++----- tests/topotests/pim_acl/test_pim_acl.py | 167 +++++---------- tests/topotests/pim_igmp_vrf/test_pim_vrf.py | 193 ++++++------------ 11 files changed, 439 insertions(+), 726 deletions(-) diff --git a/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py b/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py index 121f4a7fdc..c32800c936 100644 --- a/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py +++ b/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py @@ -45,73 +45,11 @@ from lib.micronet_compat import Topo from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger +from lib.pim import McastTesterHelper pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd, pytest.mark.pimd] -# -# Test global variables: -# They are used to handle communicating with external application. -# -HELPER_APP_PATH = os.path.join(CWD, "../lib/mcast-tester.py") -app_listener = None -app_clients = {} -app_procs = [] - - -def get_app_sock_path(): - tgen = get_topogen() - return os.path.join(tgen.logdir, "apps.sock") - - -def listen_to_applications(): - "Start listening socket to connect with applications." - # Remove old socket. - app_sock_path = get_app_sock_path() - try: - os.unlink(app_sock_path) - except OSError: - pass - - sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0) - sock.bind(app_sock_path) - sock.listen(10) - global app_listener - app_listener = sock - -def accept_host(host): - "Accept connection from application running in hosts." - global app_listener, app_clients - conn = app_listener.accept() - app_clients[host] = { - 'fd': conn[0], - 'address': conn[1] - } - -def close_applications(): - "Signal applications to stop and close all sockets." - global app_listener, app_clients - - # Close listening socket. - app_listener.close() - - app_sock_path = get_app_sock_path() - - # Remove old socket. - try: - os.unlink(app_sock_path) - except OSError: - pass - - # Close all host connections. - for host in ["h1", "h2"]: - if app_clients.get(host) is None: - continue - app_clients["h1"]["fd"].close() - - for p in app_procs: - p.terminate() - p.wait() - +app_helper = McastTesterHelper() def build_topo(tgen): "Build function" @@ -166,8 +104,8 @@ def setup_module(mod): # Initialize all routers. tgen.start_router() - # Start applications socket. - listen_to_applications() + app_helper.init(tgen) + def test_wait_ospf_convergence(): @@ -228,21 +166,12 @@ def test_wait_msdp_convergence(): assertmsg = '"{}" MSDP connection failure'.format(router) assert result is None, assertmsg - app_sock_path = get_app_sock_path() + mcastaddr = "229.0.1.10" + logger.info("Starting helper1") + app_helper.run("h1", ["--send=0.7", mcastaddr, "h1-eth0"]) - - python3_path = tgen.net.get_exec_path(["python3", "python"]) - ph_base = [python3_path, HELPER_APP_PATH, app_sock_path] - - ph1_cmd = ph_base + ["--send=0.7", "229.0.1.10", "h1-eth0"] - ph1 = tgen.gears["h1"].popen(ph1_cmd) - app_procs.append(ph1) - accept_host("h1") - - ph2_cmd = ph_base + ["229.0.1.10", "h2-eth0"] - ph2 = tgen.gears["h2"].popen(ph2_cmd) - app_procs.append(ph2) - accept_host("h2") + logger.info("Starting helper2") + app_helper.run("h2", [mcastaddr, "h2-eth0"]) # R1 peers. expect_msdp_peer("r1", "10.254.254.2") @@ -295,7 +224,7 @@ def test_msdp_sa_configuration(): def teardown_module(_mod): "Teardown the pytest environment" tgen = get_topogen() - close_applications() + app_helper.cleanup() tgen.stop_topology() diff --git a/tests/topotests/msdp_topo1/test_msdp_topo1.py b/tests/topotests/msdp_topo1/test_msdp_topo1.py index 8fad62db79..93a4f62fce 100755 --- a/tests/topotests/msdp_topo1/test_msdp_topo1.py +++ b/tests/topotests/msdp_topo1/test_msdp_topo1.py @@ -46,71 +46,11 @@ from lib.micronet_compat import Topo from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger +from lib.pim import McastTesterHelper pytestmark = [pytest.mark.bgpd, pytest.mark.pimd] -# -# Test global variables: -# They are used to handle communicating with external application. -# -HELPER_APP_PATH = os.path.join(CWD, "../lib/mcast-tester.py") -app_listener = None -app_clients = {} - - -def get_app_sock_path(): - tgen = get_topogen() - return os.path.join(tgen.logdir, "apps.sock") - - -def listen_to_applications(): - "Start listening socket to connect with applications." - - app_sock_path = get_app_sock_path() - # Remove old socket. - try: - os.unlink(app_sock_path) - except OSError: - pass - - sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0) - # Do not block forever - sock.settimeout(10) - sock.bind(app_sock_path) - sock.listen(10) - global app_listener - app_listener = sock - - -def accept_host(host): - "Accept connection from application running in hosts." - global app_listener, app_clients - conn = app_listener.accept() - app_clients[host] = { - 'fd': conn[0], - 'address': conn[1] - } - - -def close_applications(): - "Signal applications to stop and close all sockets." - global app_listener, app_clients - - # Close listening socket. - app_listener.close() - - app_sock_path = get_app_sock_path() - # Remove old socket. - try: - os.unlink(app_sock_path) - except OSError: - pass - - # Close all host connections. - for host in ["h1", "h2"]: - if app_clients.get(host) is None: - continue - app_clients[host]["fd"].close() +app_helper = McastTesterHelper() def build_topo(tgen): @@ -172,14 +112,12 @@ def setup_module(mod): # Initialize all routers. tgen.start_router() - # Start applications socket. - listen_to_applications() - + app_helper.init(tgen) def teardown_module(mod): "Teardown the pytest environment" tgen = get_topogen() - close_applications() + app_helper.cleanup() tgen.stop_topology() @@ -368,34 +306,14 @@ def test_mroute_install(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - ph1 = ph2 = None + logger.info("Starting helper1") + mcastaddr = "229.1.2.3" + app_helper.run("h1", [mcastaddr, "h1-eth0"]) - app_sock_path = get_app_sock_path() - try: - logger.info("Starting helper1") - ph1 = tgen.gears["h1"].popen( - "{} '{}' '{}' '{}'".format( - HELPER_APP_PATH, app_sock_path, "229.1.2.3", "h1-eth0" - ) - ) - logger.info("Accepting helper1") - accept_host("h1") + logger.info("Starting helper2") + app_helper.run("h2", ["--send=0.7", mcastaddr, "h2-eth0"]) - logger.info("Starting helper2") - ph2 = tgen.gears["h2"].popen( - "{} --send='0.7' '{}' '{}' '{}'".format( - HELPER_APP_PATH, app_sock_path, "229.1.2.3", "h2-eth0" - ) - ) - accept_host("h2") - - _test_mroute_install() - finally: - if ph1: - ph1.terminate() - ph1.wait() - ph2.terminate() - ph2.wait() + _test_mroute_install() def test_msdp(): """ diff --git a/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py b/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py index df1cce654f..b346e3d33b 100644 --- a/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py +++ b/tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py @@ -75,7 +75,6 @@ from lib.common_config import ( step, addKernelRoute, create_static_routes, - iperfSendIGMPJoin, stop_router, start_router, shutdown_bringup_interface, @@ -84,7 +83,6 @@ from lib.common_config import ( reset_config_on_routers, do_countdown, apply_raw_config, - kill_iperf, run_frr_cmd, required_linux_kernel_version, topo_daemons, @@ -109,6 +107,7 @@ from lib.pim import ( clear_ip_mroute, clear_ip_pim_interface_traffic, verify_pim_interface_traffic, + McastTesterHelper, ) from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json @@ -183,6 +182,10 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) + # XXX Replace this using "with McastTesterHelper()... " in each test if possible. + global app_helper + app_helper = McastTesterHelper(tgen) + logger.info("Running setup_module() done") @@ -193,8 +196,7 @@ def teardown_module(): tgen = get_topogen() - # Kill any iperfs we left running. - kill_iperf(tgen) + app_helper.cleanup() # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -388,7 +390,7 @@ def test_BSR_higher_prefer_ip_p0(request): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -465,7 +467,7 @@ def test_BSR_higher_prefer_ip_p0(request): result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet9") assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) do_countdown(5) @@ -594,7 +596,7 @@ def test_BSR_CRP_with_blackhole_address_p1(request): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -771,7 +773,7 @@ def test_new_router_fwd_p0(request): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -797,7 +799,7 @@ def test_new_router_fwd_p0(request): bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0] time.sleep(1) - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) # Verify bsr state in FHR @@ -850,7 +852,7 @@ def test_new_router_fwd_p0(request): stop_router(tgen, "i1") start_router(tgen, "i1") - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) # Verify again if BSR is installed from bsm forwarded by f1 @@ -908,7 +910,7 @@ def test_int_bsm_config_p1(request): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -930,7 +932,7 @@ def test_int_bsm_config_p1(request): bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0] time.sleep(1) - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) # Use scapy to send pre-defined packet from senser to receiver @@ -1069,7 +1071,7 @@ def test_static_rp_override_p1(request): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1094,7 +1096,7 @@ def test_static_rp_override_p1(request): bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0] time.sleep(1) - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) # Verify bsr state in FHR @@ -1220,7 +1222,7 @@ def test_bsmp_stress_add_del_restart_p2(request): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1247,7 +1249,7 @@ def test_bsmp_stress_add_del_restart_p2(request): bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0] time.sleep(1) - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) # Verify bsr state in FHR @@ -1341,7 +1343,7 @@ def test_bsmp_stress_add_del_restart_p2(request): assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) # Send IGMP join to LHR - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) do_countdown(5) @@ -1388,7 +1390,7 @@ def test_BSM_timeout_p0(request): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1413,7 +1415,7 @@ def test_BSM_timeout_p0(request): assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) # Send IGMP join for group 225.1.1.1 from receiver - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) # Verify bsr state in FHR @@ -1545,7 +1547,7 @@ def test_iif_join_state_p0(request): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1571,7 +1573,7 @@ def test_iif_join_state_p0(request): bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0] time.sleep(1) - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) # Verify bsr state in FHR diff --git a/tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py b/tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py index 64c284f7f1..69b105cc49 100644 --- a/tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py +++ b/tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py @@ -66,7 +66,6 @@ from lib.common_config import ( step, addKernelRoute, create_static_routes, - iperfSendIGMPJoin, stop_router, start_router, shutdown_bringup_interface, @@ -75,7 +74,6 @@ from lib.common_config import ( reset_config_on_routers, do_countdown, apply_raw_config, - kill_iperf, run_frr_cmd, required_linux_kernel_version, topo_daemons, @@ -100,6 +98,7 @@ from lib.pim import ( clear_ip_mroute, clear_ip_pim_interface_traffic, verify_pim_interface_traffic, + McastTesterHelper, ) from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json @@ -175,6 +174,10 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) + # XXX Replace this using "with McastTesterHelper()... " in each test if possible. + global app_helper + app_helper = McastTesterHelper(tgen) + logger.info("Running setup_module() done") @@ -185,8 +188,7 @@ def teardown_module(): tgen = get_topogen() - # Kill any iperfs we left running. - kill_iperf(tgen) + app_helper.cleanup() # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -342,7 +344,7 @@ def test_starg_mroute_p0(request): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -368,7 +370,7 @@ def test_starg_mroute_p0(request): bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0] time.sleep(1) - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) # Verify bsr state in FHR @@ -494,7 +496,7 @@ def test_overlapping_group_p0(request): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -521,7 +523,7 @@ def test_overlapping_group_p0(request): bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0] time.sleep(1) - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) # Verify bsr state in FHR @@ -600,7 +602,7 @@ def test_RP_priority_p0(request): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -627,7 +629,7 @@ def test_RP_priority_p0(request): bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0] time.sleep(1) - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) # Verify bsr state in FHR @@ -729,7 +731,7 @@ def test_BSR_election_p0(request): tc_name = request.node.name write_test_header(tc_name) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -762,7 +764,7 @@ def test_BSR_election_p0(request): ] time.sleep(1) - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) # Verify bsr state in FHR @@ -849,7 +851,7 @@ def test_RP_hash_p0(request): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -875,7 +877,7 @@ def test_RP_hash_p0(request): bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0] time.sleep(1) - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) dut = "l1" @@ -942,7 +944,7 @@ def test_BSM_fragmentation_p1(request): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -999,7 +1001,7 @@ def test_BSM_fragmentation_p1(request): result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet2") assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) # Verify bsr state in FHR @@ -1060,7 +1062,7 @@ def test_RP_with_all_ip_octet_p1(request): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1082,7 +1084,7 @@ def test_RP_with_all_ip_octet_p1(request): bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet8"]["bsr"].split("/")[0] time.sleep(1) - result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r1", GROUP_ADDRESS, "l1") assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result) dut = "l1" diff --git a/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py b/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py index 9eb3d8cc58..e6c9a30b3d 100755 --- a/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py +++ b/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py @@ -76,12 +76,9 @@ from lib.common_config import ( write_test_header, write_test_footer, step, - iperfSendIGMPJoin, addKernelRoute, apply_raw_config, reset_config_on_routers, - iperfSendTraffic, - kill_iperf, shutdown_bringup_interface, kill_router_daemons, start_router, @@ -104,6 +101,7 @@ from lib.pim import ( clear_ip_pim_interface_traffic, verify_igmp_config, clear_ip_mroute_verify, + McastTesterHelper, ) from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json @@ -202,6 +200,10 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, tgen.json_topo) + # XXX Replace this using "with McastTesterHelper()... " in each test if possible. + global app_helper + app_helper = McastTesterHelper(tgen) + logger.info("Running setup_module() done") @@ -212,8 +214,7 @@ def teardown_module(): tgen = get_topogen() - # Kill any iperfs we left running. - kill_iperf(tgen) + app_helper.cleanup() # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -321,9 +322,8 @@ def test_multicast_data_traffic_static_RP_send_join_then_traffic_p0(request): pytest.skip(tgen.errors) step("Enable IGMP on FRR1 interface and send IGMP join (225.1.1.1)") - intf_i1_l1 = topo["routers"]["i1"]["links"]["l1"]["interface"] - step("joinRx value before join sent") + step("get joinRx value before join") intf_r2_l1 = topo["routers"]["r2"]["links"]["l1"]["interface"] state_dict = {"r2": {intf_r2_l1: ["joinRx"]}} state_before = verify_pim_interface_traffic(tgen, state_dict) @@ -333,7 +333,7 @@ def test_multicast_data_traffic_static_RP_send_join_then_traffic_p0(request): tc_name, state_before ) - result = iperfSendIGMPJoin(tgen, "i1", ["{}%{}".format(IGMP_JOIN, intf_i1_l1)], join_interval=1) + result = app_helper.run_join("i1", IGMP_JOIN, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send the IGMP join first and then start the traffic") @@ -359,7 +359,7 @@ def test_multicast_data_traffic_static_RP_send_join_then_traffic_p0(request): assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to 225.1.1.1 receiver") - result = iperfSendTraffic(tgen, "i2", IGMP_JOIN, 32, 2500, bindToIntf="f1") + result = app_helper.run_traffic("i2", IGMP_JOIN, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( @@ -388,6 +388,7 @@ def test_multicast_data_traffic_static_RP_send_join_then_traffic_p0(request): ) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + step( "Verify 'show ip pim upstream' showing correct OIL and IIF" " on all the nodes" ) @@ -397,6 +398,7 @@ def test_multicast_data_traffic_static_RP_send_join_then_traffic_p0(request): ) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + step("joinRx value after join sent") state_after = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( @@ -437,7 +439,7 @@ def test_multicast_data_traffic_static_RP_send_traffic_then_join_p0(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -470,7 +472,7 @@ def test_multicast_data_traffic_static_RP_send_traffic_then_join_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, "i2", IGMP_JOIN, 32, 2500) + result = app_helper.run_traffic("i2", IGMP_JOIN, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Enable IGMP on FRR1 interface and send IGMP join (225.1.1.1)") @@ -488,7 +490,7 @@ def test_multicast_data_traffic_static_RP_send_traffic_then_join_p0(request): tc_name, result ) - result = iperfSendIGMPJoin(tgen, "i1", IGMP_JOIN, join_interval=1) + result = app_helper.run_join("i1", IGMP_JOIN, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( @@ -564,7 +566,7 @@ def test_clear_pim_neighbors_and_mroute_p0(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -597,7 +599,7 @@ def test_clear_pim_neighbors_and_mroute_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "i1", IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join("i1", IGMP_JOIN_RANGE_1, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3, wait for SPT switchover") @@ -606,7 +608,7 @@ def test_clear_pim_neighbors_and_mroute_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, "i2", IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic("i2", IGMP_JOIN_RANGE_1, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Clear the mroute on l1, wait for 5 sec") @@ -658,7 +660,7 @@ def test_verify_mroute_when_same_receiver_in_FHR_LHR_and_RP_p0(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -686,8 +688,8 @@ def test_verify_mroute_when_same_receiver_in_FHR_LHR_and_RP_p0(request): step("Enable IGMP on FRR1 interface and send IGMP join " "(225.1.1.1) to R1") input_dict = { - "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2"}}}}}, - "r2": {"igmp": {"interfaces": {"r2-i3-eth1": {"igmp": {"version": "2"}}}}}, + "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2", "query": {"query-interval": 15} }}}}}, + "r2": {"igmp": {"interfaces": {"r2-i3-eth1": {"igmp": {"version": "2", "query": {"query-interval": 15} }}}}}, } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -700,7 +702,7 @@ def test_verify_mroute_when_same_receiver_in_FHR_LHR_and_RP_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send multicast traffic from R3 to 225.1.1.1 receiver") @@ -709,7 +711,7 @@ def test_verify_mroute_when_same_receiver_in_FHR_LHR_and_RP_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, "i2", IGMP_JOIN, 32, 2500) + result = app_helper.run_traffic("i2", IGMP_JOIN, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("IGMP is received on FRR1 , FRR2 , FRR3, using " "'show ip igmp groups'") @@ -754,7 +756,7 @@ def test_verify_mroute_when_same_receiver_joining_5_diff_sources_p0(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -792,11 +794,11 @@ def test_verify_mroute_when_same_receiver_joining_5_diff_sources_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "i1", _IGMP_JOIN_RANGE, join_interval=1) + result = app_helper.run_join("i1", _IGMP_JOIN_RANGE, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) input_dict = { - "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2"}}}}} + "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2", "query": {"query-interval": 15} }}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -806,7 +808,7 @@ def test_verify_mroute_when_same_receiver_joining_5_diff_sources_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "i8", _IGMP_JOIN_RANGE, join_interval=1) + result = app_helper.run_join("i8", _IGMP_JOIN_RANGE, "f1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( @@ -828,7 +830,7 @@ def test_verify_mroute_when_same_receiver_joining_5_diff_sources_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, _IGMP_JOIN_RANGE, 32, 2500) + result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Verify (*,G) are created on FRR1 and FRR3 node " " 'show ip mroute' ") @@ -1078,7 +1080,7 @@ def test_verify_mroute_when_frr_is_transit_router_p2(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1108,7 +1110,7 @@ def test_verify_mroute_when_frr_is_transit_router_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "i1", IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join("i1", IGMP_JOIN_RANGE_1, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to 225.1.1.1-5 receivers") @@ -1117,7 +1119,7 @@ def test_verify_mroute_when_frr_is_transit_router_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, "i2", IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic("i2", IGMP_JOIN_RANGE_1, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) # Stop r2 router to make r2 router disabled from topology @@ -1191,7 +1193,7 @@ def test_verify_mroute_when_RP_unreachable_p1(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1223,7 +1225,7 @@ def test_verify_mroute_when_RP_unreachable_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "i1", IGMP_JOIN, join_interval=1) + result = app_helper.run_join("i1", IGMP_JOIN, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to 225.1.1.1 receiver") @@ -1232,12 +1234,12 @@ def test_verify_mroute_when_RP_unreachable_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, "i2", IGMP_JOIN, 32, 2500) + result = app_helper.run_traffic("i2", IGMP_JOIN, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Configure one IGMP interface on FRR3 node and send IGMP" " join (225.1.1.1)") input_dict = { - "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2"}}}}} + "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2", "query": {"query-interval": 15} }}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1247,7 +1249,7 @@ def test_verify_mroute_when_RP_unreachable_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "i8", IGMP_JOIN, join_interval=1) + result = app_helper.run_join("i8", IGMP_JOIN, "f1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) # Verify mroutes are present in FRR3(f1) @@ -1315,7 +1317,7 @@ def test_modify_igmp_query_timer_p0(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1326,7 +1328,7 @@ def test_modify_igmp_query_timer_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "i1", IGMP_JOIN, join_interval=1) + result = app_helper.run_join("i1", IGMP_JOIN, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure RP on R2 (loopback interface) for the" " group range 225.0.0.0/8") @@ -1355,7 +1357,7 @@ def test_modify_igmp_query_timer_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, "i2", IGMP_JOIN, 32, 2500) + result = app_helper.run_traffic("i2", IGMP_JOIN, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( @@ -1389,7 +1391,7 @@ def test_modify_igmp_query_timer_p0(request): "l1": { "igmp": { "interfaces": { - "l1-i1-eth1": {"igmp": {"query": {"query-interval": 100}}} + "l1-i1-eth1": {"igmp": {"query": {"query-interval": 20}}} } } } @@ -1404,7 +1406,7 @@ def test_modify_igmp_query_timer_p0(request): "l1": { "igmp": { "interfaces": { - "l1-i1-eth1": {"igmp": {"query": {"query-interval": 200}}} + "l1-i1-eth1": {"igmp": {"query": {"query-interval": 25}}} } } } @@ -1419,7 +1421,7 @@ def test_modify_igmp_query_timer_p0(request): "l1": { "igmp": { "interfaces": { - "l1-i1-eth1": {"igmp": {"query": {"query-interval": 300}}} + "l1-i1-eth1": {"igmp": {"query": {"query-interval": 30}}} } } } @@ -1454,7 +1456,7 @@ def test_modify_igmp_max_query_response_timer_p0(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1465,7 +1467,7 @@ def test_modify_igmp_max_query_response_timer_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "i1", IGMP_JOIN, join_interval=1) + result = app_helper.run_join("i1", IGMP_JOIN, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure IGMP query response time to 10 deci-sec on FRR1") @@ -1515,7 +1517,7 @@ def test_modify_igmp_max_query_response_timer_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, "i2", IGMP_JOIN, 32, 2500) + result = app_helper.run_traffic("i2", IGMP_JOIN, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( @@ -1535,6 +1537,7 @@ def test_modify_igmp_max_query_response_timer_p0(request): ) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + step( "Verify 'show ip pim upstream' showing correct OIL and IIF" " on all the nodes" ) @@ -1573,7 +1576,7 @@ def test_modify_igmp_max_query_response_timer_p0(request): result = create_pim_config(tgen, topo["routers"]) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - step("Configure max query response timer 100sec on FRR1") + step("Configure max query response timer 100 decisec on FRR1") input_dict_3 = { "l1": { "igmp": { @@ -1600,6 +1603,26 @@ def test_modify_igmp_max_query_response_timer_p0(request): " on FRR1" ) + input_dict_3 = { + "l1": { + "igmp": { + "interfaces": { + "l1-i1-eth1": { + "igmp": { + "version": "2", + "query": {"query-max-response-time": 105}, + } + } + } + } + } + } + result = create_igmp_config(tgen, topo, input_dict_3) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + result = verify_igmp_config(tgen, input_dict_3) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + input_dict_3 = { "l1": { "igmp": { @@ -1620,6 +1643,26 @@ def test_modify_igmp_max_query_response_timer_p0(request): result = verify_igmp_config(tgen, input_dict_3) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + input_dict_3 = { + "l1": { + "igmp": { + "interfaces": { + "l1-i1-eth1": { + "igmp": { + "version": "2", + "query": {"query-max-response-time": 115}, + } + } + } + } + } + } + result = create_igmp_config(tgen, topo, input_dict_3) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + result = verify_igmp_config(tgen, input_dict_3) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + input_dict_3 = { "l1": { "igmp": { @@ -1640,46 +1683,6 @@ def test_modify_igmp_max_query_response_timer_p0(request): result = verify_igmp_config(tgen, input_dict_3) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - input_dict_3 = { - "l1": { - "igmp": { - "interfaces": { - "l1-i1-eth1": { - "igmp": { - "version": "2", - "query": {"query-max-response-time": 140}, - } - } - } - } - } - } - result = create_igmp_config(tgen, topo, input_dict_3) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - - result = verify_igmp_config(tgen, input_dict_3) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - - input_dict_3 = { - "l1": { - "igmp": { - "interfaces": { - "l1-i1-eth1": { - "igmp": { - "version": "2", - "query": {"query-max-response-time": 150}, - } - } - } - } - } - } - result = create_igmp_config(tgen, topo, input_dict_3) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - - result = verify_igmp_config(tgen, input_dict_3) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - step("Enable IGMP and IGMP version 2 on FRR1 on FRR1") input_dict_4 = { diff --git a/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py b/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py index 96886b0d95..27abfae9f4 100755 --- a/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py +++ b/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py @@ -72,11 +72,8 @@ from lib.common_config import ( write_test_header, write_test_footer, step, - iperfSendIGMPJoin, addKernelRoute, reset_config_on_routers, - iperfSendTraffic, - kill_iperf, shutdown_bringup_interface, kill_router_daemons, start_router, @@ -98,6 +95,7 @@ from lib.pim import ( clear_ip_mroute, clear_ip_pim_interface_traffic, verify_igmp_config, + McastTesterHelper, ) from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json @@ -195,6 +193,10 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) + # XXX Replace this using "with McastTesterHelper()... " in each test if possible. + global app_helper + app_helper = McastTesterHelper(tgen) + logger.info("Running setup_module() done") @@ -205,8 +207,7 @@ def teardown_module(): tgen = get_topogen() - # Kill any iperfs we left running. - kill_iperf(tgen) + app_helper.cleanup() # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -318,7 +319,7 @@ def test_verify_mroute_and_traffic_when_pimd_restarted_p2(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -369,7 +370,7 @@ def test_verify_mroute_and_traffic_when_pimd_restarted_p2(request): ) input_dict = { - "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2"}}}}} + "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -382,7 +383,7 @@ def test_verify_mroute_and_traffic_when_pimd_restarted_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, _IGMP_JOIN_RANGE, join_interval=1) + result = app_helper.run_join(recvr, _IGMP_JOIN_RANGE, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( @@ -402,7 +403,7 @@ def test_verify_mroute_and_traffic_when_pimd_restarted_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, _IGMP_JOIN_RANGE, 32, 2500) + result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) # Verifying mroutes before PIMd restart, fetching uptime @@ -530,7 +531,7 @@ def test_verify_mroute_and_traffic_when_frr_restarted_p2(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -581,7 +582,7 @@ def test_verify_mroute_and_traffic_when_frr_restarted_p2(request): ) input_dict = { - "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2"}}}}} + "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -594,7 +595,7 @@ def test_verify_mroute_and_traffic_when_frr_restarted_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, _IGMP_JOIN_RANGE, join_interval=1) + result = app_helper.run_join(recvr, _IGMP_JOIN_RANGE, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( @@ -614,7 +615,7 @@ def test_verify_mroute_and_traffic_when_frr_restarted_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, _IGMP_JOIN_RANGE, 32, 2500) + result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Verifying mroutes before FRR restart, fetching uptime") @@ -741,7 +742,7 @@ def test_verify_SPT_switchover_when_RPT_and_SPT_path_is_different_p0(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -779,7 +780,7 @@ def test_verify_SPT_switchover_when_RPT_and_SPT_path_is_different_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "i1", _IGMP_JOIN_RANGE, join_interval=1) + result = app_helper.run_join("i1", _IGMP_JOIN_RANGE, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to '226.1.1.1-5'" ", '232.1.1.1-5' receiver") @@ -798,7 +799,7 @@ def test_verify_SPT_switchover_when_RPT_and_SPT_path_is_different_p0(request): tc_name, result ) - result = iperfSendTraffic(tgen, "i2", _IGMP_JOIN_RANGE, 32, 2500) + result = app_helper.run_traffic("i2", _IGMP_JOIN_RANGE, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( @@ -851,7 +852,7 @@ def test_verify_SPT_switchover_when_RPT_and_SPT_path_is_different_p0(request): step("Stop the traffic to all the receivers") - kill_iperf(tgen, "i2", "remove_traffic") + app_helper.stop_host("i2") step( "Null register packet being send periodically from FRR3 to RP, " @@ -903,7 +904,7 @@ def test_verify_mroute_after_shut_noshut_of_upstream_interface_p1(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -954,7 +955,7 @@ def test_verify_mroute_after_shut_noshut_of_upstream_interface_p1(request): ) input_dict = { - "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2"}}}}} + "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -967,7 +968,7 @@ def test_verify_mroute_after_shut_noshut_of_upstream_interface_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, _IGMP_JOIN_RANGE, join_interval=1) + result = app_helper.run_join(recvr, _IGMP_JOIN_RANGE, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( @@ -987,7 +988,7 @@ def test_verify_mroute_after_shut_noshut_of_upstream_interface_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, _IGMP_JOIN_RANGE, 32, 2500) + result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( @@ -1139,7 +1140,7 @@ def test_verify_mroute_after_shut_noshut_of_upstream_interface_p1(request): assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Stop the traffic to all the receivers") - kill_iperf(tgen) + app_helper.stop_all_hosts() for data in input_dict: result = verify_ip_mroutes( @@ -1176,7 +1177,7 @@ def test_verify_mroute_when_receiver_is_outside_frr_p0(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1213,7 +1214,7 @@ def test_verify_mroute_when_receiver_is_outside_frr_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "i1", _IGMP_JOIN_RANGE, join_interval=1) + result = app_helper.run_join("i1", _IGMP_JOIN_RANGE, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( @@ -1225,7 +1226,7 @@ def test_verify_mroute_when_receiver_is_outside_frr_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, "i2", _IGMP_JOIN_RANGE, 32, 2500) + result = app_helper.run_traffic("i2", _IGMP_JOIN_RANGE, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( @@ -1233,7 +1234,7 @@ def test_verify_mroute_when_receiver_is_outside_frr_p0(request): " join (226.1.1.1-5) and (232.1.1.1-5)" ) input_dict = { - "c2": {"igmp": {"interfaces": {"c2-i5-eth2": {"igmp": {"version": "2"}}}}} + "c2": {"igmp": {"interfaces": {"c2-i5-eth2": {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1243,7 +1244,7 @@ def test_verify_mroute_when_receiver_is_outside_frr_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "i5", _IGMP_JOIN_RANGE, join_interval=1) + result = app_helper.run_join("i5", _IGMP_JOIN_RANGE, "c2") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("FRR1 has 10 (*.G) and 10 (S,G) verify using 'show ip mroute count'") @@ -1316,7 +1317,7 @@ def test_verify_mroute_when_FRR_is_FHR_and_LHR_p0(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1356,22 +1357,22 @@ def test_verify_mroute_when_FRR_is_FHR_and_LHR_p0(request): "(226.1.1.1-5) and (232.1.1.1-5)" ) - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i1", "i1-l1-eth0", _GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + # result = config_to_send_igmp_join_and_traffic( + # tgen, topo, tc_name, "i1", "i1-l1-eth0", _GROUP_RANGE, join=True + # ) + # assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i2", "i2-f1-eth0", _GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + # result = config_to_send_igmp_join_and_traffic( + # tgen, topo, tc_name, "i2", "i2-f1-eth0", _GROUP_RANGE, traffic=True + # ) + # assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send IGMP join (226.1.1.1-5, 232.1.1.1-5) to LHR(l1)") - result = iperfSendIGMPJoin(tgen, "i1", _IGMP_JOIN_RANGE, join_interval=1) + result = app_helper.run_join("i1", _IGMP_JOIN_RANGE, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to '226.1.1.1-5'" ", '232.1.1.1-5' receiver") - result = iperfSendTraffic(tgen, "i2", _IGMP_JOIN_RANGE, 32, 2500) + result = app_helper.run_traffic("i2", _IGMP_JOIN_RANGE, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( @@ -1381,17 +1382,17 @@ def test_verify_mroute_when_FRR_is_FHR_and_LHR_p0(request): step("Configure one IGMP interface on f1 node and send IGMP" " join (225.1.1.1)") input_dict = { - "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2"}}}}} + "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i8", "i8-f1-eth0", _GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + # result = config_to_send_igmp_join_and_traffic( + # tgen, topo, tc_name, "i8", "i8-f1-eth0", _GROUP_RANGE, join=True + # ) + # assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, "i8", _IGMP_JOIN_RANGE, join_interval=1) + result = app_helper.run_join("i8", _IGMP_JOIN_RANGE, "f1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( "l1 and f1 has 10 IGMP groups (226.1.1.1-5, 232.1.1.1-5)," @@ -1446,7 +1447,7 @@ def test_verify_mroute_when_FRR_is_FHR_and_LHR_p0(request): # Stop the multicast traffic step("Stop the traffic to all the receivers") - kill_iperf(tgen) + app_helper.stop_all_hosts() step( "After traffic stopped , verify (*,G) entries are not flushed" @@ -1512,7 +1513,7 @@ def test_verify_mroute_when_5_different_receiver_joining_same_sources_p0(request pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1570,12 +1571,12 @@ def test_verify_mroute_when_5_different_receiver_joining_same_sources_p0(request "f1": { "igmp": { "interfaces": { - "f1-i8-eth2": {"igmp": {"version": "2"}}, - "f1-i2-eth1": {"igmp": {"version": "2"}}, + "f1-i8-eth2": {"igmp": {"version": "2", "query": {"query-interval": 15}}}, + "f1-i2-eth1": {"igmp": {"version": "2", "query": {"query-interval": 15}}}, } } }, - "l1": {"igmp": {"interfaces": {"l1-i6-eth2": {"igmp": {"version": "2"}}}}}, + "l1": {"igmp": {"interfaces": {"l1-i6-eth2": {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}}, } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1593,7 +1594,7 @@ def test_verify_mroute_when_5_different_receiver_joining_same_sources_p0(request ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, _IGMP_JOIN_RANGE, join_interval=1) + result = app_helper.run_join(recvr, _IGMP_JOIN_RANGE, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure one source in FRR2 , one in c1") step( @@ -1609,7 +1610,7 @@ def test_verify_mroute_when_5_different_receiver_joining_same_sources_p0(request ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, _IGMP_JOIN_RANGE, 32, 2500) + result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( "After all the IGMP groups received with correct port using" @@ -1743,7 +1744,7 @@ def test_verify_oil_iif_for_mroute_after_shut_noshut_source_interface_p1(request pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1790,7 +1791,7 @@ def test_verify_oil_iif_for_mroute_after_shut_noshut_source_interface_p1(request ) input_dict = { - "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2"}}}}} + "f1": {"igmp": {"interfaces": {"f1-i8-eth2": {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1803,7 +1804,7 @@ def test_verify_oil_iif_for_mroute_after_shut_noshut_source_interface_p1(request ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, _IGMP_JOIN_RANGE, join_interval=1) + result = app_helper.run_join(recvr, _IGMP_JOIN_RANGE, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure 1 source in FRR1 , 1 in FRR3") @@ -1820,7 +1821,7 @@ def test_verify_oil_iif_for_mroute_after_shut_noshut_source_interface_p1(request ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, _IGMP_JOIN_RANGE, 32, 2500) + result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( diff --git a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py index 7c04dba066..afefbfed10 100755 --- a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py +++ b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py @@ -74,11 +74,8 @@ from lib.common_config import ( write_test_header, write_test_footer, step, - iperfSendIGMPJoin, addKernelRoute, reset_config_on_routers, - iperfSendTraffic, - kill_iperf, shutdown_bringup_interface, kill_router_daemons, start_router, @@ -109,6 +106,7 @@ from lib.pim import ( verify_pim_rp_info, get_refCount_for_mroute, verify_multicast_flag_state, + McastTesterHelper, ) from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json @@ -212,6 +210,10 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) + # XXX Replace this using "with McastTesterHelper()... " in each test if possible. + global app_helper + app_helper = McastTesterHelper(tgen) + logger.info("Running setup_module() done") @@ -222,8 +224,7 @@ def teardown_module(): tgen = get_topogen() - # Kill any iperfs we left running. - kill_iperf(tgen) + app_helper.cleanup() # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -433,7 +434,7 @@ def test_verify_oil_when_join_prune_sent_scenario_1_p1(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -451,7 +452,7 @@ def test_verify_oil_when_join_prune_sent_scenario_1_p1(request): intf_f1_i8 = topo["routers"]["f1"]["links"]["i8"]["interface"] input_dict = { - "f1": {"igmp": {"interfaces": {intf_f1_i8: {"igmp": {"version": "2"}}}}} + "f1": {"igmp": {"interfaces": {intf_f1_i8: {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -467,7 +468,7 @@ def test_verify_oil_when_join_prune_sent_scenario_1_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure static RP for (226.1.1.1-5) in R2") @@ -502,7 +503,7 @@ def test_verify_oil_when_join_prune_sent_scenario_1_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) source_i2 = topo["routers"]["i2"]["links"]["f1"]["ipv4"].split("/")[0] @@ -808,7 +809,7 @@ def test_verify_oil_when_join_prune_sent_scenario_2_p1(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -835,7 +836,7 @@ def test_verify_oil_when_join_prune_sent_scenario_2_p1(request): intf_r2_i3 = topo["routers"]["r2"]["links"]["i3"]["interface"] input_dict = { - "r2": {"igmp": {"interfaces": {intf_r2_i3: {"igmp": {"version": "2"}}}}} + "r2": {"igmp": {"interfaces": {intf_r2_i3: {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -851,7 +852,7 @@ def test_verify_oil_when_join_prune_sent_scenario_2_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure static RP for (226.1.1.1-5) in R2") @@ -1050,7 +1051,7 @@ def test_shut_noshut_source_interface_when_upstream_cleared_from_LHR_p1(request) pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1067,7 +1068,7 @@ def test_shut_noshut_source_interface_when_upstream_cleared_from_LHR_p1(request) ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure RP on R2 (loopback interface) for " "the group range 225.0.0.0/8") @@ -1100,7 +1101,7 @@ def test_shut_noshut_source_interface_when_upstream_cleared_from_LHR_p1(request) ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( @@ -1267,7 +1268,7 @@ def test_shut_noshut_receiver_interface_when_upstream_cleared_from_LHR_p1(reques pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1284,7 +1285,7 @@ def test_shut_noshut_receiver_interface_when_upstream_cleared_from_LHR_p1(reques ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure RP on R2 (loopback interface) for " "the group range 225.0.0.0/8") @@ -1317,7 +1318,7 @@ def test_shut_noshut_receiver_interface_when_upstream_cleared_from_LHR_p1(reques ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( @@ -1469,7 +1470,7 @@ def test_verify_remove_add_igmp_config_to_receiver_interface_p0(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1486,7 +1487,7 @@ def test_verify_remove_add_igmp_config_to_receiver_interface_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure RP for (226.1.1.1-5) and (232.1.1.1-5) in cisco-1(f1)") @@ -1519,7 +1520,7 @@ def test_verify_remove_add_igmp_config_to_receiver_interface_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Configure source on FRR1 and start the traffic for" " (225.1.1.1-225.1.1.10)") @@ -1532,7 +1533,7 @@ def test_verify_remove_add_igmp_config_to_receiver_interface_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) source_i6 = topo["routers"]["i6"]["links"]["l1"]["ipv4"].split("/")[0] @@ -1639,7 +1640,7 @@ def test_verify_remove_add_igmp_config_to_receiver_interface_p0(request): ) input_dict_2 = { - "l1": {"igmp": {"interfaces": {intf_l1_i1: {"igmp": {"version": "2"}}}}} + "l1": {"igmp": {"interfaces": {intf_l1_i1: {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}} } result = create_igmp_config(tgen, topo, input_dict_2) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1722,7 +1723,7 @@ def test_verify_remove_add_igmp_config_to_receiver_interface_p0(request): ) input_dict_2 = { - "l1": {"igmp": {"interfaces": {intf_l1_i1: {"igmp": {"version": "2"}}}}} + "l1": {"igmp": {"interfaces": {intf_l1_i1: {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}} } result = create_igmp_config(tgen, topo, input_dict_2) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1845,7 +1846,7 @@ def test_verify_remove_add_igmp_commands_when_pim_configured_p0(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -1862,7 +1863,7 @@ def test_verify_remove_add_igmp_commands_when_pim_configured_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure RP for (226.1.1.1-5) and (232.1.1.1-5) in cisco-1(f1)") @@ -1895,7 +1896,7 @@ def test_verify_remove_add_igmp_commands_when_pim_configured_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Configure source on FRR1 and start the traffic for" " (225.1.1.1-225.1.1.10)") @@ -1908,7 +1909,7 @@ def test_verify_remove_add_igmp_commands_when_pim_configured_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) source_i6 = topo["routers"]["i6"]["links"]["l1"]["ipv4"].split("/")[0] @@ -2144,7 +2145,7 @@ def test_verify_remove_add_pim_commands_when_igmp_configured_p1(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -2162,7 +2163,7 @@ def test_verify_remove_add_pim_commands_when_igmp_configured_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure RP for (226.1.1.1-5) and (232.1.1.1-5) in cisco-1(f1)") @@ -2339,7 +2340,7 @@ def test_pim_dr_priority_p0(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -2357,7 +2358,7 @@ def test_pim_dr_priority_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure RP for (226.1.1.1-5) and (232.1.1.1-5) in cisco-1(f1)") @@ -2388,7 +2389,7 @@ def test_pim_dr_priority_p0(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) source_i2 = topo["routers"]["i2"]["links"]["f1"]["ipv4"].split("/")[0] @@ -2622,7 +2623,7 @@ def test_pim_hello_timer_p1(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -2640,7 +2641,7 @@ def test_pim_hello_timer_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure RP for (226.1.1.1-5) and (232.1.1.1-5) in cisco-1(f1)") @@ -2742,7 +2743,7 @@ def test_mroute_after_removing_RP_sending_IGMP_prune_p2(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -2766,7 +2767,7 @@ def test_mroute_after_removing_RP_sending_IGMP_prune_p2(request): intf_f1_i8 = topo["routers"]["f1"]["links"]["i8"]["interface"] input_dict = { - "f1": {"igmp": {"interfaces": {intf_f1_i8: {"igmp": {"version": "2"}}}}} + "f1": {"igmp": {"interfaces": {intf_f1_i8: {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -2779,7 +2780,7 @@ def test_mroute_after_removing_RP_sending_IGMP_prune_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure static RP for (225.1.1.1-5) as R2") @@ -2815,7 +2816,7 @@ def test_mroute_after_removing_RP_sending_IGMP_prune_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) source_i2 = topo["routers"]["i6"]["links"]["l1"]["ipv4"].split("/")[0] @@ -2934,7 +2935,7 @@ def test_mroute_after_removing_RP_sending_IGMP_prune_p2(request): assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Send prune from receiver-1 (using ctrl+c) on iperf interface") - kill_iperf(tgen) + app_helper.stop_all_hosts() intf_f1_i8 = topo["routers"]["f1"]["links"]["i8"]["interface"] input_traffic = {"f1": {"traffic_sent": [intf_f1_i8]}} @@ -3005,7 +3006,7 @@ def test_mroute_after_removing_RP_sending_IGMP_prune_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) for data in input_dict_starg: @@ -3027,7 +3028,7 @@ def test_mroute_after_removing_RP_sending_IGMP_prune_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) source_i2 = topo["routers"]["i6"]["links"]["l1"]["ipv4"].split("/")[0] @@ -3060,7 +3061,7 @@ def test_prune_sent_to_LHR_and_FHR_when_PIMnbr_down_p2(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -3084,7 +3085,7 @@ def test_prune_sent_to_LHR_and_FHR_when_PIMnbr_down_p2(request): intf_f1_i8 = topo["routers"]["f1"]["links"]["i8"]["interface"] input_dict = { - "f1": {"igmp": {"interfaces": {intf_f1_i8: {"igmp": {"version": "2"}}}}} + "f1": {"igmp": {"interfaces": {intf_f1_i8: {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -3097,7 +3098,7 @@ def test_prune_sent_to_LHR_and_FHR_when_PIMnbr_down_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure static RP for (225.1.1.1-5) as R2") @@ -3136,7 +3137,7 @@ def test_prune_sent_to_LHR_and_FHR_when_PIMnbr_down_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) source_i2 = topo["routers"]["i6"]["links"]["l1"]["ipv4"].split("/")[0] @@ -3390,7 +3391,7 @@ def test_prune_sent_to_LHR_and_FHR_when_PIMnbr_down_p2(request): intf_r2_l1 = topo["routers"]["r2"]["links"]["l1"]["interface"] shutdown_bringup_interface(tgen, "r2", intf_r2_l1, False) - kill_iperf(tgen, dut="i2", action="remove_traffic") + app_helper.stop_host("i2") step("Verify RP info after Shut the link from FHR to RP from RP node") dut = "l1" @@ -3542,7 +3543,7 @@ def test_prune_sent_to_LHR_and_FHR_when_PIMnbr_down_p2(request): step("Verify PIM Nbrs after Shut the link from FHR to RP from FHR node") - kill_iperf(tgen, dut="i6", action="remove_traffic") + app_helper.stop_host("i6") step("Verify RP info after Shut the link from FHR to RP from FHR node") dut = "l1" @@ -3702,7 +3703,7 @@ def test_mroute_flags_p1(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -3726,7 +3727,7 @@ def test_mroute_flags_p1(request): intf_f1_i8 = topo["routers"]["f1"]["links"]["i8"]["interface"] input_dict = { - "f1": {"igmp": {"interfaces": {intf_f1_i8: {"igmp": {"version": "2"}}}}} + "f1": {"igmp": {"interfaces": {intf_f1_i8: {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -3739,7 +3740,7 @@ def test_mroute_flags_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure static RP for (225.1.1.1-5) as R2") @@ -3778,7 +3779,7 @@ def test_mroute_flags_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) source_i2 = topo["routers"]["i6"]["links"]["l1"]["ipv4"].split("/")[0] @@ -3865,7 +3866,7 @@ def test_verify_multicast_traffic_when_LHR_connected_to_RP_p1(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -3907,7 +3908,7 @@ def test_verify_multicast_traffic_when_LHR_connected_to_RP_p1(request): intf_r2_i3 = topo["routers"]["r2"]["links"]["i3"]["interface"] input_dict = { - "r2": {"igmp": {"interfaces": {intf_r2_i3: {"igmp": {"version": "2"}}}}} + "r2": {"igmp": {"interfaces": {intf_r2_i3: {"igmp": {"version": "2", "query": {"query-interval": 15}}}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -3923,7 +3924,7 @@ def test_verify_multicast_traffic_when_LHR_connected_to_RP_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, _IGMP_JOIN_RANGE, join_interval=1) + result = app_helper.run_join(recvr, _IGMP_JOIN_RANGE, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure RP for (226.1.1.1-5) and (232.1.1.1-5) in (f1)") @@ -3956,7 +3957,7 @@ def test_verify_multicast_traffic_when_LHR_connected_to_RP_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, _IGMP_JOIN_RANGE, 32, 2500) + result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( @@ -4327,7 +4328,7 @@ def test_verify_multicast_traffic_when_FHR_connected_to_RP_p1(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -4357,7 +4358,7 @@ def test_verify_multicast_traffic_when_FHR_connected_to_RP_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, _IGMP_JOIN_RANGE, join_interval=1) + result = app_helper.run_join(recvr, _IGMP_JOIN_RANGE, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure RP for (225.1.1.1-5) in (f1)") @@ -4390,7 +4391,7 @@ def test_verify_multicast_traffic_when_FHR_connected_to_RP_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, _IGMP_JOIN_RANGE, 32, 2500) + result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( diff --git a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py index 445dab8373..dbd1dcec47 100755 --- a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py +++ b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py @@ -68,11 +68,8 @@ from lib.common_config import ( write_test_header, write_test_footer, step, - iperfSendIGMPJoin, addKernelRoute, reset_config_on_routers, - iperfSendTraffic, - kill_iperf, shutdown_bringup_interface, start_router, stop_router, @@ -97,6 +94,7 @@ from lib.pim import ( verify_pim_rp_info, verify_pim_interface_traffic, verify_igmp_interface, + McastTesterHelper, ) from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json @@ -180,6 +178,10 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) + # XXX Replace this using "with McastTesterHelper()... " in each test if possible. + global app_helper + app_helper = McastTesterHelper(tgen) + logger.info("Running setup_module() done") @@ -190,8 +192,7 @@ def teardown_module(): tgen = get_topogen() - # Kill any iperfs we left running. - kill_iperf(tgen) + app_helper.cleanup() # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -311,7 +312,7 @@ def test_mroute_when_RP_reachable_default_route_p2(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -347,7 +348,7 @@ def test_mroute_when_RP_reachable_default_route_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure static RP for (225.1.1.1-5) as R2") @@ -380,7 +381,7 @@ def test_mroute_when_RP_reachable_default_route_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) source_i4 = topo["routers"]["i4"]["links"]["c1"]["ipv4"].split("/")[0] @@ -610,7 +611,7 @@ def test_mroute_with_RP_default_route_all_nodes_p2(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -646,7 +647,7 @@ def test_mroute_with_RP_default_route_all_nodes_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure static RP for (225.1.1.1-5) as R2") @@ -679,7 +680,7 @@ def test_mroute_with_RP_default_route_all_nodes_p2(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) source_i5 = topo["routers"]["i5"]["links"]["c2"]["ipv4"].split("/")[0] @@ -898,7 +899,7 @@ def test_PIM_hello_tx_rx_p1(request): pytest.skip(tgen.errors) # Creating configuration from JSON - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) @@ -934,7 +935,7 @@ def test_PIM_hello_tx_rx_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure static RP for (225.1.1.1-5) as R2") @@ -967,7 +968,7 @@ def test_PIM_hello_tx_rx_p1(request): ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) source_i5 = topo["routers"]["i5"]["links"]["c2"]["ipv4"].split("/")[0] diff --git a/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py b/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py index b1ffd37865..d0ab12e5cc 100755 --- a/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py +++ b/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py @@ -126,15 +126,13 @@ from lib.common_config import ( write_test_footer, reset_config_on_routers, step, - iperfSendIGMPJoin, - iperfSendTraffic, addKernelRoute, shutdown_bringup_interface, kill_router_daemons, start_router_daemons, create_static_routes, - kill_iperf, topo_daemons, + ) from lib.pim import ( create_pim_config, @@ -151,6 +149,7 @@ from lib.pim import ( clear_ip_pim_interfaces, clear_ip_mroute, clear_ip_mroute_verify, + McastTesterHelper, ) pytestmark = [pytest.mark.pimd, pytest.mark.staticd] @@ -246,6 +245,10 @@ def setup_module(mod): result = verify_pim_neighbors(tgen, TOPO) assert result is True, "setup_module :Failed \n Error:" " {}".format(result) + # XXX Replace this using "with McastTesterHelper()... " in each test if possible. + global app_helper + app_helper = McastTesterHelper(tgen) + logger.info("Running setup_module() done") @@ -256,8 +259,7 @@ def teardown_module(): tgen = get_topogen() - # Kill any iperfs we left running. - kill_iperf(tgen) + app_helper.cleanup() # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -432,7 +434,7 @@ def test_add_delete_static_RP_p0(request): ) step("r0 : Send IGMP join") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify IGMP groups") @@ -566,7 +568,7 @@ def test_SPT_RPT_path_same_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -601,7 +603,7 @@ def test_SPT_RPT_path_same_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r0: Send IGMP join") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify IGMP groups") @@ -611,7 +613,7 @@ def test_SPT_RPT_path_same_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r5: Send multicast traffic for group 225.1.1.1") - result = iperfSendTraffic(tgen, "r5", GROUP_ADDRESS, 32, 2500) + result = app_helper.run_traffic("r5", GROUP_ADDRESS, "r3") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify (*, G) upstream IIF interface") @@ -722,7 +724,7 @@ def test_not_reachable_static_RP_p0(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -755,7 +757,7 @@ def test_not_reachable_static_RP_p0(request): step("Enable PIM between r1 and r2") step("r0 : Send IGMP join") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1 : Verify rp info") @@ -888,7 +890,7 @@ def test_add_RP_after_join_received_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -942,7 +944,7 @@ def test_add_RP_after_join_received_p1(request): ) step("r0 : Send IGMP join (225.1.1.1) to r1, when rp is not configured" "in r1") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: IGMP group is received on R1 verify using show ip igmp groups") @@ -1058,7 +1060,7 @@ def test_reachable_static_RP_after_join_p0(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -1096,7 +1098,7 @@ def test_reachable_static_RP_after_join_p0(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1 : Send IGMP join for 225.1.1.1") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1 : Verify IGMP groups") @@ -1225,7 +1227,7 @@ def test_send_join_on_higher_preffered_rp_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -1269,7 +1271,7 @@ def test_send_join_on_higher_preffered_rp_p1(request): ) step("r0 : Send IGMP join for 225.1.1.1") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1 : Verify IGMP groups") @@ -1466,7 +1468,7 @@ def test_RP_configured_as_LHR_1_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -1593,7 +1595,7 @@ def test_RP_configured_as_LHR_1_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r0: Send IGMP join") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify IGMP groups") @@ -1602,7 +1604,7 @@ def test_RP_configured_as_LHR_1_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r5: Send multicast traffic for group 225.1.1.1") - result = iperfSendTraffic(tgen, "r5", GROUP_ADDRESS, 32, 2500) + result = app_helper.run_traffic("r5", GROUP_ADDRESS, "r3") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify (*, G) upstream IIF interface") @@ -1682,7 +1684,7 @@ def test_RP_configured_as_LHR_2_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -1802,11 +1804,11 @@ def test_RP_configured_as_LHR_2_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r5: Send multicast traffic for group 225.1.1.1") - result = iperfSendTraffic(tgen, "r5", GROUP_ADDRESS, 32, 2500) + result = app_helper.run_traffic("r5", GROUP_ADDRESS, "r3") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r0: Send IGMP join") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify IGMP groups") @@ -1892,7 +1894,7 @@ def test_RP_configured_as_FHR_1_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -2013,7 +2015,7 @@ def test_RP_configured_as_FHR_1_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r0: Send IGMP join") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r0: Verify IGMP groups") @@ -2022,7 +2024,7 @@ def test_RP_configured_as_FHR_1_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r5: Send multicast traffic for group 225.1.1.1") - result = iperfSendTraffic(tgen, "r5", GROUP_ADDRESS, 32, 2500) + result = app_helper.run_traffic("r5", GROUP_ADDRESS, "r3") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify (*, G) upstream IIF interface") @@ -2101,7 +2103,7 @@ def test_RP_configured_as_FHR_2_p2(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -2223,11 +2225,11 @@ def test_RP_configured_as_FHR_2_p2(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r5: Send multicast traffic for group 225.1.1.1") - result = iperfSendTraffic(tgen, "r5", GROUP_ADDRESS, 32, 2500) + result = app_helper.run_traffic("r5", GROUP_ADDRESS, "r3") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r0: Send IGMP join") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r0: Verify IGMP groups") @@ -2314,7 +2316,7 @@ def test_SPT_RPT_path_different_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -2335,7 +2337,7 @@ def test_SPT_RPT_path_different_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r0: Send IGMP join") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify IGMP groups") @@ -2345,7 +2347,7 @@ def test_SPT_RPT_path_different_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r5: Send multicast traffic for group 225.1.1.1") - result = iperfSendTraffic(tgen, "r5", GROUP_ADDRESS, 32, 2500) + result = app_helper.run_traffic("r5", GROUP_ADDRESS, "r3") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify (*, G) upstream IIF interface") @@ -2469,7 +2471,7 @@ def test_clear_pim_configuration_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -2493,7 +2495,7 @@ def test_clear_pim_configuration_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r0: Send IGMP join") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify IGMP groups") @@ -2503,7 +2505,7 @@ def test_clear_pim_configuration_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r5: Send multicast traffic for group 225.1.1.1") - result = iperfSendTraffic(tgen, "r5", GROUP_ADDRESS, 32, 2500) + result = app_helper.run_traffic("r5", GROUP_ADDRESS, "r3") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify (*, G) upstream IIF interface") @@ -2566,7 +2568,7 @@ def test_restart_pimd_process_p2(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -2590,7 +2592,7 @@ def test_restart_pimd_process_p2(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r0: Send IGMP join") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify IGMP groups") @@ -2600,7 +2602,7 @@ def test_restart_pimd_process_p2(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r5: Send multicast traffic for group 225.1.1.1") - result = iperfSendTraffic(tgen, "r5", GROUP_ADDRESS, 32, 2500) + result = app_helper.run_traffic("r5", GROUP_ADDRESS, "r3") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify (*, G) upstream IIF interface") @@ -2726,7 +2728,7 @@ def test_multiple_groups_same_RP_address_p2(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -2757,7 +2759,7 @@ def test_multiple_groups_same_RP_address_p2(request): group_address_list = GROUP_ADDRESS_LIST_1 + GROUP_ADDRESS_LIST_2 step("r0: Send IGMP join for 10 groups") - result = iperfSendIGMPJoin(tgen, "r0", group_address_list, join_interval=1) + result = app_helper.run_join("r0", group_address_list, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify IGMP groups") @@ -2767,7 +2769,7 @@ def test_multiple_groups_same_RP_address_p2(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r5: Send multicast traffic for group 225.1.1.1") - result = iperfSendTraffic(tgen, "r5", group_address_list, 32, 2500) + result = app_helper.run_traffic("r5", group_address_list, "r3") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify (*, G) upstream IIF interface") @@ -3035,7 +3037,7 @@ def test_multiple_groups_different_RP_address_p2(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -3104,7 +3106,7 @@ def test_multiple_groups_different_RP_address_p2(request): group_address_list = GROUP_ADDRESS_LIST_1 + GROUP_ADDRESS_LIST_2 step("r0: Send IGMP join") - result = iperfSendIGMPJoin(tgen, "r0", group_address_list, join_interval=1) + result = app_helper.run_join("r0", group_address_list, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify IGMP groups") @@ -3114,7 +3116,7 @@ def test_multiple_groups_different_RP_address_p2(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r5: Send multicast traffic for group 225.1.1.1") - result = iperfSendTraffic(tgen, "r5", group_address_list, 32, 2500) + result = app_helper.run_traffic("r5", group_address_list, "r3") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify (*, G) upstream IIF interface") @@ -3606,7 +3608,7 @@ def test_shutdown_primary_path_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -3632,7 +3634,7 @@ def test_shutdown_primary_path_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r0: Send IGMP join") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify IGMP groups") @@ -3799,7 +3801,7 @@ def test_delete_RP_shut_noshut_upstream_interface_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -3823,7 +3825,7 @@ def test_delete_RP_shut_noshut_upstream_interface_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r0: Send IGMP join") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify IGMP groups") @@ -3932,7 +3934,7 @@ def test_delete_RP_shut_noshut_RP_interface_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) - kill_iperf(tgen) + app_helper.stop_all_hosts() clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) @@ -3956,7 +3958,7 @@ def test_delete_RP_shut_noshut_RP_interface_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r0: Send IGMP join") - result = iperfSendIGMPJoin(tgen, "r0", GROUP_ADDRESS, join_interval=1) + result = app_helper.run_join("r0", GROUP_ADDRESS, "r1") assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("r1: Verify IGMP groups") diff --git a/tests/topotests/pim_acl/test_pim_acl.py b/tests/topotests/pim_acl/test_pim_acl.py index 4414713d8e..23b0efe4b5 100755 --- a/tests/topotests/pim_acl/test_pim_acl.py +++ b/tests/topotests/pim_acl/test_pim_acl.py @@ -125,96 +125,34 @@ from lib.pim import McastTesterHelper pytestmark = [pytest.mark.pimd, pytest.mark.ospfd] -# -# Test global variables: -# They are used to handle communicating with external application. -# -APP_SOCK_PATH = '/tmp/topotests/apps.sock' -HELPER_APP_PATH = os.path.join(CWD, "../lib/mcast-tester.py") -app_listener = None -app_clients = {} -def listen_to_applications(): - "Start listening socket to connect with applications." - # Remove old socket. - try: - os.unlink(APP_SOCK_PATH) - except OSError: - pass +def build_topo(tgen): + for hostNum in range(1,3): + tgen.add_router("h{}".format(hostNum)) - sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0) - sock.bind(APP_SOCK_PATH) - sock.listen(10) - global app_listener - app_listener = sock + # Create the main router + tgen.add_router("r1") -def accept_host(host): - "Accept connection from application running in hosts." - global app_listener, app_clients - conn = app_listener.accept() - app_clients[host] = { - 'fd': conn[0], - 'address': conn[1] - } + # Create the PIM RP routers + for rtrNum in range(11, 16): + tgen.add_router("r{}".format(rtrNum)) -def close_applications(): - "Signal applications to stop and close all sockets." - global app_listener, app_clients + # Setup Switches and connections + for swNum in range(1, 3): + tgen.add_switch("sw{}".format(swNum)) - if app_listener: - # Close listening socket. - app_listener.close() + # Add connections H1 to R1 switch sw1 + tgen.gears["h1"].add_link(tgen.gears["sw1"]) + tgen.gears["r1"].add_link(tgen.gears["sw1"]) - # Remove old socket. - try: - os.unlink(APP_SOCK_PATH) - except OSError: - pass - - # Close all host connections. - for host in ["h1", "h2"]: - if app_clients.get(host) is None: - continue - app_clients[host]["fd"].close() - - # Reset listener and clients data struct - app_listener = None - app_clients = {} - - -class PIMACLTopo(Topo): - "PIM ACL Test Topology" - - def build(self): - tgen = get_topogen(self) - - # Create the hosts - for hostNum in range(1,3): - tgen.add_router("h{}".format(hostNum)) - - # Create the main router - tgen.add_router("r1") - - # Create the PIM RP routers - for rtrNum in range(11, 16): - tgen.add_router("r{}".format(rtrNum)) - - # Setup Switches and connections - for swNum in range(1, 3): - tgen.add_switch("sw{}".format(swNum)) - - # Add connections H1 to R1 switch sw1 - tgen.gears["h1"].add_link(tgen.gears["sw1"]) - tgen.gears["r1"].add_link(tgen.gears["sw1"]) - - # Add connections R1 to R1x switch sw2 - tgen.gears["r1"].add_link(tgen.gears["sw2"]) - tgen.gears["h2"].add_link(tgen.gears["sw2"]) - tgen.gears["r11"].add_link(tgen.gears["sw2"]) - tgen.gears["r12"].add_link(tgen.gears["sw2"]) - tgen.gears["r13"].add_link(tgen.gears["sw2"]) - tgen.gears["r14"].add_link(tgen.gears["sw2"]) - tgen.gears["r15"].add_link(tgen.gears["sw2"]) + # Add connections R1 to R1x switch sw2 + tgen.gears["r1"].add_link(tgen.gears["sw2"]) + tgen.gears["h2"].add_link(tgen.gears["sw2"]) + tgen.gears["r11"].add_link(tgen.gears["sw2"]) + tgen.gears["r12"].add_link(tgen.gears["sw2"]) + tgen.gears["r13"].add_link(tgen.gears["sw2"]) + tgen.gears["r14"].add_link(tgen.gears["sw2"]) + tgen.gears["r15"].add_link(tgen.gears["sw2"]) ##################################################### @@ -226,7 +164,7 @@ class PIMACLTopo(Topo): def setup_module(module): logger.info("PIM RP ACL Topology: \n {}".format(TOPOLOGY)) - tgen = Topogen(PIMACLTopo, module.__name__) + tgen = Topogen(build_topo, module.__name__) tgen.start_topology() # Starting Routers @@ -251,7 +189,6 @@ def setup_module(module): def teardown_module(module): tgen = get_topogen() tgen.stop_topology() - close_applications() def test_ospf_convergence(): @@ -305,46 +242,38 @@ def check_mcast_entry(entry, mcastaddr, pimrp): logger.info("Testing PIM RP selection for ACL {} entry using {}".format(entry, mcastaddr)); - # Start applications socket. - listen_to_applications() + with McastTesterHelper(tgen) as helper: + helper.run("h2", ["--send=0.7", mcastaddr, "h2-eth0"]) + helper.run("h1", [mcastaddr, "h1-eth0"]) - tgen.gears["h2"].run("{} --send='0.7' '{}' '{}' '{}' &".format( - HELPER_APP_PATH, APP_SOCK_PATH, mcastaddr, 'h2-eth0')) - accept_host("h2") + logger.info("mcast join and source for {} started".format(mcastaddr)) - tgen.gears["h1"].run("{} '{}' '{}' '{}' &".format( - HELPER_APP_PATH, APP_SOCK_PATH, mcastaddr, 'h1-eth0')) - accept_host("h1") + # tgen.mininet_cli() - logger.info("mcast join and source for {} started".format(mcastaddr)) + router = tgen.gears["r1"] + reffile = os.path.join(CWD, "r1/acl_{}_pim_join.json".format(entry)) + expected = json.loads(open(reffile).read()) - # tgen.mininet_cli() + logger.info("verifying pim join on r1 for {}".format(mcastaddr)) + test_func = functools.partial( + topotest.router_json_cmp, router, "show ip pim join json", expected + ) + _, res = topotest.run_and_expect(test_func, None, count=60, wait=2) + assertmsg = "PIM router r1 did not show join status" + assert res is None, assertmsg - router = tgen.gears["r1"] - reffile = os.path.join(CWD, "r1/acl_{}_pim_join.json".format(entry)) - expected = json.loads(open(reffile).read()) + logger.info("verifying pim join on PIM RP {} for {}".format(pimrp, mcastaddr)) + router = tgen.gears[pimrp] + reffile = os.path.join(CWD, "{}/acl_{}_pim_join.json".format(pimrp, entry)) + expected = json.loads(open(reffile).read()) - logger.info("verifying pim join on r1 for {}".format(mcastaddr)) - test_func = functools.partial( - topotest.router_json_cmp, router, "show ip pim join json", expected - ) - _, res = topotest.run_and_expect(test_func, None, count=60, wait=2) - assertmsg = "PIM router r1 did not show join status" - assert res is None, assertmsg + test_func = functools.partial( + topotest.router_json_cmp, router, "show ip pim join json", expected + ) + _, res = topotest.run_and_expect(test_func, None, count=60, wait=2) + assertmsg = "PIM router {} did not get selected as the PIM RP".format(pimrp) + assert res is None, assertmsg - logger.info("verifying pim join on PIM RP {} for {}".format(pimrp, mcastaddr)) - router = tgen.gears[pimrp] - reffile = os.path.join(CWD, "{}/acl_{}_pim_join.json".format(pimrp, entry)) - expected = json.loads(open(reffile).read()) - - test_func = functools.partial( - topotest.router_json_cmp, router, "show ip pim join json", expected - ) - _, res = topotest.run_and_expect(test_func, None, count=60, wait=2) - assertmsg = "PIM router {} did not get selected as the PIM RP".format(pimrp) - assert res is None, assertmsg - - close_applications() return diff --git a/tests/topotests/pim_igmp_vrf/test_pim_vrf.py b/tests/topotests/pim_igmp_vrf/test_pim_vrf.py index a0f9e87b2a..badd224199 100755 --- a/tests/topotests/pim_igmp_vrf/test_pim_vrf.py +++ b/tests/topotests/pim_igmp_vrf/test_pim_vrf.py @@ -110,116 +110,53 @@ from lib.topolog import logger from lib.topotest import iproute2_is_vrf_capable from lib.common_config import ( required_linux_kernel_version) +from lib.pim import McastTesterHelper -# Required to instantiate the topology builder class. -from mininet.topo import Topo pytestmark = [pytest.mark.ospfd, pytest.mark.pimd] -# -# Test global variables: -# They are used to handle communicating with external application. -# -APP_SOCK_PATH = '/tmp/topotests/apps.sock' -HELPER_APP_PATH = os.path.join(CWD, "../lib/mcast-tester.py") -app_listener = None -app_clients = {} -def listen_to_applications(): - "Start listening socket to connect with applications." - # Remove old socket. - try: - os.unlink(APP_SOCK_PATH) - except OSError: - pass +def build_topo(tgen): + for hostNum in range(1,5): + tgen.add_router("h{}".format(hostNum)) - sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0) - sock.bind(APP_SOCK_PATH) - sock.listen(10) - global app_listener - app_listener = sock + # Create the main router + tgen.add_router("r1") -def accept_host(host): - "Accept connection from application running in hosts." - global app_listener, app_clients - conn = app_listener.accept() - app_clients[host] = { - 'fd': conn[0], - 'address': conn[1] - } + # Create the PIM RP routers + for rtrNum in range(11, 13): + tgen.add_router("r{}".format(rtrNum)) -def close_applications(): - "Signal applications to stop and close all sockets." - global app_listener, app_clients + # Setup Switches and connections + for swNum in range(1, 5): + tgen.add_switch("sw{}".format(swNum)) - if app_listener: - # Close listening socket. - app_listener.close() + ################ + # 1st set of connections to routers for VRF red + ################ - # Remove old socket. - try: - os.unlink(APP_SOCK_PATH) - except OSError: - pass + # Add connections H1 to R1 switch sw1 + tgen.gears["h1"].add_link(tgen.gears["sw1"]) + tgen.gears["r1"].add_link(tgen.gears["sw1"]) - # Close all host connections. - for host in ["h1", "h2"]: - if app_clients.get(host) is None: - continue - app_clients[host]["fd"].close() + # Add connections R1 to R1x switch sw2 + tgen.gears["r1"].add_link(tgen.gears["sw2"]) + tgen.gears["h2"].add_link(tgen.gears["sw2"]) + tgen.gears["r11"].add_link(tgen.gears["sw2"]) - # Reset listener and clients data struct - app_listener = None - app_clients = {} + ################ + # 2nd set of connections to routers for vrf blue + ################ + # Add connections H1 to R1 switch sw1 + tgen.gears["h3"].add_link(tgen.gears["sw3"]) + tgen.gears["r1"].add_link(tgen.gears["sw3"]) -class PIMVRFTopo(Topo): - "PIM VRF Test Topology" - - def build(self): - tgen = get_topogen(self) - - # Create the hosts - for hostNum in range(1,5): - tgen.add_router("h{}".format(hostNum)) - - # Create the main router - tgen.add_router("r1") - - # Create the PIM RP routers - for rtrNum in range(11, 13): - tgen.add_router("r{}".format(rtrNum)) - - # Setup Switches and connections - for swNum in range(1, 5): - tgen.add_switch("sw{}".format(swNum)) - - ################ - # 1st set of connections to routers for VRF red - ################ - - # Add connections H1 to R1 switch sw1 - tgen.gears["h1"].add_link(tgen.gears["sw1"]) - tgen.gears["r1"].add_link(tgen.gears["sw1"]) - - # Add connections R1 to R1x switch sw2 - tgen.gears["r1"].add_link(tgen.gears["sw2"]) - tgen.gears["h2"].add_link(tgen.gears["sw2"]) - tgen.gears["r11"].add_link(tgen.gears["sw2"]) - - ################ - # 2nd set of connections to routers for vrf blue - ################ - - # Add connections H1 to R1 switch sw1 - tgen.gears["h3"].add_link(tgen.gears["sw3"]) - tgen.gears["r1"].add_link(tgen.gears["sw3"]) - - # Add connections R1 to R1x switch sw2 - tgen.gears["r1"].add_link(tgen.gears["sw4"]) - tgen.gears["h4"].add_link(tgen.gears["sw4"]) - tgen.gears["r12"].add_link(tgen.gears["sw4"]) + # Add connections R1 to R1x switch sw2 + tgen.gears["r1"].add_link(tgen.gears["sw4"]) + tgen.gears["h4"].add_link(tgen.gears["sw4"]) + tgen.gears["r12"].add_link(tgen.gears["sw4"]) ##################################################### # @@ -230,7 +167,7 @@ class PIMVRFTopo(Topo): def setup_module(module): logger.info("PIM IGMP VRF Topology: \n {}".format(TOPOLOGY)) - tgen = Topogen(PIMVRFTopo, module.__name__) + tgen = Topogen(build_topo, module.__name__) tgen.start_topology() vrf_setup_cmds = [ @@ -264,13 +201,13 @@ def setup_module(module): router.load_config( TopoRouter.RD_PIM, os.path.join(CWD, "{}/pimd.conf".format(rname)) ) + tgen.start_router() def teardown_module(module): tgen = get_topogen() tgen.stop_topology() - close_applications() def test_ospf_convergence(): @@ -394,48 +331,36 @@ def check_mcast_entry(mcastaddr, pimrp, receiver, sender, vrf): logger.info("Testing PIM for VRF {} entry using {}".format(vrf, mcastaddr)); - # Start applications socket. - listen_to_applications() + with McastTesterHelper(tgen) as helper: + helper.run(sender, ["--send=0.7", mcastaddr, str(sender) + "-eth0"]) + helper.run(receiver, [mcastaddr, str(receiver) + "-eth0"]) - tgen.gears[sender].run("{} --send='0.7' '{}' '{}' '{}' &".format( - HELPER_APP_PATH, APP_SOCK_PATH, mcastaddr, '{}-eth0'.format(sender))) - accept_host(sender) + logger.info("mcast join and source for {} started".format(mcastaddr)) - tgen.gears[receiver].run("{} '{}' '{}' '{}' &".format( - HELPER_APP_PATH, APP_SOCK_PATH, mcastaddr, '{}-eth0'.format(receiver))) - accept_host(receiver) + router = tgen.gears["r1"] + reffile = os.path.join(CWD, "r1/pim_{}_join.json".format(vrf)) + expected = json.loads(open(reffile).read()) - logger.info("mcast join and source for {} started".format(mcastaddr)) + logger.info("verifying pim join on r1 for {} on VRF {}".format(mcastaddr, vrf)) + test_func = functools.partial( + topotest.router_json_cmp, router, "show ip pim vrf {} join json".format(vrf), + expected + ) + _, res = topotest.run_and_expect(test_func, None, count=10, wait=2) + assertmsg = "PIM router r1 did not show join status on VRF {}".format(vrf) + assert res is None, assertmsg - # tgen.mininet_cli() + logger.info("verifying pim join on PIM RP {} for {}".format(pimrp, mcastaddr)) + router = tgen.gears[pimrp] + reffile = os.path.join(CWD, "{}/pim_{}_join.json".format(pimrp, vrf)) + expected = json.loads(open(reffile).read()) - router = tgen.gears["r1"] - reffile = os.path.join(CWD, "r1/pim_{}_join.json".format(vrf)) - expected = json.loads(open(reffile).read()) - - logger.info("verifying pim join on r1 for {} on VRF {}".format(mcastaddr, vrf)) - test_func = functools.partial( - topotest.router_json_cmp, router, "show ip pim vrf {} join json".format(vrf), - expected - ) - _, res = topotest.run_and_expect(test_func, None, count=10, wait=2) - assertmsg = "PIM router r1 did not show join status on VRF".format(vrf) - assert res is None, assertmsg - - logger.info("verifying pim join on PIM RP {} for {}".format(pimrp, mcastaddr)) - router = tgen.gears[pimrp] - reffile = os.path.join(CWD, "{}/pim_{}_join.json".format(pimrp, vrf)) - expected = json.loads(open(reffile).read()) - - test_func = functools.partial( - topotest.router_json_cmp, router, "show ip pim join json", expected - ) - _, res = topotest.run_and_expect(test_func, None, count=10, wait=2) - assertmsg = "PIM router {} did not get selected as the PIM RP for VRF {}".format(pimrp, vrf) - assert res is None, assertmsg - - close_applications() - return + test_func = functools.partial( + topotest.router_json_cmp, router, "show ip pim join json", expected + ) + _, res = topotest.run_and_expect(test_func, None, count=10, wait=2) + assertmsg = "PIM router {} did not get selected as the PIM RP for VRF {}".format(pimrp, vrf) + assert res is None, assertmsg def test_mcast_vrf_blue(): From 04464749b666e4e04ce35c3a078c6f25dca1079e Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Sun, 1 Aug 2021 10:36:09 +0000 Subject: [PATCH 16/25] tests: keep revisions of configs Signed-off-by: Christian Hopps --- tests/topotests/lib/common_config.py | 32 +++++++++++++++++++--------- tests/topotests/lib/topogen.py | 1 + 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index fc51b11141..a4f2ac8050 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -488,6 +488,9 @@ def reset_config_on_routers(tgen, routerName=None): logger.debug("Entering API: reset_config_on_routers") + tgen.cfg_gen += 1 + gen = tgen.cfg_gen + # Trim the router list if needed router_list = tgen.routers() if routerName: @@ -496,9 +499,10 @@ def reset_config_on_routers(tgen, routerName=None): return True router_list = { routerName: router_list[routerName] } - delta_fmt = tgen.logdir + "/{}/delta.conf" - init_cfg_fmt = tgen.logdir + "/{}/frr_json_initial.conf" - run_cfg_fmt = tgen.logdir + "/{}/frr.sav" + delta_fmt = tgen.logdir + "/{}/delta-{}.conf" + # FRRCFG_BKUP_FILE + target_cfg_fmt = tgen.logdir + "/{}/frr_json_initial.conf" + run_cfg_fmt = tgen.logdir + "/{}/frr-{}.sav" # # Get all running configs in parallel @@ -509,7 +513,7 @@ def reset_config_on_routers(tgen, routerName=None): procs[rname] = router_list[rname].popen( ["/usr/bin/env", "vtysh", "-c", "show running-config no-header"], stdin=None, - stdout=open(run_cfg_fmt.format(rname), "w"), + stdout=open(run_cfg_fmt.format(rname, gen), "w"), stderr=subprocess.PIPE, ) for rname, p in procs.items(): @@ -523,16 +527,16 @@ def reset_config_on_routers(tgen, routerName=None): # procs = {} for rname in router_list: - logger.info("Generating delta for router %s to new configuration", rname) + logger.info("Generating delta for router %s to new configuration (gen %d)", rname, gen) procs[rname] = tgen.net.popen( [ "/usr/lib/frr/frr-reload.py", "--test-reset", "--input", - run_cfg_fmt.format(rname), + run_cfg_fmt.format(rname, gen), "--test", - init_cfg_fmt.format(rname) ], + target_cfg_fmt.format(rname) ], stdin=None, - stdout=open(delta_fmt.format(rname), "w"), + stdout=open(delta_fmt.format(rname, gen), "w"), stderr=subprocess.PIPE, ) for rname, p in procs.items(): @@ -549,14 +553,14 @@ def reset_config_on_routers(tgen, routerName=None): logger.info("Applying delta config on router %s", rname) procs[rname] = router_list[rname].popen( - ["/usr/bin/env", "vtysh", "-f", delta_fmt.format(rname)], + ["/usr/bin/env", "vtysh", "-f", delta_fmt.format(rname, gen)], stdin=None, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, ) for rname, p in procs.items(): output, _ = p.communicate() - vtysh_command = "vtysh -f {}".format(delta_fmt.format(rname)) + vtysh_command = "vtysh -f {}".format(delta_fmt.format(rname, gen)) if not p.returncode: router_list[rname].logger.info( '\nvtysh config apply => "{}"\nvtysh output <= "{}"'.format(vtysh_command, output) @@ -615,6 +619,9 @@ def load_config_to_routers(tgen, routers, save_bkup=False): logger.debug("Entering API: load_config_to_routers") + tgen.cfg_gen += 1 + gen = tgen.cfg_gen + base_router_list = tgen.routers() router_list = {} for router in routers: @@ -623,6 +630,7 @@ def load_config_to_routers(tgen, routers, save_bkup=False): router_list[router] = base_router_list[router] frr_cfg_file_fmt = tgen.logdir + "/{}/" + FRRCFG_FILE + frr_cfg_save_file_fmt = tgen.logdir + "/{}/{}-" + FRRCFG_FILE frr_cfg_bkup_fmt = tgen.logdir + "/{}/" + FRRCFG_BKUP_FILE procs = {} @@ -630,6 +638,7 @@ def load_config_to_routers(tgen, routers, save_bkup=False): router = router_list[rname] try: frr_cfg_file = frr_cfg_file_fmt.format(rname) + frr_cfg_save_file = frr_cfg_save_file_fmt.format(rname, gen) frr_cfg_bkup = frr_cfg_bkup_fmt.format(rname) with open(frr_cfg_file, "r+") as cfg: data = cfg.read() @@ -637,6 +646,9 @@ def load_config_to_routers(tgen, routers, save_bkup=False): "Applying following configuration on router %s (gen: %d):\n%s", rname, gen, data ) + # Always save a copy of what we just did + with open(frr_cfg_save_file, "w") as bkup: + bkup.write(data) if save_bkup: with open(frr_cfg_bkup, "w") as bkup: bkup.write(data) diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 5c2ff1bf85..495c286b13 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -172,6 +172,7 @@ class Topogen(object): self.exabgp_cmd = None self._init_topo(topodef) + logger.info("loading topology: {}".format(self.modname)) # @staticmethod From 77a7a87cdd4efed632c0bfa07c27b0fa3d637133 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Wed, 4 Aug 2021 15:58:28 -0400 Subject: [PATCH 17/25] tools: move frr-reload.py to python3 explicitly We already, reasonably, require python3 elsewhere. Do so here, and reap some benefit. Signed-off-by: Christian Hopps --- tools/frr-reload.py | 97 +++++++++++++-------------------------------- 1 file changed, 28 insertions(+), 69 deletions(-) diff --git a/tools/frr-reload.py b/tools/frr-reload.py index 7c6a83a51d..a7f205c48c 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # Frr Reloader # Copyright (C) 2014 Cumulus Networks, Inc. # @@ -39,26 +39,12 @@ import string import subprocess import sys from collections import OrderedDict - -try: - from ipaddress import IPv6Address, ip_network -except ImportError: - from ipaddr import IPv6Address, IPNetwork +from ipaddress import IPv6Address, ip_network from pprint import pformat -try: - dict.iteritems -except AttributeError: - # Python 3 - def iteritems(d): - return iter(d.items()) - - -else: - # Python 2 - def iteritems(d): - return d.iteritems() - +# Python 3 +def iteritems(d): + return iter(d.items()) log = logging.getLogger(__name__) @@ -372,22 +358,13 @@ class Config(object): addr = re_key_rt.group(2) if "/" in addr: try: - if "ipaddress" not in sys.modules: - newaddr = IPNetwork(addr) - key[0] = "%s route %s/%s%s" % ( - re_key_rt.group(1), - newaddr.network, - newaddr.prefixlen, - re_key_rt.group(3), - ) - else: - newaddr = ip_network(addr, strict=False) - key[0] = "%s route %s/%s%s" % ( - re_key_rt.group(1), - str(newaddr.network_address), - newaddr.prefixlen, - re_key_rt.group(3), - ) + newaddr = ip_network(addr, strict=False) + key[0] = "%s route %s/%s%s" % ( + re_key_rt.group(1), + str(newaddr.network_address), + newaddr.prefixlen, + re_key_rt.group(3), + ) except ValueError: pass @@ -398,17 +375,11 @@ class Config(object): addr = re_key_rt.group(4) if "/" in addr: try: - if "ipaddress" not in sys.modules: - newaddr = "%s/%s" % ( - IPNetwork(addr).network, - IPNetwork(addr).prefixlen, - ) - else: - network_addr = ip_network(addr, strict=False) - newaddr = "%s/%s" % ( - str(network_addr.network_address), - network_addr.prefixlen, - ) + network_addr = ip_network(addr, strict=False) + newaddr = "%s/%s" % ( + str(network_addr.network_address), + network_addr.prefixlen, + ) except ValueError: newaddr = addr else: @@ -444,20 +415,12 @@ class Config(object): addr = addr + "/8" try: - if "ipaddress" not in sys.modules: - newaddr = IPNetwork(addr) - line = "network %s/%s %s" % ( - newaddr.network, - newaddr.prefixlen, - re_net.group(2), - ) - else: - network_addr = ip_network(addr, strict=False) - line = "network %s/%s %s" % ( - str(network_addr.network_address), - network_addr.prefixlen, - re_net.group(2), - ) + network_addr = ip_network(addr, strict=False) + line = "network %s/%s %s" % ( + str(network_addr.network_address), + network_addr.prefixlen, + re_net.group(2), + ) newlines.append(line) except ValueError: # Really this should be an error. Whats a network @@ -785,15 +748,11 @@ def get_normalized_ipv6_line(line): norm_word = None if "/" in word: try: - if "ipaddress" not in sys.modules: - v6word = IPNetwork(word) - norm_word = "%s/%s" % (v6word.network, v6word.prefixlen) - else: - v6word = ip_network(word, strict=False) - norm_word = "%s/%s" % ( - str(v6word.network_address), - v6word.prefixlen, - ) + v6word = ip_network(word, strict=False) + norm_word = "%s/%s" % ( + str(v6word.network_address), + v6word.prefixlen, + ) except ValueError: pass if not norm_word: From 784ad2307e8fef997b4ab5e737f4538428ff0067 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Fri, 6 Aug 2021 04:40:39 -0400 Subject: [PATCH 18/25] tests: add back a 10 second delay to see if this fixes the failures Signed-off-by: Christian Hopps --- .../test_bgp_evpn_overlay_index_gateway.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py b/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py index 20459adbdb..beb033c716 100755 --- a/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py +++ b/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py @@ -203,6 +203,8 @@ def setup_module(mod): logger.info("Running setup_module() done") + time.sleep(10) + def teardown_module(mod): """Teardown the pytest environment""" From 0ce28e746e82443677cc62f9bf9810af5c048173 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Wed, 18 Aug 2021 13:03:42 -0400 Subject: [PATCH 19/25] tests: remove unneeded mcast group kernel routes and sysctl - The PIM tests do not need kernel routes to help them bind joins and sources to specific interfaces. They should do that themselves directly. Also do not change system wide "rp_filter" sysctl away from the value required by everyone else. Signed-off-by: Christian Hopps --- .../test_multicast_pim_sm_topo1.py | 125 ----------- .../test_multicast_pim_sm_topo2.py | 131 +----------- .../test_multicast_pim_sm_topo3.py | 195 ------------------ .../test_multicast_pim_sm_topo4.py | 79 ------- .../test_multicast_pim_static_rp.py | 104 ---------- 5 files changed, 1 insertion(+), 633 deletions(-) diff --git a/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py b/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py index e6c9a30b3d..002a79485c 100755 --- a/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py +++ b/tests/topotests/multicast_pim_sm_topo1/test_multicast_pim_sm_topo1.py @@ -232,41 +232,6 @@ def teardown_module(): ##################################################### -def config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, iperf, iperf_intf, GROUP_RANGE, join=False, traffic=False -): - """ - API to do pre-configuration to send IGMP join and multicast - traffic - - parameters: - ----------- - * `tgen`: topogen object - * `topo`: input json data - * `tc_name`: caller test case name - * `iperf`: router running iperf - * `iperf_intf`: interface name router running iperf - * `GROUP_RANGE`: group range - * `join`: IGMP join, default False - * `traffic`: multicast traffic, default False - """ - - if join: - # Add route to kernal - result = addKernelRoute(tgen, iperf, iperf_intf, GROUP_RANGE) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - - if traffic: - # Add route to kernal - result = addKernelRoute(tgen, iperf, iperf_intf, GROUP_RANGE) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - - rnode = tgen.gears[iperf] - rnode.run("echo 2 > /proc/sys/net/ipv4/conf/all/rp_filter") - - return True - - def verify_state_incremented(state_before, state_after): """ API to compare interface traffic state incrementing @@ -467,20 +432,10 @@ def test_multicast_data_traffic_static_RP_send_traffic_then_join_p0(request): step("Start traffic first and then send the IGMP join") step("Send multicast traffic from FRR3 to 225.1.1.1 receiver") - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i2", "i2-f1-eth0", GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic("i2", IGMP_JOIN, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Enable IGMP on FRR1 interface and send IGMP join (225.1.1.1)") - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i1", "i1-l1-eth0", GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - step("joinRx value before join sent") state_dict = {"r2": {"r2-l1-eth2": ["joinRx"]}} state_before = verify_pim_interface_traffic(tgen, state_dict) @@ -594,20 +549,10 @@ def test_clear_pim_neighbors_and_mroute_p0(request): "Enable IGMP on FRR1 interface and send IGMP join 225.1.1.1 " "to 225.1.1.5 from different interfaces" ) - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i1", "i1-l1-eth0", GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join("i1", IGMP_JOIN_RANGE_1, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3, wait for SPT switchover") - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i2", "i2-f1-eth0", GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic("i2", IGMP_JOIN_RANGE_1, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -697,20 +642,10 @@ def test_verify_mroute_when_same_receiver_in_FHR_LHR_and_RP_p0(request): input_join = {"i1": "i1-l1-eth0", "i8": "i8-f1-eth0", "i3": "i3-r2-eth0"} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send multicast traffic from R3 to 225.1.1.1 receiver") - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i2", "i2-f1-eth0", GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic("i2", IGMP_JOIN, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -789,11 +724,6 @@ def test_verify_mroute_when_same_receiver_joining_5_diff_sources_p0(request): "for group (226.1.1.1-5, 232.1.1.1-5)" ) - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i1", "i1-l1-eth0", _GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join("i1", _IGMP_JOIN_RANGE, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -803,11 +733,6 @@ def test_verify_mroute_when_same_receiver_joining_5_diff_sources_p0(request): result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i8", "i8-f1-eth0", _GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join("i8", _IGMP_JOIN_RANGE, "f1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -825,11 +750,6 @@ def test_verify_mroute_when_same_receiver_joining_5_diff_sources_p0(request): } for src, src_intf in input_traffic.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, _GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -1105,20 +1025,10 @@ def test_verify_mroute_when_frr_is_transit_router_p2(request): assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Enable IGMP on FRR1 interface and send IGMP join " "(225.1.1.1-5) to FRR1") - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i1", "i1-l1-eth0", GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join("i1", IGMP_JOIN_RANGE_1, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to 225.1.1.1-5 receivers") - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i2", "i2-f1-eth0", GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic("i2", IGMP_JOIN_RANGE_1, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -1220,20 +1130,10 @@ def test_verify_mroute_when_RP_unreachable_p1(request): step("Enable IGMP on FRR1 interface and send IGMP join (225.1.1.1)") - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i1", "i1-l1-eth0", GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join("i1", IGMP_JOIN, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to 225.1.1.1 receiver") - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i2", "i2-f1-eth0", GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic("i2", IGMP_JOIN, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -1244,11 +1144,6 @@ def test_verify_mroute_when_RP_unreachable_p1(request): result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i8", "i8-f1-eth0", GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join("i8", IGMP_JOIN, "f1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1323,11 +1218,6 @@ def test_modify_igmp_query_timer_p0(request): clear_ip_pim_interface_traffic(tgen, topo) step("Enable IGMP on FRR1 interface and send IGMP join (225.1.1.1)") - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i1", "i1-l1-eth0", GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join("i1", IGMP_JOIN, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1352,11 +1242,6 @@ def test_modify_igmp_query_timer_p0(request): assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to 225.1.1.1 receiver") - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i2", "i2-f1-eth0", GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic("i2", IGMP_JOIN, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -1462,11 +1347,6 @@ def test_modify_igmp_max_query_response_timer_p0(request): clear_ip_pim_interface_traffic(tgen, topo) step("Enable IGMP on FRR1 interface and send IGMP join (225.1.1.1)") - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i1", "i1-l1-eth0", GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join("i1", IGMP_JOIN, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1512,11 +1392,6 @@ def test_modify_igmp_max_query_response_timer_p0(request): assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to 225.1.1.1 receiver") - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i2", "i2-f1-eth0", GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic("i2", IGMP_JOIN, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) diff --git a/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py b/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py index 27abfae9f4..c0fa53af1d 100755 --- a/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py +++ b/tests/topotests/multicast_pim_sm_topo2/test_multicast_pim_sm_topo2.py @@ -225,46 +225,6 @@ def teardown_module(): ##################################################### -def config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, iperf, iperf_intf, GROUP_RANGE, join=False, traffic=False -): - """ - API to do pre-configuration to send IGMP join and multicast - traffic - - parameters: - ----------- - * `tgen`: topogen object - * `topo`: input json data - * `tc_name`: caller test case name - * `iperf`: router running iperf - * `iperf_intf`: interface name router running iperf - * `GROUP_RANGE`: group range - * `join`: IGMP join, default False - * `traffic`: multicast traffic, default False - """ - - if join: - # Add route to kernal - result = addKernelRoute(tgen, iperf, iperf_intf, GROUP_RANGE) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - - if traffic: - # Add route to kernal - result = addKernelRoute(tgen, iperf, iperf_intf, GROUP_RANGE) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - - router_list = tgen.routers() - for router in router_list.keys(): - if router == iperf: - continue - - rnode = router_list[router] - rnode.run("echo 2 > /proc/sys/net/ipv4/conf/all/rp_filter") - - return True - - def verify_state_incremented(state_before, state_after): """ API to compare interface traffic state incrementing @@ -378,11 +338,6 @@ def test_verify_mroute_and_traffic_when_pimd_restarted_p2(request): input_join = {"i1": "i1-l1-eth0", "i8": "i8-f1-eth0"} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, _GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, _IGMP_JOIN_RANGE, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -398,11 +353,6 @@ def test_verify_mroute_and_traffic_when_pimd_restarted_p2(request): input_src = {"i2": "i2-f1-eth0", "i5": "i5-c2-eth0"} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, _GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -590,11 +540,6 @@ def test_verify_mroute_and_traffic_when_frr_restarted_p2(request): input_join = {"i1": "i1-l1-eth0", "i8": "i8-f1-eth0"} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, _GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, _IGMP_JOIN_RANGE, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -610,11 +555,6 @@ def test_verify_mroute_and_traffic_when_frr_restarted_p2(request): input_src = {"i2": "i2-f1-eth0", "i5": "i5-c2-eth0"} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, _GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -775,21 +715,11 @@ def test_verify_SPT_switchover_when_RPT_and_SPT_path_is_different_p0(request): "(226.1.1.1-5) and (232.1.1.1-5)" ) - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i1", "i1-l1-eth0", _GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join("i1", _IGMP_JOIN_RANGE, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to '226.1.1.1-5'" ", '232.1.1.1-5' receiver") - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i2", "i2-f1-eth0", _GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - step("registerRx and registerStopTx value before traffic sent") state_dict = {"c2": {"c2-f1-eth1": ["registerRx", "registerStopTx"]}} state_before = verify_pim_interface_traffic(tgen, state_dict) @@ -963,11 +893,6 @@ def test_verify_mroute_after_shut_noshut_of_upstream_interface_p1(request): input_join = {"i1": "i1-l1-eth0", "i8": "i8-f1-eth0"} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, _GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, _IGMP_JOIN_RANGE, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -983,11 +908,6 @@ def test_verify_mroute_after_shut_noshut_of_upstream_interface_p1(request): input_src = {"i2": "i2-f1-eth0", "i5": "i5-c2-eth0"} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, _GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -1209,11 +1129,6 @@ def test_verify_mroute_when_receiver_is_outside_frr_p0(request): "Enable IGMP on FRR1 interface and send IGMP join" " (226.1.1.1-5) and (232.1.1.1-5)" ) - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i1", "i1-l1-eth0", _GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join("i1", _IGMP_JOIN_RANGE, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1221,11 +1136,6 @@ def test_verify_mroute_when_receiver_is_outside_frr_p0(request): "Send multicast traffic from FRR3 to all the receivers " "(226.1.1.1-5) and (232.1.1.1-5)" ) - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i2", "i2-f1-eth0", _GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic("i2", _IGMP_JOIN_RANGE, "f1") assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -1239,11 +1149,6 @@ def test_verify_mroute_when_receiver_is_outside_frr_p0(request): result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, "i5", "i5-c2-eth0", _GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join("i5", _IGMP_JOIN_RANGE, "c2") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1357,16 +1262,6 @@ def test_verify_mroute_when_FRR_is_FHR_and_LHR_p0(request): "(226.1.1.1-5) and (232.1.1.1-5)" ) - # result = config_to_send_igmp_join_and_traffic( - # tgen, topo, tc_name, "i1", "i1-l1-eth0", _GROUP_RANGE, join=True - # ) - # assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - - # result = config_to_send_igmp_join_and_traffic( - # tgen, topo, tc_name, "i2", "i2-f1-eth0", _GROUP_RANGE, traffic=True - # ) - # assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - step("Send IGMP join (226.1.1.1-5, 232.1.1.1-5) to LHR(l1)") result = app_helper.run_join("i1", _IGMP_JOIN_RANGE, "l1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1387,11 +1282,6 @@ def test_verify_mroute_when_FRR_is_FHR_and_LHR_p0(request): result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - # result = config_to_send_igmp_join_and_traffic( - # tgen, topo, tc_name, "i8", "i8-f1-eth0", _GROUP_RANGE, join=True - # ) - # assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join("i8", _IGMP_JOIN_RANGE, "f1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( @@ -1589,13 +1479,9 @@ def test_verify_mroute_when_5_different_receiver_joining_same_sources_p0(request } for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, _GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, _IGMP_JOIN_RANGE, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + step("Configure one source in FRR2 , one in c1") step( "Send multicast traffic from both the sources to all the" @@ -1605,11 +1491,6 @@ def test_verify_mroute_when_5_different_receiver_joining_same_sources_p0(request input_src = {"i3": "i3-r2-eth0"} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, _GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step( @@ -1799,11 +1680,6 @@ def test_verify_oil_iif_for_mroute_after_shut_noshut_source_interface_p1(request input_join = {"i1": "i1-l1-eth0", "i8": "i8-f1-eth0"} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, _GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, _IGMP_JOIN_RANGE, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1816,11 +1692,6 @@ def test_verify_oil_iif_for_mroute_after_shut_noshut_source_interface_p1(request input_src = {"i6": "i6-l1-eth0", "i2": "i2-f1-eth0"} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, _GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) diff --git a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py index afefbfed10..84e274ab2d 100755 --- a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py +++ b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo3.py @@ -242,56 +242,6 @@ def teardown_module(): ##################################################### -def config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, iperf, iperf_intf, GROUP_RANGE, join=False, traffic=False -): - """ - API to do pre-configuration to send IGMP join and multicast - traffic - - parameters: - ----------- - * `tgen`: topogen object - * `topo`: input json data - * `tc_name`: caller test case name - * `iperf`: router running iperf - * `iperf_intf`: interface name router running iperf - * `GROUP_RANGE`: group range - * `join`: IGMP join, default False - * `traffic`: multicast traffic, default False - """ - - if join: - # Add route to kernal - result = addKernelRoute(tgen, iperf, iperf_intf, GROUP_RANGE) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - - if traffic: - # Add route to kernal - result = addKernelRoute(tgen, iperf, iperf_intf, GROUP_RANGE) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - - router_list = tgen.routers() - for router in router_list.keys(): - if router == iperf: - continue - - rnode = router_list[router] - rnode.run("echo 2 > /proc/sys/net/ipv4/conf/all/rp_filter") - - for router in topo["routers"].keys(): - if "static_routes" in topo["routers"][router]: - static_routes = topo["routers"][router]["static_routes"] - for static_route in static_routes: - network = static_route["network"] - next_hop = static_route["next_hop"] - if type(network) is not list: - network = [network] - for net in network: - addKernelRoute(tgen, router, iperf_intf, net, next_hop) - return True - - def verify_mroute_repopulated(uptime_before, uptime_after): """ API to compare uptime for mroutes @@ -463,11 +413,6 @@ def test_verify_oil_when_join_prune_sent_scenario_1_p1(request): } for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -498,11 +443,6 @@ def test_verify_oil_when_join_prune_sent_scenario_1_p1(request): input_src = {"i2": topo["routers"]["i2"]["links"]["f1"]["interface"]} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -847,11 +787,6 @@ def test_verify_oil_when_join_prune_sent_scenario_2_p1(request): } for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1063,11 +998,6 @@ def test_shut_noshut_source_interface_when_upstream_cleared_from_LHR_p1(request) input_join = {"i1": topo["routers"]["i1"]["links"]["l1"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1096,11 +1026,6 @@ def test_shut_noshut_source_interface_when_upstream_cleared_from_LHR_p1(request) input_src = {"i2": topo["routers"]["i2"]["links"]["f1"]["interface"]} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -1280,11 +1205,6 @@ def test_shut_noshut_receiver_interface_when_upstream_cleared_from_LHR_p1(reques input_join = {"i1": topo["routers"]["i1"]["links"]["l1"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1313,11 +1233,6 @@ def test_shut_noshut_receiver_interface_when_upstream_cleared_from_LHR_p1(reques input_src = {"i2": topo["routers"]["i2"]["links"]["f1"]["interface"]} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -1482,11 +1397,6 @@ def test_verify_remove_add_igmp_config_to_receiver_interface_p0(request): input_join = {"i1": topo["routers"]["i1"]["links"]["l1"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1515,11 +1425,6 @@ def test_verify_remove_add_igmp_config_to_receiver_interface_p0(request): input_src = {"i2": topo["routers"]["i2"]["links"]["f1"]["interface"]} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -1528,11 +1433,6 @@ def test_verify_remove_add_igmp_config_to_receiver_interface_p0(request): input_src = {"i6": topo["routers"]["i6"]["links"]["l1"]["interface"]} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -1858,11 +1758,6 @@ def test_verify_remove_add_igmp_commands_when_pim_configured_p0(request): input_join = {"i1": topo["routers"]["i1"]["links"]["l1"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -1891,11 +1786,6 @@ def test_verify_remove_add_igmp_commands_when_pim_configured_p0(request): input_src = {"i2": topo["routers"]["i2"]["links"]["f1"]["interface"]} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -1904,11 +1794,6 @@ def test_verify_remove_add_igmp_commands_when_pim_configured_p0(request): input_src = {"i6": topo["routers"]["i6"]["links"]["l1"]["interface"]} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -2158,11 +2043,6 @@ def test_verify_remove_add_pim_commands_when_igmp_configured_p1(request): input_join = {"i1": topo["routers"]["i1"]["links"]["l1"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -2353,11 +2233,6 @@ def test_pim_dr_priority_p0(request): input_join = {"i1": topo["routers"]["i1"]["links"]["l1"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -2384,11 +2259,6 @@ def test_pim_dr_priority_p0(request): input_src = {"i2": topo["routers"]["i2"]["links"]["f1"]["interface"]} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -2636,11 +2506,6 @@ def test_pim_hello_timer_p1(request): input_join = {"i1": topo["routers"]["i1"]["links"]["l1"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -2775,11 +2640,6 @@ def test_mroute_after_removing_RP_sending_IGMP_prune_p2(request): input_join = {"i8": topo["routers"]["i8"]["links"]["f1"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -2811,11 +2671,6 @@ def test_mroute_after_removing_RP_sending_IGMP_prune_p2(request): input_src = {"i6": topo["routers"]["i6"]["links"]["l1"]["interface"]} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -3001,11 +2856,6 @@ def test_mroute_after_removing_RP_sending_IGMP_prune_p2(request): step("Send IGMP joins again from LHR,check IGMP joins and starg received") for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -3023,11 +2873,6 @@ def test_mroute_after_removing_RP_sending_IGMP_prune_p2(request): step("Send traffic from FHR and verify mroute upstream") for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -3093,11 +2938,6 @@ def test_prune_sent_to_LHR_and_FHR_when_PIMnbr_down_p2(request): input_join = {"i8": topo["routers"]["i8"]["links"]["f1"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -3132,11 +2972,6 @@ def test_prune_sent_to_LHR_and_FHR_when_PIMnbr_down_p2(request): } for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -3735,11 +3570,6 @@ def test_mroute_flags_p1(request): input_join = {"i8": topo["routers"]["i8"]["links"]["f1"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -3774,11 +3604,6 @@ def test_mroute_flags_p1(request): } for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -3919,11 +3744,6 @@ def test_verify_multicast_traffic_when_LHR_connected_to_RP_p1(request): input_join = {"i3": topo["routers"]["i3"]["links"]["r2"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, _GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, _IGMP_JOIN_RANGE, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -3952,11 +3772,6 @@ def test_verify_multicast_traffic_when_LHR_connected_to_RP_p1(request): input_src = {"i1": topo["routers"]["i1"]["links"]["l1"]["interface"]} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, _GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -4353,11 +4168,6 @@ def test_verify_multicast_traffic_when_FHR_connected_to_RP_p1(request): input_join = {"i1": topo["routers"]["i1"]["links"]["l1"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, _GROUP_RANGE, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, _IGMP_JOIN_RANGE, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -4386,11 +4196,6 @@ def test_verify_multicast_traffic_when_FHR_connected_to_RP_p1(request): input_src = {"i3": topo["routers"]["i3"]["links"]["r2"]["interface"]} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, _GROUP_RANGE, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, _IGMP_JOIN_RANGE, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) diff --git a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py index dbd1dcec47..275578a5b1 100755 --- a/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py +++ b/tests/topotests/multicast_pim_sm_topo3/test_multicast_pim_sm_topo4.py @@ -210,55 +210,6 @@ def teardown_module(): ##################################################### -def config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, iperf, iperf_intf, GROUP_RANGE, join=False, traffic=False -): - """ - API to do pre-configuration to send IGMP join and multicast - traffic - - parameters: - ----------- - * `tgen`: topogen object - * `topo`: input json data - * `tc_name`: caller test case name - * `iperf`: router running iperf - * `iperf_intf`: interface name router running iperf - * `GROUP_RANGE`: group range - * `join`: IGMP join, default False - * `traffic`: multicast traffic, default False - """ - - if join: - # Add route to kernal - result = addKernelRoute(tgen, iperf, iperf_intf, GROUP_RANGE) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - - if traffic: - # Add route to kernal - result = addKernelRoute(tgen, iperf, iperf_intf, GROUP_RANGE) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - - router_list = tgen.routers() - for router in router_list.keys(): - if router == iperf: - continue - - rnode = router_list[router] - rnode.run("echo 2 > /proc/sys/net/ipv4/conf/all/rp_filter") - - for router in topo["routers"].keys(): - if "static_routes" in topo["routers"][router]: - static_routes = topo["routers"][router]["static_routes"] - for static_route in static_routes: - network = static_route["network"] - next_hop = static_route["next_hop"] - if type(network) is not list: - network = [network] - - return True - - def verify_state_incremented(state_before, state_after): """ API to compare interface traffic state incrementing @@ -343,11 +294,6 @@ def test_mroute_when_RP_reachable_default_route_p2(request): input_join = {"i5": topo["routers"]["i5"]["links"]["c2"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -376,11 +322,6 @@ def test_mroute_when_RP_reachable_default_route_p2(request): input_src = {"i4": topo["routers"]["i4"]["links"]["c1"]["interface"]} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -642,11 +583,6 @@ def test_mroute_with_RP_default_route_all_nodes_p2(request): input_join = {"i4": topo["routers"]["i4"]["links"]["c1"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -675,11 +611,6 @@ def test_mroute_with_RP_default_route_all_nodes_p2(request): input_src = {"i5": topo["routers"]["i5"]["links"]["c2"]["interface"]} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) @@ -930,11 +861,6 @@ def test_PIM_hello_tx_rx_p1(request): input_join = {"i4": topo["routers"]["i4"]["links"]["c1"]["interface"]} for recvr, recvr_intf in input_join.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) @@ -963,11 +889,6 @@ def test_PIM_hello_tx_rx_p1(request): input_src = {"i5": topo["routers"]["i5"]["links"]["c2"]["interface"]} for src, src_intf in input_src.items(): - result = config_to_send_igmp_join_and_traffic( - tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True - ) - assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) diff --git a/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py b/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py index d0ab12e5cc..d599b07a70 100755 --- a/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py +++ b/tests/topotests/multicast_pim_static_rp_topo1/test_multicast_pim_static_rp.py @@ -275,40 +275,6 @@ def teardown_module(): ##################################################### -def config_to_send_igmp_join_and_traffic(tgen, tc_name): - """ - API to do pre-configuration to send IGMP join and multicast - traffic - - parameters: - ----------- - * `tgen`: topogen object - * `tc_name`: caller test case name - """ - - step("r0: Add route to kernal") - result = addKernelRoute(tgen, "r0", "r0-r1-eth0", GROUP_RANGE_ALL) - assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) - - step("r5: Add route to kernal") - result = addKernelRoute(tgen, "r5", "r5-r3-eth0", GROUP_RANGE_ALL) - assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) - - rnode = tgen.routers()["r1"] - rnode.run("ip route add 10.0.6.0/24 via 10.0.2.2") - rnode = tgen.routers()["r2"] - rnode.run("ip route add 10.0.6.0/24 via 10.0.4.2") - rnode = tgen.routers()["r4"] - rnode.run("ip route add 10.0.6.0/24 via 10.0.5.1") - - router_list = tgen.routers() - for router in router_list.keys(): - rnode = router_list[router] - rnode.run("echo 2 > /proc/sys/net/ipv4/conf/all/rp_filter") - - return True - - def verify_mroute_repopulated(uptime_before, uptime_after): """ API to compare uptime for mroutes @@ -405,8 +371,6 @@ def test_add_delete_static_RP_p0(request): pytest.skip(tgen.errors) step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) step("Enable IGMP on r1 interface and send IGMP " "join (225.1.1.1) to r1") step("Configure r2 loopback interface as RP") @@ -572,10 +536,6 @@ def test_SPT_RPT_path_same_p1(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - dut = "r1" intf = "r1-r3-eth2" shutdown_bringup_interface(tgen, dut, intf, False) @@ -728,10 +688,6 @@ def test_not_reachable_static_RP_p0(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - dut = "r1" intf = "r1-r3-eth2" shutdown_bringup_interface(tgen, dut, intf, False) @@ -894,10 +850,6 @@ def test_add_RP_after_join_received_p1(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - step("Enable IGMP on R1 interface") step("Configure r2 loopback interface as RP") step("Enable PIM between r1 and r2") @@ -1064,10 +1016,6 @@ def test_reachable_static_RP_after_join_p0(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - step("Enable IGMP on r1 interface and send IGMP " "join (225.1.1.1) to r1") step("Configure r2 loopback interface as RP") step("Enable PIM between r1 and r2") @@ -1231,10 +1179,6 @@ def test_send_join_on_higher_preffered_rp_p1(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - step("Enable IGMP on r1 interface") step("Configure RP on r2 (loopback interface) for the group range " "224.0.0.0/4") step("Configure RP on r4 (loopback interface) for the group range " "225.1.1.1/32") @@ -1472,10 +1416,6 @@ def test_RP_configured_as_LHR_1_p1(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - step("Enable IGMP on r1 interface") step("Configure RP on r1 (loopback interface) for the group range" " 224.0.0.0/4") step("Enable the PIM on all the interfaces of r1, r2, r3 and r4 routers") @@ -1688,10 +1628,6 @@ def test_RP_configured_as_LHR_2_p1(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - step("Enable IGMP on r1 interface") step("Configure RP on r1 (loopback interface) for the group range" " 224.0.0.0/4") step("Enable the PIM on all the interfaces of r1, r2, r3 and r4 routers") @@ -1898,10 +1834,6 @@ def test_RP_configured_as_FHR_1_p1(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - step("Enable IGMP on r1 interface") step("Configure RP on r2 (loopback interface) for the group range" " 225.1.1.0/24") step("Enable the PIM on all the interfaces of r1, r2, r3 and r4 routers") @@ -2107,10 +2039,6 @@ def test_RP_configured_as_FHR_2_p2(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - step("Enable IGMP on r1 interface") step("Configure RP on r2 (loopback interface) for the group range" " 225.1.1.0/24") step("Enable the PIM on all the interfaces of r1, r2, r3 and r4 routers") @@ -2320,10 +2248,6 @@ def test_SPT_RPT_path_different_p1(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - step("Enable IGMP on r1 interface and send IGMP join (225.1.1.1) to r1") step("Configure RP on r2 (loopback interface) for the group range" " 224.0.0.0/4") step("Enable the PIM on all the interfaces of r1, r2, r3 and r4 routers") @@ -2475,10 +2399,6 @@ def test_clear_pim_configuration_p1(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - step("Enable IGMP on r1 interface") step("Configure RP on r2 (loopback interface) for the group range" " 224.0.0.0/4") step("Enable the PIM on all the interfaces of r1, r2, r3 and r4 routers") @@ -2572,10 +2492,6 @@ def test_restart_pimd_process_p2(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - step("Enable IGMP on r1 interface and send IGMP join (225.1.1.1) to R1") step("Configure RP on r3 (loopback interface) for the group range" " 224.0.0.0/4") step("Enable the PIM on all the interfaces of r1, r2, r3 and r4 routers") @@ -2732,10 +2648,6 @@ def test_multiple_groups_same_RP_address_p2(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - step("Enable IGMP on r1 interface and send IGMP join (225.1.1.1) to r1") step("Configure RP on r2 (loopback interface) for the group range" "225.1.1.0/24") step("Enable the PIM on all the interfaces of r1-r2-r3") @@ -3041,10 +2953,6 @@ def test_multiple_groups_different_RP_address_p2(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - step("Delete existing RP configuration") input_dict = { "r2": { @@ -3612,10 +3520,6 @@ def test_shutdown_primary_path_p1(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - # Steps to execute step("Enable IGMP on r1 interface") step("Configure RP on r2 (loopback interface) for the group range" " 224.0.0.0/4") @@ -3805,10 +3709,6 @@ def test_delete_RP_shut_noshut_upstream_interface_p1(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - step("Enable IGMP on r1 interface") step("Configure RP on r2 (loopback interface) for the group range" " 224.0.0.0/4") step("r1: Delete the RP config") @@ -3938,10 +3838,6 @@ def test_delete_RP_shut_noshut_RP_interface_p1(request): clear_ip_mroute(tgen) clear_ip_pim_interface_traffic(tgen, TOPO) - step("pre-configuration to send IGMP join and multicast traffic") - result = config_to_send_igmp_join_and_traffic(tgen, tc_name) - assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result) - step("Enable IGMP on r1 interface") step("Configure RP on r2 (lo) for the group range" " 224.0.0.0/4") step("r2: Delete the RP configuration") From 62c608a9fb860624c4ace75edb01a844218d6f2f Mon Sep 17 00:00:00 2001 From: Martin Winter Date: Thu, 19 Aug 2021 00:01:04 +0200 Subject: [PATCH 20/25] tests: Make bgp_multiview_topo1 predictable Signed-off-by: Martin Winter --- .../test_bgp_multiview_topo1.py | 119 +++--------------- 1 file changed, 16 insertions(+), 103 deletions(-) diff --git a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py index 25240791ce..76a06bccd2 100644 --- a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py +++ b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py @@ -62,6 +62,7 @@ test_bgp_multiview_topo1.py: Simple FRR Route-Server Test ~~~~~~~~~~~~~ """ +import json import os import re import sys @@ -75,6 +76,7 @@ from functools import partial sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lib import topotest from lib.topogen import get_topogen, Topogen +from lib.common_config import step pytestmark = [pytest.mark.bgpd] @@ -161,6 +163,7 @@ def test_bgp_converge(): pytest.skip(tgen.errors) # Wait for BGP to converge (All Neighbors in either Full or TwoWay State) + step("Verify for BGP to converge") timeout = 125 while timeout > 0: @@ -190,17 +193,6 @@ def test_bgp_converge(): bgpStatus = tgen.net["r%s" % i].cmd('vtysh -c "show ip bgp view %s summary"' % view) assert False, "BGP did not converge:\n%s" % bgpStatus - # Wait for an extra 5s to announce all routes - print("Waiting 5s for routes to be announced") - sleep(5) - - print("BGP converged.") - - # if timeout < 60: - # # Only wait if we actually went through a convergence - # print("\nwaiting 15s for routes to populate") - # sleep(15) - tgen.routers_have_failure() @@ -212,103 +204,24 @@ def test_bgp_routingTable(): thisDir = os.path.dirname(os.path.realpath(__file__)) - print("\n\n** Verifying BGP Routing Tables") - print("******************************************\n") - diffresult = {} - for i in range(1, 2): - for view in range(1, 4): - success = 0 - # This glob pattern should work as long as number of views < 10 - for refTableFile in glob.glob( - "%s/r%s/show_ip_bgp_view_%s*.ref" % (thisDir, i, view) - ): + step("Verifying BGP Routing Tables") - if os.path.isfile(refTableFile): - # Read expected result from file - expected = open(refTableFile).read().rstrip() - # Fix newlines (make them all the same) - expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) - - # Actual output from router - actual = ( - tgen.net["r%s" % i] - .cmd('vtysh -c "show ip bgp view %s" 2> /dev/null' % view) - .rstrip() - ) - - # Fix inconsitent spaces between 0.99.24 and newer versions - actual = re.sub("0 0", "0 0", actual) - actual = re.sub( - r"([0-9]) 32768", r"\1 32768", actual - ) - # Remove summary line (changed recently) - actual = re.sub(r"Total number.*", "", actual) - actual = re.sub(r"Displayed.*", "", actual) - actual = actual.rstrip() - # Fix table version (ignore it) - actual = re.sub(r"(BGP table version is )[0-9]+", r"\1XXX", actual) - - # Fix newlines (make them all the same) - actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) - - # Generate Diff - diff = topotest.get_textdiff( - actual, - expected, - title1="actual BGP routing table", - title2="expected BGP routing table", - ) - - if diff: - diffresult[refTableFile] = diff - else: - success = 1 - print("template %s matched: r%s ok" % (refTableFile, i)) - break - - if not success: - resultstr = "No template matched.\n" - for f in diffresult.keys(): - resultstr += ( - "template %s: r%s failed Routing Table Check for view %s:\n%s\n" - % (f, i, view, diffresult[f]) - ) - raise AssertionError( - "Routing Table verification failed for router r%s, view %s:\n%s" - % (i, view, resultstr) - ) + router = tgen.gears["r1"] + for view in range(1, 4): + json_file = "{}/{}/view_{}.json".format(thisDir, router.name, view) + expected = json.loads(open(json_file).read()) + test_func = partial( + topotest.router_json_cmp, router, "show ip bgp view {} json".format(view), expected + ) + _, result = topotest.run_and_expect(test_func, None, count=5, wait=1) + assertmsg = "Routing Table verification failed for router {}, view {}".format( + router.name, view + ) + assert result is None, assertmsg tgen.routers_have_failure() -def test_shutdown_check_stderr(): - tgen = get_topogen() - - # Skip if previous fatal error condition is raised - if tgen.routers_have_failure(): - pytest.skip(tgen.errors) - - if os.environ.get("TOPOTESTS_CHECK_STDERR") is None: - print( - "SKIPPED final check on StdErr output: Disabled (TOPOTESTS_CHECK_STDERR undefined)\n" - ) - pytest.skip("Skipping test for Stderr output") - - thisDir = os.path.dirname(os.path.realpath(__file__)) - - print("\n\n** Verifying unexpected STDERR output from daemons") - print("******************************************\n") - - tgen.net["r1"].stopRouter() - - log = tgen.net["r1"].getStdErr("bgpd") - if log: - print("\nBGPd StdErr Log:\n" + log) - log = tgen.net["r1"].getStdErr("zebra") - if log: - print("\nZebra StdErr Log:\n" + log) - - def test_shutdown_check_memleak(): tgen = get_topogen() if not tgen.is_memleak_enabled(): From 2905398814bed538c841c49c5ece769d40dd5d97 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Sun, 22 Aug 2021 02:24:58 -0400 Subject: [PATCH 21/25] 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)) From f862fe55a48ea5177a04971c6a0b810d46dfa3e6 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Sun, 22 Aug 2021 02:28:24 -0400 Subject: [PATCH 22/25] tests: use common exa-receive.py script New generic script uses a new default node specific log dir to avoid collisions when running in parallel. Signed-off-by: Christian Hopps --- .../bgp_ecmp_topo1/peer1/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer10/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer11/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer12/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer13/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer14/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer15/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer16/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer17/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer18/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer19/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer2/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer20/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer3/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer4/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer5/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer6/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer7/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer8/exa-receive.py | 38 ------------------- .../bgp_ecmp_topo1/peer9/exa-receive.py | 38 ------------------- .../bgp_multiview_topo1/peer1/exa-receive.py | 38 ------------------- .../bgp_multiview_topo1/peer2/exa-receive.py | 38 ------------------- .../bgp_multiview_topo1/peer3/exa-receive.py | 38 ------------------- .../bgp_multiview_topo1/peer4/exa-receive.py | 38 ------------------- .../bgp_multiview_topo1/peer5/exa-receive.py | 38 ------------------- .../bgp_multiview_topo1/peer6/exa-receive.py | 38 ------------------- .../bgp_multiview_topo1/peer7/exa-receive.py | 38 ------------------- .../bgp_multiview_topo1/peer8/exa-receive.py | 38 ------------------- .../peer1/exa-receive.py | 38 ------------------- .../peer2/exa-receive.py | 38 ------------------- .../peer3/exa-receive.py | 38 ------------------- .../peer4/exa-receive.py | 38 ------------------- .../bgp_prefix_sid/peer2/exa-receive.py | 37 ------------------ .../topotests/bgp_prefix_sid/peer2/exabgp.cfg | 2 +- .../bgp_prefix_sid/test_bgp_prefix_sid.py | 5 ++- .../bgp_vrf_netns/peer1/exa-receive.py | 38 ------------------- 36 files changed, 4 insertions(+), 1294 deletions(-) delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer1/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer10/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer11/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer12/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer13/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer14/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer15/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer16/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer17/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer18/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer19/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer2/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer20/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer3/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer4/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer5/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer6/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer7/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer8/exa-receive.py delete mode 100755 tests/topotests/bgp_ecmp_topo1/peer9/exa-receive.py delete mode 100755 tests/topotests/bgp_multiview_topo1/peer1/exa-receive.py delete mode 100755 tests/topotests/bgp_multiview_topo1/peer2/exa-receive.py delete mode 100755 tests/topotests/bgp_multiview_topo1/peer3/exa-receive.py delete mode 100755 tests/topotests/bgp_multiview_topo1/peer4/exa-receive.py delete mode 100755 tests/topotests/bgp_multiview_topo1/peer5/exa-receive.py delete mode 100755 tests/topotests/bgp_multiview_topo1/peer6/exa-receive.py delete mode 100755 tests/topotests/bgp_multiview_topo1/peer7/exa-receive.py delete mode 100755 tests/topotests/bgp_multiview_topo1/peer8/exa-receive.py delete mode 100755 tests/topotests/bgp_peer_type_multipath_relax/peer1/exa-receive.py delete mode 100755 tests/topotests/bgp_peer_type_multipath_relax/peer2/exa-receive.py delete mode 100755 tests/topotests/bgp_peer_type_multipath_relax/peer3/exa-receive.py delete mode 100755 tests/topotests/bgp_peer_type_multipath_relax/peer4/exa-receive.py delete mode 100755 tests/topotests/bgp_prefix_sid/peer2/exa-receive.py delete mode 100755 tests/topotests/bgp_vrf_netns/peer1/exa-receive.py diff --git a/tests/topotests/bgp_ecmp_topo1/peer1/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer1/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer1/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer10/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer10/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer10/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer11/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer11/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer11/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer12/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer12/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer12/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer13/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer13/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer13/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer14/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer14/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer14/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer15/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer15/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer15/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer16/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer16/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer16/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer17/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer17/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer17/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer18/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer18/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer18/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer19/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer19/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer19/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer2/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer2/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer2/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer20/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer20/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer20/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer3/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer3/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer3/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer4/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer4/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer4/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer5/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer5/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer5/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer6/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer6/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer6/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer7/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer7/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer7/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer8/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer8/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer8/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_ecmp_topo1/peer9/exa-receive.py b/tests/topotests/bgp_ecmp_topo1/peer9/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_ecmp_topo1/peer9/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_multiview_topo1/peer1/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer1/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_multiview_topo1/peer1/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_multiview_topo1/peer2/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer2/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_multiview_topo1/peer2/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_multiview_topo1/peer3/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer3/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_multiview_topo1/peer3/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_multiview_topo1/peer4/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer4/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_multiview_topo1/peer4/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_multiview_topo1/peer5/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer5/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_multiview_topo1/peer5/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_multiview_topo1/peer6/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer6/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_multiview_topo1/peer6/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_multiview_topo1/peer7/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer7/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_multiview_topo1/peer7/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_multiview_topo1/peer8/exa-receive.py b/tests/topotests/bgp_multiview_topo1/peer8/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_multiview_topo1/peer8/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_peer_type_multipath_relax/peer1/exa-receive.py b/tests/topotests/bgp_peer_type_multipath_relax/peer1/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_peer_type_multipath_relax/peer1/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_peer_type_multipath_relax/peer2/exa-receive.py b/tests/topotests/bgp_peer_type_multipath_relax/peer2/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_peer_type_multipath_relax/peer2/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_peer_type_multipath_relax/peer3/exa-receive.py b/tests/topotests/bgp_peer_type_multipath_relax/peer3/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_peer_type_multipath_relax/peer3/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_peer_type_multipath_relax/peer4/exa-receive.py b/tests/topotests/bgp_peer_type_multipath_relax/peer4/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_peer_type_multipath_relax/peer4/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_prefix_sid/peer2/exa-receive.py b/tests/topotests/bgp_prefix_sid/peer2/exa-receive.py deleted file mode 100755 index f1ec9fa5ba..0000000000 --- a/tests/topotests/bgp_prefix_sid/peer2/exa-receive.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - routesavefile.write(line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() diff --git a/tests/topotests/bgp_prefix_sid/peer2/exabgp.cfg b/tests/topotests/bgp_prefix_sid/peer2/exabgp.cfg index dabd88e03d..379d0a3f43 100644 --- a/tests/topotests/bgp_prefix_sid/peer2/exabgp.cfg +++ b/tests/topotests/bgp_prefix_sid/peer2/exabgp.cfg @@ -1,7 +1,7 @@ group controller { process receive-routes { - run "/etc/exabgp/exa-receive.py 2"; + run "/etc/exabgp/exa-receive.py --no-timestamp 2"; receive-routes; encoder json; } diff --git a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py index 8acf7feae1..49a4049c00 100644 --- a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py +++ b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py @@ -120,7 +120,7 @@ def test_r1_receive_and_advertise_prefix_sid_type1(): def exabgp_get_update_prefix(filename, afi, nexthop, prefix): - with open("/tmp/peer2-received.log") as f: + with open(filename) as f: for line in f.readlines(): output = json.loads(line) ret = output.get("neighbor") @@ -151,10 +151,11 @@ def exabgp_get_update_prefix(filename, afi, nexthop, prefix): def test_peer2_receive_prefix_sid_type1(): tgen = get_topogen() peer2 = tgen.gears["peer2"] + logfile = "{}/{}-received.log".format(peer2.gearlogdir, peer2.name) def _check_type1_peer2(prefix, labelindex): output = exabgp_get_update_prefix( - "/tmp/peer2-received.log", "ipv4 nlri-mpls", "10.0.0.101", prefix + logfile, "ipv4 nlri-mpls", "10.0.0.101", prefix ) expected = { "type": "update", diff --git a/tests/topotests/bgp_vrf_netns/peer1/exa-receive.py b/tests/topotests/bgp_vrf_netns/peer1/exa-receive.py deleted file mode 100755 index 031ff455ca..0000000000 --- a/tests/topotests/bgp_vrf_netns/peer1/exa-receive.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -""" -exa-receive.py: Save received routes form ExaBGP into file -""" - -from sys import stdin, argv -from datetime import datetime - -# 1st arg is peer number -peer = int(argv[1]) - -# When the parent dies we are seeing continual newlines, so we only access so many before stopping -counter = 0 - -routesavefile = open("/tmp/peer%s-received.log" % peer, "w") - -while True: - try: - line = stdin.readline() - timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") - routesavefile.write(timestamp + line) - routesavefile.flush() - - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass - -routesavefile.close() From 57f774f56d25f2906dc4072488572fe274ed3910 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Thu, 2 Sep 2021 16:05:09 -0400 Subject: [PATCH 23/25] tests: Disable test which fails under micronet Signed-off-by: Christian Hopps --- .../test_bgp_evpn_overlay_index_gateway.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py b/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py index beb033c716..802d29dbaf 100755 --- a/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py +++ b/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py @@ -265,6 +265,9 @@ def test_evpn_gateway_ip_basic_topo(request): tc_name = request.node.name write_test_header(tc_name) + # Temporarily Disabled + tgen.set_error("%s: Failing under new micronet framework, please debug and re-enable", tc_name) + kernelv = platform.release() if topotest.version_cmp(kernelv, "4.15") < 0: logger.info("For EVPN, kernel version should be minimum 4.15") From 4953ca977f3a5de8109ee6353ad07f816ca1774c Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Fri, 3 Sep 2021 08:43:32 -0400 Subject: [PATCH 24/25] tests: cleanup - remove unused imports Signed-off-by: Christian Hopps --- .../test_all_protocol_startup.py | 1 - tests/topotests/analyze.py | 2 -- .../test_bfd_bgp_cbit_topo3.py | 1 - .../bfd_isis_topo1/test_bfd_isis_topo1.py | 2 -- .../bfd_ospf_topo1/test_bfd_ospf_topo1.py | 3 --- tests/topotests/bfd_topo3/test_bfd_topo3.py | 1 - .../bfd_vrf_topo1/test_bfd_vrf_topo1.py | 1 - .../test_bgp_aggregate-address_origin.py | 3 --- .../test_bgp_aggregate-address_route-map.py | 3 --- .../test_bgp_aggregate_address_topo1.py | 3 --- .../test_bgp_aggregator_zero.py | 3 --- .../bgp_as_allow_in/test_bgp_as_allow_in.py | 2 -- .../test_bgp_as_wide_bgp_identifier.py | 3 --- .../bgp_aspath_zero/test_bgp_aspath_zero.py | 3 --- tests/topotests/bgp_auth/test_bgp_auth.py | 5 ----- .../test_bgp_basic_functionality.py | 4 +--- .../test_bgp_blackhole_community.py | 2 -- .../test_bgp_comm-list_delete.py | 4 ---- .../test_bgp_communities.py | 5 +---- .../test_bgp_communities_topo2.py | 7 +------ .../test_bgp-community-alias.py | 3 --- .../test_bgp_community_change_update.py | 2 -- .../test_bgp_conditional_advertisement.py | 1 - .../test_bgp-default-afi-safi.py | 4 ---- .../test_bgp_default-originate.py | 3 --- ...st_bgp_default-originate_route-map_match.py | 3 --- ...t_bgp_default-originate_route-map_match2.py | 3 --- ...gp_default-originate_route-map_match_set.py | 3 --- ...test_bgp_default-originate_route-map_set.py | 3 --- .../test_bgp_distance_change.py | 3 --- .../test_bgp_dont_capability_negotiate.py | 2 -- ...bgp-ebgp-common-subnet-nexthop-unchanged.py | 3 --- .../test_bgp_ebgp_requires_policy.py | 2 -- .../bgp_ecmp_topo1/test_bgp_ecmp_topo1.py | 1 - .../bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py | 4 +--- .../bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py | 4 +--- .../bgp_ecmp_topo3/test_ibgp_ecmp_topo3.py | 9 ++------- tests/topotests/bgp_evpn_mh/test_evpn_mh.py | 3 --- .../test_bgp_evpn_overlay_index_gateway.py | 1 - tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py | 3 --- .../test_bgp_evpn_vxlan.py | 2 -- .../bgp_features/test_bgp_features.py | 1 - .../bgp_flowspec/test_bgp_flowspec_topo.py | 4 ---- .../test_bgp_gr_functionality_topo1.py | 10 ++-------- .../test_bgp_gr_functionality_topo2.py | 10 ++-------- tests/topotests/bgp_gshut/test_bgp_gshut.py | 3 --- .../bgp_gshut_topo1/test_ebgp_gshut_topo1.py | 9 +-------- .../bgp_gshut_topo1/test_ibgp_gshut_topo1.py | 13 +------------ .../test_rfc5549_ebgp_ibgp_nbr.py | 9 +-------- .../test_rfc5549_ebgp_nbr.py | 15 +-------------- .../test_rfc5549_ebgp_unnumbered_nbr.py | 11 ++--------- .../test_rfc5549_ibgp_nbr.py | 8 +------- .../test_rfc5549_ibgp_unnumbered_nbr.py | 8 ++------ .../bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py | 1 - .../bgp_l3vpn_to_bgp_direct/customize.py | 7 +------ .../bgp_l3vpn_to_bgp_vrf/customize.py | 6 +----- .../test_bgp_large_community_topo_1.py | 4 +--- .../test_bgp_large_community_topo_2.py | 5 +---- .../bgp_link_bw_ip/test_bgp_linkbw_ip.py | 2 -- .../test_bgp_listen_on_multiple_addresses.py | 4 +--- .../test_bgp_local_as_private_remove.py | 3 --- tests/topotests/bgp_lu_topo1/test_bgp_lu.py | 3 --- .../test_bgp_maximum_prefix_invalid_update.py | 4 ---- .../test_bgp_maximum_prefix_out.py | 3 --- .../test_bgp_minimum_holdtime.py | 3 --- .../test_bgp_multi_vrf_topo1.py | 6 +----- .../test_bgp_multi_vrf_topo2.py | 4 +--- .../test_bgp_multiview_topo1.py | 2 -- .../test_bgp_path_attributes.py | 14 ++------------ .../bgp_peer_group/test_bgp_peer-group.py | 2 -- .../test_bgp_peer-type_multipath-relax.py | 1 - .../bgp_prefix_list_topo1/test_prefix_lists.py | 4 +--- .../bgp_prefix_sid/test_bgp_prefix_sid.py | 1 - .../bgp_prefix_sid2/test_bgp_prefix_sid2.py | 1 - .../test_bgp_recursive_route_ebgp_multi_hop.py | 9 +-------- .../test_bgp_reject_as_sets.py | 3 --- .../bgp_rfapi_basic_sanity/customize.py | 7 +------ .../test_bgp_rmap_extcommunity_none.py | 2 -- .../test_bgp_aggregation.py | 9 +-------- .../bgp_route_map/test_route_map_topo1.py | 16 +--------------- .../bgp_route_map/test_route_map_topo2.py | 6 +----- .../bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py | 2 -- .../test_bgp_sender-as-path-loop-detection.py | 3 --- ...st_bgp_set_local-preference_add_subtract.py | 3 --- .../test_bgp_snmp_mplsvpn.py | 6 ------ .../test_bgp_srv6l3vpn_to_bgp_vrf.py | 2 -- .../bgp_suppress_fib/test_bgp_suppress_fib.py | 3 --- .../topotests/bgp_tcp_mss/test_bgp_tcp_mss.py | 2 -- .../bgp_update_delay/test_bgp_update_delay.py | 3 --- .../test_bgp_vrf_dynamic_route_leak_topo1.py | 9 +-------- .../test_bgp_vrf_dynamic_route_leak_topo2.py | 5 ----- .../test_bgp_vrf_lite_ipv6_rtadv.py | 2 -- .../bgp_vrf_netns/test_bgp_vrf_netns_topo.py | 1 - .../test_bgp-vrf-route-leak-basic.py | 2 -- .../config_timing/test_config_timing.py | 1 - .../topotests/eigrp_topo1/test_eigrp_topo1.py | 1 - .../evpn_pim_1/test_evpn_pim_topo1.py | 2 -- .../test_evpn_type5_chaos_topo1.py | 13 +------------ .../test_evpn_type5_topo1.py | 9 --------- tests/topotests/example_test/test_template.py | 2 -- .../test_example_topojson_multiple_links.py | 2 -- .../test_example_topojson.py | 1 - .../test_example_topojson.py | 2 -- .../isis_lfa_topo1/test_isis_lfa_topo1.py | 3 --- .../test_isis_lsp_bits_topo1.py | 4 ---- .../isis_rlfa_topo1/test_isis_rlfa_topo1.py | 3 --- tests/topotests/isis_snmp/test_isis_snmp.py | 3 --- .../isis_sr_te_topo1/test_isis_sr_te_topo1.py | 3 --- .../isis_sr_topo1/test_isis_sr_topo1.py | 2 -- .../isis_tilfa_topo1/test_isis_tilfa_topo1.py | 3 --- tests/topotests/isis_topo1/test_isis_topo1.py | 2 -- .../isis_topo1_vrf/test_isis_topo1_vrf.py | 2 -- .../ldp_oc_acl_topo1/test_ldp_oc_acl_topo1.py | 1 - .../ldp_oc_topo1/test_ldp_oc_topo1.py | 2 -- .../topotests/ldp_snmp/test_ldp_snmp_topo1.py | 3 --- .../test_ldp_sync_isis_topo1.py | 2 -- .../test_ldp_sync_ospf_topo1.py | 2 -- tests/topotests/ldp_topo1/test_ldp_topo1.py | 1 - .../ldp_vpls_topo1/test_ldp_vpls_topo1.py | 2 -- tests/topotests/lib/bgp.py | 6 +----- tests/topotests/lib/common_config.py | 5 ----- tests/topotests/lib/ltemplate.py | 1 - tests/topotests/lib/lutil.py | 1 - tests/topotests/lib/micronet.py | 2 -- tests/topotests/lib/micronet_cli.py | 5 ----- tests/topotests/lib/micronet_compat.py | 4 ---- tests/topotests/lib/ospf.py | 5 ----- tests/topotests/lib/pim.py | 5 +---- tests/topotests/lib/topolog.py | 4 ++-- .../msdp_mesh_topo1/test_msdp_mesh_topo1.py | 3 --- tests/topotests/msdp_topo1/test_msdp_topo1.py | 3 --- .../test_mcast_pim_bsmp_01.py | 4 +--- .../test_mcast_pim_bsmp_02.py | 15 +-------------- .../test_multicast_pim_sm_topo1.py | 12 +----------- .../test_multicast_pim_sm_topo2.py | 9 +-------- .../test_multicast_pim_sm_topo3.py | 14 +------------- .../test_multicast_pim_sm_topo4.py | 17 +---------------- .../test_multicast_pim_static_rp.py | 3 --- tests/topotests/nhrp_topo/test_nhrp_topo.py | 1 - .../topotests/ospf6_topo1/test_ospf6_topo1.py | 3 --- .../ospf6_topo1_vrf/test_ospf6_topo1_vrf.py | 3 --- .../topotests/ospf6_topo2/test_ospf6_topo2.py | 1 - .../test_ospf_asbr_summary_topo1.py | 4 +--- .../test_ospf_asbr_summary_type7_lsa.py | 15 +-------------- .../test_ospf_authentication.py | 4 +--- .../test_ospf_chaos.py | 7 +------ .../ospf_basic_functionality/test_ospf_ecmp.py | 11 +---------- .../test_ospf_ecmp_lan.py | 15 +-------------- .../ospf_basic_functionality/test_ospf_lan.py | 12 +----------- .../ospf_basic_functionality/test_ospf_nssa.py | 11 +---------- .../ospf_basic_functionality/test_ospf_p2mp.py | 15 +-------------- .../test_ospf_routemaps.py | 11 ++--------- .../test_ospf_rte_calc.py | 5 +---- .../test_ospf_single_area.py | 10 +--------- .../ospf_dual_stack/test_ospf_dual_stack.py | 18 +----------------- .../ospf_gr_helper/test_ospf_gr_helper.py | 12 +----------- .../ospf_gr_topo1/test_ospf_gr_topo1.py | 3 --- .../ospf_sr_te_topo1/test_ospf_sr_te_topo1.py | 2 -- .../ospf_sr_topo1/test_ospf_sr_topo1.py | 3 --- .../ospf_suppress_fa/test_ospf_suppress_fa.py | 1 - .../ospf_te_topo1/test_ospf_te_topo1.py | 1 - .../ospf_tilfa_topo1/test_ospf_tilfa_topo1.py | 3 --- tests/topotests/ospf_topo1/test_ospf_topo1.py | 1 - .../ospf_topo1_vrf/test_ospf_topo1_vrf.py | 2 -- tests/topotests/ospf_topo2/test_ospf_topo2.py | 2 -- .../test_ospfv3_asbr_summary_topo1.py | 7 +------ .../test_ospfv3_ecmp.py | 14 +------------- .../test_ospfv3_routemaps.py | 14 +------------- .../test_ospfv3_rte_calc.py | 14 +------------- .../test_ospfv3_single_area.py | 15 +-------------- tests/topotests/pbr_topo1/test_pbr_topo1.py | 2 -- tests/topotests/pim_acl/test_pim_acl.py | 4 ---- tests/topotests/pim_basic/test_pim.py | 1 - .../pim_basic_topo2/test_pim_basic_topo2.py | 2 -- tests/topotests/pim_igmp_vrf/test_pim_vrf.py | 4 ---- tests/topotests/rip_topo1/test_rip_topo1.py | 1 - .../topotests/ripng_topo1/test_ripng_topo1.py | 2 -- .../topotests/route_scale/test_route_scale.py | 1 - .../simple_snmp_test/test_simple_snmp.py | 5 ----- .../srv6_locator/test_srv6_locator.py | 1 - .../test_static_routes_topo1_ebgp.py | 5 +---- .../test_static_routes_topo2_ebgp.py | 4 +--- .../test_static_routes_topo3_ebgp.py | 5 +---- .../test_static_routes_topo4_ebgp.py | 5 +---- .../test_static_routes_topo1_ibgp.py | 6 +----- .../test_static_routes_topo2_ibgp.py | 6 +----- .../test_static_routes_topo3_ibgp.py | 7 +------ .../test_static_routes_topo4_ibgp.py | 5 +---- .../zebra_netlink/test_zebra_netlink.py | 3 --- .../zebra_opaque/test_zebra_opaque.py | 2 -- .../zebra_seg6_route/test_zebra_seg6_route.py | 3 --- .../test_zebra_seg6local_route.py | 3 --- tools/frr-reload.py | 1 - 193 files changed, 75 insertions(+), 828 deletions(-) diff --git a/tests/topotests/all_protocol_startup/test_all_protocol_startup.py b/tests/topotests/all_protocol_startup/test_all_protocol_startup.py index 52526e0c73..d272aab78c 100644 --- a/tests/topotests/all_protocol_startup/test_all_protocol_startup.py +++ b/tests/topotests/all_protocol_startup/test_all_protocol_startup.py @@ -34,7 +34,6 @@ import pytest import glob from time import sleep -from functools import partial pytestmark = [ pytest.mark.babeld, diff --git a/tests/topotests/analyze.py b/tests/topotests/analyze.py index aea5fae00e..09aa22f03c 100755 --- a/tests/topotests/analyze.py +++ b/tests/topotests/analyze.py @@ -21,10 +21,8 @@ # import argparse import glob -import json import logging import os -import pdb import re import subprocess import sys diff --git a/tests/topotests/bfd_bgp_cbit_topo3/test_bfd_bgp_cbit_topo3.py b/tests/topotests/bfd_bgp_cbit_topo3/test_bfd_bgp_cbit_topo3.py index 29c25bba29..92432669c8 100644 --- a/tests/topotests/bfd_bgp_cbit_topo3/test_bfd_bgp_cbit_topo3.py +++ b/tests/topotests/bfd_bgp_cbit_topo3/test_bfd_bgp_cbit_topo3.py @@ -46,7 +46,6 @@ pytestmark = [pytest.mark.bgpd, pytest.mark.bfdd] def setup_module(mod): "Sets up the pytest environment" - from collections import OrderedDict topodef = { "s1": ("r1", "r2"), "s2": ("r2", "r3"), diff --git a/tests/topotests/bfd_isis_topo1/test_bfd_isis_topo1.py b/tests/topotests/bfd_isis_topo1/test_bfd_isis_topo1.py index 6a19b1ea46..4c44ca4400 100644 --- a/tests/topotests/bfd_isis_topo1/test_bfd_isis_topo1.py +++ b/tests/topotests/bfd_isis_topo1/test_bfd_isis_topo1.py @@ -72,9 +72,7 @@ import os import sys import pytest import json -import re from time import sleep -from time import time from functools import partial # Save the Current Working Directory to find configuration files. diff --git a/tests/topotests/bfd_ospf_topo1/test_bfd_ospf_topo1.py b/tests/topotests/bfd_ospf_topo1/test_bfd_ospf_topo1.py index c82b4b590a..09b8631740 100755 --- a/tests/topotests/bfd_ospf_topo1/test_bfd_ospf_topo1.py +++ b/tests/topotests/bfd_ospf_topo1/test_bfd_ospf_topo1.py @@ -72,9 +72,7 @@ import os import sys import pytest import json -import re from time import sleep -from time import time from functools import partial # Save the Current Working Directory to find configuration files. @@ -84,7 +82,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib import topotest -from lib.micronet_compat import Topo from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger diff --git a/tests/topotests/bfd_topo3/test_bfd_topo3.py b/tests/topotests/bfd_topo3/test_bfd_topo3.py index 9ed8f5fcbf..978593e41a 100644 --- a/tests/topotests/bfd_topo3/test_bfd_topo3.py +++ b/tests/topotests/bfd_topo3/test_bfd_topo3.py @@ -39,7 +39,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib import topotest -from lib.micronet_compat import Topo from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger diff --git a/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py b/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py index 06b20c4430..acb86ea7f2 100644 --- a/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py +++ b/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py @@ -44,7 +44,6 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bfdd, pytest.mark.bgpd] diff --git a/tests/topotests/bgp_aggregate_address_origin/test_bgp_aggregate-address_origin.py b/tests/topotests/bgp_aggregate_address_origin/test_bgp_aggregate-address_origin.py index 517154987e..0d01fa2ade 100644 --- a/tests/topotests/bgp_aggregate_address_origin/test_bgp_aggregate-address_origin.py +++ b/tests/topotests/bgp_aggregate_address_origin/test_bgp_aggregate-address_origin.py @@ -34,7 +34,6 @@ router bgp 65031 import os import sys import json -import time import pytest import functools @@ -44,8 +43,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_aggregate_address_route_map/test_bgp_aggregate-address_route-map.py b/tests/topotests/bgp_aggregate_address_route_map/test_bgp_aggregate-address_route-map.py index 74c9e83ce0..df20594566 100644 --- a/tests/topotests/bgp_aggregate_address_route_map/test_bgp_aggregate-address_route-map.py +++ b/tests/topotests/bgp_aggregate_address_route_map/test_bgp_aggregate-address_route-map.py @@ -37,7 +37,6 @@ route-map aggr-rmap permit 10 import os import sys import json -import time import pytest import functools @@ -47,8 +46,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_aggregate_address_topo1/test_bgp_aggregate_address_topo1.py b/tests/topotests/bgp_aggregate_address_topo1/test_bgp_aggregate_address_topo1.py index 4e82a61e11..d724b586d9 100644 --- a/tests/topotests/bgp_aggregate_address_topo1/test_bgp_aggregate_address_topo1.py +++ b/tests/topotests/bgp_aggregate_address_topo1/test_bgp_aggregate_address_topo1.py @@ -28,8 +28,6 @@ Test BGP aggregate address features. import os import sys -import json -import time import pytest import functools @@ -40,7 +38,6 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_aggregator_zero/test_bgp_aggregator_zero.py b/tests/topotests/bgp_aggregator_zero/test_bgp_aggregator_zero.py index 76eafbce4e..6836dc11ac 100644 --- a/tests/topotests/bgp_aggregator_zero/test_bgp_aggregator_zero.py +++ b/tests/topotests/bgp_aggregator_zero/test_bgp_aggregator_zero.py @@ -27,7 +27,6 @@ is continued to be processed, but AGGREGATOR attribute is discarded. import os import sys import json -import time import pytest import functools @@ -37,8 +36,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py b/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py index 5613b75d7a..9b789f4eac 100644 --- a/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py +++ b/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py @@ -51,7 +51,6 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration @@ -71,7 +70,6 @@ from lib.topolog import logger from lib.bgp import ( verify_bgp_convergence, create_router_bgp, - clear_bgp_and_verify, verify_bgp_rib, ) from lib.topojson import build_topo_from_json, build_config_from_json diff --git a/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py b/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py index 2f7a9cc587..571e28cf7b 100644 --- a/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py +++ b/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py @@ -32,7 +32,6 @@ affected and should work. import os import sys import json -import time import pytest import functools @@ -42,8 +41,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_aspath_zero/test_bgp_aspath_zero.py b/tests/topotests/bgp_aspath_zero/test_bgp_aspath_zero.py index 875ff38d83..63c890f138 100644 --- a/tests/topotests/bgp_aspath_zero/test_bgp_aspath_zero.py +++ b/tests/topotests/bgp_aspath_zero/test_bgp_aspath_zero.py @@ -27,7 +27,6 @@ is threated as withdrawal. import os import sys import json -import time import pytest import functools @@ -37,8 +36,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_auth/test_bgp_auth.py b/tests/topotests/bgp_auth/test_bgp_auth.py index 48ba0cca58..3e5b80f83f 100644 --- a/tests/topotests/bgp_auth/test_bgp_auth.py +++ b/tests/topotests/bgp_auth/test_bgp_auth.py @@ -48,7 +48,6 @@ import os import sys import json import platform -from functools import partial import pytest from time import sleep @@ -60,12 +59,9 @@ sys.path.append(os.path.join(CWD, "../")) # Import topogen and topotest helpers from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo -from lib.common_config import apply_raw_config ERROR_LIST = ["Malformed", "Failure", "Unknown", "Incomplete"] @@ -74,7 +70,6 @@ pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd] class InvalidCLIError(Exception): """Raise when the CLI command is wrong""" - pass def build_topo(tgen): # Create routers diff --git a/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py b/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py index ee241b653a..3de3bcd4db 100644 --- a/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py +++ b/tests/topotests/bgp_basic_functionality_topo1/test_bgp_basic_functionality.py @@ -45,7 +45,6 @@ Test steps import os import sys -import json import time import pytest from copy import deepcopy @@ -69,11 +68,10 @@ from lib.common_config import (addKernelRoute, apply_raw_config, verify_bgp_community, verify_fib_routes, verify_rib, write_test_footer, write_test_header) -from lib.micronet_compat import Topo # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from lib.topojson import build_config_from_json, build_topo_from_json +from lib.topojson import build_config_from_json from lib.topolog import logger pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py b/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py index aaa65004f1..4f8fc0d67a 100644 --- a/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py +++ b/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py @@ -36,8 +36,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo from lib.common_config import step pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_comm_list_delete/test_bgp_comm-list_delete.py b/tests/topotests/bgp_comm_list_delete/test_bgp_comm-list_delete.py index 2524756168..4db4e37f7f 100644 --- a/tests/topotests/bgp_comm_list_delete/test_bgp_comm-list_delete.py +++ b/tests/topotests/bgp_comm_list_delete/test_bgp_comm-list_delete.py @@ -33,17 +33,13 @@ route-map test permit 10 import os import sys import json -import time import pytest CWD = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 -from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_communities_topo1/test_bgp_communities.py b/tests/topotests/bgp_communities_topo1/test_bgp_communities.py index be0d87d22e..123461caa9 100644 --- a/tests/topotests/bgp_communities_topo1/test_bgp_communities.py +++ b/tests/topotests/bgp_communities_topo1/test_bgp_communities.py @@ -29,7 +29,6 @@ Following tests are covered to test bgp community functionality: import os import sys import time -import json import pytest # Save the Current Working Directory to find configuration files. @@ -38,7 +37,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration @@ -60,10 +58,9 @@ from lib.topolog import logger from lib.bgp import ( verify_bgp_convergence, create_router_bgp, - clear_bgp_and_verify, verify_bgp_rib, ) -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json from copy import deepcopy pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py b/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py index 80bcae6312..947efa8f8a 100644 --- a/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py +++ b/tests/topotests/bgp_communities_topo1/test_bgp_communities_topo2.py @@ -31,7 +31,6 @@ Following tests are covered to test bgp community functionality: import os import sys import time -import json import pytest # Save the Current Working Directory to find configuration files. @@ -40,7 +39,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration @@ -54,7 +52,6 @@ from lib.common_config import ( check_address_types, step, create_route_maps, - create_prefix_lists, create_route_maps, required_linux_kernel_version, ) @@ -63,12 +60,10 @@ from lib.topolog import logger from lib.bgp import ( verify_bgp_convergence, create_router_bgp, - clear_bgp_and_verify, verify_bgp_rib, verify_bgp_community, ) -from lib.topojson import build_topo_from_json, build_config_from_json -from copy import deepcopy +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_community_alias/test_bgp-community-alias.py b/tests/topotests/bgp_community_alias/test_bgp-community-alias.py index cc81660298..b95bf74876 100644 --- a/tests/topotests/bgp_community_alias/test_bgp-community-alias.py +++ b/tests/topotests/bgp_community_alias/test_bgp-community-alias.py @@ -25,7 +25,6 @@ Test if BGP community alias is visible in CLI outputs import os import sys import json -import time import pytest import functools @@ -37,8 +36,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_community_change_update/test_bgp_community_change_update.py b/tests/topotests/bgp_community_change_update/test_bgp_community_change_update.py index 472a0b9557..138512bc62 100644 --- a/tests/topotests/bgp_community_change_update/test_bgp_community_change_update.py +++ b/tests/topotests/bgp_community_change_update/test_bgp_community_change_update.py @@ -53,8 +53,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo from lib.common_config import step from time import sleep diff --git a/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py b/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py index 02fcd5445a..e9b393ba7f 100644 --- a/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py +++ b/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py @@ -137,7 +137,6 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_default_afi_safi/test_bgp-default-afi-safi.py b/tests/topotests/bgp_default_afi_safi/test_bgp-default-afi-safi.py index 4bcf2ebb46..3f4be3da4e 100644 --- a/tests/topotests/bgp_default_afi_safi/test_bgp-default-afi-safi.py +++ b/tests/topotests/bgp_default_afi_safi/test_bgp-default-afi-safi.py @@ -33,7 +33,6 @@ import os import sys import json import pytest -import functools pytestmark = [pytest.mark.bgpd] @@ -41,10 +40,7 @@ CWD = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 -from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo from lib.common_config import step pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_default_route/test_bgp_default-originate.py b/tests/topotests/bgp_default_route/test_bgp_default-originate.py index 9da8d0a491..b2d530b423 100644 --- a/tests/topotests/bgp_default_route/test_bgp_default-originate.py +++ b/tests/topotests/bgp_default_route/test_bgp_default-originate.py @@ -25,7 +25,6 @@ Test if default-originate works without route-map. import os import sys import json -import time import pytest import functools @@ -35,8 +34,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_default_route_route_map_match/test_bgp_default-originate_route-map_match.py b/tests/topotests/bgp_default_route_route_map_match/test_bgp_default-originate_route-map_match.py index e6298dd782..11eaa7b373 100644 --- a/tests/topotests/bgp_default_route_route_map_match/test_bgp_default-originate_route-map_match.py +++ b/tests/topotests/bgp_default_route_route_map_match/test_bgp_default-originate_route-map_match.py @@ -25,7 +25,6 @@ Test if default-originate works with ONLY match operations. import os import sys import json -import time import pytest import functools @@ -35,8 +34,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_default_route_route_map_match2/test_bgp_default-originate_route-map_match2.py b/tests/topotests/bgp_default_route_route_map_match2/test_bgp_default-originate_route-map_match2.py index 8f23cf25b5..99528f675e 100644 --- a/tests/topotests/bgp_default_route_route_map_match2/test_bgp_default-originate_route-map_match2.py +++ b/tests/topotests/bgp_default_route_route_map_match2/test_bgp_default-originate_route-map_match2.py @@ -27,7 +27,6 @@ to r2. import os import sys import json -import time import pytest import functools @@ -37,8 +36,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo from lib.common_config import step pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py b/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py index 728819525a..27451ec7b3 100644 --- a/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py +++ b/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py @@ -26,7 +26,6 @@ And verify if set operations work as well. import os import sys import json -import time import pytest import functools @@ -36,8 +35,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py b/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py index 4be98c08f6..cc2243a1c4 100644 --- a/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py +++ b/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py @@ -25,7 +25,6 @@ Test if default-originate works with ONLY set operations. import os import sys import json -import time import pytest import functools @@ -35,8 +34,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_distance_change/test_bgp_distance_change.py b/tests/topotests/bgp_distance_change/test_bgp_distance_change.py index 9af237986f..a7040dbe8c 100644 --- a/tests/topotests/bgp_distance_change/test_bgp_distance_change.py +++ b/tests/topotests/bgp_distance_change/test_bgp_distance_change.py @@ -36,7 +36,6 @@ Changed distance should reflect to RIB after changes. import os import sys import json -import time import pytest import functools @@ -46,8 +45,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_dont_capability_negogiate/test_bgp_dont_capability_negotiate.py b/tests/topotests/bgp_dont_capability_negogiate/test_bgp_dont_capability_negotiate.py index 6025ad935c..f8099492db 100644 --- a/tests/topotests/bgp_dont_capability_negogiate/test_bgp_dont_capability_negotiate.py +++ b/tests/topotests/bgp_dont_capability_negogiate/test_bgp_dont_capability_negotiate.py @@ -26,7 +26,6 @@ sets `dont-capability-negotiate`. import os import sys import json -import time import pytest import functools @@ -38,7 +37,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_ebgp_common_subnet_nexthop_unchanged/test_bgp-ebgp-common-subnet-nexthop-unchanged.py b/tests/topotests/bgp_ebgp_common_subnet_nexthop_unchanged/test_bgp-ebgp-common-subnet-nexthop-unchanged.py index c0886de856..2e6c3c48ab 100644 --- a/tests/topotests/bgp_ebgp_common_subnet_nexthop_unchanged/test_bgp-ebgp-common-subnet-nexthop-unchanged.py +++ b/tests/topotests/bgp_ebgp_common_subnet_nexthop_unchanged/test_bgp-ebgp-common-subnet-nexthop-unchanged.py @@ -36,7 +36,6 @@ common subnet with this address. import os import sys import json -import time import pytest import functools @@ -48,8 +47,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py b/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py index 4f33e81248..4a6eaf81a7 100644 --- a/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py +++ b/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py @@ -44,7 +44,6 @@ Scenario 3: import os import sys import json -import time import pytest import functools @@ -55,7 +54,6 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py b/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py index 66714fd2f3..7b9ef0a505 100644 --- a/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py +++ b/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py @@ -43,7 +43,6 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py b/tests/topotests/bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py index a82ed8ec8c..3c0706ed88 100644 --- a/tests/topotests/bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py +++ b/tests/topotests/bgp_ecmp_topo2/test_ebgp_ecmp_topo2.py @@ -39,7 +39,6 @@ Following tests are covered to test ecmp functionality on EBGP. import os import sys import time -import json import pytest # Save the Current Working Directory to find configuration files. @@ -50,7 +49,6 @@ sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from lib.micronet_compat import Topo from lib.common_config import ( start_topology, @@ -65,7 +63,7 @@ from lib.common_config import ( ) from lib.topolog import logger from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py b/tests/topotests/bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py index 561ba0edf7..cf1b0cfa0e 100644 --- a/tests/topotests/bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py +++ b/tests/topotests/bgp_ecmp_topo2/test_ibgp_ecmp_topo2.py @@ -39,7 +39,6 @@ Following tests are covered to test ecmp functionality on EBGP. import os import sys import time -import json import pytest # Save the Current Working Directory to find configuration files. @@ -50,7 +49,6 @@ sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from lib.micronet_compat import Topo from lib.common_config import ( start_topology, @@ -65,7 +63,7 @@ from lib.common_config import ( ) from lib.topolog import logger from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_ecmp_topo3/test_ibgp_ecmp_topo3.py b/tests/topotests/bgp_ecmp_topo3/test_ibgp_ecmp_topo3.py index 66ebe5b58e..e57dffee36 100644 --- a/tests/topotests/bgp_ecmp_topo3/test_ibgp_ecmp_topo3.py +++ b/tests/topotests/bgp_ecmp_topo3/test_ibgp_ecmp_topo3.py @@ -28,7 +28,6 @@ Following tests are covered to test ecmp functionality on iBGP. import os import sys import time -import json import pytest from time import sleep @@ -39,25 +38,21 @@ sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from lib.topogen import Topogen, get_topogen +from lib.topogen import get_topogen from lib import topojson from lib.common_config import ( - start_topology, write_test_header, write_test_footer, verify_rib, create_static_routes, check_address_types, - interface_status, reset_config_on_routers, - required_linux_kernel_version, shutdown_bringup_interface, apply_raw_config, ) from lib.topolog import logger -from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.bgp import create_router_bgp, verify_bgp_convergence pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_evpn_mh/test_evpn_mh.py b/tests/topotests/bgp_evpn_mh/test_evpn_mh.py index bad4da116a..c9f6d1dc9d 100644 --- a/tests/topotests/bgp_evpn_mh/test_evpn_mh.py +++ b/tests/topotests/bgp_evpn_mh/test_evpn_mh.py @@ -28,7 +28,6 @@ test_evpn_mh.py: Testing EVPN multihoming """ import os -import re import sys import subprocess from functools import partial @@ -48,9 +47,7 @@ sys.path.append(os.path.join(CWD, "../")) # Import topogen and topotest helpers from lib import topotest # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger pytestmark = [pytest.mark.bgpd, pytest.mark.pimd] diff --git a/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py b/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py index 802d29dbaf..91e76fd265 100755 --- a/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py +++ b/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py @@ -75,7 +75,6 @@ from lib.common_config import ( ) # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py b/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py index 98411938c4..52a6d0c9f3 100644 --- a/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py +++ b/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py @@ -28,8 +28,6 @@ import os import sys -import json -from functools import partial import pytest import platform @@ -44,7 +42,6 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py b/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py index d300561e1f..c713fb926e 100755 --- a/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py +++ b/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py @@ -28,7 +28,6 @@ test_bgp_evpn_vxlan.py: Test VXLAN EVPN MAC a route signalling over BGP. import os import sys import json -import re from functools import partial from time import sleep import pytest @@ -44,7 +43,6 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd] diff --git a/tests/topotests/bgp_features/test_bgp_features.py b/tests/topotests/bgp_features/test_bgp_features.py index f2e09fb010..00f5d1fcb1 100644 --- a/tests/topotests/bgp_features/test_bgp_features.py +++ b/tests/topotests/bgp_features/test_bgp_features.py @@ -45,7 +45,6 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd] diff --git a/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py b/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py index 05ea944ebf..682ff4ceec 100644 --- a/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py +++ b/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py @@ -54,7 +54,6 @@ import functools import os import sys import pytest -import getopt # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -65,11 +64,8 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from lib.lutil import lUtil -from lib.lutil import luCommand # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py b/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py index 4ee3b97080..56f6e1a3be 100644 --- a/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py +++ b/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py @@ -89,9 +89,7 @@ Basic Common Test steps for all the test case below : import os import sys -import json import time -import inspect import pytest # Save the Current Working Directory to find configuration files. @@ -101,15 +99,13 @@ sys.path.append(os.path.join("../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from lib import topotest -from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topogen import Topogen, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo # Import topoJson from lib, to create topology and initial configuration -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json from lib.bgp import ( clear_bgp, verify_bgp_rib, @@ -117,7 +113,6 @@ from lib.bgp import ( create_router_bgp, verify_r_bit, verify_f_bit, - verify_graceful_restart_timers, verify_bgp_convergence, verify_bgp_convergence_from_running_config, ) @@ -135,7 +130,6 @@ from lib.common_config import ( shutdown_bringup_interface, step, get_frr_ipv6_linklocal, - create_route_maps, required_linux_kernel_version, ) diff --git a/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py b/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py index 5fc361f8fe..bf5aea1dad 100644 --- a/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py +++ b/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py @@ -84,11 +84,9 @@ TC_30: import os import sys -import json import time import pytest from time import sleep -from copy import deepcopy # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -97,15 +95,13 @@ sys.path.append(os.path.join("../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers -from lib import topotest -from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topogen import Topogen, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo # Import topoJson from lib, to create topology and initial configuration -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json from lib.bgp import ( clear_bgp, verify_bgp_rib, @@ -131,10 +127,8 @@ from lib.common_config import ( check_address_types, write_test_footer, check_router_status, - shutdown_bringup_interface, step, get_frr_ipv6_linklocal, - create_route_maps, required_linux_kernel_version, ) diff --git a/tests/topotests/bgp_gshut/test_bgp_gshut.py b/tests/topotests/bgp_gshut/test_bgp_gshut.py index a08f74d6c4..764252d962 100644 --- a/tests/topotests/bgp_gshut/test_bgp_gshut.py +++ b/tests/topotests/bgp_gshut/test_bgp_gshut.py @@ -60,9 +60,7 @@ import os import re import sys import json -import time import pytest -import functools import platform from functools import partial @@ -73,7 +71,6 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_gshut_topo1/test_ebgp_gshut_topo1.py b/tests/topotests/bgp_gshut_topo1/test_ebgp_gshut_topo1.py index 2bddd9c77f..7a19939a5c 100644 --- a/tests/topotests/bgp_gshut_topo1/test_ebgp_gshut_topo1.py +++ b/tests/topotests/bgp_gshut_topo1/test_ebgp_gshut_topo1.py @@ -31,7 +31,6 @@ Following tests are covered to test ecmp functionality on BGP GSHUT. import os import sys import time -import json import pytest # Save the Current Working Directory to find configuration files. @@ -42,17 +41,13 @@ sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from lib.micronet_compat import Topo -from time import sleep from lib.common_config import ( start_topology, write_test_header, write_test_footer, verify_rib, - create_static_routes, check_address_types, - interface_status, reset_config_on_routers, step, get_frr_ipv6_linklocal, @@ -62,18 +57,16 @@ from lib.common_config import ( start_router, create_route_maps, create_bgp_community_lists, - delete_route_maps, required_linux_kernel_version, ) from lib.topolog import logger from lib.bgp import ( verify_bgp_convergence, create_router_bgp, - clear_bgp, verify_bgp_rib, verify_bgp_attributes, ) -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_gshut_topo1/test_ibgp_gshut_topo1.py b/tests/topotests/bgp_gshut_topo1/test_ibgp_gshut_topo1.py index 90d285f0f2..95578bada9 100644 --- a/tests/topotests/bgp_gshut_topo1/test_ibgp_gshut_topo1.py +++ b/tests/topotests/bgp_gshut_topo1/test_ibgp_gshut_topo1.py @@ -31,7 +31,6 @@ Following tests are covered to test ecmp functionality on BGP GSHUT. import os import sys import time -import json import pytest # Save the Current Working Directory to find configuration files. @@ -42,38 +41,28 @@ sys.path.append(os.path.join(CWD, "../../")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from lib.micronet_compat import Topo -from time import sleep from lib.common_config import ( start_topology, write_test_header, write_test_footer, verify_rib, - create_static_routes, check_address_types, - interface_status, reset_config_on_routers, step, get_frr_ipv6_linklocal, - kill_router_daemons, - start_router_daemons, - stop_router, - start_router, create_route_maps, create_bgp_community_lists, - delete_route_maps, required_linux_kernel_version, ) from lib.topolog import logger from lib.bgp import ( verify_bgp_convergence, create_router_bgp, - clear_bgp, verify_bgp_rib, verify_bgp_attributes, ) -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_ibgp_nbr.py b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_ibgp_nbr.py index 04945a94a5..e9de3a5e15 100644 --- a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_ibgp_nbr.py +++ b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_ibgp_nbr.py @@ -25,11 +25,8 @@ import os import sys import time -import json import pytest from copy import deepcopy -import ipaddr -from re import search as re_search # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -45,23 +42,19 @@ from lib.common_config import ( write_test_header, get_frr_ipv6_linklocal, write_test_footer, - create_prefix_lists, verify_rib, create_static_routes, check_address_types, reset_config_on_routers, step, - create_route_maps, - create_interfaces_cfg, ) from lib.topolog import logger from lib.bgp import ( - clear_bgp_and_verify, verify_bgp_convergence, create_router_bgp, verify_bgp_rib, ) -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json # Global variables topo = None diff --git a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_nbr.py b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_nbr.py index f09da23bc4..b31c8499e8 100644 --- a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_nbr.py +++ b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_nbr.py @@ -25,12 +25,7 @@ import os import sys import time -import json import pytest -import datetime -from copy import deepcopy -import ipaddr -from re import search as re_search # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -45,28 +40,20 @@ from lib.common_config import ( start_topology, write_test_header, write_test_footer, - create_prefix_lists, get_frr_ipv6_linklocal, verify_rib, create_static_routes, check_address_types, reset_config_on_routers, step, - create_route_maps, - addKernelRoute, - kill_router_daemons, - start_router_daemons, - create_interfaces_cfg, ) from lib.topolog import logger from lib.bgp import ( - clear_bgp_and_verify, - clear_bgp, verify_bgp_convergence, create_router_bgp, verify_bgp_rib, ) -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json # Global variables topo = None diff --git a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_unnumbered_nbr.py b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_unnumbered_nbr.py index 5966ffdedd..bc5c4ddcd7 100644 --- a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_unnumbered_nbr.py +++ b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_unnumbered_nbr.py @@ -25,11 +25,7 @@ import os import sys import time -import json import pytest -import ipaddr -from copy import deepcopy -from re import search as re_search # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -41,7 +37,6 @@ from lib.topogen import Topogen, get_topogen from lib.common_config import ( write_test_header, start_topology, - create_route_maps, write_test_footer, start_router, stop_router, @@ -50,14 +45,12 @@ from lib.common_config import ( check_address_types, reset_config_on_routers, step, - shutdown_bringup_interface, - create_interfaces_cfg, get_frr_ipv6_linklocal, ) from lib.topolog import logger -from lib.bgp import clear_bgp, verify_bgp_convergence, create_router_bgp, verify_bgp_rib +from lib.bgp import create_router_bgp, verify_bgp_convergence, verify_bgp_rib -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json # Global variables topo = None diff --git a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_nbr.py b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_nbr.py index 9b5e48e08f..3ce0293ffe 100644 --- a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_nbr.py +++ b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_nbr.py @@ -25,11 +25,8 @@ import os import sys import time -import json import pytest from copy import deepcopy -import ipaddr -from re import search as re_search # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -48,21 +45,18 @@ from lib.common_config import ( create_prefix_lists, verify_rib, create_static_routes, - check_address_types, reset_config_on_routers, step, create_route_maps, - create_interfaces_cfg, get_frr_ipv6_linklocal, ) from lib.topolog import logger from lib.bgp import ( - clear_bgp_and_verify, verify_bgp_convergence, create_router_bgp, verify_bgp_rib, ) -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json # Global variables topo = None diff --git a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_unnumbered_nbr.py b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_unnumbered_nbr.py index 5e804df232..a5a8b5fe68 100644 --- a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_unnumbered_nbr.py +++ b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ibgp_unnumbered_nbr.py @@ -25,10 +25,7 @@ import os import sys import time -import json import pytest -import ipaddr -from re import search as re_search # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -43,7 +40,6 @@ from lib.common_config import ( start_topology, write_test_header, write_test_footer, - create_interfaces_cfg, verify_rib, create_static_routes, check_address_types, @@ -52,8 +48,8 @@ from lib.common_config import ( get_frr_ipv6_linklocal, ) from lib.topolog import logger -from lib.bgp import clear_bgp, verify_bgp_convergence, create_router_bgp -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.bgp import create_router_bgp, verify_bgp_convergence +from lib.topojson import build_config_from_json # Global variables topo = None diff --git a/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py b/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py index 04cf0395d6..981028ff76 100644 --- a/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py +++ b/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py @@ -43,7 +43,6 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py b/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py index f344ee76b0..7d7a4bd155 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/customize.py @@ -74,20 +74,15 @@ r3-eth1 .3 | | .3 r3-eth0 | .4 r4-eth0 """ import os -import re -import pytest # pylint: disable=C0413 # Import topogen and topotest helpers -from lib import topotest -from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topogen import get_topogen from lib.topolog import logger from lib.ltemplate import ltemplateRtrCmd # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo -import shutil CWD = os.path.dirname(os.path.realpath(__file__)) # test name based on directory diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py index 91291d89e3..8fd344696e 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py @@ -74,21 +74,17 @@ r3-eth1 .3 | | .3 r3-eth0 | .4 r4-eth0 """ import os -import re -import pytest import platform # pylint: disable=C0413 # Import topogen and topotest helpers from lib import topotest -from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topogen import get_topogen from lib.topolog import logger from lib.ltemplate import ltemplateRtrCmd # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo -import shutil CWD = os.path.dirname(os.path.realpath(__file__)) # test name based on directory diff --git a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py index fb472c4495..fa3598ff8e 100644 --- a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py +++ b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py @@ -50,11 +50,9 @@ import pytest import time from os import path as os_path import sys -from json import load as json_load # Required to instantiate the topology builder class. from lib.topogen import Topogen, get_topogen -from lib.micronet_compat import Topo from lib.common_config import ( start_topology, @@ -71,7 +69,7 @@ from lib.common_config import ( ) from lib.topolog import logger from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py index a94d20da36..6b62b2c5ee 100644 --- a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py +++ b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py @@ -61,7 +61,6 @@ Following tests are covered: import os import sys -import json import pytest import time @@ -74,7 +73,6 @@ sys.path.append(os.path.join(CWD, "../lib/")) # Import topogen and topotest helpers # Import topoJson from lib, to create topology and initial configuration from lib.topogen import Topogen, get_topogen -from lib.micronet_compat import Topo from lib.common_config import ( start_topology, @@ -83,7 +81,6 @@ from lib.common_config import ( reset_config_on_routers, create_route_maps, create_bgp_community_lists, - create_prefix_lists, verify_bgp_community, step, verify_create_community_list, @@ -95,7 +92,7 @@ from lib.common_config import ( ) from lib.topolog import logger from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py b/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py index 799b5f93f1..4eec69f7f4 100644 --- a/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py +++ b/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py @@ -27,7 +27,6 @@ test_bgp_linkbw_ip.py: Test weighted ECMP using BGP link-bandwidth """ import os -import re import sys from functools import partial import pytest @@ -44,7 +43,6 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_listen_on_multiple_addresses/test_bgp_listen_on_multiple_addresses.py b/tests/topotests/bgp_listen_on_multiple_addresses/test_bgp_listen_on_multiple_addresses.py index bc4336b6f3..4b4335a014 100755 --- a/tests/topotests/bgp_listen_on_multiple_addresses/test_bgp_listen_on_multiple_addresses.py +++ b/tests/topotests/bgp_listen_on_multiple_addresses/test_bgp_listen_on_multiple_addresses.py @@ -40,7 +40,6 @@ connections on multiple addresses. import os import sys -import json import pytest @@ -49,11 +48,10 @@ CWD = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(CWD, "../")) from lib.topogen import Topogen, get_topogen -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json from lib.topojson import linux_intf_config_from_json from lib.common_config import start_topology from lib.topotest import router_json_cmp, run_and_expect -from lib.micronet_compat import Topo from functools import partial pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py b/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py index f648e1791f..bb2c43d1fc 100644 --- a/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py +++ b/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py @@ -38,10 +38,7 @@ CWD = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 -from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_lu_topo1/test_bgp_lu.py b/tests/topotests/bgp_lu_topo1/test_bgp_lu.py index 6318044eaa..8941854593 100644 --- a/tests/topotests/bgp_lu_topo1/test_bgp_lu.py +++ b/tests/topotests/bgp_lu_topo1/test_bgp_lu.py @@ -29,7 +29,6 @@ import os import sys import json from functools import partial -from time import sleep import pytest # Save the Current Working Directory to find configuration files. @@ -40,10 +39,8 @@ sys.path.append(os.path.join(CWD, "../")) # Import topogen and topotest helpers from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py b/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py index 66fcd355ee..5c34ebf919 100644 --- a/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py +++ b/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py @@ -35,17 +35,13 @@ is not sent if maximum-prefix count is overflow. import os import sys import json -import time import pytest CWD = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 -from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py b/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py index 07d1cb02b1..d45f00f697 100644 --- a/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py +++ b/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py @@ -30,7 +30,6 @@ correctly. import os import sys import json -import time import pytest import functools @@ -40,8 +39,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_minimum_holdtime/test_bgp_minimum_holdtime.py b/tests/topotests/bgp_minimum_holdtime/test_bgp_minimum_holdtime.py index 5facdd26ea..b1641b3c13 100755 --- a/tests/topotests/bgp_minimum_holdtime/test_bgp_minimum_holdtime.py +++ b/tests/topotests/bgp_minimum_holdtime/test_bgp_minimum_holdtime.py @@ -25,7 +25,6 @@ Test if minimum-holdtime works. import os import sys import json -import time import pytest import functools @@ -35,8 +34,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from mininet.topo import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py b/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py index ffa1c3fb61..eefb965f80 100644 --- a/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py +++ b/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py @@ -99,10 +99,8 @@ FUNC_16_3: import os import sys -import json import time import pytest -from copy import deepcopy # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -114,7 +112,6 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from lib.micronet_compat import Topo from lib.topotest import iproute2_is_vrf_capable from lib.common_config import ( step, @@ -136,14 +133,13 @@ from lib.common_config import ( from lib.topolog import logger from lib.bgp import ( - clear_bgp, verify_bgp_rib, create_router_bgp, verify_bgp_community, verify_bgp_convergence, verify_best_path_as_per_bgp_attribute, ) -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py b/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py index 609fdf3587..3163fd75a4 100644 --- a/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py +++ b/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py @@ -53,7 +53,6 @@ CHAOS_8: import os import sys -import json import time import pytest from copy import deepcopy @@ -70,7 +69,6 @@ sys.path.append(os.path.join(CWD, "../lib/")) # pylint: disable=C0413 # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen -from lib.micronet_compat import Topo from lib.topotest import iproute2_is_vrf_capable from lib.common_config import ( step, @@ -99,7 +97,7 @@ from lib.common_config import ( from lib.topolog import logger from lib.bgp import clear_bgp, verify_bgp_rib, create_router_bgp, verify_bgp_convergence -from lib.topojson import build_config_from_json, build_topo_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py index 76a06bccd2..d32cbeb751 100644 --- a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py +++ b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py @@ -64,10 +64,8 @@ test_bgp_multiview_topo1.py: Simple FRR Route-Server Test import json import os -import re import sys import pytest -import glob import json from time import sleep diff --git a/tests/topotests/bgp_path_attributes_topo1/test_bgp_path_attributes.py b/tests/topotests/bgp_path_attributes_topo1/test_bgp_path_attributes.py index f34ecc30a0..a2566bd382 100644 --- a/tests/topotests/bgp_path_attributes_topo1/test_bgp_path_attributes.py +++ b/tests/topotests/bgp_path_attributes_topo1/test_bgp_path_attributes.py @@ -52,11 +52,7 @@ Teardown module: import os import sys -import pdb -import json import time -import inspect -from time import sleep import pytest # Save the Current Working Directory to find configuration files. @@ -65,9 +61,7 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from lib.micronet_compat import Topo -from lib import topotest -from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topogen import Topogen, get_topogen # Required to instantiate the topology builder class. from lib.common_config import ( @@ -78,7 +72,6 @@ from lib.common_config import ( verify_rib, create_static_routes, create_prefix_lists, - verify_prefix_lists, create_route_maps, check_address_types, ) @@ -86,13 +79,10 @@ from lib.topolog import logger from lib.bgp import ( verify_bgp_convergence, create_router_bgp, - clear_bgp_and_verify, verify_best_path_as_per_bgp_attribute, verify_best_path_as_per_admin_distance, - modify_as_number, - verify_as_numbers, ) -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_peer_group/test_bgp_peer-group.py b/tests/topotests/bgp_peer_group/test_bgp_peer-group.py index 172426b2c8..494f6c68b9 100644 --- a/tests/topotests/bgp_peer_group/test_bgp_peer-group.py +++ b/tests/topotests/bgp_peer_group/test_bgp_peer-group.py @@ -35,8 +35,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py b/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py index 4cd14367bf..8321a57552 100755 --- a/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py +++ b/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py @@ -71,7 +71,6 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_prefix_list_topo1/test_prefix_lists.py b/tests/topotests/bgp_prefix_list_topo1/test_prefix_lists.py index f046f442e0..64093497cb 100644 --- a/tests/topotests/bgp_prefix_list_topo1/test_prefix_lists.py +++ b/tests/topotests/bgp_prefix_list_topo1/test_prefix_lists.py @@ -44,7 +44,6 @@ IP prefix-list tests """ import sys -import json import time import os import pytest @@ -55,7 +54,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration @@ -71,7 +69,7 @@ from lib.common_config import ( ) from lib.topolog import logger from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py index 49a4049c00..d36bc31237 100644 --- a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py +++ b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py @@ -39,7 +39,6 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_prefix_sid2/test_bgp_prefix_sid2.py b/tests/topotests/bgp_prefix_sid2/test_bgp_prefix_sid2.py index 5c85895ed2..323c065275 100755 --- a/tests/topotests/bgp_prefix_sid2/test_bgp_prefix_sid2.py +++ b/tests/topotests/bgp_prefix_sid2/test_bgp_prefix_sid2.py @@ -39,7 +39,6 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py b/tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py index 918c16e34a..e255b4e88c 100644 --- a/tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py +++ b/tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py @@ -40,10 +40,8 @@ multi-hop functionality: import os import sys import time -import json import pytest from time import sleep -from copy import deepcopy # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -51,8 +49,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from lib import topotest -from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration @@ -69,21 +65,18 @@ from lib.common_config import ( create_route_maps, create_interface_in_kernel, shutdown_bringup_interface, - addKernelRoute, - delete_route_maps, ) from lib.topolog import logger from lib.bgp import ( verify_bgp_convergence, create_router_bgp, - clear_bgp_and_verify, verify_bgp_rib, verify_bgp_convergence_from_running_config, modify_as_number, verify_bgp_attributes, clear_bgp, ) -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py b/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py index 271db0a7c9..8d1e834986 100644 --- a/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py +++ b/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py @@ -37,7 +37,6 @@ BGP speakers conforming to this document (i.e., conformant BGP import os import sys import json -import time import pytest import functools @@ -47,8 +46,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_rfapi_basic_sanity/customize.py b/tests/topotests/bgp_rfapi_basic_sanity/customize.py index 3cf53a184d..1a86746e37 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/customize.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/customize.py @@ -61,20 +61,15 @@ r3-eth1 .3 | | .3 r3-eth0 | .4 r4-eth0 """ import os -import re -import pytest # pylint: disable=C0413 # Import topogen and topotest helpers -from lib import topotest -from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topogen import get_topogen from lib.topolog import logger from lib.ltemplate import ltemplateRtrCmd # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo -import shutil CWD = os.path.dirname(os.path.realpath(__file__)) # test name based on directory diff --git a/tests/topotests/bgp_rmap_extcommunity_none/test_bgp_rmap_extcommunity_none.py b/tests/topotests/bgp_rmap_extcommunity_none/test_bgp_rmap_extcommunity_none.py index d2a602f9a2..d34ac3cdda 100644 --- a/tests/topotests/bgp_rmap_extcommunity_none/test_bgp_rmap_extcommunity_none.py +++ b/tests/topotests/bgp_rmap_extcommunity_none/test_bgp_rmap_extcommunity_none.py @@ -28,7 +28,6 @@ route-map permit 10 import os import sys import json -import time import pytest import functools @@ -40,7 +39,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py b/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py index 007e640f58..1367d77e55 100644 --- a/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py +++ b/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py @@ -31,10 +31,7 @@ Following tests are covered to test bgp aggregation functionality: import os import sys import time -import json import pytest -from time import sleep -from copy import deepcopy # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -42,15 +39,12 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from lib import topotest -from lib.micronet_compat import Topo from lib.topogen import Topogen, get_topogen # Import topoJson from lib, to create topology and initial configuration from lib.common_config import ( start_topology, write_test_header, - apply_raw_config, write_test_footer, reset_config_on_routers, verify_rib, @@ -66,9 +60,8 @@ from lib.bgp import ( create_router_bgp, verify_bgp_rib, verify_bgp_community, - verify_bgp_timers_and_functionality, ) -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_route_map/test_route_map_topo1.py b/tests/topotests/bgp_route_map/test_route_map_topo1.py index ba4456e717..5af7296fcb 100644 --- a/tests/topotests/bgp_route_map/test_route_map_topo1.py +++ b/tests/topotests/bgp_route_map/test_route_map_topo1.py @@ -21,12 +21,9 @@ # import sys -import json import time import pytest -import inspect import os -from time import sleep # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -34,38 +31,27 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from lib import topotest from lib.topogen import Topogen, get_topogen -from lib.micronet_compat import Topo # Required to instantiate the topology builder class. -from lib.topojson import * from lib.common_config import ( start_topology, write_test_header, write_test_footer, - verify_bgp_community, verify_rib, - delete_route_maps, - create_bgp_community_lists, - interface_status, create_route_maps, create_static_routes, create_prefix_lists, - verify_route_maps, check_address_types, - shutdown_bringup_interface, - verify_prefix_lists, reset_config_on_routers, ) from lib.topolog import logger from lib.bgp import ( verify_bgp_convergence, create_router_bgp, - clear_bgp_and_verify, verify_bgp_attributes, ) -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_route_map/test_route_map_topo2.py b/tests/topotests/bgp_route_map/test_route_map_topo2.py index ca05ba45d9..eccb2c1bf2 100644 --- a/tests/topotests/bgp_route_map/test_route_map_topo2.py +++ b/tests/topotests/bgp_route_map/test_route_map_topo2.py @@ -101,7 +101,6 @@ TC_60 """ import sys -import json import time import pytest import inspect @@ -114,9 +113,7 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from lib import topotest from lib.topogen import Topogen, get_topogen -from lib.micronet_compat import Topo # Required to instantiate the topology builder class. from lib.common_config import ( @@ -127,7 +124,6 @@ from lib.common_config import ( verify_rib, delete_route_maps, create_bgp_community_lists, - interface_status, create_route_maps, create_prefix_lists, verify_route_maps, @@ -145,7 +141,7 @@ from lib.bgp import ( clear_bgp_and_verify, verify_bgp_attributes, ) -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py b/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py index d40ea2ed85..cf8315f594 100644 --- a/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py +++ b/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py @@ -31,7 +31,6 @@ routes around """ import os -import re import sys import pytest import json @@ -47,7 +46,6 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py b/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py index 9d3c3a7652..b5c33f359b 100644 --- a/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py +++ b/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py @@ -30,7 +30,6 @@ command works as expeced. import os import sys import json -import time import pytest import functools @@ -40,8 +39,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_set_local_preference_add_subtract/test_bgp_set_local-preference_add_subtract.py b/tests/topotests/bgp_set_local_preference_add_subtract/test_bgp_set_local-preference_add_subtract.py index 0ef5f61d97..d238cc94ec 100644 --- a/tests/topotests/bgp_set_local_preference_add_subtract/test_bgp_set_local-preference_add_subtract.py +++ b/tests/topotests/bgp_set_local_preference_add_subtract/test_bgp_set_local-preference_add_subtract.py @@ -31,7 +31,6 @@ LOCAL_PREF in route-maps. import os import sys import json -import time import pytest import functools @@ -41,8 +40,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/test_bgp_snmp_mplsvpn.py b/tests/topotests/bgp_snmp_mplsl3vpn/test_bgp_snmp_mplsvpn.py index 7f58c65ab0..3e6e417211 100755 --- a/tests/topotests/bgp_snmp_mplsl3vpn/test_bgp_snmp_mplsvpn.py +++ b/tests/topotests/bgp_snmp_mplsl3vpn/test_bgp_snmp_mplsvpn.py @@ -27,11 +27,8 @@ test_bgp_snmp_mplsl3vpn.py: Test mplsL3Vpn MIB [RFC4382]. import os import sys -import json -from functools import partial from time import sleep import pytest -import re # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -39,13 +36,10 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers -from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger from lib.snmptest import SnmpTester # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.isisd, pytest.mark.snmp] diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py index 60e419ab1c..2f2bdbc8eb 100755 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py @@ -22,7 +22,6 @@ # import os -import re import sys import json import functools @@ -37,7 +36,6 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from lib.common_config import required_linux_kernel_version -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py b/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py index 2c14ad9dee..5a22fbbc54 100644 --- a/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py +++ b/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py @@ -26,7 +26,6 @@ import os import sys import json -import time import pytest from functools import partial from time import sleep @@ -37,8 +36,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_tcp_mss/test_bgp_tcp_mss.py b/tests/topotests/bgp_tcp_mss/test_bgp_tcp_mss.py index db90bbd5df..eed0b34371 100644 --- a/tests/topotests/bgp_tcp_mss/test_bgp_tcp_mss.py +++ b/tests/topotests/bgp_tcp_mss/test_bgp_tcp_mss.py @@ -35,7 +35,6 @@ Need to verify if the tcp-mss value is reflected in the TCP session. import os import sys import json -import time import pytest import functools @@ -49,7 +48,6 @@ sys.path.append(os.path.join(CWD, "../")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_update_delay/test_bgp_update_delay.py b/tests/topotests/bgp_update_delay/test_bgp_update_delay.py index 31a887b6c3..b3e6ad3a12 100644 --- a/tests/topotests/bgp_update_delay/test_bgp_update_delay.py +++ b/tests/topotests/bgp_update_delay/test_bgp_update_delay.py @@ -60,7 +60,6 @@ event of packet loss. import os import sys import json -import time import pytest import functools @@ -70,8 +69,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py index b2e2250a9c..07ba0964d4 100644 --- a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py +++ b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py @@ -33,7 +33,6 @@ Following tests are covered to test BGP Multi-VRF Dynamic Route Leaking: import os import sys -import json import time import pytest import platform @@ -49,25 +48,20 @@ sys.path.append(os.path.join(CWD, "../lib/")) # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen from lib.topotest import version_cmp -from lib.micronet_compat import Topo from lib.common_config import ( start_topology, write_test_header, check_address_types, write_test_footer, - reset_config_on_routers, - verify_rib, step, create_route_maps, - shutdown_bringup_interface, create_static_routes, create_prefix_lists, create_bgp_community_lists, create_interface_in_kernel, check_router_status, verify_cli_json, - get_frr_ipv6_linklocal, verify_fib_routes, ) @@ -75,11 +69,10 @@ from lib.topolog import logger from lib.bgp import ( verify_bgp_convergence, create_router_bgp, - clear_bgp, verify_bgp_community, verify_bgp_rib, ) -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py index 8e3e32fc8f..30d05a6401 100644 --- a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py +++ b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py @@ -47,19 +47,14 @@ sys.path.append(os.path.join(CWD, "../lib/")) # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen from lib.topotest import version_cmp -from lib.micronet_compat import Topo from lib.common_config import ( start_topology, write_test_header, check_address_types, write_test_footer, - verify_rib, step, create_route_maps, - create_static_routes, - stop_router, - start_router, create_prefix_lists, create_bgp_community_lists, check_router_status, diff --git a/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py b/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py index 5d6a5859cf..b70e273155 100644 --- a/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py +++ b/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py @@ -31,7 +31,6 @@ import sys import json from functools import partial import pytest -import platform # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -45,7 +44,6 @@ from lib.topolog import logger from lib.common_config import required_linux_kernel_version # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py b/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py index d0011f9df2..8d2cb08ca8 100644 --- a/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py +++ b/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py @@ -42,7 +42,6 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/bgp_vrf_route_leak_basic/test_bgp-vrf-route-leak-basic.py b/tests/topotests/bgp_vrf_route_leak_basic/test_bgp-vrf-route-leak-basic.py index 66a52841fb..e630ef9102 100644 --- a/tests/topotests/bgp_vrf_route_leak_basic/test_bgp-vrf-route-leak-basic.py +++ b/tests/topotests/bgp_vrf_route_leak_basic/test_bgp-vrf-route-leak-basic.py @@ -25,7 +25,6 @@ test_bgp-vrf-route-leak-basic.py.py: Test basic vrf route leaking """ -import json import os import sys from functools import partial @@ -39,7 +38,6 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd] diff --git a/tests/topotests/config_timing/test_config_timing.py b/tests/topotests/config_timing/test_config_timing.py index b68f52bbda..69b3edcf32 100644 --- a/tests/topotests/config_timing/test_config_timing.py +++ b/tests/topotests/config_timing/test_config_timing.py @@ -45,7 +45,6 @@ sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from lib.micronet_compat import Topo pytestmark = [pytest.mark.staticd] diff --git a/tests/topotests/eigrp_topo1/test_eigrp_topo1.py b/tests/topotests/eigrp_topo1/test_eigrp_topo1.py index f97b1f2daa..8b7c9fc6d7 100644 --- a/tests/topotests/eigrp_topo1/test_eigrp_topo1.py +++ b/tests/topotests/eigrp_topo1/test_eigrp_topo1.py @@ -46,7 +46,6 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo ##################################################### ## diff --git a/tests/topotests/evpn_pim_1/test_evpn_pim_topo1.py b/tests/topotests/evpn_pim_1/test_evpn_pim_topo1.py index 216494d4e6..6d5c096c0a 100644 --- a/tests/topotests/evpn_pim_1/test_evpn_pim_topo1.py +++ b/tests/topotests/evpn_pim_1/test_evpn_pim_topo1.py @@ -28,7 +28,6 @@ test_evpn_pim_topo1.py: Testing evpn-pim """ import os -import re import sys import pytest import json @@ -47,7 +46,6 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger # Required to instantiate the topology builder class. -from lib.micronet_compat import Topo pytestmark = [pytest.mark.bgpd, pytest.mark.bgpd] diff --git a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py index 83c415c0f3..72d1251d25 100644 --- a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py +++ b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py @@ -30,14 +30,11 @@ Following tests are covered to test EVPN-Type5 functionality: """ import os -import re import sys -import json import time import pytest import platform from copy import deepcopy -from time import sleep # Save the Current Working Directory to find configuration files. @@ -51,7 +48,6 @@ sys.path.append(os.path.join(CWD, "../lib/")) # Import topogen and topotest helpers from lib.topotest import version_cmp from lib.topogen import Topogen, get_topogen -from lib.micronet_compat import Topo from lib.common_config import ( start_topology, @@ -61,15 +57,11 @@ from lib.common_config import ( reset_config_on_routers, verify_rib, step, - start_router_daemons, create_static_routes, create_vrf_cfg, - create_route_maps, - create_interface_in_kernel, check_router_status, configure_vxlan, configure_brctl, - apply_raw_config, verify_vrf_vni, verify_cli_json, ) @@ -78,12 +70,9 @@ from lib.topolog import logger from lib.bgp import ( verify_bgp_convergence, create_router_bgp, - clear_bgp, - verify_best_path_as_per_bgp_attribute, verify_attributes_for_evpn_routes, - verify_evpn_routes, ) -from lib.topojson import build_topo_from_json, build_config_from_json +from lib.topojson import build_config_from_json pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] diff --git a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py index 3a101b4533..6cce0958a4 100644 --- a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py +++ b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py @@ -34,14 +34,12 @@ Following tests are covered to test EVPN-Type5 functionality: """ import os -import re import sys import json import time import pytest import platform from copy import deepcopy -from time import sleep # Save the Current Working Directory to find configuration files. @@ -55,7 +53,6 @@ sys.path.append(os.path.join(CWD, "../lib/")) # Import topogen and topotest helpers from lib.topotest import version_cmp from lib.topogen import Topogen, get_topogen -from lib.micronet_compat import Topo from lib.common_config import ( start_topology, @@ -66,17 +63,12 @@ from lib.common_config import ( verify_rib, step, create_route_maps, - verify_cli_json, - start_router_daemons, create_static_routes, - stop_router, - start_router, create_vrf_cfg, check_router_status, apply_raw_config, configure_vxlan, configure_brctl, - verify_vrf_vni, create_interface_in_kernel, ) @@ -84,7 +76,6 @@ from lib.topolog import logger from lib.bgp import ( verify_bgp_convergence, create_router_bgp, - clear_bgp, verify_best_path_as_per_bgp_attribute, verify_attributes_for_evpn_routes, verify_evpn_routes, diff --git a/tests/topotests/example_test/test_template.py b/tests/topotests/example_test/test_template.py index 7bd434d756..dfc0bb4a04 100644 --- a/tests/topotests/example_test/test_template.py +++ b/tests/topotests/example_test/test_template.py @@ -26,13 +26,11 @@