#!/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 recursive route and ebgp
import os
import sys
import time
-import json
import pytest
from time import sleep
-from copy import deepcopy
# Save the Current Working Directory to find configuration files.
CWD = os.path.dirname(os.path.realpath(__file__))
# pylint: disable=C0413
# Import topogen and topotest helpers
-from lib import topotest
-from mininet.topo import Topo
from lib.topogen import Topogen, get_topogen
# Import topoJson from lib, to create topology and initial configuration
create_route_maps,
create_interface_in_kernel,
shutdown_bringup_interface,
- addKernelRoute,
- delete_route_maps,
)
from lib.topolog import logger
from lib.bgp import (
verify_bgp_convergence,
create_router_bgp,
- clear_bgp_and_verify,
verify_bgp_rib,
verify_bgp_convergence_from_running_config,
modify_as_number,
verify_bgp_attributes,
clear_bgp,
)
-from lib.topojson import build_topo_from_json, build_config_from_json
+from lib.topojson import build_config_from_json
pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
-# Reading the data from JSON File for topology and configuration creation
-jsonFile = "{}/bgp_recursive_route_ebgp_multi_hop.json".format(CWD)
-try:
- with open(jsonFile, "r") as topoJson:
- topo = json.load(topoJson)
-except IOError:
- logger.info("Could not read file:", jsonFile)
-
# Global variables
BGP_CONVERGENCE = False
KEEP_ALIVE_TIMER = 2
}
-class CreateTopo(Topo):
- """
- Test BasicTopo - 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
logger.info("Running setup_module to create topology")
# This function initiates the topology build with Topogen...
- tgen = Topogen(CreateTopo, mod.__name__)
+ json_file = "{}/bgp_recursive_route_ebgp_multi_hop.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
input_dict_4,
next_hop=topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0],
)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)
}
}
result = create_static_routes(tgen, input_dict_3)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)
next_hop=topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0],
protocol="bgp",
)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)
}
}
result = create_static_routes(tgen, input_dict_3)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)
}
}
result = create_static_routes(tgen, input_dict_3)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)
next_hop=topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0],
protocol="bgp",
)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)
}
}
result = create_static_routes(tgen, input_dict_4)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)
}
}
result = create_static_routes(tgen, input_dict_4)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)
input_dict_4,
next_hop=topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)
input_dict_4,
next_hop=topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)
result = verify_rib(
tc_name, result
)
- step("Toggle the interface on R3(ifconfig 192.34).")
+ step("Toggle the interface on R3.")
intf_r3_r4 = topo["routers"]["r3"]["links"]["r4"]["interface"]
shutdown_bringup_interface(tgen, "r3", intf_r3_r4)
tc_name, result
)
- step("Toggle the interface on R4(ifconfig 192.34).")
+ step("Toggle the interface on R4.")
intf_r4_r3 = topo["routers"]["r4"]["links"]["r3"]["interface"]
shutdown_bringup_interface(tgen, "r4", intf_r4_r3)
topo["routers"]["r3"]["links"]["r4"][addr_type].split("/")[0],
],
)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)
rmap_name="rmap_pf",
input_dict=input_dict_4,
)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)
rmap_name="rmap_pf",
input_dict=input_dict_4,
)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)
input_dict=input_dict_4,
nexthop=None,
)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)
topo["routers"]["r3"]["links"]["r4"][addr_type].split("/")[0],
],
)
- assert result is True, "Testcase : Failed \n Error : {}".format(
+ assert result is True, "Testcase {}: Failed \n Error : {}".format(
tc_name, result
)