]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/rip_allow_ecmp/test_rip_allow_ecmp.py
Merge pull request #13141 from mjstapp/fix_ospf_json_keys
[mirror_frr.git] / tests / topotests / rip_allow_ecmp / test_rip_allow_ecmp.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: ISC
3
4 # Copyright (c) 2023 by
5 # Donatas Abraitis <donatas@opensourcerouting.org>
6 #
7
8 """
9 Test if RIP `allow-ecmp` command works correctly.
10 """
11
12 import os
13 import sys
14 import json
15 import pytest
16 import functools
17
18 CWD = os.path.dirname(os.path.realpath(__file__))
19 sys.path.append(os.path.join(CWD, "../"))
20
21 # pylint: disable=C0413
22 from lib import topotest
23 from lib.topogen import Topogen, TopoRouter, get_topogen
24
25 pytestmark = [pytest.mark.ripd]
26
27
28 def setup_module(mod):
29 topodef = {"s1": ("r1", "r2", "r3")}
30 tgen = Topogen(topodef, mod.__name__)
31 tgen.start_topology()
32
33 router_list = tgen.routers()
34
35 for _, (rname, router) in enumerate(router_list.items(), 1):
36 router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname)))
37
38 tgen.start_router()
39
40
41 def teardown_module(mod):
42 tgen = get_topogen()
43 tgen.stop_topology()
44
45
46 def test_rip_allow_ecmp():
47 tgen = get_topogen()
48
49 if tgen.routers_have_failure():
50 pytest.skip(tgen.errors)
51
52 r1 = tgen.gears["r1"]
53
54 def _show_rip_routes():
55 output = json.loads(
56 r1.vtysh_cmd("show yang operational-data /frr-ripd:ripd ripd")
57 )
58 try:
59 output = output["frr-ripd:ripd"]["instance"][0]["state"]["routes"]
60 except KeyError:
61 return False
62
63 expected = {
64 "route": [
65 {
66 "prefix": "10.10.10.1/32",
67 "nexthops": {
68 "nexthop": [
69 {
70 "nh-type": "ip4",
71 "protocol": "rip",
72 "rip-type": "normal",
73 "gateway": "192.168.1.2",
74 "from": "192.168.1.2",
75 "tag": 0,
76 },
77 {
78 "nh-type": "ip4",
79 "protocol": "rip",
80 "rip-type": "normal",
81 "gateway": "192.168.1.3",
82 "from": "192.168.1.3",
83 "tag": 0,
84 },
85 ]
86 },
87 "metric": 2,
88 },
89 ]
90 }
91 return topotest.json_cmp(output, expected)
92
93 test_func = functools.partial(_show_rip_routes)
94 _, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
95 assert result is None, "Can't see 10.10.10.1/32 as multipath in `show ip rip`"
96
97 def _show_routes():
98 output = json.loads(r1.vtysh_cmd("show ip route json"))
99 expected = {
100 "10.10.10.1/32": [
101 {
102 "nexthops": [
103 {
104 "ip": "192.168.1.2",
105 "active": True,
106 },
107 {
108 "ip": "192.168.1.3",
109 "active": True,
110 },
111 ]
112 }
113 ]
114 }
115 return topotest.json_cmp(output, expected)
116
117 test_func = functools.partial(_show_routes)
118 _, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
119 assert result is None, "Can't see 10.10.10.1/32 as multipath in `show ip route`"
120
121
122 if __name__ == "__main__":
123 args = ["-s"] + sys.argv[1:]
124 sys.exit(pytest.main(args))