]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/simple_snmp_test/test_simple_snmp.py
Merge pull request #9435 from SaiGomathiN/sai-igmp
[mirror_frr.git] / tests / topotests / simple_snmp_test / test_simple_snmp.py
1 #!/usr/bin/env python
2
3 #
4 # test_simple_snmp.py
5 # Part of NetDEF Topology Tests
6 #
7 # Copyright (c) 2020 by Volta Networks
8 #
9 # Permission to use, copy, modify, and/or distribute this software
10 # for any purpose with or without fee is hereby granted, provided
11 # that the above copyright notice and this permission notice appear
12 # in all copies.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
15 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
17 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
18 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
20 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 # OF THIS SOFTWARE.
22 #
23
24 """
25 test_bgp_simple snmp.py: Test snmp infrastructure.
26 """
27
28 import os
29 import sys
30 import json
31 from functools import partial
32 from time import sleep
33 import pytest
34
35 # Save the Current Working Directory to find configuration files.
36 CWD = os.path.dirname(os.path.realpath(__file__))
37 sys.path.append(os.path.join(CWD, "../"))
38
39 # pylint: disable=C0413
40 # Import topogen and topotest helpers
41 from lib import topotest
42 from lib.topogen import Topogen, TopoRouter, get_topogen
43 from lib.topolog import logger
44 from lib.snmptest import SnmpTester
45
46 # Required to instantiate the topology builder class.
47 from mininet.topo import Topo
48
49 pytestmark = [pytest.mark.bgpd, pytest.mark.isisd, pytest.mark.snmp]
50
51
52 class TemplateTopo(Topo):
53 "Test topology builder"
54
55 def build(self, *_args, **_opts):
56 "Build function"
57 tgen = get_topogen(self)
58
59 # This function only purpose is to define allocation and relationship
60 # between routers, switches and hosts.
61 #
62 #
63 # Create routers
64 tgen.add_router("r1")
65
66 # r1-eth0
67 switch = tgen.add_switch("s1")
68 switch.add_link(tgen.gears["r1"])
69
70 # r1-eth1
71 switch = tgen.add_switch("s2")
72 switch.add_link(tgen.gears["r1"])
73
74 # r1-eth2
75 switch = tgen.add_switch("s3")
76 switch.add_link(tgen.gears["r1"])
77
78
79 def setup_module(mod):
80 "Sets up the pytest environment"
81
82 # skip tests is SNMP not installed
83 if not os.path.isfile("/usr/sbin/snmpd"):
84 error_msg = "SNMP not installed - skipping"
85 pytest.skip(error_msg)
86 # This function initiates the topology build with Topogen...
87 tgen = Topogen(TemplateTopo, mod.__name__)
88 # ... and here it calls Mininet initialization functions.
89 tgen.start_topology()
90
91 r1 = tgen.gears["r1"]
92
93 r1.run("ip addr add 192.168.12.12/24 dev r1-eth0")
94 r1.run("ip -6 addr add 2000:1:1:12::12/64 dev r1-eth0")
95 r1.run("ip addr add 192.168.13.13/24 dev r1-eth1")
96 r1.run("ip -6 addr add 2000:1:1:13::13/64 dev r1-eth1")
97 r1.run("ip addr add 192.168.14.14/24 dev r1-eth2")
98 r1.run("ip -6 addr add 2000:1:1:14::14/64 dev r1-eth2")
99 r1.run("ip addr add 1.1.1.1/32 dev lo")
100 r1.run("ip -6 addr add 2000:1:1:1::1/128 dev lo")
101 r1.run("ip addr show")
102
103 router_list = tgen.routers()
104
105 # For all registred routers, load the zebra configuration file
106 for rname, router in router_list.items():
107 router.load_config(
108 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
109 )
110 router.load_config(
111 TopoRouter.RD_ISIS, os.path.join(CWD, "{}/isisd.conf".format(rname))
112 )
113 router.load_config(
114 TopoRouter.RD_BGP,
115 os.path.join(CWD, "{}/bgpd.conf".format(rname)),
116 "-M snmp",
117 )
118 router.load_config(
119 TopoRouter.RD_SNMP,
120 os.path.join(CWD, "{}/snmpd.conf".format(rname)),
121 "-Le -Ivacm_conf,usmConf,iquery -V -DAgentX,trap",
122 )
123
124 # After loading the configurations, this function loads configured daemons.
125 tgen.start_router()
126
127
128 def teardown_module(mod):
129 "Teardown the pytest environment"
130 tgen = get_topogen()
131
132 # This function tears down the whole topology.
133 tgen.stop_topology()
134
135
136 def test_r1_bgp_version():
137 "Wait for protocol convergence"
138 tgen = get_topogen()
139
140 # Skip if previous fatal error condition is raised
141 if tgen.routers_have_failure():
142 pytest.skip(tgen.errors)
143
144 # tgen.mininet_cli()
145 r1 = tgen.net.get("r1")
146 r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c")
147 assert r1_snmp.test_oid("bgpVersin", None)
148 assert r1_snmp.test_oid("bgpVersion", "10")
149 assert r1_snmp.test_oid_walk("bgpVersion", ["10"])
150 assert r1_snmp.test_oid_walk("bgpVersion", ["10"], ["0"])
151
152
153 def test_memory_leak():
154 "Run the memory leak test and report results."
155 tgen = get_topogen()
156 if not tgen.is_memleak_enabled():
157 pytest.skip("Memory leak test/report is disabled")
158
159 tgen.report_memory_leaks()
160
161
162 if __name__ == "__main__":
163 args = ["-s"] + sys.argv[1:]
164 sys.exit(pytest.main(args))