]>
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.
32 # Save the Current Working Directory to find configuration files.
33 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
34 sys
.path
.append(os
.path
.join(CWD
, "../"))
36 # pylint: disable=C0413
37 # Import topogen and topotest helpers
38 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
39 from lib
.snmptest
import SnmpTester
42 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.isisd
, pytest
.mark
.snmp
]
45 def setup_module(mod
):
46 "Sets up the pytest environment"
48 # skip tests is SNMP not installed
49 if not os
.path
.isfile("/usr/sbin/snmpd"):
50 error_msg
= "SNMP not installed - skipping"
51 pytest
.skip(error_msg
)
52 # This function initiates the topology build with Topogen...
53 topodef
= {"s1": "r1", "s2": "r1", "s3": "r1"}
54 tgen
= Topogen(topodef
, mod
.__name
__)
55 # ... and here it calls Mininet initialization functions.
60 r1
.run("ip addr add 192.168.12.12/24 dev r1-eth0")
61 r1
.run("ip -6 addr add 2000:1:1:12::12/64 dev r1-eth0")
62 r1
.run("ip addr add 192.168.13.13/24 dev r1-eth1")
63 r1
.run("ip -6 addr add 2000:1:1:13::13/64 dev r1-eth1")
64 r1
.run("ip addr add 192.168.14.14/24 dev r1-eth2")
65 r1
.run("ip -6 addr add 2000:1:1:14::14/64 dev r1-eth2")
66 r1
.run("ip addr add 1.1.1.1/32 dev lo")
67 r1
.run("ip -6 addr add 2000:1:1:1::1/128 dev lo")
68 r1
.run("ip addr show")
70 router_list
= tgen
.routers()
72 # For all registred routers, load the zebra configuration file
73 for rname
, router
in router_list
.items():
75 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
78 TopoRouter
.RD_ISIS
, os
.path
.join(CWD
, "{}/isisd.conf".format(rname
))
82 os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
)),
87 os
.path
.join(CWD
, "{}/snmpd.conf".format(rname
)),
88 "-Le -Ivacm_conf,usmConf,iquery -V -DAgentX,trap",
91 # After loading the configurations, this function loads configured daemons.
95 def teardown_module(mod
):
96 "Teardown the pytest environment"
99 # This function tears down the whole topology.
103 def test_r1_bgp_version():
104 "Wait for protocol convergence"
107 # Skip if previous fatal error condition is raised
108 if tgen
.routers_have_failure():
109 pytest
.skip(tgen
.errors
)
112 r1
= tgen
.gears
["r1"]
113 r1_snmp
= SnmpTester(r1
, "1.1.1.1", "public", "2c")
114 assert r1_snmp
.test_oid("bgpVersin", None)
115 assert r1_snmp
.test_oid("bgpVersion", "10")
116 assert r1_snmp
.test_oid_walk("bgpVersion", ["10"])
117 assert r1_snmp
.test_oid_walk("bgpVersion", ["10"], ["0"])
120 def test_memory_leak():
121 "Run the memory leak test and report results."
123 if not tgen
.is_memleak_enabled():
124 pytest
.skip("Memory leak test/report is disabled")
126 tgen
.report_memory_leaks()
129 if __name__
== "__main__":
130 args
= ["-s"] + sys
.argv
[1:]
131 sys
.exit(pytest
.main(args
))