]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_instance_redistribute/test_ospf_instance_redistribute.py
2 # SPDX-License-Identifier: ISC
5 # test_ospf_instance_redistribute.py
7 # Copyright (c) 2022 by
13 test_ospf_instance_redistribute
23 pytestmark
= [pytest
.mark
.ospfd
, pytest
.mark
.sharpd
]
25 # Save the Current Working Directory to find configuration files.
26 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
27 sys
.path
.append(os
.path
.join(CWD
, "../"))
29 # pylint: disable=C0413
30 # Import topogen and topotest helpers
31 from lib
import topotest
32 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
33 from lib
.topolog
import logger
34 from functools
import partial
36 # Required to instantiate the topology builder class.
38 #####################################################
40 ## Network Topology Definition
42 #####################################################
48 # Connect r1 and r2 through the eth0 interface
49 switch
= tgen
.add_switch("sw1")
50 switch
.add_link(tgen
.gears
["r1"])
53 #####################################################
57 #####################################################
60 def setup_module(module
):
62 tgen
= Topogen(build_topo
, module
.__name
__)
65 # This is a sample of configuration loading.
68 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "r1/zebra.conf")
71 TopoRouter
.RD_OSPF
, os
.path
.join(CWD
, "r1/ospfd-3.conf"),
75 TopoRouter
.RD_SHARP
, os
.path
.join(CWD
, "r1/sharpd.conf")
81 def teardown_module(_mod
):
82 "Teardown the pytest environment"
85 # This function tears down the whole topology.
89 def test_install_sharp_instance_routes():
92 if tgen
.routers_have_failure():
93 pytest
.skip(tgen
.errors
)
95 logger
.info("Installing sharp routes")
97 r1
.vtysh_cmd("sharp install route 4.5.6.7 nexthop 192.168.100.2 1")
98 r1
.vtysh_cmd("sharp install route 4.5.6.8 nexthop 192.168.100.2 1 instance 3")
99 r1
.vtysh_cmd("sharp install route 4.5.6.9 nexthop 192.168.100.3 1 instance 4")
100 r1
.vtysh_cmd("conf\nrouter ospf 3\nredistribute sharp")
102 json_file
= "{}/r1/sharp_installed.json".format(CWD
)
103 expected
= json
.loads(open(json_file
).read())
106 topotest
.router_json_cmp
, r1
, "show ip route summ json", expected
)
108 logger
.info("Ensuring that they exist in the rib/fib")
109 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=1)
110 assertmsg
= '"r1" sharp routes are not installed'
111 assert result
is None, assertmsg
113 def test_ospf_instance_redistribute():
116 if tgen
.routers_have_failure():
117 pytest
.skip(tgen
.errors
)
119 logger
.info("Testing that ospf instance 3 has the redistributed sharp route")
120 r1
= tgen
.gears
["r1"]
121 r1
.vtysh_cmd("conf\nrouter ospf 3\nredistribute sharp")
123 json_file
= "{}/r1/ospf_instance_lsa.json".format(CWD
)
124 expected
= json
.loads(open(json_file
).read())
127 topotest
.router_json_cmp
, r1
, "show ip ospf 3 data json", expected
)
129 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=1)
130 assertmsg
= '"r1" ospf instance 3 does not have the proper redistributed routes'
131 assert result
is None, assertmsg
133 r1
.vtysh_cmd("sharp install route 4.5.6.10 nexthop 192.168.100.2 1")
134 r1
.vtysh_cmd("sharp install route 4.5.6.11 nexthop 192.168.100.2 1 instance 3")
135 r1
.vtysh_cmd("sharp install route 4.5.6.12 nexthop 192.168.100.2 1 instance 4")
137 logger
.info("Added new sharp routes let's see if we pick up only the .10")
138 json_file
= "{}/r1/ospf_instance_lsa2.json".format(CWD
)
139 expected
= json
.loads(open(json_file
).read())
142 topotest
.router_json_cmp
, r1
, "show ip ospf 3 data json", expected
)
144 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=1)
145 assertmsg
= '"r1" ospf instance 3 does not have the proper redistributed routes'
146 assert result
is None, assertmsg
149 def test_ospf_instance_default_information():
152 if tgen
.routers_have_failure():
153 pytest
.skip(tgen
.errors
)
155 logger
.info("Testing the using default information originate")
156 r1
= tgen
.gears
["r1"]
157 r1
.vtysh_cmd("conf\nrouter ospf 3\ndefault-information originate")
159 r1
.vtysh_cmd("conf\nip route 0.0.0.0/0 192.168.100.2")
160 json_file
= "{}/r1/ospf_default_information.json".format(CWD
)
161 expected
= json
.loads(open(json_file
).read())
164 topotest
.router_json_cmp
, r1
, "show ip ospf 3 data json", expected
)
166 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=1)
167 assertmsg
= '"r1" ospf instance 3 does not properly redistribute the default route'
168 assert result
is None, assertmsg
172 if __name__
== "__main__":
173 args
= ["-s"] + sys
.argv
[1:]
174 sys
.exit(pytest
.main(args
))