]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/example_test/test_template.py
2 # -*- coding: utf-8 eval: (blacken-mode 1) -*-
3 # SPDX-License-Identifier: ISC
6 # Part of NetDEF Topology Tests
8 # Copyright (c) 2017 by
9 # Network Device Education Foundation, Inc. ("NetDEF")
13 <template>.py: Test <template>.
19 from lib
.topogen
import Topogen
, TopoRouter
20 from lib
.topolog
import logger
22 # TODO: select markers based on daemons used during test
23 # pytest module level markers
40 # pytest.mark.staticd,
44 # Function we pass to Topogen to create the topology
49 r1
= tgen
.add_router("r1")
50 r2
= tgen
.add_router("r2")
52 # Create a p2p connection between r1 and r2
55 # Create a switch with one router connected to it to simulate a empty network.
56 switch
= tgen
.add_switch("s1")
59 # Create a p2p connection between r1 and r2
60 switch
= tgen
.add_switch("s2")
65 # New form of setup/teardown using pytest fixture
66 @pytest.fixture(scope
="module")
68 "Setup/Teardown the environment and provide tgen argument to tests"
70 # This function initiates the topology build with Topogen...
71 tgen
= Topogen(build_topo
, request
.module
.__name
__)
73 # A basic topology similar to the above could also have be more easily specified
74 # using a # dictionary, remove the build_topo function and use the following
81 # tgen = Topogen(topodef, request.module.__name__)
83 # ... and here it calls initialization functions.
86 # This is a sample of configuration loading.
87 router_list
= tgen
.routers()
89 # For all routers arrange for:
90 # - starting zebra using config file from <rtrname>/zebra.conf
91 # - starting ospfd using an empty config file.
92 for rname
, router
in router_list
.items():
93 router
.load_config(TopoRouter
.RD_ZEBRA
, "zebra.conf")
94 router
.load_config(TopoRouter
.RD_OSPF
)
96 # Start and configure the router daemons
99 # Provide tgen as argument to each test function
102 # Teardown after last test runs
106 # Fixture that executes before each test
107 @pytest.fixture(autouse
=True)
108 def skip_on_failure(tgen
):
109 if tgen
.routers_have_failure():
110 pytest
.skip("skipped because of previous test failure")
113 # ===================
114 # The tests functions
115 # ===================
118 def test_get_version(tgen
):
119 "Test the logs the FRR version"
121 r1
= tgen
.gears
["r1"]
122 version
= r1
.vtysh_cmd("show version")
123 logger
.info("FRR version is: " + version
)
126 def test_connectivity(tgen
):
127 "Test the logs the FRR version"
129 r1
= tgen
.gears
["r1"]
130 r2
= tgen
.gears
["r2"]
131 output
= r1
.cmd_raises("ping -c1 192.168.1.2")
132 output
= r2
.cmd_raises("ping -c1 192.168.3.1")
136 def test_expect_failure(tgen
):
137 "A test that is current expected to fail but should be fixed"
139 assert False, "Example of temporary expected failure that will eventually be fixed"
143 def test_will_be_skipped(tgen
):
144 "A test that will be skipped"
148 # Memory leak test template
149 def test_memory_leak(tgen
):
150 "Run the memory leak test and report results."
152 if not tgen
.is_memleak_enabled():
153 pytest
.skip("Memory leak test/report is disabled")
155 tgen
.report_memory_leaks()
158 if __name__
== "__main__":
159 args
= ["-s"] + sys
.argv
[1:]
160 sys
.exit(pytest
.main(args
))