]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/example_topojson_test/test_topo_json_single_link_loopback/test_example_topojson.py
4 # Copyright (c) 2019 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
6 # ("NetDEF") in this file.
8 # Permission to use, copy, modify, and/or distribute this software
9 # for any purpose with or without fee is hereby granted, provided
10 # that the above copyright notice and this permission notice appear
13 # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
14 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
16 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
17 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 <example>.py: Test <example tests>.
33 # Save the Current Working Directory to find configuration files.
34 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
35 sys
.path
.append(os
.path
.join(CWD
, "../"))
36 sys
.path
.append(os
.path
.join(CWD
, "../../"))
38 # pylint: disable=C0413
39 # Import topogen and topotest helpers
40 from lib
.topogen
import Topogen
, get_topogen
42 # Required to instantiate the topology builder class.
44 # Import topoJson from lib, to create topology and initial configuration
45 from lib
.common_config
import (
51 from lib
.topolog
import logger
52 from lib
.bgp
import verify_bgp_convergence
53 from lib
.topojson
import build_topo_from_json
, build_config_from_json
56 # TODO: select markers based on daemons used during test
57 # pytest module level markers
59 pytestmark = pytest.mark.bfdd # single marker
68 # Reading the data from JSON File for topology and configuration creation
69 jsonFile
= "{}/example_topojson.json".format(CWD
)
72 with
open(jsonFile
, "r") as topoJson
:
73 topo
= json
.load(topoJson
)
75 assert False, "Could not read file {}".format(jsonFile
)
78 bgp_convergence
= False
85 # This function only purpose is to create topology
86 # as defined in input json file.
90 # Creating 2 routers having single links in between,
91 # which is used to establised BGP neighborship
93 # Building topology from json file
94 build_topo_from_json(tgen
, topo
)
97 def setup_module(mod
):
99 Sets up the pytest environment
104 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
105 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
106 logger
.info("=" * 40)
108 logger
.info("Running setup_module to create topology")
110 # This function initiates the topology build with Topogen...
111 tgen
= Topogen(build_topo
, mod
.__name
__)
112 # ... and here it calls Mininet initialization functions.
114 # Starting topology, create tmp files which are loaded to routers
115 # to start deamons and then start routers
118 # This function only purpose is to create configuration
119 # as defined in input json file.
123 # Creating configuration defined in input JSON
124 # file, example, BGP config, interface config, static routes
125 # config, prefix list config
127 # Creating configuration from JSON
128 build_config_from_json(tgen
, topo
)
130 logger
.info("Running setup_module() done")
133 def teardown_module(mod
):
135 Teardown the pytest environment
140 logger
.info("Running teardown_module to delete topology")
144 # Stop toplogy and Remove tmp files
148 def test_bgp_convergence(request
):
149 "Test BGP daemon convergence"
152 global bgp_convergence
154 tc_name
= request
.node
.name
155 write_test_header(tc_name
)
157 # Don't run this test if we have any failure.
158 if tgen
.routers_have_failure():
159 pytest
.skip(tgen
.errors
)
161 # Api call verify whether BGP is converged
162 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
164 bgp_convergence
is True
165 ), "test_bgp_convergence failed.. \n" " Error: {}".format(bgp_convergence
)
167 logger
.info("BGP is converged successfully \n")
168 write_test_footer(tc_name
)
171 def test_static_routes(request
):
172 "Test to create and verify static routes."
175 if bgp_convergence
is not True:
176 pytest
.skip("skipped because of BGP Convergence failure")
179 tc_name
= request
.node
.name
180 write_test_header(tc_name
)
182 # Static routes are created as part of initial configuration,
185 next_hop
= ["10.0.0.1", "10.0.0.5"]
190 "network": "100.0.20.1/32",
192 "admin_distance": 100,
193 "next_hop": "10.0.0.1",
198 # Uncomment below to debug
200 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, next_hop
=next_hop
)
201 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
203 write_test_footer(tc_name
)
206 if __name__
== "__main__":
207 args
= ["-s"] + sys
.argv
[1:]
208 sys
.exit(pytest
.main(args
))