]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: move redistribute function into lib 7837/head
authorckishimo <carles.kishimoto@gmail.com>
Fri, 8 Jan 2021 15:10:38 +0000 (16:10 +0100)
committerckishimo <carles.kishimoto@gmail.com>
Tue, 12 Jan 2021 10:18:22 +0000 (11:18 +0100)
Signed-off-by: ckishimo <carles.kishimoto@gmail.com>
tests/topotests/lib/ospf.py
tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py
tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py
tests/topotests/ospf_basic_functionality/test_ospf_lan.py
tests/topotests/ospf_basic_functionality/test_ospf_nssa.py
tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py
tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py

index 966c7f4214f5624f45693b293fd80f43c9769ed2..3e368cd7d3de3c1865d28c598cc4353adb9714b1 100644 (file)
@@ -462,6 +462,32 @@ def clear_ospf(tgen, router):
     logger.debug("Exiting lib API: clear_ospf()")
 
 
+def redistribute_ospf(tgen, topo, dut, route_type, **kwargs):
+    """
+    Redstribution of routes inside ospf.
+
+    Parameters
+    ----------
+    * `tgen`: Topogen object
+    * `topo` : json file data
+    * `dut`: device under test
+    * `route_type`: "static" or "connected" or ....
+    * `kwargs`: pass extra information (see below)
+
+    Usage
+    -----
+    redistribute_ospf(tgen, topo, "r0", "static", delete=True)
+    redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4")
+    """
+
+    ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": route_type}]}}}
+    for k, v in kwargs.items():
+        ospf_red[dut]["ospf"]["redistribute"][0][k] = v
+
+    result = create_router_ospf(tgen, topo, ospf_red)
+    assert result is True, "Testcase : Failed \n Error: {}".format(result)
+
+
 ################################
 # Verification procs
 ################################
index 2494bf0a1ea26c124d901724e8ab6e7469180d48..441368e8fa040aa952b2e7aa0e924923b0347580 100644 (file)
@@ -65,6 +65,7 @@ from lib.ospf import (
     verify_ospf_rib,
     create_router_ospf,
     verify_ospf_interface,
+    redistribute_ospf,
 )
 
 topo = None
@@ -184,19 +185,6 @@ def teardown_module(mod):
     logger.info("=" * 40)
 
 
-def redistribute(dut, route_type, **kwargs):
-    """Local def for redstribution of routes inside ospf."""
-    global topo
-    tgen = get_topogen()
-
-    ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": route_type}]}}}
-    for k, v in kwargs.items():
-        ospf_red[dut]["ospf"]["redistribute"][0][k] = v
-
-    result = create_router_ospf(tgen, topo, ospf_red)
-    assert result is True, "Testcase : Failed \n Error: {}".format(result)
-
-
 # ##################################
 # Test cases start here.
 # ##################################
@@ -245,7 +233,7 @@ def test_ospf_ecmp_tc16_p0(request):
     assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
 
     dut = "r0"
-    redistribute(dut, "static")
+    redistribute_ospf(tgen, topo, dut, "static")
 
     step("Verify that route in R2 in stalled with 8 next hops.")
     nh = []
@@ -326,7 +314,7 @@ def test_ospf_ecmp_tc16_p0(request):
     step(" Un configure static route on R0")
 
     dut = "r0"
-    redistribute(dut, "static", delete=True)
+    redistribute_ospf(tgen, topo, dut, "static", delete=True)
 
     # Wait for R0 to flush external LSAs.
     sleep(10)
@@ -357,7 +345,7 @@ def test_ospf_ecmp_tc16_p0(request):
 
     step("Re configure the static route in R0.")
     dut = "r0"
-    redistribute(dut, "static")
+    redistribute_ospf(tgen, topo, dut, "static")
 
     dut = "r1"
     result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
@@ -412,7 +400,7 @@ def test_ospf_ecmp_tc17_p0(request):
     assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
 
     dut = "r0"
-    redistribute(dut, "static")
+    redistribute_ospf(tgen, topo, dut, "static")
 
     step("Verify that route in R2 in stalled with 2 next hops.")
 
@@ -431,7 +419,7 @@ def test_ospf_ecmp_tc17_p0(request):
     step(" Un configure static route on R0")
 
     dut = "r0"
-    redistribute(dut, "static", delete=True)
+    redistribute_ospf(tgen, topo, dut, "static", delete=True)
     # sleep till the route gets withdrawn
     sleep(10)
 
