]>
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>.
34 # Save the Current Working Directory to find configuration files.
35 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
36 sys
.path
.append(os
.path
.join(CWD
, "../"))
37 sys
.path
.append(os
.path
.join(CWD
, "../../"))
39 # pylint: disable=C0413
40 # Import topogen and topotest helpers
41 from lib
.topogen
import Topogen
, get_topogen
43 # Required to instantiate the topology builder class.
44 from mininet
.topo
import Topo
46 # Import topoJson from lib, to create topology and initial configuration
47 from lib
.common_config
import (
53 from lib
.topolog
import logger
54 from lib
.bgp
import verify_bgp_convergence
55 from lib
.topojson
import build_topo_from_json
, build_config_from_json
58 # TODO: select markers based on daemons used during test
59 # pytest module level markers
61 pytestmark = pytest.mark.bfdd # single marker
70 # Reading the data from JSON File for topology and configuration creation
71 jsonFile
= "{}/example_topojson.json".format(CWD
)
74 with
open(jsonFile
, "r") as topoJson
:
75 topo
= json
.load(topoJson
)
77 assert False, "Could not read file {}".format(jsonFile
)
80 bgp_convergence
= False
84 class TemplateTopo(Topo
):
88 * `Topo`: Topology object
91 def build(self
, *_args
, **_opts
):
93 tgen
= get_topogen(self
)
95 # This function only purpose is to create topology
96 # as defined in input json file.
100 # Creating 2 routers having single links in between,
101 # which is used to establised BGP neighborship
103 # Building topology from json file
104 build_topo_from_json(tgen
, topo
)
107 def setup_module(mod
):
109 Sets up the pytest environment
114 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
115 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
116 logger
.info("=" * 40)
118 logger
.info("Running setup_module to create topology")
120 # This function initiates the topology build with Topogen...
121 tgen
= Topogen(TemplateTopo
, mod
.__name
__)
122 # ... and here it calls Mininet initialization functions.
124 # Starting topology, create tmp files which are loaded to routers
125 # to start deamons and then start routers
128 # This function only purpose is to create configuration
129 # as defined in input json file.
133 # Creating configuration defined in input JSON
134 # file, example, BGP config, interface config, static routes
135 # config, prefix list config
137 # Creating configuration from JSON
138 build_config_from_json(tgen
, topo
)
140 logger
.info("Running setup_module() done")
143 def teardown_module(mod
):
145 Teardown the pytest environment
150 logger
.info("Running teardown_module to delete topology")
154 # Stop toplogy and Remove tmp files
158 def test_bgp_convergence(request
):
159 " Test BGP daemon convergence "
162 global bgp_convergence
164 tc_name
= request
.node
.name
165 write_test_header(tc_name
)
167 # Don't run this test if we have any failure.
168 if tgen
.routers_have_failure():
169 pytest
.skip(tgen
.errors
)
171 # Api call verify whether BGP is converged
172 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
174 bgp_convergence
is True
175 ), "test_bgp_convergence failed.. \n" " Error: {}".format(bgp_convergence
)
177 logger
.info("BGP is converged successfully \n")
178 write_test_footer(tc_name
)
181 def test_static_routes(request
):
182 " Test to create and verify static routes. "
185 if bgp_convergence
is not True:
186 pytest
.skip("skipped because of BGP Convergence failure")
189 tc_name
= request
.node
.name
190 write_test_header(tc_name
)
192 # Static routes are created as part of initial configuration,
195 next_hop
= ["10.0.0.1", "10.0.0.5"]
200 "network": "100.0.20.1/32",
202 "admin_distance": 100,
203 "next_hop": "10.0.0.1",
208 # Uncomment below to debug
210 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, next_hop
=next_hop
)
211 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
213 write_test_footer(tc_name
)
216 if __name__
== "__main__":
217 args
= ["-s"] + sys
.argv
[1:]
218 sys
.exit(pytest
.main(args
))