]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/example_topojson_test/test_topo_json_single_link_loopback/test_example_topojson.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.
7 # ("NetDEF") in this file.
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 # Import topogen and topotest helpers
27 from lib
.topogen
import Topogen
, get_topogen
29 # Required to instantiate the topology builder class.
31 # Import topoJson from lib, to create topology and initial configuration
32 from lib
.common_config
import (
38 from lib
.topolog
import logger
39 from lib
.bgp
import verify_bgp_convergence
40 from lib
.topojson
import build_topo_from_json
, build_config_from_json
43 # TODO: select markers based on daemons used during test
44 # pytest module level markers
46 pytestmark = pytest.mark.bfdd # single marker
55 # Reading the data from JSON File for topology and configuration creation
56 jsonFile
= "{}/example_topojson.json".format(CWD
)
59 with
open(jsonFile
, "r") as topoJson
:
60 topo
= json
.load(topoJson
)
62 assert False, "Could not read file {}".format(jsonFile
)
65 bgp_convergence
= False
72 # This function only purpose is to create topology
73 # as defined in input json file.
77 # Creating 2 routers having single links in between,
78 # which is used to establised BGP neighborship
80 # Building topology from json file
81 build_topo_from_json(tgen
, topo
)
84 def setup_module(mod
):
86 Sets up the pytest environment
91 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
92 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
95 logger
.info("Running setup_module to create topology")
97 # This function initiates the topology build with Topogen...
98 tgen
= Topogen(build_topo
, mod
.__name
__)
99 # ... and here it calls Mininet initialization functions.
101 # Starting topology, create tmp files which are loaded to routers
102 # to start daemons and then start routers
105 # This function only purpose is to create configuration
106 # as defined in input json file.
110 # Creating configuration defined in input JSON
111 # file, example, BGP config, interface config, static routes
112 # config, prefix list config
114 # Creating configuration from JSON
115 build_config_from_json(tgen
, topo
)
117 logger
.info("Running setup_module() done")
120 def teardown_module(mod
):
122 Teardown the pytest environment
127 logger
.info("Running teardown_module to delete topology")
131 # Stop toplogy and Remove tmp files
135 def test_bgp_convergence(request
):
136 "Test BGP daemon convergence"
139 global bgp_convergence
141 tc_name
= request
.node
.name
142 write_test_header(tc_name
)
144 # Don't run this test if we have any failure.
145 if tgen
.routers_have_failure():
146 pytest
.skip(tgen
.errors
)
148 # Api call verify whether BGP is converged
149 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
151 bgp_convergence
is True
152 ), "test_bgp_convergence failed.. \n" " Error: {}".format(bgp_convergence
)
154 logger
.info("BGP is converged successfully \n")
155 write_test_footer(tc_name
)
158 def test_static_routes(request
):
159 "Test to create and verify static routes."
162 if bgp_convergence
is not True:
163 pytest
.skip("skipped because of BGP Convergence failure")
166 tc_name
= request
.node
.name
167 write_test_header(tc_name
)
169 # Static routes are created as part of initial configuration,
172 next_hop
= ["10.0.0.1", "10.0.0.5"]
177 "network": "100.0.20.1/32",
179 "admin_distance": 100,
180 "next_hop": "10.0.0.1",
185 # Uncomment below to debug
187 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, next_hop
=next_hop
)
188 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
190 write_test_footer(tc_name
)
193 if __name__
== "__main__":
194 args
= ["-s"] + sys
.argv
[1:]
195 sys
.exit(pytest
.main(args
))