@@ -461,7 +449,7 @@ def test_ospf_ecmp_tc17_p0(request):
 
     step("Reconfigure the static route in R0.Change ECMP value to 2.")
     dut = "r0"
-    redistribute(dut, "static")
+    redistribute_ospf(tgen, topo, dut, "static")
 
     step("Configure cost on R0 as 100")
     r0_ospf_cost = {"r0": {"links": {"r1": {"ospf": {"cost": 100}}}}}
index f8752f3543b39d0164ac19b868bcacd5ef5f8a4a..2da1dcd21ab53a0a0abd14c824b02c263bb37b84 100644 (file)
@@ -66,6 +66,7 @@ from lib.ospf import (
     verify_ospf_rib,
     create_router_ospf,
     verify_ospf_interface,
+    redistribute_ospf,
 )
 from ipaddress import IPv4Address
 
@@ -187,19 +188,6 @@ def teardown_module():
         pass
 
 
-def redistribute(dut, route_type, **kwargs):
-    """Local def for redstribution of routes inside ospf."""
-    global topo
-    tgen = get_topogen()
-
-    ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": route_type}]}}}
-    for k, v in kwargs.items():
-        ospf_red[dut]["ospf"]["redistribute"][0][k] = v
-
-    result = create_router_ospf(tgen, topo, ospf_red)
-    assert result is True, "Testcase : Failed \n Error: {}".format(result)
-
-
 # ##################################
 # Test cases start here.
 # ##################################
@@ -252,7 +240,7 @@ def test_ospf_lan_ecmp_tc18_p0(request):
         )
 
         dut = rtr
