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
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()
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
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()
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()
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()
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()
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