From: Christian Hopps Date: Tue, 10 Aug 2021 09:36:46 +0000 (-0400) Subject: tests: remove legacy Topo class from infra X-Git-Tag: base_8.1~112^2~13 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=fe50239bc679cf9d4c64991f220bc214f96b18ec;p=matthieu%2Ffrr.git tests: remove legacy Topo class from infra Signed-off-by: Christian Hopps --- 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))