]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/zebra_opaque/test_zebra_opaque.py
Merge pull request #10360 from opensourcerouting/clippy-rel-endian
[mirror_frr.git] / tests / topotests / zebra_opaque / test_zebra_opaque.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2021 by
4 # Donatas Abraitis <donatas.abraitis@gmail.com>
5 #
6 # Permission to use, copy, modify, and/or distribute this software
7 # for any purpose with or without fee is hereby granted, provided
8 # that the above copyright notice and this permission notice appear
9 # in all copies.
10 #
11 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
15 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
16 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
17 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
18 # OF THIS SOFTWARE.
19 #
20
21 """
22 Test if Opaque Data is accessable from other daemons in Zebra
23 """
24
25 import os
26 import sys
27 import json
28 import pytest
29 import functools
30
31 CWD = os.path.dirname(os.path.realpath(__file__))
32 sys.path.append(os.path.join(CWD, "../"))
33
34 # pylint: disable=C0413
35 from lib import topotest
36 from lib.topogen import Topogen, TopoRouter, get_topogen
37
38 pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd, pytest.mark.ospf6d]
39
40
41 def setup_module(mod):
42 topodef = {"s1": ("r1", "r2"), "s2": ("r3", "r4")}
43 tgen = Topogen(topodef, mod.__name__)
44 tgen.start_topology()
45
46 router_list = tgen.routers()
47
48 for i, (rname, router) in enumerate(router_list.items(), 1):
49 router.load_config(
50 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
51 )
52 router.load_config(
53 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
54 )
55 router.load_config(
56 TopoRouter.RD_OSPF, os.path.join(CWD, "{}/ospfd.conf".format(rname))
57 )
58 router.load_config(
59 TopoRouter.RD_OSPF6, os.path.join(CWD, "{}/ospf6d.conf".format(rname))
60 )
61
62 tgen.start_router()
63
64
65 def teardown_module(mod):
66 tgen = get_topogen()
67 tgen.stop_topology()
68
69
70 def test_zebra_opaque():
71 tgen = get_topogen()
72
73 if tgen.routers_have_failure():
74 pytest.skip(tgen.errors)
75
76 def _bgp_converge(router):
77 output = json.loads(router.vtysh_cmd("show ip route 192.168.1.0/24 json"))
78 expected = {
79 "192.168.1.0/24": [
80 {
81 "communities": "65002:1 65002:2",
82 "largeCommunities": "65002:1:1 65002:2:1",
83 }
84 ]
85 }
86 return topotest.json_cmp(output, expected)
87
88 def _ospf_converge(router):
89 output = json.loads(router.vtysh_cmd("show ip route 192.168.1.0/24 json"))
90 expected = {
91 "192.168.1.0/24": [
92 {
93 "ospfPathType": "Intra-Area",
94 "ospfAreaId": "0.0.0.0",
95 }
96 ]
97 }
98 return topotest.json_cmp(output, expected)
99
100 def _ospf6_converge(router):
101 output = json.loads(router.vtysh_cmd("show ipv6 route 2001:db8:1::/64 json"))
102 expected = {
103 "2001:db8:1::/64": [
104 {
105 "ospfPathType": "Intra-Area",
106 "ospfAreaId": "0.0.0.0",
107 }
108 ]
109 }
110 return topotest.json_cmp(output, expected)
111
112 router = tgen.gears["r1"]
113 test_func = functools.partial(_bgp_converge, router)
114 success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
115 assert result is None, 'Cannot see BGP community aliases "{}"'.format(router)
116
117 router = tgen.gears["r3"]
118 test_func = functools.partial(_ospf_converge, router)
119 success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
120 assert result is None, 'Cannot see OSPFv2 opaque attributes "{}"'.format(router)
121
122 router = tgen.gears["r3"]
123 test_func = functools.partial(_ospf6_converge, router)
124 success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
125 assert result is None, 'Cannot see OSPFv3 opaque attributes "{}"'.format(router)
126
127
128 if __name__ == "__main__":
129 args = ["-s"] + sys.argv[1:]
130 sys.exit(pytest.main(args))