Example #1
0
def test_set_up_query_manager_error(instance):
    check = IbmICheck('ibm_i', {}, [instance])
    check.log = mock.MagicMock()
    with mock.patch('datadog_checks.ibm_i.IbmICheck.fetch_system_info',
                    return_value=None):
        check.set_up_query_manager()
    assert check._query_manager is None
Example #2
0
def test_check(aggregator, instance):
    # type: (AggregatorStub, Dict[str, Any]) -> None
    check = IbmICheck('ibm_i', {}, [instance])
    check.check(instance)

    aggregator.assert_all_metrics_covered()
    aggregator.assert_metrics_using_metadata(get_metadata_metrics())
Example #3
0
def test_connnection_string_no_fields(instance):
    instance = {
        **instance,
        **{
            'driver': 'driver',
        },
    }
    check = IbmICheck('ibm_i', {}, [instance])
    check.load_configuration_models()
    assert check.connection_string == 'Driver={driver};'
Example #4
0
def test_connection_subprocess(instance):
    check = IbmICheck('ibm_i', {}, [instance])
    check.load_configuration_models()
    with mock.patch(
            'datadog_checks.ibm_i.IbmICheck._create_connection_subprocess'
    ) as m:
        check.connection_subprocess
        check._subprocess = mock.MagicMock()
        check.connection_subprocess
    m.assert_called_once()
Example #5
0
def test_connnection_string(instance):
    instance = {
        **instance,
        **{
            'driver': 'driver',
            'system': 'system',
            'username': '******',
            'password': '******',
        },
    }
    check = IbmICheck('ibm_i', {}, [instance])
    check.load_configuration_models()
    assert check.connection_string == 'Driver={driver};System=system;UID=username;PWD=password;'
Example #6
0
def test_connnection_string_defined(instance):
    instance = {
        **instance,
        **{
            'connection_string': 'constring',
            'driver': 'driver',
            'system': 'system',
            'username': '******',
            'password': '******',
        },
    }
    check = IbmICheck('ibm_i', {}, [instance])
    check.load_configuration_models()
    assert check.connection_string == 'constring'
    check._connection_string = 'modified'
    assert check.connection_string == 'modified'
Example #7
0
def test_check_no_query_manager(aggregator, instance):
    check = IbmICheck('ibm_i', {}, [instance])
    check.log = mock.MagicMock()
    check.load_configuration_models()
    with mock.patch('datadog_checks.ibm_i.IbmICheck.fetch_system_info',
                    return_value=None):
        check.check(instance)
    assert check._query_manager is None
    check.log.warning.assert_called_once()
    aggregator.assert_all_metrics_covered()
Example #8
0
def test_set_up_query_manager_7_4(instance):
    check = IbmICheck('ibm_i', {}, [instance])
    check.log = mock.MagicMock()
    check.load_configuration_models()
    with mock.patch('datadog_checks.ibm_i.IbmICheck.fetch_system_info',
                    return_value=SystemInfo("host", 7, 4)):
        check.set_up_query_manager()
    assert check._query_manager is not None
    assert check._query_manager.hostname == "host"
    assert len(check._query_manager.queries) == 10
Example #9
0
def test_check_query_error(aggregator, instance):
    check = IbmICheck('ibm_i', {}, [instance])
    check.log = mock.MagicMock()
    check.load_configuration_models()

    with mock.patch('datadog_checks.ibm_i.IbmICheck.fetch_system_info',
                    return_value=SystemInfo("host", 7, 4)), mock.patch(
                        'datadog_checks.ibm_i.IbmICheck.execute_query',
                        side_effect=Exception("boom")):
        assert check._query_manager is None
        check.check(instance)
        assert check._query_manager is not None
        assert check._query_manager.hostname == "host"
        check.check(instance)
    aggregator.assert_service_check("ibm_i.can_connect",
                                    count=2,
                                    status=AgentCheck.CRITICAL)
    aggregator.assert_all_metrics_covered()
Example #10
0
def test_cancel(instance):
    check = IbmICheck('ibm_i', {}, [instance])
    check.load_configuration_models()

    with mock.patch(
            'datadog_checks.ibm_i.IbmICheck._delete_connection_subprocess'
    ) as m:
        check.cancel()
    m.assert_called_once()
Example #11
0
def test_query_error_system_info(instance):
    check = IbmICheck('ibm_i', {}, [instance])
    check.log = mock.MagicMock()
    check.load_configuration_models()
    exc = Exception("boom")
    with mock.patch('datadog_checks.ibm_i.IbmICheck.execute_query',
                    side_effect=exc):
        system_info = check.fetch_system_info()

    assert system_info is None
    check.log.error.assert_called_once()
Example #12
0
def test_execute_query(instance):
    """Check that execute_query reads and parses the process stdout."""
    check = IbmICheck('ibm_i', {}, [instance])
    check.load_configuration_models()
    check._subprocess = mock.MagicMock()
    check._subprocess.stdout = mock.MagicMock()
    check._subprocess.stdout.readline = mock.MagicMock(
        return_value='{"a": "b"}')
    assert next(check.execute_query({
        'text': 'query',
        'timeout': 2
    })) == {
        'a': 'b'
    }
Example #13
0
def test_failed_fetch_system_info(instance):
    check = IbmICheck('ibm_i', {}, [instance])
    check.log = mock.MagicMock()
    check.load_configuration_models()
    with mock.patch(
            'datadog_checks.ibm_i.IbmICheck.execute_query',
            return_value=[]), mock.patch(
                'datadog_checks.ibm_i.IbmICheck._delete_connection_subprocess'
            ) as delete_conn:
        system_info = check.fetch_system_info()

    assert system_info is None
    delete_conn.assert_not_called()
    check.log.error.assert_called_once()
Example #14
0
def test_fetch_system_info(instance):
    check = IbmICheck('ibm_i', {}, [instance])
    check.log = mock.MagicMock()
    check.load_configuration_models()
    with mock.patch(
            'datadog_checks.ibm_i.IbmICheck.execute_query',
            return_value=[("hostname", "7", "3")]), mock.patch(
                'datadog_checks.ibm_i.IbmICheck._delete_connection_subprocess'
            ) as delete_conn:
        system_info = check.fetch_system_info()

    assert system_info == SystemInfo(hostname="hostname",
                                     os_version=7,
                                     os_release=3)
    delete_conn.assert_not_called()
    check.log.assert_not_called()
Example #15
0
def test_set_up_query_manager_7_2_queries_list(instance):
    instance = {
        **instance,
        **{
            'queries': [
                {
                    'name': 'disk_usage'
                },
                {
                    'name': 'cpu_usage'
                },
                {
                    'name': 'job_memory_usage'
                },
                {
                    'name': 'memory_info'
                },
                {
                    'name': 'subsystem'
                },
                {
                    'name': 'job_queue'
                },
                {
                    'name': 'message_queue_info'
                },
            ]
        },
    }
    check = IbmICheck('ibm_i', {}, [instance])
    check.log = mock.MagicMock()
    check.load_configuration_models()
    with mock.patch('datadog_checks.ibm_i.IbmICheck.fetch_system_info',
                    return_value=SystemInfo("host", 7, 2)):
        check.set_up_query_manager()
    assert check._query_manager is not None
    # disk_usage counts like 1, subsystem like 0 (not available on 7.2), the rest (5 queries) count as 1
    assert len(check._query_manager.queries) == 5 + 0 + 1