diff --git a/ansible/library/snmp_facts.py b/ansible/library/snmp_facts.py index 6166e954595..51488757c40 100644 --- a/ansible/library/snmp_facts.py +++ b/ansible/library/snmp_facts.py @@ -44,7 +44,11 @@ required: false is_dell: description: - - Whether the bos is dell or not + - Whether the nos is dell or not + required: false + is_eos: + description: + - Whether the nos is eos or not required: false level: description: @@ -291,6 +295,7 @@ def main(): authkey=dict(required=False), privkey=dict(required=False), is_dell=dict(required=False, default=False, type='bool'), + is_eos=dict(required=False, default=False, type='bool'), removeplaceholder=dict(required=False)), required_together = ( ['username','level','integrity','authkey'],['privacy','privkey'],), supports_check_mode=False) @@ -371,8 +376,6 @@ def main(): cmdgen.MibVariable(p.sysContact,), cmdgen.MibVariable(p.sysName,), cmdgen.MibVariable(p.sysLocation,), - cmdgen.MibVariable(p.sysTotalMemery,), - cmdgen.MibVariable(p.sysTotalFreeMemery,), lookupMib=False, lexicographicMode=False ) @@ -392,10 +395,6 @@ def main(): results['ansible_sysname'] = current_val elif current_oid == v.sysLocation: results['ansible_syslocation'] = current_val - elif current_oid == v.sysTotalMemery: - results['ansible_sysTotalMemery'] = decode_type(module, current_oid, val) - elif current_oid == v.sysTotalFreeMemery: - results['ansible_sysTotalFreeMemery'] = decode_type(module, current_oid, val) errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd( snmp_auth, @@ -849,6 +848,26 @@ def main(): psuIndex = int(current_oid.split('.')[-1]) results['snmp_psu'][psuIndex]['operstatus'] = current_val + if not m_args['is_eos']: + errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( + snmp_auth, + cmdgen.UdpTransportTarget((m_args['host'], 161)), + cmdgen.MibVariable(p.sysTotalMemery,), + cmdgen.MibVariable(p.sysTotalFreeMemery,), + lookupMib=False, lexicographicMode=False + ) + + if errorIndication: + module.fail_json(msg=str(errorIndication) + ' querying system infomation.') + + for oid, val in varBinds: + current_oid = oid.prettyPrint() + current_val = val.prettyPrint() + if current_oid == v.sysTotalMemery: + results['ansible_sysTotalMemery'] = decode_type(module, current_oid, val) + elif current_oid == v.sysTotalFreeMemery: + results['ansible_sysTotalFreeMemery'] = decode_type(module, current_oid, val) + module.exit_json(ansible_facts=results) main() diff --git a/tests/test_nbr_health.py b/tests/test_nbr_health.py index 4b960b706c3..9bd55708155 100644 --- a/tests/test_nbr_health.py +++ b/tests/test_nbr_health.py @@ -16,7 +16,7 @@ def test_neighbors_health(duthost, testbed_devices, eos): nei_meta = config_facts.get('DEVICE_NEIGHBOR_METADATA', {}) for k, v in nei_meta.items(): logger.info("Check neighbor {}, mgmt ip {} snmp".format(k, v['mgmt_addr'])) - res = localhost.snmp_facts(host=v['mgmt_addr'], version='v2c', community=eos['snmp_rocommunity']) + res = localhost.snmp_facts(host=v['mgmt_addr'], version='v2c', is_eos=True, community=eos['snmp_rocommunity']) try: snmp_data = res['ansible_facts'] except: