def test_pattern_preceedes_autodiscovery(instance): instance['auto_discover_queues'] = True instance['queue_patterns'] = ['pattern'] config = IBMMQConfig(instance) collector = QueueMetricCollector(config, Mock(), Mock(), Mock(), Mock(), Mock()) collector._discover_queues = Mock(return_value=['pattern_queue']) queue_manager = Mock() discovered_queues = collector.discover_queues(queue_manager) collector._discover_queues.assert_called_once_with(queue_manager, 'pattern') assert discovered_queues == {'pattern_queue', 'DEV.QUEUE.1'}
def test_ssl_check_normal_connection_before_ssl_connection(instance_ssl_dummy): import logging import pymqi from datadog_checks.ibm_mq.config import IBMMQConfig from datadog_checks.ibm_mq.connection import get_queue_manager_connection logger = logging.getLogger(__file__) config = IBMMQConfig(instance_ssl_dummy) error = pymqi.MQMIError(pymqi.CMQC.MQCC_FAILED, pymqi.CMQC.MQRC_UNKNOWN_CHANNEL_NAME) with mock.patch('datadog_checks.ibm_mq.connection.get_normal_connection', side_effect=error) as get_normal_connection, mock.patch( 'datadog_checks.ibm_mq.connection.get_ssl_connection' ) as get_ssl_connection: with pytest.raises(pymqi.MQMIError): get_queue_manager_connection(config, logger) get_normal_connection.assert_called_with(config, logger) assert not get_ssl_connection.called # normal connection failed with with error other those listed in get_queue_manager_connection for error_reason in [ pymqi.CMQC.MQRC_HOST_NOT_AVAILABLE, pymqi.CMQC.MQRC_SSL_CONFIG_ERROR ]: error = pymqi.MQMIError(pymqi.CMQC.MQCC_FAILED, error_reason) with mock.patch( 'datadog_checks.ibm_mq.connection.get_normal_connection', side_effect=error) as get_normal_connection, mock.patch( 'datadog_checks.ibm_mq.connection.get_ssl_connection' ) as get_ssl_connection: get_queue_manager_connection(config, logger) get_normal_connection.assert_called_with(config, logger) get_ssl_connection.assert_called_with(config, logger) # no issue with normal connection with mock.patch('datadog_checks.ibm_mq.connection.get_normal_connection' ) as get_normal_connection, mock.patch( 'datadog_checks.ibm_mq.connection.get_ssl_connection' ) as get_ssl_connection: get_queue_manager_connection(config, logger) get_normal_connection.assert_called_with(config, logger) get_ssl_connection.assert_called_with(config, logger)
def test_channel_status_service_check_custom_mapping(aggregator, instance): # Late import to not require it for e2e import pymqi instance['channel_status_mapping'] = { 'inactive': 'warning', 'binding': 'warning', 'starting': 'warning', 'running': 'ok', 'stopping': 'critical', 'retrying': 'warning', 'stopped': 'critical', 'requesting': 'warning', 'paused': 'warning', # 'initializing': '', # missing mapping are reported as unknown } check = IbmMqCheck('ibm_mq', {}, [instance]) config = IBMMQConfig(instance) service_check_map = { pymqi.CMQCFC.MQCHS_INACTIVE: AgentCheck.WARNING, pymqi.CMQCFC.MQCHS_BINDING: AgentCheck.WARNING, pymqi.CMQCFC.MQCHS_STARTING: AgentCheck.WARNING, pymqi.CMQCFC.MQCHS_RUNNING: AgentCheck.OK, pymqi.CMQCFC.MQCHS_STOPPING: AgentCheck.CRITICAL, pymqi.CMQCFC.MQCHS_RETRYING: AgentCheck.WARNING, pymqi.CMQCFC.MQCHS_STOPPED: AgentCheck.CRITICAL, pymqi.CMQCFC.MQCHS_REQUESTING: AgentCheck.WARNING, pymqi.CMQCFC.MQCHS_PAUSED: AgentCheck.WARNING, pymqi.CMQCFC.MQCHS_INITIALIZING: AgentCheck.UNKNOWN, } for status in service_check_map: check._submit_status_check('my_channel', status, ["channel:my_channel_{}".format(status)], config) for status, service_check_status in iteritems(service_check_map): aggregator.assert_service_check( 'ibm_mq.channel.status', service_check_status, tags=["channel:my_channel_{}".format(status)])
def test_channel_queue_config_ok(instance_config): from datadog_checks.ibm_mq.config import IBMMQConfig instance_config.update({'host': 'localhost', 'port': 1000}) IBMMQConfig(instance_config)
def test_channel_queue_config_ok(instance_config): instance_config.update({'host': 'localhost', 'port': 1000}) IBMMQConfig(instance_config)
def test_connection_config_ok(instance_config, expected_connection_name): instance_config.update({'channel': 'foo', 'queue_manager': 'bar'}) config = IBMMQConfig(instance_config) assert config.connection_name == expected_connection_name
def test_set_mqcd_version(instance): import pymqi instance['mqcd_version'] = 9 config = IBMMQConfig(instance) assert config.mqcd_version == pymqi.CMQC.MQCD_VERSION_9
def test_cannot_override_hostname_if_no_host_provided(instance): del instance['host'] instance['override_hostname'] = True with pytest.raises(ConfigurationError, match="You cannot override the hostname if you don't provide a `host`"): IBMMQConfig(instance)
def test_cannot_set_host_and_connection_name(instance): instance['connection_name'] = "localhost(8080)" with pytest.raises(ConfigurationError, match="Specify only one host/port or connection_name configuration"): IBMMQConfig(instance)