mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-15 05:18:47 +00:00
tests: remove legacy Topo class from infra
Signed-off-by: Christian Hopps <chopps@labn.net>
This commit is contained in:
parent
e82b531df9
commit
fe50239bc6
@ -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
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user