]> git.proxmox.com Git - mirror_frr.git/blobdiff - tests/topotests/bgp_communities_topo1/test_bgp_communities.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / bgp_communities_topo1 / test_bgp_communities.py
index f2e54b24d6bc57b38b5f409c01b07397edf6402f..f3e03a06af3b3cfd36350dfe465a7371a5bd353b 100644 (file)
@@ -1,24 +1,11 @@
 #!/usr/bin/python
+# SPDX-License-Identifier: ISC
 
 #
 # Copyright (c) 2020 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.
-#
 
 """
 Following tests are covered to test bgp community functionality:
@@ -29,7 +16,6 @@ Following tests are covered to test bgp community functionality:
 import os
 import sys
 import time
-import json
 import pytest
 
 # Save the Current Working Directory to find configuration files.
@@ -38,7 +24,6 @@ sys.path.append(os.path.join(CWD, "../"))
 
 # pylint: disable=C0413
 # Import topogen and topotest helpers
-from mininet.topo import Topo
 from lib.topogen import Topogen, get_topogen
 
 # Import topoJson from lib, to create topology and initial configuration
@@ -60,19 +45,13 @@ from lib.topolog import logger
 from lib.bgp import (
     verify_bgp_convergence,
     create_router_bgp,
-    clear_bgp_and_verify,
     verify_bgp_rib,
 )
-from lib.topojson import build_topo_from_json, build_config_from_json
+from lib.topojson import build_config_from_json
 from copy import deepcopy
 
-# Reading the data from JSON File for topology creation
-jsonFile = "{}/bgp_communities.json".format(CWD)
-try:
-    with open(jsonFile, "r") as topoJson:
-        topo = json.load(topoJson)
-except IOError:
-    assert False, "Could not read file {}".format(jsonFile)
+pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
+
 
 # Global variables
 BGP_CONVERGENCE = False
@@ -81,21 +60,6 @@ NETWORK = {"ipv4": "2.2.2.2/32", "ipv6": "22:22::2/128"}
 NEXT_HOP_IP = {}
 
 
-class BGPCOMMUNITIES(Topo):
-    """
-    Test BGPCOMMUNITIES - topology 1
-
-    * `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
@@ -106,7 +70,7 @@ def setup_module(mod):
     # Required linux kernel version for this suite to run.
     result = required_linux_kernel_version("4.15")
     if result is not True:
-        pytest.skip("Kernel requirements are not met")
+        pytest.skip("Kernel requirements are not met, kernel version should be >= 4.15")
 
     testsuite_run_time = time.asctime(time.localtime(time.time()))
     logger.info("Testsuite start time: {}".format(testsuite_run_time))
@@ -115,11 +79,14 @@ def setup_module(mod):
     logger.info("Running setup_module to create topology")
 
     # This function initiates the topology build with Topogen...
-    tgen = Topogen(BGPCOMMUNITIES, mod.__name__)
+    json_file = "{}/bgp_communities.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
-    #  to start deamons and then start routers
+    #  to start daemons and then start routers
     start_topology(tgen)
 
     # Creating configuration from JSON
@@ -337,14 +304,19 @@ def test_bgp_no_advertise_community_p0(request):
         )
 
         result = verify_bgp_rib(tgen, addr_type, dut, input_dict, expected=False)
-        assert result is not True, "Testcase {} : Failed \n "
-        " Routes still present in R3 router. Error: {}".format(tc_name, result)
+        assert result is not True, (
+            "Testcase {} : Failed \n Expected: "
+            "Routes still present in {} router. Found: {}".format(tc_name, dut, result)
+        )
 
         result = verify_rib(
             tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
         )
-        assert result is not True, "Testcase {} : Failed \n "
-        " Routes still present in R3 router. Error: {}".format(tc_name, result)
+        assert (
+            result is not True
+        ), "Testcase {} : Failed \n  Expected: Routes still present in {} router. Found: {}".format(
+            tc_name, dut, result
+        )
 
         step("Remove and Add no advertise community")
         # Configure neighbor for route map
@@ -389,12 +361,18 @@ def test_bgp_no_advertise_community_p0(request):
         )
 
         result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
-        assert result is True, "Testcase {} : Failed \n "
-        " Routes still present in R3 router. Error: {}".format(tc_name, result)
+        assert (
+            result is True
+        ), "Testcase {} : Failed \n  Routes still present in R3 router. Error: {}".format(
+            tc_name, result
+        )
 
         result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
-        assert result is True, "Testcase {} : Failed \n "
-        " Routes still present in R3 router. Error: {}".format(tc_name, result)
+        assert (
+            result is True
+        ), "Testcase {} : Failed \n  Routes still present in R3 router. Error: {}".format(
+            tc_name, result
+        )
 
     step("Repeat above steps when IBGP nbr configured between R1, R2 & R2, R3")
     topo1 = deepcopy(topo)
@@ -576,12 +554,18 @@ def test_bgp_no_advertise_community_p0(request):
         )
 
         result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
-        assert result is True, "Testcase {} : Failed \n "
-        " Routes still present in R3 router. Error: {}".format(tc_name, result)
+        assert (
+            result is True
+        ), "Testcase {} : Failed \n  Routes still present in R3 router. Error: {}".format(
+            tc_name, result
+        )
 
         result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
-        assert result is True, "Testcase {} : Failed \n "
-        " Routes still present in R3 router. Error: {}".format(tc_name, result)
+        assert (
+            result is True
+        ), "Testcase {} : Failed \n  Routes still present in R3 router. Error: {}".format(
+            tc_name, result
+        )
 
         step("Remove and Add no advertise community")
         # Configure neighbor for route map
@@ -626,12 +610,18 @@ def test_bgp_no_advertise_community_p0(request):
         )
 
         result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
-        assert result is True, "Testcase {} : Failed \n "
-        " Routes still present in R3 router. Error: {}".format(tc_name, result)
+        assert (
+            result is True
+        ), "Testcase {} : Failed \n  Routes still present in R3 router. Error: {}".format(
+            tc_name, result
+        )
 
         result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
-        assert result is True, "Testcase {} : Failed \n "
-        " Routes still present in R3 router. Error: {}".format(tc_name, result)
+        assert (
+            result is True
+        ), "Testcase {} : Failed \n  Routes still present in R3 router. Error: {}".format(
+            tc_name, result
+        )
 
     write_test_footer(tc_name)