]> git.proxmox.com Git - mirror_frr.git/blobdiff - tests/topotests/bgp_prefix_list_topo1/test_prefix_lists.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / bgp_prefix_list_topo1 / test_prefix_lists.py
index 10dee0f77bea4f4c4ebb7ec79714b74b1775de01..f351dde7453f07af4a04adcbb134fa4adca244ab 100644 (file)
@@ -1,24 +1,11 @@
 #!/usr/bin/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.
-#
 
 """
 Following tests are covered to test prefix-list functionality:
@@ -44,7 +31,6 @@ IP prefix-list tests
 """
 
 import sys
-import json
 import time
 import os
 import pytest
@@ -55,7 +41,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
@@ -71,39 +56,16 @@ from lib.common_config import (
 )
 from lib.topolog import logger
 from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify
-from lib.topojson import build_topo_from_json, build_config_from_json
-
-pytestmark = [pytest.mark.bgpd]
+from lib.topojson import build_config_from_json
 
 
-# Reading the data from JSON File for topology creation
-jsonFile = "{}/prefix_lists.json".format(CWD)
+pytestmark = [pytest.mark.bgpd]
 
-try:
-    with open(jsonFile, "r") as topoJson:
-        topo = json.load(topoJson)
-except IOError:
-    assert False, "Could not read file {}".format(jsonFile)
 
 # Global variables
 bgp_convergence = False
 
 
-class BGPPrefixListTopo(Topo):
-    """
-    Test BGPPrefixListTopo - 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
@@ -118,11 +80,14 @@ def setup_module(mod):
     logger.info("Running setup_module to create topology")
 
     # This function initiates the topology build with Topogen...
-    tgen = Topogen(BGPPrefixListTopo, mod.__name__)
+    json_file = "{}/prefix_lists.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
@@ -368,9 +333,12 @@ def test_ip_prefix_lists_out_permit(request):
     result = verify_rib(
         tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
     )
-    assert (
-        result is not True
-    ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name)
+    assert result is not True, (
+        "Testcase {} : Failed \n "
+        "Expected: Routes should not be present in {} FIB \n "
+        "Found: {}".format(tc_name, dut, result)
+    )
+
     write_test_footer(tc_name)
 
 
@@ -466,9 +434,11 @@ def test_ip_prefix_lists_in_deny_and_permit_any(request):
     result = verify_rib(
         tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
     )
-    assert (
-        result is not True
-    ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name)
+    assert result is not True, (
+        "Testcase {} : Failed \n "
+        "Expected: Routes should not be present in {} BGP RIB \n "
+        "Found: {}".format(tc_name, dut, result)
+    )
 
     write_test_footer(tc_name)
 
@@ -666,9 +636,12 @@ def test_ip_prefix_lists_out_deny_and_permit_any(request):
     result = verify_rib(
         tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
     )
-    assert (
-        result is not True
-    ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name)
+    assert result is not True, (
+        "Testcase {} : Failed \n "
+        "Expected: Routes should not be present in {} BGP RIB \n "
+        "Found: {}".format(tc_name, dut, result)
+    )
+
     write_test_footer(tc_name)
 
 
@@ -800,9 +773,11 @@ def test_modify_prefix_lists_in_permit_to_deny(request):
     result = verify_rib(
         tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
     )
-    assert (
-        result is not True
-    ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name)
+    assert result is not True, (
+        "Testcase {} : Failed \n "
+        "Expected: Routes should not be present in {} BGP RIB \n "
+        "Found: {}".format(tc_name, dut, result)
+    )
 
     write_test_footer(tc_name)
 
@@ -904,9 +879,11 @@ def test_modify_prefix_lists_in_deny_to_permit(request):
     result = verify_rib(
         tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
     )
-    assert (
-        result is not True
-    ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name)
+    assert result is not True, (
+        "Testcase {} : Failed \n "
+        "Expected: Routes should not be present in {} BGP RIB \n "
+        "Found: {}".format(tc_name, dut, result)
+    )
 
     # Modify  ip prefix list
     input_dict_1 = {
@@ -1073,9 +1050,11 @@ def test_modify_prefix_lists_out_permit_to_deny(request):
     result = verify_rib(
         tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
     )
-    assert (
-        result is not True
-    ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name)
+    assert result is not True, (
+        "Testcase {} : Failed \n "
+        "Expected: Routes should not be present in {} BGP RIB \n "
+        "Found: {}".format(tc_name, dut, result)
+    )
 
     write_test_footer(tc_name)
 
@@ -1179,9 +1158,11 @@ def test_modify_prefix_lists_out_deny_to_permit(request):
     result = verify_rib(
         tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
     )
-    assert (
-        result is not True
-    ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name)
+    assert result is not True, (
+        "Testcase {} : Failed \n "
+        "Expected: Routes should not be present in {} BGP RIB \n "
+        "Found: {}".format(tc_name, dut, result)
+    )
 
     # Modify ip prefix list
     input_dict_1 = {
@@ -1346,9 +1327,11 @@ def test_ip_prefix_lists_implicit_deny(request):
     result = verify_rib(
         tgen, "ipv4", dut, input_dict_1, protocol=protocol, expected=False
     )
-    assert (
-        result is not True
-    ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name)
+    assert result is not True, (
+        "Testcase {} : Failed \n "
+        "Expected: Routes should not be present in {} BGP RIB \n "
+        "Found: {}".format(tc_name, dut, result)
+    )
 
     write_test_footer(tc_name)