Skip to content

Commit

Permalink
[test_snmp_cpu]Use timeout configuration in all SNMP request, increas…
Browse files Browse the repository at this point in the history
…e SNMP request timeout to 20 (#16290)

Description of PR
Summary:
Fixes #30112399

Approach
What is the motivation for this PR?
Fix test_snmp_cpu failures on Cisco chassis.

How did you do it?
Incorporate timeout setting in all SNMP commands
Increase chassis SNMP request timeout to 20s
How did you verify/test it?
Run on Cisco chassis and it stably pass.

co-authorized by: jianquanye@microsoft.com
  • Loading branch information
yejianquan authored and mssonicbld committed Jan 15, 2025
1 parent ba1e21d commit bc56df5
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions ansible/library/snmp_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,10 @@ def main():
module = AnsibleModule(
argument_spec=dict(
host=dict(required=True),
timeout=dict(reqired=False, type='int', default=5),
# https://github.com/sonic-net/sonic-buildimage/blob/7a21cab07dbd0ace80833a57e391dec0ebde9978/dockers/docker-snmp/snmpd.conf.j2#L197
# In snmpd.conf, we set the timeout as 5s and 4 retries.
# Total time window = 4 * 5 = 20 seconds
timeout=dict(reqired=False, type='int', default=20),
version=dict(required=True, choices=['v2', 'v2c', 'v3']),
community=dict(required=False, default=False),
username=dict(required=False),
Expand Down Expand Up @@ -436,7 +439,7 @@ def Tree(): return defaultdict(Tree)

errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.sysObjectId,),
cmdgen.MibVariable(p.sysUpTime,),
cmdgen.MibVariable(p.sysContact,),
Expand Down Expand Up @@ -549,7 +552,7 @@ def Tree(): return defaultdict(Tree)

errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.ifInDiscards,),
cmdgen.MibVariable(p.ifOutDiscards,),
cmdgen.MibVariable(p.ifInErrors,),
Expand Down Expand Up @@ -596,7 +599,7 @@ def Tree(): return defaultdict(Tree)

errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.entPhysDescr,),
cmdgen.MibVariable(p.entPhysContainedIn, ),
cmdgen.MibVariable(p.entPhysClass,),
Expand Down Expand Up @@ -662,7 +665,7 @@ def Tree(): return defaultdict(Tree)

errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.entPhySensorType,),
cmdgen.MibVariable(p.entPhySensorScale,),
cmdgen.MibVariable(p.entPhySensorPrecision,),
Expand Down Expand Up @@ -717,7 +720,7 @@ def Tree(): return defaultdict(Tree)
if m_args['is_dell']:
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.ChStackUnitCpuUtil5sec,),
lookupMib=False, lexicographicMode=False
)
Expand All @@ -735,7 +738,7 @@ def Tree(): return defaultdict(Tree)

errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.lldpLocChassisIdSubtype,),
cmdgen.MibVariable(p.lldpLocChassisId,),
cmdgen.MibVariable(p.lldpLocSysName,),
Expand All @@ -761,7 +764,7 @@ def Tree(): return defaultdict(Tree)

errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.lldpLocPortIdSubtype,),
cmdgen.MibVariable(p.lldpLocPortId,),
cmdgen.MibVariable(p.lldpLocPortDesc,),
Expand All @@ -788,7 +791,7 @@ def Tree(): return defaultdict(Tree)

errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.lldpLocManAddrLen,),
cmdgen.MibVariable(p.lldpLocManAddrIfSubtype,),
cmdgen.MibVariable(p.lldpLocManAddrIfId,),
Expand All @@ -815,7 +818,7 @@ def Tree(): return defaultdict(Tree)

errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.lldpRemChassisIdSubtype,),
cmdgen.MibVariable(p.lldpRemChassisId,),
cmdgen.MibVariable(p.lldpRemPortIdSubtype,),
Expand Down Expand Up @@ -866,7 +869,7 @@ def Tree(): return defaultdict(Tree)

errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.lldpRemManAddrIfSubtype,),
cmdgen.MibVariable(p.lldpRemManAddrIfId,),
cmdgen.MibVariable(p.lldpRemManAddrOID,),
Expand Down Expand Up @@ -926,7 +929,7 @@ def Tree(): return defaultdict(Tree)

errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.csqIfQosGroupStats,),
lookupMib=False,
)
Expand All @@ -947,7 +950,7 @@ def Tree(): return defaultdict(Tree)

errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.cefcFRUPowerOperStatus,),
lookupMib=False,
)
Expand All @@ -965,7 +968,7 @@ def Tree(): return defaultdict(Tree)

errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.ipCidrRouteEntry,),
cmdgen.MibVariable(p.ipCidrRouteStatus,),
lookupMib=False,
Expand All @@ -989,7 +992,7 @@ def Tree(): return defaultdict(Tree)
if not m_args['is_eos']:
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.sysTotalMemory,),
cmdgen.MibVariable(p.sysTotalFreeMemory,),
cmdgen.MibVariable(p.sysTotalSharedMemory,),
Expand Down Expand Up @@ -1023,7 +1026,7 @@ def Tree(): return defaultdict(Tree)
if m_args['include_swap']:
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.sysTotalSwap,),
cmdgen.MibVariable(p.sysTotalFreeSwap,),
lookupMib=False, lexicographicMode=False
Expand All @@ -1044,7 +1047,7 @@ def Tree(): return defaultdict(Tree)

errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.UdpTransportTarget((m_args['host'], 161), timeout=m_args['timeout']),
cmdgen.MibVariable(p.dot1qTpFdbEntry,),
lookupMib=False,
)
Expand Down

0 comments on commit bc56df5

Please sign in to comment.