def test_snmp_get_invalid_object_with_abort_enabled(sess_args): if sess_args['version'] == 1: with pytest.raises(EasySNMPNoSuchNameError): snmp_get('iso', abort_on_nonexistent=True, **sess_args) else: with pytest.raises(EasySNMPNoSuchObjectError): snmp_get('iso', abort_on_nonexistent=True, **sess_args)
def test_snmp_get_invalid_object(sess_args): if sess_args['version'] == 1: with pytest.raises(EasySNMPNoSuchNameError): snmp_get('iso', **sess_args) else: res = snmp_get('iso', **sess_args) assert res.snmp_type == 'NOSUCHOBJECT'
def test_snmp_get_invalid_instance_with_abort_enabled(sess_args): # Sadly, SNMP v1 doesn't distinguish between an invalid instance and an # invalid object ID, so it raises the same exception for both if sess_args['version'] == 1: with pytest.raises(EasySNMPNoSuchNameError): snmp_get('sysContact.1', abort_on_nonexistent=True, **sess_args) else: with pytest.raises(EasySNMPNoSuchInstanceError): snmp_get('sysContact.1', abort_on_nonexistent=True, **sess_args)
def test_snmp_get_invalid_instance(sess_args): # Sadly, SNMP v1 doesn't distinguish between an invalid instance and an # invalid object ID, instead it excepts with noSuchName if sess_args['version'] == 1: with pytest.raises(EasySNMPNoSuchNameError): snmp_get('sysContact.1', **sess_args) else: res = snmp_get('sysContact.1', **sess_args) assert res.snmp_type == 'NOSUCHINSTANCE'
def test_snmp_set_multiple(sess_args): res = snmp_get(['sysLocation.0', 'nsCacheTimeout.1.3.6.1.2.1.2.2'], **sess_args) assert res[0].value != 'my newer location' assert res[1].value != '162' success = snmp_set_multiple( [('sysLocation.0', 'my newer location'), (('nsCacheTimeout', '.1.3.6.1.2.1.2.2'), 162)], **sess_args) assert success res = snmp_get(['sysLocation.0', 'nsCacheTimeout.1.3.6.1.2.1.2.2'], **sess_args) assert res[0].value == 'my newer location' assert res[1].value == '162'
def test_snmp_set_string(sess_args): res = snmp_get(('sysLocation', '0'), **sess_args) assert res.oid == 'sysLocation' assert res.oid_index == '0' assert res.value != 'my newer location' assert res.snmp_type == 'OCTETSTR' success = snmp_set(('sysLocation', '0'), 'my newer location', **sess_args) assert success res = snmp_get(('sysLocation', '0'), **sess_args) assert res.oid == 'sysLocation' assert res.oid_index == '0' assert res.value == 'my newer location' assert res.snmp_type == 'OCTETSTR'
def test_snmp_get_numeric_tuple(sess_args): res = snmp_get(('.1.3.6.1.2.1.1.1', '0'), **sess_args) assert platform.version() in res.value assert res.oid == 'sysDescr' assert res.oid_index == '0' assert res.snmp_type == 'OCTETSTR'
def test_snmp_get_numeric_no_leading_dot(sess_args): res = snmp_get('1.3.6.1.2.1.1.1.0', **sess_args) assert platform.version() in res.value assert res.oid == 'sysDescr' assert res.oid_index == '0' assert res.snmp_type == 'OCTETSTR'
def test_snmp_get_regular(sess_args): res = snmp_get('sysDescr.0', **sess_args) assert platform.version() in res.value assert res.oid == 'sysDescr' assert res.oid_index == '0' assert res.snmp_type == 'OCTETSTR'
def test_snmp_get_fully_qualified_tuple(sess_args): res = snmp_get(('.iso.org.dod.internet.mgmt.mib-2.system.sysDescr', '0'), **sess_args) assert platform.version() in res.value assert res.oid == 'sysDescr' assert res.oid_index == '0' assert res.snmp_type == 'OCTETSTR'
def test_snmp_set_integer(sess_args): success = snmp_set(('nsCacheTimeout', '.1.3.6.1.2.1.2.2'), 65, **sess_args) assert success res = snmp_get(('nsCacheTimeout', '.1.3.6.1.2.1.2.2'), **sess_args) assert res.oid == 'nsCacheTimeout' assert res.oid_index == '1.3.6.1.2.1.2.2' assert res.value == '65' assert res.snmp_type == 'INTEGER'
def test_snmp_get_unknown(sess_args): with pytest.raises(EasySNMPUnknownObjectIDError): snmp_get('sysDescripto.0', **sess_args)