]> git.proxmox.com Git - mirror_frr.git/blobdiff - tests/topotests/bgp_ecmp_topo3/test_ibgp_ecmp_topo3.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / bgp_ecmp_topo3 / test_ibgp_ecmp_topo3.py
index 5f3ac4e716815ed29bc4d4dffc4c3679a6ba4195..366cf3d4a5f520e79b8d177a0a059b84e1bebd48 100644 (file)
@@ -1,24 +1,11 @@
 #!/usr/bin/env python
+# SPDX-License-Identifier: ISC
 
 #
 # Copyright (c) 2019 by VMware, Inc. ("VMware")
 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
 # ("NetDEF") in this file.
 #
-# Permission to use, copy, modify, and/or distribute this software
-# for any purpose with or without fee is hereby granted, provided
-# that the above copyright notice and this permission notice appear
-# in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
-# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
-# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
-# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
-# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
-# OF THIS SOFTWARE.
-#
 
 
 """
@@ -28,8 +15,8 @@ Following tests are covered to test ecmp functionality on iBGP.
 import os
 import sys
 import time
-import json
 import pytest
+import re
 from time import sleep
 
 # Save the Current Working Directory to find configuration files.
@@ -40,38 +27,25 @@ sys.path.append(os.path.join(CWD, "../../"))
 # pylint: disable=C0413
 # Import topogen and topotest helpers
 from lib.topogen import Topogen, get_topogen
-from mininet.topo import Topo
 
 from lib.common_config import (
-    start_topology,
     write_test_header,
     write_test_footer,
     verify_rib,
     create_static_routes,
     check_address_types,
-    interface_status,
     reset_config_on_routers,
-    required_linux_kernel_version,
     shutdown_bringup_interface,
     apply_raw_config,
+    start_topology,
 )
 from lib.topolog import logger
-from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp
-from lib.topojson import build_topo_from_json, build_config_from_json
-
+from lib.topojson import build_config_from_json
+from lib.bgp import create_router_bgp, verify_bgp_convergence
 
 pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
 
 
-# Reading the data from JSON File for topology and configuration creation
-jsonFile = "{}/ibgp_ecmp_topo3.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
 NEXT_HOPS = {"ipv4": [], "ipv6": []}
 NETWORK = {"ipv4": "192.168.1.10/32", "ipv6": "fd00:0:0:1::10/128"}
@@ -79,41 +53,26 @@ NEXT_HOP_IP = {"ipv4": "10.0.0.1", "ipv6": "fd00::1"}
 BGP_CONVERGENCE = False
 
 
-class CreateTopo(Topo):
-    """
-    Test topology builder.
-
-    * `Topo`: Topology object
-    """
-
-    def build(self, *_args, **_opts):
-        """Build function."""
-        tgen = get_topogen(self)
-
-        # Building topology from json file
-        build_topo_from_json(tgen, topo)
-
-
 def setup_module(mod):
     """
     Sets up the pytest environment.
 
     * `mod`: module name
     """
-    global NEXT_HOPS, INTF_LIST_R3, INTF_LIST_R2, TEST_STATIC
     global ADDR_TYPES
 
     testsuite_run_time = time.asctime(time.localtime(time.time()))
     logger.info("Testsuite start time: {}".format(testsuite_run_time))
     logger.info("=" * 40)
 
-    logger.info("Running setup_module to create topology")
-
     # This function initiates the topology build with Topogen...
-    tgen = Topogen(CreateTopo, mod.__name__)
+    json_file = "{}/ibgp_ecmp_topo3.json".format(CWD)
+    tgen = Topogen(json_file, mod.__name__)
+    global topo
+    topo = tgen.json_topo
 
     # Starting topology, create tmp files which are loaded to routers
-    #  to start deamons and then start routers
+    #  to start daemons and then start routers
     start_topology(tgen)
 
     # Creating configuration from JSON
@@ -136,18 +95,7 @@ def setup_module(mod):
 
 
 def teardown_module():
-    """
-    Teardown the pytest environment.
-
-    * `mod`: module name
-    """
-
-    logger.info("Running teardown_module to delete topology")
-
-    tgen = get_topogen()
-
-    # Stop toplogy and Remove tmp files
-    tgen.stop_topology()
+    get_topogen().stop_topology()
 
 
 def static_or_nw(tgen, topo, tc_name, test_type, dut):
@@ -221,12 +169,11 @@ def static_or_nw(tgen, topo, tc_name, test_type, dut):
 
 
 @pytest.mark.parametrize("test_type", ["redist_static"])
-def test_ecmp_fast_convergence(request, test_type):
+def test_ecmp_fast_convergence(request, test_type, tgen, topo):
     """This test is to verify bgp fast-convergence cli functionality"""
 
     tc_name = request.node.name
     write_test_header(tc_name)
-    tgen = get_topogen()
 
     # Verifying RIB routes
     dut = "r3"
@@ -272,25 +219,36 @@ def test_ecmp_fast_convergence(request, test_type):
     shutdown_bringup_interface(tgen, "r2", intf1, True)
     shutdown_bringup_interface(tgen, "r2", intf2, True)
 
+    logger.info("Ensure that the links are still up")
+    result = verify_bgp_convergence(tgen, topo)
+
     logger.info("Enable bgp fast-convergence cli")
     raw_config = {
-       "r2": {
-          "raw_config": [
-            "router bgp {}".format(topo["routers"]["r2"]["bgp"]["local_as"]),
-            "bgp fast-convergence",
-          ]
-       }
+        "r2": {
+            "raw_config": [
+                "router bgp {}".format(topo["routers"]["r2"]["bgp"]["local_as"]),
+                "bgp fast-convergence",
+            ]
+        }
     }
     result = apply_raw_config(tgen, raw_config)
     assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
 
+    logger.info("Ensure BGP has processed the cli")
+    r2 = tgen.gears["r2"]
+    output = r2.vtysh_cmd("show run")
+    verify = re.search(r"fast-convergence", output)
+    assert verify is not None, "r2 does not have the fast convergence command yet"
+
     logger.info("Shutdown one link b/w r2 and r3")
     shutdown_bringup_interface(tgen, "r2", intf1, False)
 
     logger.info("Verify bgp neighbors goes down immediately")
     result = verify_bgp_convergence(tgen, topo, dut="r2", expected=False)
-    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
-        tc_name, result
+    assert result is not True, (
+        "Testcase {} : Failed \n "
+        "Expected: BGP should not be converged for {} \n "
+        "Found: {}".format(tc_name, "r2", result)
     )
 
     logger.info("Shutdown second link b/w r2 and r3")
@@ -298,8 +256,10 @@ def test_ecmp_fast_convergence(request, test_type):
 
     logger.info("Verify bgp neighbors goes down immediately")
     result = verify_bgp_convergence(tgen, topo, dut="r2", expected=False)
-    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
-        tc_name, result
+    assert result is not True, (
+        "Testcase {} : Failed \n "
+        "Expected: BGP should not be converged for {} \n "
+        "Found: {}".format(tc_name, "r2", result)
     )
 
     write_test_footer(tc_name)