Example #1
0
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'
Example #2
0
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'
Example #3
0
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)
Example #4
0
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)
Example #5
0
def test_snmp_get_invalid_instance(sess_args):
    # Sadly, SNMP v1 doesn't distuingish 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'
Example #6
0
def test_snmp_get_invalid_instance_with_abort_enabled(sess_args):
    # Sadly, SNMP v1 doesn't distuingish 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)
Example #7
0
def test_snmp_get_invalid_instance(sess_args):
    # Sadly, SNMP v1 doesn't distuingish 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'
Example #8
0
def test_snmp_get_invalid_instance_with_abort_enabled(sess_args):
    # Sadly, SNMP v1 doesn't distuingish 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)
Example #9
0
def test_snmp_set_string(sess_args, request, reset_values):
    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"
Example #10
0
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'
Example #11
0
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'
Example #12
0
def test_snmp_get_tuple(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'
Example #13
0
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'
Example #14
0
def test_snmp_set_multiple(sess_args, reset_values):
    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"
Example #15
0
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"
Example #16
0
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"
Example #17
0
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"
Example #18
0
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'
Example #19
0
def test_snmp_get_next_with_retry_no_such(sess_args):
    res = snmp_get(["iso.9", "sysDescr.0", "iso.9"],
                   retry_no_such=True,
                   **sess_args)

    assert res[0]
    if sess_args["version"] == 1:
        assert res[0].value == "NOSUCHNAME"
        assert res[0].oid == "iso"
        assert res[0].oid_index == "9"
        assert res[0].snmp_type == "NOSUCHNAME"
    else:
        assert res[0].snmp_type == "NOSUCHOBJECT"

    assert res[1]
    assert platform.version() in res[1].value
    assert res[1].oid == "sysDescr"
    assert res[1].oid_index == "0"
    assert res[1].snmp_type == "OCTETSTR"

    assert res[2]
    if sess_args["version"] == 1:
        assert res[2].value == "NOSUCHNAME"
        assert res[2].oid == "iso"
        assert res[2].oid_index == "9"
        assert res[2].snmp_type == "NOSUCHNAME"
    else:
        assert res[2].snmp_type == "NOSUCHOBJECT"
Example #20
0
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'
Example #21
0
def test_snmp_get_tuple(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'
Example #22
0
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'
Example #23
0
def test_snmp_set_string_short_type(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', 's', **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'
Example #24
0
def test_snmp_get_fully_qualified(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"
Example #25
0
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'
Example #26
0
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'
Example #27
0
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'
Example #28
0
def test_snmp_set_integer(sess_args, reset_values):
    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"
Example #29
0
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'
Example #30
0
def test_snmp_set_integer_short_type(sess_args):
    success = snmp_set(
        ('nsCacheTimeout', '.1.3.6.1.2.1.2.2'), 65, 'i', **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'
Example #31
0
def test_snmp_v1_get_with_retry_no_such(sess_args):
    sess_args['retry_no_such'] = True

    res = snmp_get(['iso', 'sysDescr.0', 'iso'], **sess_args)

    assert res[0]
    assert res[0].oid == 'iso'
    assert res[0].snmp_type == 'NOSUCHNAME'

    assert res[1]
    assert platform.version() in res[1].value
    assert res[1].oid == 'sysDescr'
    assert res[1].oid_index == '0'
    assert res[1].snmp_type == 'OCTETSTR'

    assert res[2]
    assert res[2].oid == 'iso'
    assert res[2].snmp_type == 'NOSUCHNAME'
Example #32
0
def test_snmp_v1_get_with_retry_no_such(sess_args):
    sess_args['retry_no_such'] = True

    res = snmp_get(['iso', 'sysDescr.0', 'iso'], **sess_args)

    assert res[0]
    assert res[0].oid == 'iso'
    assert res[0].snmp_type == 'NOSUCHNAME'

    assert res[1]
    assert platform.version() in res[1].value
    assert res[1].oid == 'sysDescr'
    assert res[1].oid_index == '0'
    assert res[1].snmp_type == 'OCTETSTR'

    assert res[2]
    assert res[2].oid == 'iso'
    assert res[2].snmp_type == 'NOSUCHNAME'
Example #33
0
def test_snmp_get_unknown(sess_args):
    with pytest.raises(EasySNMPUnknownObjectIDError):
        snmp_get('sysDescripto.0', **sess_args)
Example #34
0
def test_snmp_get_unknown(sess_args):
    with pytest.raises(EasySNMPUnknownObjectIDError):
        snmp_get('sysDescripto.0', **sess_args)