]> git.proxmox.com Git - mirror_frr.git/blobdiff - tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py
Merge pull request #13060 from opensourcerouting/feature/allow_peering_with_127.0.0.1
[mirror_frr.git] / tests / topotests / static_routing_with_ibgp / test_static_routes_topo4_ibgp.py
index a82ee64538b6aee722ce949d33ceaf1ca971a35f..03782409593eb1b2fa734e3767bcc04e46db7b9d 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.
-#
 
 """
 
@@ -29,7 +16,6 @@ Following tests are covered in the script.
 """
 
 import sys
-import json
 import time
 import os
 import pytest
@@ -43,7 +29,6 @@ sys.path.append(os.path.join(CWD, "../"))
 sys.path.append(os.path.join(CWD, "../lib/"))
 # pylint: disable=C0413
 # Import topogen and topotest helpers
-from mininet.topo import Topo
 from lib.topogen import Topogen, get_topogen
 
 from lib.common_config import (
@@ -56,7 +41,6 @@ from lib.common_config import (
     step,
     create_prefix_lists,
     create_route_maps,
-    create_interfaces_cfg,
     verify_prefix_lists,
     verify_route_maps,
 )
@@ -67,16 +51,9 @@ from lib.bgp import (
     clear_bgp_and_verify,
     clear_bgp,
 )
-from lib.topojson import build_topo_from_json, build_config_from_json
+from lib.topojson import build_config_from_json
 from lib.topotest import version_cmp
 
-# Reading the data from JSON File for topology creation
-jsonFile = "{}/static_routes_topo4_ibgp.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
 BGP_CONVERGENCE = False
@@ -87,27 +64,11 @@ NEXT_HOP_IP = {}
 pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
 
 
-class CreateTopo(Topo):
-    """
-    Test CreateTopo - 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):
     """
     Set up the pytest environment.
     * `mod`: module name
     """
-    global topo
     testsuite_run_time = time.asctime(time.localtime(time.time()))
     logger.info("Testsuite start time: {}".format(testsuite_run_time))
     logger.info("=" * 40)
@@ -115,11 +76,14 @@ def setup_module(mod):
     logger.info("Running setup_module to create topology")
 
     # This function initiates the topology build with Topogen...
-    tgen = Topogen(CreateTopo, mod.__name__)
+    json_file = "{}/static_routes_topo4_ibgp.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
@@ -198,7 +162,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
     )
 
     for addr_type in ADDR_TYPES:
-        # Api call to modfiy BGP timerse
+        # Api call to modify BGP timerse
         input_dict = {
             "r2": {
                 "bgp": {
@@ -236,12 +200,12 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
         )
         clear_bgp(tgen, addr_type, "r2")
 
-    step(" All BGP nbrs are down as authentication is mismatch on both" " the sides")
+    step(" All BGP nbrs are down as authentication is mismatch on both  the sides")
 
     bgp_convergence = verify_bgp_convergence(tgen, topo, expected=False)
     assert (
         bgp_convergence is not True
-    ), "Testcase {} : " "Failed \n BGP nbrs must be down. Error: {}".format(
+    ), "Testcase {} :  Failed \n BGP nbrs must be down. Error: {}".format(
         tc_name, bgp_convergence
     )
 
@@ -288,7 +252,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
 
     step("All BGP nbrs are up as authentication is matched now")
     bgp_convergence = verify_bgp_convergence(tgen, topo)
-    assert bgp_convergence is True, "Testcase {} : Failed \n " "Error: {}".format(
+    assert bgp_convergence is True, "Testcase {} : Failed \n  Error: {}".format(
         tc_name, bgp_convergence
     )
 
@@ -338,7 +302,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
             "show ip prefix list"
         )
         result = verify_prefix_lists(tgen, input_dict_2)
-        assert result is not True, "Testcase {} : Failed \n" " Error: {}".format(
+        assert result is not True, "Testcase {} : Failed \n  Error: {}".format(
             tc_name, result
         )
 
@@ -441,7 +405,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
             tc_name, result
         )
 
-        step("Apply prefix list P1 on BGP neighbors 1 2 3 4 connected from " "frr r1")
+        step("Apply prefix list P1 on BGP neighbors 1 2 3 4 connected from  frr r1")
         # Configure prefix list to bgp neighbor
         input_dict_4 = {
             "r2": {
@@ -955,7 +919,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
         )
         assert (
             result4 is not True
-        ), "Testcase {} : Failed \n" "routes are still present \n Error: {}".format(
+        ), "Testcase {} : Failed \n routes are still present \n Error: {}".format(
             tc_name, result4
         )