Ejemplo n.º 1
0
def test_broken_instance():
    logger = FakeLogger()
    config_name = 'broken_instance'

    with pytest.raises(KeyError):
        snmp_trap_handler.determine_action(
            oid=config_name,
            oid_lookup=mock.Mock(),
            logger=logger,
        )

    expected_path = CONF_PATH.format(oid=config_name)
    assert logger.string_appears_in('debug', expected_path)

    assert logger.string_appears_in('debug', 'loading instance')
Ejemplo n.º 2
0
def test_oid_for_message_and_instance():
    logger = FakeLogger()
    config_name = 'instance_and_message_oid'
    lookups = {
        'instanceoid': 'lookedupinstance',
        'messageoid': 'lookedupmessage',
    }
    oid_lookup = FakeOidLookup(lookups=lookups)

    result = snmp_trap_handler.determine_action(
        oid=config_name,
        oid_lookup=oid_lookup,
        logger=logger,
    )

    expected_path = CONF_PATH.format(oid=config_name)
    assert logger.string_appears_in('debug', expected_path)

    assert logger.string_appears_in('debug', 'loading instance')
    assert logger.string_appears_in('debug', 'loading oid_for_message')

    assert result['instance'] == {
        'oid': lookups['instanceoid'],
        'finder': re.compile(u'testfinder'),
    }
    assert result['oid_for_message'] == lookups['messageoid']
Ejemplo n.º 3
0
def test_empty_action():
    logger = FakeLogger()
    config_name = 'empty'

    with pytest.raises(ValueError):
        snmp_trap_handler.determine_action(
            oid=config_name,
            oid_lookup=mock.Mock(),
            logger=logger,
        )

    expected_path = CONF_PATH.format(oid=config_name)
    assert logger.string_appears_in('debug', expected_path)

    assert 'not' in logger.messages['exception'][-1]
    assert 'JSON' in logger.messages['exception'][-1]
    assert 'empty' in logger.messages['exception'][-1]
Ejemplo n.º 4
0
def test_oid_for_message_lookup_exception():
    logger = FakeLogger()
    config_name = 'just_oid_for_message'
    oid_lookup = mock.Mock()
    oid_lookup.get.side_effect = RuntimeError

    with pytest.raises(RuntimeError):
        snmp_trap_handler.determine_action(
            oid=config_name,
            oid_lookup=oid_lookup,
            logger=logger,
        )

    expected_path = CONF_PATH.format(oid=config_name)
    assert logger.string_appears_in('debug', expected_path)

    assert logger.string_appears_in('debug', 'loading oid_for_message')
Ejemplo n.º 5
0
def test_missing_action():
    logger = FakeLogger()
    config_name = 'missing'

    result = snmp_trap_handler.determine_action(
        oid=config_name,
        oid_lookup=mock.Mock(),
        logger=logger,
    )

    assert result is None

    expected_path = CONF_PATH.format(oid=config_name)
    assert logger.string_appears_in('debug', expected_path)

    assert 'not found' in logger.messages['warn'][-1]
Ejemplo n.º 6
0
def test_just_oid_for_message():
    logger = FakeLogger()
    config_name = 'just_oid_for_message'
    oid_lookup = FakeOidLookup(default='looked_up_message_oid')

    result = snmp_trap_handler.determine_action(
        oid=config_name,
        oid_lookup=oid_lookup,
        logger=logger,
    )

    expected_path = CONF_PATH.format(oid=config_name)
    assert logger.string_appears_in('debug', expected_path)

    assert not logger.string_appears_in('debug', 'loading instance')
    assert logger.string_appears_in('debug', 'loading oid_for_message')

    assert result['oid_for_message'] == 'looked_up_message_oid'