tests: remove legacy Topo class from infra

Signed-off-by: Christian Hopps <chopps@labn.net>
This commit is contained in:
Christian Hopps 2021-08-10 05:36:46 -04:00
parent e82b531df9
commit fe50239bc6
4 changed files with 19 additions and 18 deletions

View File

@ -44,7 +44,6 @@ except ImportError:
import configparser import configparser
from io import StringIO from io import StringIO
from lib.micronet_compat import Mininet
from lib.topogen import TopoRouter, get_topogen from lib.topogen import TopoRouter, get_topogen
from lib.topolog import get_logger, logger from lib.topolog import get_logger, logger
from lib.topotest import frr_unicode, interface_set_status, version_cmp from lib.topotest import frr_unicode, interface_set_status, version_cmp

View File

@ -26,7 +26,6 @@ import math
import time import time
from lib.topolog import logger from lib.topolog import logger
from lib.topotest import json_cmp from lib.topotest import json_cmp
from lib.micronet_compat import Mininet
# L utility functions # L utility functions

View File

@ -160,7 +160,6 @@ class Topogen(object):
* `modname`: module name must be a unique name to identify logs later. * `modname`: module name must be a unique name to identify logs later.
""" """
self.config = None self.config = None
self.topo = None
self.net = None self.net = None
self.gears = {} self.gears = {}
self.routern = 1 self.routern = 1
@ -220,14 +219,13 @@ class Topogen(object):
# Allow anyone, but set the sticky bit to avoid file deletions # Allow anyone, but set the sticky bit to avoid file deletions
os.chmod(self.logdir, 0o1777) os.chmod(self.logdir, 0o1777)
# Old twisty way of creating sub-classed topology object which has it's build # Remove old twisty way of creating sub-classed topology object which has it's
# method invoked which calls Topogen methods which then call Topo methods to # build method invoked which calls Topogen methods which then call Topo methods
# create a topology within the Topo object, which is then used by # to create a topology within the Topo object, which is then used by
# Mininet(Micronet) to build the actual topology. # Mininet(Micronet) to build the actual topology.
if inspect.isclass(topodef): assert not inspect.isclass(topodef)
self.topo = 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 # 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 # 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) node1.register_link(ifname1, node2, ifname2)
node2.register_link(ifname2, node1, ifname1) node2.register_link(ifname2, node1, ifname1)
if self.net: self.net.add_link(node1.name, node2.name, ifname1, ifname2)
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): def get_gears(self, geartype):
""" """

View File

@ -42,14 +42,16 @@ from lib.topolog import logger
ROUTER_LIST = [] 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 Reads configuration from JSON file. Adds routers, creates interface
names dynamically and link routers as defined in JSON to create names dynamically and link routers as defined in JSON to create
topology. Assigns IPs dynamically to all interfaces of each router. topology. Assigns IPs dynamically to all interfaces of each router.
* `tgen`: Topogen object * `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( ROUTER_LIST = sorted(
topo["routers"].keys(), key=lambda x: int(re_search(r"\d+", x).group(0)) 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.""" """Configure interfaces from linux based on topo."""
if topo is None:
topo = tgen.json_topo
routers = topo["routers"] routers = topo["routers"]
for rname in routers: for rname in routers:
router = tgen.net[rname] 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)) 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 Reads initial configuraiton from JSON for each router, builds
configuration and loads its to router. configuration and loads its to router.
* `tgen`: Topogen object * `tgen`: Topogen object
* `topo`: json file data * `topo`: json file data, or use tgen.json_topo if None
""" """
func_dict = OrderedDict( 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"] data = topo["routers"]
for func_type in func_dict.keys(): for func_type in func_dict.keys():
logger.info("Checking for {} configuration in input data".format(func_type)) logger.info("Checking for {} configuration in input data".format(func_type))