9 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
10 sys
.path
.append(os
.path
.join(CWD
, "../"))
11 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
13 from lib
.micronet_compat
import Topo
14 from lib
.topogen
import Topogen
, get_topogen
16 from lib
.common_config
import (
20 reset_config_on_routers
,
27 shutdown_bringup_interface
,
30 create_interfaces_cfg
,
33 from lib
.topolog
import logger
34 from lib
.topojson
import build_topo_from_json
, build_config_from_json
35 from lib
.ospf
import (
37 verify_ospf6_neighbor
,
45 pytestmark
= [pytest
.mark
.ospfd
, pytest
.mark
.staticd
]
51 # Reading the data from JSON File for topology creation
52 jsonFile
= "{}/test_ospf_dual_stack.json".format(CWD
)
54 with
open(jsonFile
, "r") as topoJson
:
55 topo
= json
.load(topoJson
)
57 assert False, "Could not read file {}".format(jsonFile
)
60 class CreateTopo(Topo
):
61 """Test topology builder."""
63 def build(self
, *_args
, **_opts
):
65 tgen
= get_topogen(self
)
67 # Building topology from json file
68 build_topo_from_json(tgen
, topo
)
71 def setup_module(mod
):
72 """Sets up the pytest environment."""
74 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
75 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
78 logger
.info("Running setup_module to create topology")
80 # This function initiates the topology build with Topogen...
81 tgen
= Topogen(CreateTopo
, mod
.__name
__)
82 # ... and here it calls Mininet initialization functions.
84 # get list of daemons needs to be started for this suite.
85 daemons
= topo_daemons(tgen
, topo
)
87 # Starting topology, create tmp files which are loaded to routers
88 # to start daemons and then start routers
89 start_topology(tgen
, daemons
)
91 # Creating configuration from JSON
92 build_config_from_json(tgen
, topo
)
94 # Don't run this test if we have any failure.
95 if tgen
.routers_have_failure():
96 pytest
.skip(tgen
.errors
)
98 # Api call verify whether OSPF converged
99 ospf_covergence_ipv4
= verify_ospf_neighbor(tgen
, topo
)
100 assert ospf_covergence_ipv4
is True, "setup_module :Failed \n Error:" " {}".format(
104 # Api call verify whether OSPF6 converged
105 ospf_covergence_ipv6
= verify_ospf6_neighbor(tgen
, topo
)
106 assert ospf_covergence_ipv6
is True, "setup_module :Failed \n Error:" " {}".format(
109 logger
.info("Running setup_module() done")
112 def teardown_module(mod
):
114 Teardown the pytest environment.
119 logger
.info("Running teardown_module to delete topology")
121 # Stop topology and remove tmp files
124 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
126 logger
.info("=" * 40)
130 # ##################################
131 # Test cases start here.
132 # ##################################
135 def test_ospf_dual_stack(request
):
136 """OSPF test dual stack."""
138 tc_name
= request
.node
.name
139 write_test_header(tc_name
)
141 # Don't run this test if we have any failure.
143 if tgen
.routers_have_failure():
144 pytest
.skip(tgen
.errors
)
148 step("Bring up the base configuration as per the JSON topology")
149 reset_config_on_routers(tgen
)
150 write_test_footer(tc_name
)
153 if __name__
== "__main__":
154 args
= ["-s"] + sys
.argv
[1:]
155 sys
.exit(pytest
.main(args
))