]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/simple_snmp_test/test_simple_snmp.py
Merge pull request #9539 from ton31337/fix/floating_point_cli
[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 pytest
31
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, "../"))
35
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
40
41
42 pytestmark = [pytest.mark.bgpd, pytest.mark.isisd, pytest.mark.snmp]
43
44
45 def setup_module(mod):
46 "Sets up the pytest environment"
47
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.
56 tgen.start_topology()
57
58 r1 = tgen.gears["r1"]
59
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")
69
70 router_list = tgen.routers()
71
72 # For all registred routers, load the zebra configuration file
73 for rname, router in router_list.items():
74 router.load_config(
75 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
76 )
77 router.load_config(
78 TopoRouter.RD_ISIS, os.path.join(CWD, "{}/isisd.conf".format(rname))
79 )
80 router.load_config(
81 TopoRouter.RD_BGP,
82 os.path.join(CWD, "{}/bgpd.conf".format(rname)),
83 "-M snmp",
84 )
85 router.load_config(
86 TopoRouter.RD_SNMP,
87 os.path.join(CWD, "{}/snmpd.conf".format(rname)),
88 "-Le -Ivacm_conf,usmConf,iquery -V -DAgentX,trap",
89 )
90
91 # After loading the configurations, this function loads configured daemons.
92 tgen.start_router()
93
94
95 def teardown_module(mod):
96 "Teardown the pytest environment"
97 tgen = get_topogen()
98
99 # This function tears down the whole topology.
100 tgen.stop_topology()
101
102
103 def test_r1_bgp_version():
104 "Wait for protocol convergence"
105 tgen = get_topogen()
106
107 # Skip if previous fatal error condition is raised
108 if tgen.routers_have_failure():
109 pytest.skip(tgen.errors)
110
111 # tgen.mininet_cli()
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"])
118
119
120 def test_memory_leak():
121 "Run the memory leak test and report results."
122 tgen = get_topogen()
123 if not tgen.is_memleak_enabled():
124 pytest.skip("Memory leak test/report is disabled")
125
126 tgen.report_memory_leaks()
127
128
129 if __name__ == "__main__":
130 args = ["-s"] + sys.argv[1:]
131 sys.exit(pytest.main(args))