]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/simple_snmp_test/test_simple_snmp.py
Merge pull request #12248 from pguibert6WIND/bgpasdot
[mirror_frr.git] / tests / topotests / simple_snmp_test / test_simple_snmp.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: ISC
3
4 #
5 # test_simple_snmp.py
6 # Part of NetDEF Topology Tests
7 #
8 # Copyright (c) 2020 by Volta Networks
9 #
10
11 """
12 test_bgp_simple snmp.py: Test snmp infrastructure.
13 """
14
15 import os
16 import sys
17 import pytest
18
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, "../"))
22
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
27
28
29 pytestmark = [pytest.mark.bgpd, pytest.mark.isisd, pytest.mark.snmp]
30
31
32 def setup_module(mod):
33 "Sets up the pytest environment"
34
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.
43 tgen.start_topology()
44
45 r1 = tgen.gears["r1"]
46
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")
56
57 router_list = tgen.routers()
58
59 # For all registered routers, load the zebra configuration file
60 for rname, router in router_list.items():
61 router.load_config(
62 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
63 )
64 router.load_config(
65 TopoRouter.RD_ISIS, os.path.join(CWD, "{}/isisd.conf".format(rname))
66 )
67 router.load_config(
68 TopoRouter.RD_BGP,
69 os.path.join(CWD, "{}/bgpd.conf".format(rname)),
70 "-M snmp",
71 )
72 router.load_config(
73 TopoRouter.RD_SNMP,
74 os.path.join(CWD, "{}/snmpd.conf".format(rname)),
75 "-Le -Ivacm_conf,usmConf,iquery -V -DAgentX,trap",
76 )
77
78 # After loading the configurations, this function loads configured daemons.
79 tgen.start_router()
80
81
82 def teardown_module(mod):
83 "Teardown the pytest environment"
84 tgen = get_topogen()
85
86 # This function tears down the whole topology.
87 tgen.stop_topology()
88
89
90 def test_r1_bgp_version():
91 "Wait for protocol convergence"
92 tgen = get_topogen()
93
94 # Skip if previous fatal error condition is raised
95 if tgen.routers_have_failure():
96 pytest.skip(tgen.errors)
97
98 # tgen.mininet_cli()
99 r1 = tgen.gears["r1"]
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"])
105
106
107 def test_memory_leak():
108 "Run the memory leak test and report results."
109 tgen = get_topogen()
110 if not tgen.is_memleak_enabled():
111 pytest.skip("Memory leak test/report is disabled")
112
113 tgen.report_memory_leaks()
114
115
116 if __name__ == "__main__":
117 args = ["-s"] + sys.argv[1:]
118 sys.exit(pytest.main(args))