]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_instance_redistribute/test_ospf_instance_redistribute.py
4 # test_ospf_instance_redistribute.py
6 # Copyright (c) 2022 by
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 test_ospf_instance_redistribute
36 pytestmark
= [pytest
.mark
.ospfd
, pytest
.mark
.sharpd
]
38 # Save the Current Working Directory to find configuration files.
39 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
40 sys
.path
.append(os
.path
.join(CWD
, "../"))
42 # pylint: disable=C0413
43 # Import topogen and topotest helpers
44 from lib
import topotest
45 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
46 from lib
.topolog
import logger
47 from functools
import partial
49 # Required to instantiate the topology builder class.
51 #####################################################
53 ## Network Topology Definition
55 #####################################################
61 # Connect r1 and r2 through the eth0 interface
62 switch
= tgen
.add_switch("sw1")
63 switch
.add_link(tgen
.gears
["r1"])
66 #####################################################
70 #####################################################
73 def setup_module(module
):
75 tgen
= Topogen(build_topo
, module
.__name
__)
78 # This is a sample of configuration loading.
81 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "r1/zebra.conf")
84 TopoRouter
.RD_OSPF
, os
.path
.join(CWD
, "r1/ospfd-3.conf"),
88 TopoRouter
.RD_SHARP
, os
.path
.join(CWD
, "r1/sharpd.conf")
94 def teardown_module(_mod
):
95 "Teardown the pytest environment"
98 # This function tears down the whole topology.
102 def test_install_sharp_instance_routes():
105 if tgen
.routers_have_failure():
106 pytest
.skip(tgen
.errors
)
108 logger
.info("Installing sharp routes")
109 r1
= tgen
.gears
["r1"]
110 r1
.vtysh_cmd("sharp install route 4.5.6.7 nexthop 192.168.100.2 1")
111 r1
.vtysh_cmd("sharp install route 4.5.6.8 nexthop 192.168.100.2 1 instance 3")
112 r1
.vtysh_cmd("sharp install route 4.5.6.9 nexthop 192.168.100.3 1 instance 4")
113 r1
.vtysh_cmd("conf\nrouter ospf 3\nredistribute sharp")
115 json_file
= "{}/r1/sharp_installed.json".format(CWD
)
116 expected
= json
.loads(open(json_file
).read())
119 topotest
.router_json_cmp
, r1
, "show ip route summ json", expected
)
121 logger
.info("Ensuring that they exist in the rib/fib")
122 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=1)
123 assertmsg
= '"r1" sharp routes are not installed'
124 assert result
is None, assertmsg
126 def test_ospf_instance_redistribute():
129 if tgen
.routers_have_failure():
130 pytest
.skip(tgen
.errors
)
132 logger
.info("Testing that ospf instance 3 has the redistributed sharp route")
133 r1
= tgen
.gears
["r1"]
134 r1
.vtysh_cmd("conf\nrouter ospf 3\nredistribute sharp")
136 json_file
= "{}/r1/ospf_instance_lsa.json".format(CWD
)
137 expected
= json
.loads(open(json_file
).read())
140 topotest
.router_json_cmp
, r1
, "show ip ospf 3 data json", expected
)
142 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=1)
143 assertmsg
= '"r1" ospf instance 3 does not have the proper redistributed routes'
144 assert result
is None, assertmsg
146 r1
.vtysh_cmd("sharp install route 4.5.6.10 nexthop 192.168.100.2 1")
147 r1
.vtysh_cmd("sharp install route 4.5.6.11 nexthop 192.168.100.2 1 instance 3")
148 r1
.vtysh_cmd("sharp install route 4.5.6.12 nexthop 192.168.100.2 1 instance 4")
150 logger
.info("Added new sharp routes let's see if we pick up only the .10")
151 json_file
= "{}/r1/ospf_instance_lsa2.json".format(CWD
)
152 expected
= json
.loads(open(json_file
).read())
155 topotest
.router_json_cmp
, r1
, "show ip ospf 3 data json", expected
)
157 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=1)
158 assertmsg
= '"r1" ospf instance 3 does not have the proper redistributed routes'
159 assert result
is None, assertmsg
162 def test_ospf_instance_default_information():
165 if tgen
.routers_have_failure():
166 pytest
.skip(tgen
.errors
)
168 logger
.info("Testing the using default information originate")
169 r1
= tgen
.gears
["r1"]
170 r1
.vtysh_cmd("conf\nrouter ospf 3\ndefault-information originate")
172 r1
.vtysh_cmd("conf\nip route 0.0.0.0/0 192.168.100.2")
173 json_file
= "{}/r1/ospf_default_information.json".format(CWD
)
174 expected
= json
.loads(open(json_file
).read())
177 topotest
.router_json_cmp
, r1
, "show ip ospf 3 data json", expected
)
179 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=1)
180 assertmsg
= '"r1" ospf instance 3 does not properly redistribute the default route'
181 assert result
is None, assertmsg
185 if __name__
== "__main__":
186 args
= ["-s"] + sys
.argv
[1:]
187 sys
.exit(pytest
.main(args
))