]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/simple_snmp_test/test_simple_snmp.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2020 by Volta Networks
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
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
25 test_bgp_simple snmp.py: Test snmp infrastructure.
31 from functools
import partial
32 from time
import sleep
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
, "../"))
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
46 # Required to instantiate the topology builder class.
47 from mininet
.topo
import Topo
49 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.isisd
, pytest
.mark
.snmp
]
52 class TemplateTopo(Topo
):
53 "Test topology builder"
55 def build(self
, *_args
, **_opts
):
57 tgen
= get_topogen(self
)
59 # This function only purpose is to define allocation and relationship
60 # between routers, switches and hosts.
67 switch
= tgen
.add_switch("s1")
68 switch
.add_link(tgen
.gears
["r1"])
71 switch
= tgen
.add_switch("s2")
72 switch
.add_link(tgen
.gears
["r1"])
75 switch
= tgen
.add_switch("s3")
76 switch
.add_link(tgen
.gears
["r1"])
79 def setup_module(mod
):
80 "Sets up the pytest environment"
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.
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")
103 router_list
= tgen
.routers()
105 # For all registred routers, load the zebra configuration file
106 for rname
, router
in router_list
.items():
108 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
111 TopoRouter
.RD_ISIS
, os
.path
.join(CWD
, "{}/isisd.conf".format(rname
))
115 os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
)),
120 os
.path
.join(CWD
, "{}/snmpd.conf".format(rname
)),
121 "-Le -Ivacm_conf,usmConf,iquery -V -DAgentX,trap",
124 # After loading the configurations, this function loads configured daemons.
128 def teardown_module(mod
):
129 "Teardown the pytest environment"
132 # This function tears down the whole topology.
136 def test_r1_bgp_version():
137 "Wait for protocol convergence"
140 # Skip if previous fatal error condition is raised
141 if tgen
.routers_have_failure():
142 pytest
.skip(tgen
.errors
)
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"])
153 def test_memory_leak():
154 "Run the memory leak test and report results."
156 if not tgen
.is_memleak_enabled():
157 pytest
.skip("Memory leak test/report is disabled")
159 tgen
.report_memory_leaks()
162 if __name__
== "__main__":
163 args
= ["-s"] + sys
.argv
[1:]
164 sys
.exit(pytest
.main(args
))