]>
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 router_list
= tgen
.routers()
95 # For all registred routers, load the zebra configuration file
96 for rname
, router
in router_list
.items():
98 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
101 TopoRouter
.RD_ISIS
, os
.path
.join(CWD
, "{}/isisd.conf".format(rname
))
105 os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
)),
110 os
.path
.join(CWD
, "{}/snmpd.conf".format(rname
)),
111 "-Le -Ivacm_conf,usmConf,iquery -V -DAgentX,trap",
114 # After loading the configurations, this function loads configured daemons.
118 def teardown_module(mod
):
119 "Teardown the pytest environment"
122 # This function tears down the whole topology.
126 def test_r1_bgp_version():
127 "Wait for protocol convergence"
130 # Skip if previous fatal error condition is raised
131 if tgen
.routers_have_failure():
132 pytest
.skip(tgen
.errors
)
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"])
143 def test_memory_leak():
144 "Run the memory leak test and report results."
146 if not tgen
.is_memleak_enabled():
147 pytest
.skip("Memory leak test/report is disabled")
149 tgen
.report_memory_leaks()
152 if __name__
== "__main__":
153 args
= ["-s"] + sys
.argv
[1:]
154 sys
.exit(pytest
.main(args
))