Example #1
0
def test_removing_host():
    """If a discovered host is failing 3 times in a row, we stop querying it."""
    instance = common.generate_instance_config(common.SUPPORTED_METRIC_TYPES)
    discovered_instance = instance.copy()
    discovered_instance['ip_address'] = '1.1.1.1'
    discovered_instance['retries'] = 0
    instance.pop('ip_address')
    instance['network_address'] = '192.168.0.0/24'
    check = SnmpCheck('snmp', {}, [instance])
    warnings = []
    check.warning = warnings.append
    check._config.discovered_instances['1.1.1.1'] = InstanceConfig(
        discovered_instance, None, None, [], '', {}, {})
    msg = 'No SNMP response received before timeout for instance 1.1.1.1'

    check.check(instance)
    assert warnings == [msg]

    check.check(instance)
    assert warnings == [msg, msg]

    check.check(instance)
    assert warnings == [msg, msg, msg]

    check.check(instance)
    assert warnings == [msg, msg, msg, msg]
    # Instance has been removed
    assert check._config.discovered_instances == {}

    check.check(instance)
    # No new warnings produced
    assert warnings == [msg, msg, msg, msg]
Example #2
0
def test_removing_host():
    """If a discovered host is failing 3 times in a row, we stop querying it."""
    instance = common.generate_instance_config(common.SUPPORTED_METRIC_TYPES)
    discovered_instance = instance.copy()
    discovered_instance['ip_address'] = '1.1.1.1'
    discovered_instance['retries'] = 0
    instance.pop('ip_address')
    instance['network_address'] = '192.168.0.0/24'
    check = SnmpCheck('snmp', {}, [instance])
    warnings = []
    check.warning = warnings.append
    check._config.discovered_instances['1.1.1.1'] = InstanceConfig(discovered_instance)

    check._start_discovery = lambda: None
    check._executor = futures.ThreadPoolExecutor(max_workers=1)
    check.check(instance)

    assert len(warnings) == 1
    warning = warnings[0]
    msg = 'Failed to collect some metrics: No SNMP response received before timeout'
    assert msg in warning

    check.check(instance)
    assert warnings == [warning, warning]

    check.check(instance)
    assert warnings == [warning, warning, warning]
    # Instance has been removed
    assert check._config.discovered_instances == {}

    check.check(instance)
    # No new warnings produced
    assert warnings == [warning, warning, warning]