]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/simple_snmp_test/test_simple_snmp.py
2 # SPDX-License-Identifier: ISC
6 # Part of NetDEF Topology Tests
8 # Copyright (c) 2020 by Volta Networks
12 test_bgp_simple snmp.py: Test snmp infrastructure.
19 # Save the Current Working Directory to find configuration files.
20 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
21 sys
.path
.append(os
.path
.join(CWD
, "../"))
23 # pylint: disable=C0413
24 # Import topogen and topotest helpers
25 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
26 from lib
.snmptest
import SnmpTester
29 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.isisd
, pytest
.mark
.snmp
]
32 def setup_module(mod
):
33 "Sets up the pytest environment"
35 # skip tests is SNMP not installed
36 if not os
.path
.isfile("/usr/sbin/snmpd"):
37 error_msg
= "SNMP not installed - skipping"
38 pytest
.skip(error_msg
)
39 # This function initiates the topology build with Topogen...
40 topodef
= {"s1": "r1", "s2": "r1", "s3": "r1"}
41 tgen
= Topogen(topodef
, mod
.__name
__)
42 # ... and here it calls Mininet initialization functions.
47 r1
.run("ip addr add 192.168.12.12/24 dev r1-eth0")
48 r1
.run("ip -6 addr add 2000:1:1:12::12/64 dev r1-eth0")
49 r1
.run("ip addr add 192.168.13.13/24 dev r1-eth1")
50 r1
.run("ip -6 addr add 2000:1:1:13::13/64 dev r1-eth1")
51 r1
.run("ip addr add 192.168.14.14/24 dev r1-eth2")
52 r1
.run("ip -6 addr add 2000:1:1:14::14/64 dev r1-eth2")
53 r1
.run("ip addr add 1.1.1.1/32 dev lo")
54 r1
.run("ip -6 addr add 2000:1:1:1::1/128 dev lo")
55 r1
.run("ip addr show")
57 router_list
= tgen
.routers()
59 # For all registered routers, load the zebra configuration file
60 for rname
, router
in router_list
.items():
62 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
65 TopoRouter
.RD_ISIS
, os
.path
.join(CWD
, "{}/isisd.conf".format(rname
))
69 os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
)),
74 os
.path
.join(CWD
, "{}/snmpd.conf".format(rname
)),
75 "-Le -Ivacm_conf,usmConf,iquery -V -DAgentX,trap",
78 # After loading the configurations, this function loads configured daemons.
82 def teardown_module(mod
):
83 "Teardown the pytest environment"
86 # This function tears down the whole topology.
90 def test_r1_bgp_version():
91 "Wait for protocol convergence"
94 # Skip if previous fatal error condition is raised
95 if tgen
.routers_have_failure():
96 pytest
.skip(tgen
.errors
)
100 r1_snmp
= SnmpTester(r1
, "1.1.1.1", "public", "2c")
101 assert r1_snmp
.test_oid("bgpVersin", None)
102 assert r1_snmp
.test_oid("bgpVersion", "10")
103 assert r1_snmp
.test_oid_walk("bgpVersion", ["10"])
104 assert r1_snmp
.test_oid_walk("bgpVersion", ["10"], ["0"])
107 def test_memory_leak():
108 "Run the memory leak test and report results."
110 if not tgen
.is_memleak_enabled():
111 pytest
.skip("Memory leak test/report is disabled")
113 tgen
.report_memory_leaks()
116 if __name__
== "__main__":
117 args
= ["-s"] + sys
.argv
[1:]
118 sys
.exit(pytest
.main(args
))