From dc4c450fc2807d00a5f2de6f14c59ed094e498c7 Mon Sep 17 00:00:00 2001 From: Kuldeep Kashyap Date: Fri, 9 Dec 2022 07:21:29 -0800 Subject: [PATCH] tests: Topotests daemon start as per feature test Currently topotests starts all daemons by default, made changes to f/w so only needed daemons can be started, daemons which are needed to tests particular test suite. Signed-off-by: Kuldeep Kashyap --- .../bgp_as_allow_in/test_bgp_as_allow_in.py | 22 ++---- .../test_bgp_vrf_dynamic_route_leak_topo2.py | 20 +----- .../test_evpn_type5_topo1.py | 18 ++--- tests/topotests/lib/common_config.py | 70 ++++++++++++++----- .../ospf_rte_calc.json | 2 +- 5 files changed, 64 insertions(+), 68 deletions(-) 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 ec66c8caef..7ded0ce8b4 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 @@ -76,15 +76,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 = "{}/bgp_as_allow_in.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,13 +83,6 @@ NETWORK = {"ipv4": "2.2.2.2/32", "ipv6": "22:22::2/128"} NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"} -def build_topo(tgen): - """Build function""" - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -118,7 +102,11 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(build_topo, mod.__name__) + json_file = "{}/bgp_as_allow_in.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 391c272dbc..f193317b1e 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 @@ -75,15 +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 = "{}/bgp_vrf_dynamic_route_leak_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": "11.11.11.1/32", "ipv6": "11:11::1/128"} NETWORK3_3 = {"ipv4": "50.50.50.5/32", "ipv6": "50:50::5/128"} @@ -92,13 +83,6 @@ NETWORK3_4 = {"ipv4": "50.50.50.50/32", "ipv6": "50:50::50/128"} PREFERRED_NEXT_HOP = "global" -def build_topo(tgen): - """Build function""" - - # Building topology from json file - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -114,7 +98,9 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - tgen = Topogen(build_topo, mod.__name__) + json_file = "{}/bgp_vrf_dynamic_route_leak_topo2.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + 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 a641fec584..313d56a981 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 @@ -86,15 +86,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 = "{}/evpn_type5_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": "10.1.1.1/32", "ipv6": "10::1/128"} NETWORK1_2 = {"ipv4": "40.1.1.1/32", "ipv6": "40::1/128"} @@ -135,10 +126,6 @@ BRCTL = { } -def build_topo(tgen): - build_topo_from_json(tgen, topo) - - def setup_module(mod): """ Sets up the pytest environment @@ -154,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(build_topo, mod.__name__) + json_file = "{}/evpn_type5_topo1.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + 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/lib/common_config.py b/tests/topotests/lib/common_config.py index 737226c7fe..3bc88b7d9c 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -1009,40 +1009,72 @@ def start_topology(tgen, daemon=None): 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 + topo = tgen.json_topo + feature = set() + + if "feature" in topo: + feature.update(topo["feature"]) + + if rname in topo["routers"]: + for key in topo["routers"][rname].keys(): + feature.add(key) + + for val in topo["routers"][rname]["links"].values(): + if "pim" in val: + feature.add("pim") + break + for val in topo["routers"][rname]["links"].values(): + if "pim6" in val: + feature.add("pim6") + break + for val in topo["routers"][rname]["links"].values(): + if "ospf6" in val: + feature.add("ospf6") + break + if "switches" in topo and rname in topo["switches"]: + for val in topo["switches"][rname]["links"].values(): + if "ospf" in val: + feature.add("ospf") + break + if "ospf6" in val: + feature.add("ospf6") + break + + # Loading empty zebra.conf file to router, to start the zebra deamon router.load_config( 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(tgen.logdir, rname) - ) - - if daemon and "ospfd" in daemon: - # Loading empty ospf.conf file to router, to start the bgp daemon + # Loading empty bgpd.conf file to router, to start the bgp deamon + if "bgp" in feature: router.load_config( - TopoRouter.RD_OSPF, "{}/{}/ospfd.conf".format(tgen.logdir, rname) + TopoRouter.RD_BGP, "{}/{}/bgpd.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(tgen.logdir, rname) - ) - - if daemon and "pimd" in daemon: - # Loading empty pimd.conf file to router, to start the pim deamon + # Loading empty pimd.conf file to router, to start the pim deamon + if "pim" in feature: router.load_config( TopoRouter.RD_PIM, "{}/{}/pimd.conf".format(tgen.logdir, rname) ) - if daemon and "pim6d" in daemon: - # Loading empty pimd.conf file to router, to start the pim6d deamon + # Loading empty pimd.conf file to router, to start the pim deamon + if "pim6" in feature: router.load_config( TopoRouter.RD_PIM6, "{}/{}/pim6d.conf".format(tgen.logdir, rname) ) + if "ospf" in feature: + # Loading empty ospf.conf file to router, to start the ospf deamon + router.load_config( + TopoRouter.RD_OSPF, "{}/{}/ospfd.conf".format(tgen.logdir, rname) + ) + + if "ospf6" in feature: + # Loading empty ospf.conf file to router, to start the ospf deamon + router.load_config( + TopoRouter.RD_OSPF6, "{}/{}/ospf6d.conf".format(tgen.logdir, rname) + ) + # Starting routers logger.info("Starting all routers once topology is created") tgen.start_router() diff --git a/tests/topotests/ospf_basic_functionality/ospf_rte_calc.json b/tests/topotests/ospf_basic_functionality/ospf_rte_calc.json index 9062a09091..1fe076ea15 100644 --- a/tests/topotests/ospf_basic_functionality/ospf_rte_calc.json +++ b/tests/topotests/ospf_basic_functionality/ospf_rte_calc.json @@ -1,5 +1,5 @@ { - + "feature": ["bgp"], "ipv4base": "10.0.0.0", "ipv4mask": 24, "link_ip_start": {