]> git.puffer.fish Git - matthieu/frr.git/commitdiff
tests: remove legacy Topo class from infra
authorChristian Hopps <chopps@labn.net>
Tue, 10 Aug 2021 09:36:46 +0000 (05:36 -0400)
committerChristian Hopps <chopps@labn.net>
Sat, 4 Sep 2021 13:04:47 +0000 (09:04 -0400)
Signed-off-by: Christian Hopps <chopps@labn.net>
tests/topotests/lib/common_config.py
tests/topotests/lib/lutil.py
tests/topotests/lib/topogen.py
tests/topotests/lib/topojson.py

index 99a3a4a87db6febcfd3b8c4208df5ee3842350bf..de3aa534a4566cbca20d78b349c34f278bc5ddf9 100644 (file)
@@ -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
index 7248ce267f92340adaa85648798a2c8a763bb6cb..c49488ed9d1c29e95f8fb33ef3135bdad8e1c945 100644 (file)
@@ -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
index c0529c68e2527bc3f31f98bca0ceebbe37a757b4..5c2ff1bf8510116097cd707ed81059d8b04a7d60 100644 (file)
@@ -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):
         """
index 1b00f83ab2b55b62096e77d3c2dfa61725b01618..d8e0e5d182c125cc6d6c83c454fabec0c9e7c6d3 100644 (file)
@@ -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))