]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: [topojson]Enhance lib/topojson.py to support PIM automation 7820/head
authorkuldeepkash <kashyapk@vmware.com>
Wed, 6 Jan 2021 05:13:05 +0000 (05:13 +0000)
committerkuldeepkash <kashyapk@vmware.com>
Wed, 6 Jan 2021 05:13:05 +0000 (05:13 +0000)
1. Enhanced lib/topojson.py for creating topologies with switches and routers
2. Ran it through (black) for expected formatting

Signed-off-by: kuldeepkash <kashyapk@vmware.com>
tests/topotests/lib/topojson.py

index 0e59f90a20a3878212c2e628259074e6255cde5a..88e6f78b922a71dc405b38ca5c4215f339b9acf3 100644 (file)
@@ -43,6 +43,7 @@ from lib.common_config import (
     create_vrf_cfg,
 )
 
+from lib.pim import create_pim_config, create_igmp_config
 from lib.bgp import create_router_bgp
 from lib.ospf import create_router_ospf
 
@@ -68,20 +69,18 @@ def build_topo_from_json(tgen, topo):
             topo["switches"].keys(), key=lambda x: int(re_search("\d+", x).group(0))
         )
 
-    listRouters = ROUTER_LIST[:]
-    listSwitches = SWITCH_LIST[:]
+    listRouters = sorted(ROUTER_LIST[:])
+    listSwitches = sorted(SWITCH_LIST[:])
     listAllRouters = deepcopy(listRouters)
     dictSwitches = {}
 
     for routerN in ROUTER_LIST:
         logger.info("Topo: Add router {}".format(routerN))
         tgen.add_router(routerN)
-        listRouters.append(routerN)
 
     for switchN in SWITCH_LIST:
         logger.info("Topo: Add switch {}".format(switchN))
         dictSwitches[switchN] = tgen.add_switch(switchN)
-        listSwitches.append(switchN)
 
     if "ipv4base" in topo:
         ipv4Next = ipaddress.IPv4Address(topo["link_ip_start"]["ipv4"])
@@ -101,18 +100,8 @@ def build_topo_from_json(tgen, topo):
         curRouter = listRouters.pop(0)
         # Physical Interfaces
         if "links" in topo["routers"][curRouter]:
-
-            def link_sort(x):
-                if x == "lo":
-                    return 0
-                elif "link" in x:
-                    return int(x.split("-link")[1])
-                else:
-                    return int(re_search("\d+", x).group(0))
-
             for destRouterLink, data in sorted(
-                topo["routers"][curRouter]["links"].items(),
-                key=lambda x: link_sort(x[0]),
+                topo["routers"][curRouter]["links"].iteritems()
             ):
                 currRouter_lo_json = topo["routers"][curRouter]["links"][destRouterLink]
                 # Loopback interfaces
@@ -321,6 +310,8 @@ def build_config_from_json(tgen, topo, save_bkup=True):
             ("prefix_lists", create_prefix_lists),
             ("bgp_community_list", create_bgp_community_lists),
             ("route_maps", create_route_maps),
+            ("pim", create_pim_config),
+            ("igmp", create_igmp_config),
             ("bgp", create_router_bgp),
             ("ospf", create_router_ospf),
         ]