]>
git.puffer.fish Git - mirror/frr.git/blob
09ac9f2fa43cecdf5e2ce1c590b66a5568babe9a
4 # Copyright (c) 2019 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. ("NetDEF")
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 from lib
.topogen
import Topogen
, get_topogen
42 # Required to instantiate the topology builder class.
43 from mininet
.topo
import Topo
45 # Import topoJson from lib, to create topology and initial configuration
46 from lib
.common_config
import (
52 from lib
.topolog
import logger
53 from lib
.bgp
import verify_bgp_convergence
54 from lib
.topojson
import build_topo_from_json
, build_config_from_json
57 # TODO: select markers based on daemons used during test
58 # pytest module level markers
60 pytestmark = pytest.mark.bfdd # single marker
69 # Reading the data from JSON File for topology and configuration creation
70 jsonFile
= "{}/example_topojson_multiple_links.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
82 class TemplateTopo(Topo
):
86 * `Topo`: Topology object
89 def build(self
, *_args
, **_opts
):
91 tgen
= get_topogen(self
)
93 # This function only purpose is to create topology
94 # as defined in input json file.
98 # Creating 2 routers having 2 links in between,
99 # one is used to establised BGP neighborship
101 # Building topology from json file
102 build_topo_from_json(tgen
, topo
)
105 def setup_module(mod
):
107 Sets up the pytest environment
112 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
113 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
114 logger
.info("=" * 40)
116 logger
.info("Running setup_module to create topology")
118 # This function initiates the topology build with Topogen...
119 tgen
= Topogen(TemplateTopo
, mod
.__name
__)
120 # ... and here it calls Mininet initialization functions.
122 # Starting topology, create tmp files which are loaded to routers
123 # to start deamons and then start routers
126 # This function only purpose is to create configuration
127 # as defined in input json file.
131 # Creating configuration defined in input JSON
132 # file, example, BGP config, interface config, static routes
133 # config, prefix list config
135 # Creating configuration from JSON
136 build_config_from_json(tgen
, topo
)
138 logger
.info("Running setup_module() done")
141 def teardown_module(mod
):
143 Teardown the pytest environment
148 logger
.info("Running teardown_module to delete topology")
152 # Stop toplogy and Remove tmp files
156 def test_bgp_convergence(request
):
157 " Test BGP daemon convergence "
160 global bgp_convergence
162 tc_name
= request
.node
.name
163 write_test_header(tc_name
)
165 # Don't run this test if we have any failure.
166 if tgen
.routers_have_failure():
167 pytest
.skip(tgen
.errors
)
169 # Api call verify whether BGP is converged
170 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
172 bgp_convergence
is True
173 ), "test_bgp_convergence failed.. \n" " Error: {}".format(bgp_convergence
)
175 logger
.info("BGP is converged successfully \n")
176 write_test_footer(tc_name
)
179 def test_static_routes(request
):
180 " Test to create and verify static routes. "
183 if bgp_convergence
is not True:
184 pytest
.skip("skipped because of BGP Convergence failure")
187 tc_name
= request
.node
.name
188 write_test_header(tc_name
)
190 # Static routes are created as part of initial configuration,
194 next_hop
= "10.0.0.1"
195 input_dict
= {"r1": topo
["routers"]["r1"]}
197 # Uncomment below to debug
199 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, next_hop
=next_hop
)
200 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
202 write_test_footer(tc_name
)
205 if __name__
== "__main__":
206 args
= ["-s"] + sys
.argv
[1:]
207 sys
.exit(pytest
.main(args
))