]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/example_topojson_test/test_topo_json_multiple_links/test_example_topojson_multiple_links.py
2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2019 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. ("NetDEF")
11 <example>.py: Test <example tests>.
20 # Save the Current Working Directory to find configuration files.
21 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
22 sys
.path
.append(os
.path
.join(CWD
, "../"))
23 sys
.path
.append(os
.path
.join(CWD
, "../../"))
25 # pylint: disable=C0413
26 from lib
.topogen
import Topogen
, get_topogen
28 # Required to instantiate the topology builder class.
30 # Import topoJson from lib, to create topology and initial configuration
31 from lib
.common_config
import (
37 from lib
.topolog
import logger
38 from lib
.bgp
import verify_bgp_convergence
39 from lib
.topojson
import build_topo_from_json
, build_config_from_json
42 # TODO: select markers based on daemons used during test
43 # pytest module level markers
45 pytestmark = pytest.mark.bfdd # single marker
54 # Reading the data from JSON File for topology and configuration creation
55 jsonFile
= "{}/example_topojson_multiple_links.json".format(CWD
)
57 with
open(jsonFile
, "r") as topoJson
:
58 topo
= json
.load(topoJson
)
60 assert False, "Could not read file {}".format(jsonFile
)
63 bgp_convergence
= False
70 # This function only purpose is to create topology
71 # as defined in input json file.
75 # Creating 2 routers having 2 links in between,
76 # one is used to establised BGP neighborship
78 # Building topology from json file
79 build_topo_from_json(tgen
, topo
)
82 def setup_module(mod
):
84 Sets up the pytest environment
89 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
90 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
93 logger
.info("Running setup_module to create topology")
95 # This function initiates the topology build with Topogen...
96 tgen
= Topogen(build_topo
, mod
.__name
__)
97 # ... and here it calls Mininet initialization functions.
99 # Starting topology, create tmp files which are loaded to routers
100 # to start daemons and then start routers
103 # This function only purpose is to create configuration
104 # as defined in input json file.
108 # Creating configuration defined in input JSON
109 # file, example, BGP config, interface config, static routes
110 # config, prefix list config
112 # Creating configuration from JSON
113 build_config_from_json(tgen
, topo
)
115 logger
.info("Running setup_module() done")
118 def teardown_module(mod
):
120 Teardown the pytest environment
125 logger
.info("Running teardown_module to delete topology")
129 # Stop toplogy and Remove tmp files
133 def test_bgp_convergence(request
):
134 "Test BGP daemon convergence"
137 global bgp_convergence
139 tc_name
= request
.node
.name
140 write_test_header(tc_name
)
142 # Don't run this test if we have any failure.
143 if tgen
.routers_have_failure():
144 pytest
.skip(tgen
.errors
)
146 # Api call verify whether BGP is converged
147 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
149 bgp_convergence
is True
150 ), "test_bgp_convergence failed.. \n" " Error: {}".format(bgp_convergence
)
152 logger
.info("BGP is converged successfully \n")
153 write_test_footer(tc_name
)
156 def test_static_routes(request
):
157 "Test to create and verify static routes."
160 if bgp_convergence
is not True:
161 pytest
.skip("skipped because of BGP Convergence failure")
164 tc_name
= request
.node
.name
165 write_test_header(tc_name
)
167 # Static routes are created as part of initial configuration,
171 next_hop
= "10.0.0.1"
172 input_dict
= {"r1": topo
["routers"]["r1"]}
174 # Uncomment below to debug
176 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, next_hop
=next_hop
)
177 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
179 write_test_footer(tc_name
)
182 if __name__
== "__main__":
183 args
= ["-s"] + sys
.argv
[1:]
184 sys
.exit(pytest
.main(args
))