From 92be50e63eb397b663964d64dec451a14317fe26 Mon Sep 17 00:00:00 2001 From: Babis Chalios Date: Wed, 11 Nov 2020 14:34:32 +0000 Subject: [PATCH] tests: API to launch snmpd in a topotest scenario Prepare the infrastructure to allow configuring and launching an SNMP daemon as part of testing scenario. Signed-off-by: Babis Chalios Signed-off-by: Pat Ruddy Chalios --- tests/topotests/lib/topogen.py | 6 ++++-- tests/topotests/lib/topotest.py | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 7c52e824c1..f958cc11d3 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -555,6 +555,7 @@ class TopoRouter(TopoGear): RD_BABEL = 15 RD_PBRD = 16 RD_PATH = 17 + RD_SNMP = 18 RD = { RD_ZEBRA: "zebra", RD_RIP: "ripd", @@ -572,7 +573,8 @@ class TopoRouter(TopoGear): RD_SHARP: "sharpd", RD_BABEL: "babeld", RD_PBRD: "pbrd", - RD_PATH: 'pathd', + RD_PATH: "pathd", + RD_SNMP: "snmpd", } def __init__(self, tgen, cls, name, **params): @@ -657,7 +659,7 @@ class TopoRouter(TopoGear): Possible daemon values are: TopoRouter.RD_ZEBRA, TopoRouter.RD_RIP, TopoRouter.RD_RIPNG, TopoRouter.RD_OSPF, TopoRouter.RD_OSPF6, TopoRouter.RD_ISIS, TopoRouter.RD_BGP, TopoRouter.RD_LDP, - TopoRouter.RD_PIM, TopoRouter.RD_PBR. + TopoRouter.RD_PIM, TopoRouter.RD_PBR, TopoRouter.RD_SNMP. """ daemonstr = self.RD.get(daemon) self.logger.info('loading "{}" configuration: {}'.format(daemonstr, source)) diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index ef0ac27118..3ab5663066 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -1105,7 +1105,8 @@ class Router(Node): "sharpd": 0, "babeld": 0, "pbrd": 0, - 'pathd': 0 + "pathd": 0, + "snmpd": 0, } self.daemons_options = {"zebra": ""} self.reportCores = True @@ -1289,6 +1290,8 @@ class Router(Node): % (self.routertype, self.routertype, self.routertype, daemon) ) self.waitOutput() + if (daemon == "snmpd") and (self.routertype == "frr"): + self.cmd('echo "agentXSocket /etc/frr/agentx" > /etc/snmp/frr.conf') if (daemon == "zebra") and (self.daemons["staticd"] == 0): # Add staticd with zebra - if it exists staticd_path = os.path.join(self.daemondir, "staticd") @@ -1445,6 +1448,20 @@ class Router(Node): while "staticd" in daemons_list: daemons_list.remove("staticd") + if "snmpd" in daemons_list: + snmpd_path = "/usr/sbin/snmpd" + snmpd_option = self.daemons_options["snmpd"] + self.cmd( + "{0} {1} -C -c /etc/frr/snmpd.conf -p /var/run/{2}/snmpd.pid -x /etc/frr/agentx > snmpd.out 2> snmpd.err".format( + snmpd_path, snmpd_option, self.routertype + ) + ) + logger.info("{}: {} snmpd started".format(self, self.routertype)) + + # Remove `snmpd` so we don't attempt to start it again. + while "snmpd" in daemons_list: + daemons_list.remove("snmpd") + # Fix Link-Local Addresses # Somehow (on Mininet only), Zebra removes the IPv6 Link-Local addresses on start. Fix this self.cmd( -- 2.39.5