-        redistribute(dut, "static")
+        redistribute_ospf(tgen, topo, dut, "static")
 
     step(
         "Verify that route in R0 in stalled with 8 hops. "
index 331f48bdea56b6e0ebe7cf3aa71d7cf95831fcd5..dac32090bcc7136c39d9a642d1d50928631d91d2 100644 (file)
@@ -183,19 +183,6 @@ def teardown_module():
         pass
 
 
-def redistribute(dut, route_type, **kwargs):
-    """Local def for redstribution of routes inside ospf."""
-    global topo
-    tgen = get_topogen()
-
-    ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": route_type}]}}}
-    for k, v in kwargs.items():
-        ospf_red[dut]["ospf"]["redistribute"][0][k] = v
-
-    result = create_router_ospf(tgen, topo, ospf_red)
-    assert result is True, "Testcase : Failed \n Error: {}".format(result)
-
-
 # ##################################
 # Test cases start here.
 # ##################################
index 7ec80e4560f00c1155ec41177889490a4d8740f3..3644bff3dcaeff9839aec7acb8e9ec6aa2980716 100644 (file)
@@ -30,6 +30,7 @@ from lib.ospf import (
     verify_ospf_rib,
     create_router_ospf,
     verify_ospf_interface,
+    redistribute_ospf,
 )
 from lib.topojson import build_topo_from_json, build_config_from_json
 from lib.topolog import logger
@@ -181,19 +182,6 @@ def teardown_module(mod):
     logger.info("=" * 40)
 
 
-def redistribute(dut, route_type, **kwargs):
-    """Local def for redstribution of routes inside ospf."""
-    global topo
-    tgen = get_topogen()
-
-    ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": route_type}]}}}
-    for k, v in kwargs.items():
-        ospf_red[dut]["ospf"]["redistribute"][0][k] = v
-
-    result = create_router_ospf(tgen, topo, ospf_red)
-    assert result is True, "Testcase : Failed \n Error: {}".format(result)
-
-
 # ##################################
 # Test cases start here.
 # ##################################
@@ -249,7 +237,7 @@ def test_ospf_learning_tc15_p0(request):
 
     step("Redistribute static route in R2 ospf.")
     dut = "r2"
-    redistribute(dut, "static")
+    redistribute_ospf(tgen, topo, dut, "static")
 
     step("Verify that Type 5 LSA is originated by R2.")
     dut = "r0"
index b6a13cbe5bb066a05016ab0606bb9f8500b0ae4a..ceadb3975b0895d945de2a186d32bef096e5cb6c 100644 (file)
@@ -62,6 +62,7 @@ from lib.ospf import (
     verify_ospf_rib,
     create_router_ospf,
     verify_ospf_database,
+    redistribute_ospf,
 )
 
 # Global variables
@@ -193,19 +194,6 @@ def teardown_module(mod):
     logger.info("=" * 40)
 
 
-def redistribute(dut, route_type, **kwargs):
-    """Local def for redstribution of routes inside ospf."""
-    global topo
-    tgen = get_topogen()
-
-    ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": route_type}]}}}
-    for k, v in kwargs.items():
-        ospf_red[dut]["ospf"]["redistribute"][0][k] = v
-
-    result = create_router_ospf(tgen, topo, ospf_red)
-    assert result is True, "Testcase : Failed \n Error: {}".format(result)
-
-
 # ##################################
 # Test cases start here.
 # ##################################
@@ -239,7 +227,7 @@ def test_ospf_routemaps_functionality_tc19_p0(request):
     result = create_static_routes(tgen, input_dict)
     assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
 
-    redistribute("r0", "static")
+    redistribute_ospf(tgen, topo, "r0", "static")
 
     dut = "r1"
     lsid = NETWORK["ipv4"][0].split("/")[0]
@@ -251,7 +239,7 @@ def test_ospf_routemaps_functionality_tc19_p0(request):
     result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
     assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
 
-    redistribute("r0", "static", delete=True)
+    redistribute_ospf(tgen, topo, "r0", "static", delete=True)
 
     step(
         "Create prefix-list in R0 to permit 10.0.20.1/32 prefix &" " deny 10.0.20.2/32"
@@ -298,7 +286,7 @@ def test_ospf_routemaps_functionality_tc19_p0(request):
         " ospf using route map rmap1"
     )
 
-    redistribute("r0", "static", route_map="rmap_ipv4")
+    redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4")
 
     step("Change prefix rules to permit 10.0.20.2 and deny 10.0.20.1")
     # Create ip prefix list
@@ -492,7 +480,7 @@ def test_ospf_routemaps_functionality_tc20_p0(request):
     assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
 
     step("Redistribute to ospf using route map ( non existent route map)")
-    redistribute("r0", "static", route_map="rmap_ipv4")
+    redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4")
 
     step(
         "Verify that routes are not allowed in OSPF even tough no "
@@ -622,7 +610,7 @@ def test_ospf_routemaps_functionality_tc21_p0(request):
     result = create_static_routes(tgen, input_dict)
     assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
 
-    redistribute("r0", "static", route_map="rmap_ipv4")
+    redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4")
 
     # Create route map
     routemaps = {
@@ -858,7 +846,7 @@ def test_ospf_routemaps_functionality_tc24_p0(request):
     result = create_static_routes(tgen, input_dict)
     assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
 
-    redistribute("r0", "static", route_map="rmap_ipv4")
+    redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4")
 
     # Create ip prefix list
     pfx_list = {
index fd2da830644df8e7549a0a2efddfa730c0377051..5aa2779aee5a8e99adcea8bec9d92a9940c57699 100644 (file)
@@ -61,6 +61,7 @@ from lib.ospf import (
     clear_ospf,
     verify_ospf_rib,
     create_router_ospf,
+    redistribute_ospf,
 )
 
 # Global variables
@@ -183,19 +184,6 @@ def teardown_module(mod):
     logger.info("=" * 40)
 
 
-def redistribute(dut, route_type, **kwargs):
-    """Local def for redstribution of routes inside ospf."""
-    global topo
-    tgen = get_topogen()
-
-    ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": route_type}]}}}
-    for k, v in kwargs.items():
-        ospf_red[dut]["ospf"]["redistribute"][0][k] = v
-
-    result = create_router_ospf(tgen, topo, ospf_red)
-    assert result is True, "Testcase : Failed \n Error: {}".format(result)
-
-
 # ##################################
 # Test cases start here.
 # ##################################
@@ -463,8 +451,8 @@ def test_ospf_redistribution_tc8_p1(request):
         "advertised/exchaged via ospf"
     )
     for rtr in topo["routers"]:
-        redistribute(rtr, "static")
-        redistribute(rtr, "connected")
+        redistribute_ospf(tgen, topo, rtr, "static")
+        redistribute_ospf(tgen, topo, rtr, "connected")
     for node in topo["routers"]:
         input_dict = {
             "r0": {
@@ -521,7 +509,7 @@ def test_ospf_redistribution_tc8_p1(request):
     )
 
     for rtr in topo["routers"]:
-        redistribute(rtr, "static", delete=True)
+        redistribute_ospf(tgen, topo, rtr, "static", delete=True)
 
     input_dict = {
         "r0": {