From 035267a3745bbe1f92b612a4414adb0ab65c3596 Mon Sep 17 00:00:00 2001 From: nguggarigoud Date: Tue, 8 Sep 2020 11:29:21 +0530 Subject: [PATCH] tests: Adding daemon check for ospfd in common_config.py start ospfd only when ospf config is used. Signed-off-by: nguggarigoud --- tests/topotests/lib/common_config.py | 32 +++++++++++++++---- .../test_ospf_authentication.py | 6 +++- .../test_ospf_ecmp.py | 6 +++- .../test_ospf_ecmp_lan.py | 7 +++- .../ospf_basic_functionality/test_ospf_lan.py | 6 +++- .../test_ospf_nssa.py | 7 +++- .../test_ospf_routemaps.py | 6 +++- .../test_ospf_rte_calc.py | 6 +++- .../test_ospf_single_area.py | 6 +++- 9 files changed, 68 insertions(+), 14 deletions(-) diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index 09e7fa7873..9a79693840 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -685,7 +685,7 @@ def generate_support_bundle(): return True -def start_topology(tgen): +def start_topology(tgen, daemon=None): """ Starting topology, create tmp files which are loaded to routers to start deamons and then start routers @@ -737,14 +737,16 @@ def start_topology(tgen): router.load_config( TopoRouter.RD_ZEBRA, "{}/{}/zebra.conf".format(TMPDIR, rname) ) + # Loading empty bgpd.conf file to router, to start the bgp deamon router.load_config(TopoRouter.RD_BGP, "{}/{}/bgpd.conf".format(TMPDIR, rname)) - # Loading empty ospf.conf file to router, to start the bgp deamon - router.load_config( - TopoRouter.RD_OSPF, - '{}/{}/ospfd.conf'.format(TMPDIR, rname) - ) + if daemon and 'ospfd' in daemon: + # Loading empty ospf.conf file to router, to start the bgp deamon + router.load_config( + TopoRouter.RD_OSPF, + '{}/{}/ospfd.conf'.format(TMPDIR, rname) + ) # Starting routers logger.info("Starting all routers once topology is created") tgen.start_router() @@ -817,6 +819,24 @@ def number_to_column(routerName): return ord(routerName[0]) - 97 +def topo_daemons(tgen, topo): + """ + Returns daemon list required for the suite based on topojson. + """ + daemon_list = [] + + router_list = tgen.routers() + ROUTER_LIST = sorted( + router_list.keys(), key=lambda x: int(re_search("\d+", x).group(0)) + ) + + for rtr in ROUTER_LIST: + if 'ospf' in topo['routers'][rtr] and 'ospfd' not in daemon_list: + daemon_list.append('ospfd') + + return daemon_list + + ############################################# # Common APIs, will be used by all protocols ############################################# diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py b/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py index e6485de250..a2f9c03ab4 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py @@ -48,6 +48,7 @@ from lib.common_config import ( reset_config_on_routers, step, shutdown_bringup_interface, + topo_daemons ) from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json @@ -119,9 +120,12 @@ def setup_module(mod): tgen = Topogen(CreateTopo, mod.__name__) # ... and here it calls Mininet initialization functions. + # get list of daemons needs to be started for this suite. + daemons = topo_daemons(tgen, topo) + # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers - start_topology(tgen) + start_topology(tgen, daemons) # Creating configuration from JSON build_config_from_json(tgen, topo) diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py index 30f50a78c4..399fa02230 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py @@ -53,6 +53,7 @@ from lib.common_config import ( create_route_maps, shutdown_bringup_interface, create_interfaces_cfg, + topo_daemons ) from lib.topolog import logger @@ -141,9 +142,12 @@ def setup_module(mod): tgen = Topogen(CreateTopo, mod.__name__) # ... and here it calls Mininet initialization functions. + # get list of daemons needs to be started for this suite. + daemons = topo_daemons(tgen, topo) + # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers - start_topology(tgen) + start_topology(tgen, daemons) # Creating configuration from JSON build_config_from_json(tgen, topo) diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py index c31f7f2bfd..17a3676e2e 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py @@ -53,6 +53,7 @@ from lib.common_config import ( shutdown_bringup_interface, stop_router, start_router, + topo_daemons ) from lib.bgp import verify_bgp_convergence, create_router_bgp from lib.topolog import logger @@ -146,9 +147,13 @@ def setup_module(mod): tgen = Topogen(CreateTopo, mod.__name__) # ... and here it calls Mininet initialization functions. + # get list of daemons needs to be started for this suite. + daemons = topo_daemons(tgen, topo) + # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers - start_topology(tgen) + start_topology(tgen, daemons) + # Creating configuration from JSON build_config_from_json(tgen, topo) diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_lan.py b/tests/topotests/ospf_basic_functionality/test_ospf_lan.py index f1c24ae50d..968cb608e8 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_lan.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_lan.py @@ -55,6 +55,7 @@ from lib.common_config import ( shutdown_bringup_interface, stop_router, start_router, + topo_daemons ) from lib.bgp import verify_bgp_convergence, create_router_bgp from lib.topolog import logger @@ -141,9 +142,12 @@ def setup_module(mod): tgen = Topogen(CreateTopo, mod.__name__) # ... and here it calls Mininet initialization functions. + # get list of daemons needs to be started for this suite. + daemons = topo_daemons(tgen, topo) + # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers - start_topology(tgen) + start_topology(tgen, daemons) # Creating configuration from JSON build_config_from_json(tgen, topo) diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py b/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py index 557549db71..ff4399f19e 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py @@ -44,6 +44,7 @@ from lib.common_config import ( create_route_maps, shutdown_bringup_interface, create_interfaces_cfg, + topo_daemons ) from ipaddress import IPv4Address from lib.topogen import Topogen, get_topogen @@ -138,9 +139,13 @@ def setup_module(mod): tgen = Topogen(CreateTopo, mod.__name__) # ... and here it calls Mininet initialization functions. + # get list of daemons needs to be started for this suite. + daemons = topo_daemons(tgen, topo) + # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers - start_topology(tgen) + start_topology(tgen, daemons) + # Creating configuration from JSON build_config_from_json(tgen, topo) diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py b/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py index ee7acf535d..6ebc74a013 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py @@ -52,6 +52,7 @@ from lib.common_config import ( step, create_route_maps, verify_prefix_lists, + topo_daemons ) from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json @@ -150,9 +151,12 @@ def setup_module(mod): tgen = Topogen(CreateTopo, mod.__name__) # ... and here it calls Mininet initialization functions. + # get list of daemons needs to be started for this suite. + daemons = topo_daemons(tgen, topo) + # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers - start_topology(tgen) + start_topology(tgen, daemons) # Creating configuration from JSON build_config_from_json(tgen, topo) diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py b/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py index a46fa6fcce..5e0e35854e 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py @@ -50,6 +50,7 @@ from lib.common_config import ( create_static_routes, step, shutdown_bringup_interface, + topo_daemons ) from lib.bgp import verify_bgp_convergence, create_router_bgp from lib.topolog import logger @@ -136,9 +137,12 @@ def setup_module(mod): tgen = Topogen(CreateTopo, mod.__name__) # ... and here it calls Mininet initialization functions. + # get list of daemons needs to be started for this suite. + daemons = topo_daemons(tgen, topo) + # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers - start_topology(tgen) + start_topology(tgen, daemons) # Creating configuration from JSON build_config_from_json(tgen, topo) diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py b/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py index 29f61827f9..b70c25ff1e 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py @@ -53,6 +53,7 @@ from lib.common_config import ( create_route_maps, shutdown_bringup_interface, create_interfaces_cfg, + topo_daemons ) from lib.topolog import logger from lib.topojson import build_topo_from_json, build_config_from_json @@ -134,9 +135,12 @@ def setup_module(mod): tgen = Topogen(CreateTopo, mod.__name__) # ... and here it calls Mininet initialization functions. + # get list of daemons needs to be started for this suite. + daemons = topo_daemons(tgen, topo) + # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers - start_topology(tgen) + start_topology(tgen, daemons) # Creating configuration from JSON build_config_from_json(tgen, topo) -- 2.39.5