]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/example_test/test_template.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / example_test / test_template.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 eval: (blacken-mode 1) -*-
3 # SPDX-License-Identifier: ISC
4 #
5 # <template>.py
6 # Part of NetDEF Topology Tests
7 #
8 # Copyright (c) 2017 by
9 # Network Device Education Foundation, Inc. ("NetDEF")
10 #
11
12 """
13 <template>.py: Test <template>.
14 """
15
16 import sys
17 import pytest
18
19 from lib.topogen import Topogen, TopoRouter
20 from lib.topolog import logger
21
22 # TODO: select markers based on daemons used during test
23 # pytest module level markers
24 pytestmark = [
25 # pytest.mark.babeld,
26 # pytest.mark.bfdd,
27 # pytest.mark.bgpd,
28 # pytest.mark.eigrpd,
29 # pytest.mark.isisd,
30 # pytest.mark.ldpd,
31 # pytest.mark.nhrpd,
32 # pytest.mark.ospf6d,
33 pytest.mark.ospfd,
34 # pytest.mark.pathd,
35 # pytest.mark.pbrd,
36 # pytest.mark.pimd,
37 # pytest.mark.ripd,
38 # pytest.mark.ripngd,
39 # pytest.mark.sharpd,
40 # pytest.mark.staticd,
41 # pytest.mark.vrrpd,
42 ]
43
44 # Function we pass to Topogen to create the topology
45 def build_topo(tgen):
46 "Build function"
47
48 # Create 2 routers
49 r1 = tgen.add_router("r1")
50 r2 = tgen.add_router("r2")
51
52 # Create a p2p connection between r1 and r2
53 tgen.add_link(r1, r2)
54
55 # Create a switch with one router connected to it to simulate a empty network.
56 switch = tgen.add_switch("s1")
57 switch.add_link(r1)
58
59 # Create a p2p connection between r1 and r2
60 switch = tgen.add_switch("s2")
61 switch.add_link(r1)
62 switch.add_link(r2)
63
64
65 # New form of setup/teardown using pytest fixture
66 @pytest.fixture(scope="module")
67 def tgen(request):
68 "Setup/Teardown the environment and provide tgen argument to tests"
69
70 # This function initiates the topology build with Topogen...
71 tgen = Topogen(build_topo, request.module.__name__)
72
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
75 # instead:
76 #
77 # topodef = {
78 # "s1": "r1"
79 # "s2": ("r1", "r2")
80 # }
81 # tgen = Topogen(topodef, request.module.__name__)
82
83 # ... and here it calls initialization functions.
84 tgen.start_topology()
85
86 # This is a sample of configuration loading.
87 router_list = tgen.routers()
88
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)
95
96 # Start and configure the router daemons
97 tgen.start_router()
98
99 # Provide tgen as argument to each test function
100 yield tgen
101
102 # Teardown after last test runs
103 tgen.stop_topology()
104
105
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")
111
112
113 # ===================
114 # The tests functions
115 # ===================
116
117
118 def test_get_version(tgen):
119 "Test the logs the FRR version"
120
121 r1 = tgen.gears["r1"]
122 version = r1.vtysh_cmd("show version")
123 logger.info("FRR version is: " + version)
124
125
126 def test_connectivity(tgen):
127 "Test the logs the FRR version"
128
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")
133
134
135 @pytest.mark.xfail
136 def test_expect_failure(tgen):
137 "A test that is current expected to fail but should be fixed"
138
139 assert False, "Example of temporary expected failure that will eventually be fixed"
140
141
142 @pytest.mark.skip
143 def test_will_be_skipped(tgen):
144 "A test that will be skipped"
145 assert False
146
147
148 # Memory leak test template
149 def test_memory_leak(tgen):
150 "Run the memory leak test and report results."
151
152 if not tgen.is_memleak_enabled():
153 pytest.skip("Memory leak test/report is disabled")
154
155 tgen.report_memory_leaks()
156
157
158 if __name__ == "__main__":
159 args = ["-s"] + sys.argv[1:]
160 sys.exit(pytest.main(args))