]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/simple_snmp_test/test_simple_snmp.py
Merge pull request #8304 from mjstapp/fix_zmq_xref
[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 router_list = tgen.routers()
94
95 # For all registred routers, load the zebra configuration file
96 for rname, router in router_list.items():
97 router.load_config(
98 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
99 )
100 router.load_config(
101 TopoRouter.RD_ISIS, os.path.join(CWD, "{}/isisd.conf".format(rname))
102 )
103 router.load_config(
104 TopoRouter.RD_BGP,
105 os.path.join(CWD, "{}/bgpd.conf".format(rname)),
106 "-M snmp",
107 )
108 router.load_config(
109 TopoRouter.RD_SNMP,
110 os.path.join(CWD, "{}/snmpd.conf".format(rname)),
111 "-Le -Ivacm_conf,usmConf,iquery -V -DAgentX,trap",
112 )
113
114 # After loading the configurations, this function loads configured daemons.
115 tgen.start_router()
116
117
118 def teardown_module(mod):
119 "Teardown the pytest environment"
120 tgen = get_topogen()
121
122 # This function tears down the whole topology.
123 tgen.stop_topology()
124
125
126 def test_r1_bgp_version():
127 "Wait for protocol convergence"
128 tgen = get_topogen()
129
130 # Skip if previous fatal error condition is raised
131 if tgen.routers_have_failure():
132 pytest.skip(tgen.errors)
133
134 # tgen.mininet_cli()
135 r1 = tgen.net.get("r1")
136 r1_snmp = SnmpTester(r1, "1.1.1.1", "public", "2c")
137 assert r1_snmp.test_oid("bgpVersin", None)
138 assert r1_snmp.test_oid("bgpVersion", "10")
139 assert r1_snmp.test_oid_walk("bgpVersion", ["10"])
140 assert r1_snmp.test_oid_walk("bgpVersion", ["10"], ["0"])
141
142
143 def test_memory_leak():
144 "Run the memory leak test and report results."
145 tgen = get_topogen()
146 if not tgen.is_memleak_enabled():
147 pytest.skip("Memory leak test/report is disabled")
148
149 tgen.report_memory_leaks()
150
151
152 if __name__ == "__main__":
153 args = ["-s"] + sys.argv[1:]
154 sys.exit(pytest.main(args))