def test_desired_queue_not_in_rabbit(self): queue_conf = {'foo': self.thresholds, 'bar': self.thresholds} queue_prefix_conf = {'test_': self.thresholds} queues = [{'name': 'foo', 'messages_ready': self.warning}] with self.assertRaises(RabbitCritical) as excinfo: check_lengths(queues, queue_conf, queue_prefix_conf) exc = excinfo.exception self.assertEqual(exc.errors, {'bar': ['Queue not found']})
def test_policy_is_wrong(self): conf = copy(self.thresholds) conf['policy'] = {'max-length': 500} queue_conf = {'test_foo': conf} queues = [{ 'name': 'test_foo', 'messages_ready': self.normal, 'effective_policy_definition': { 'max-length': 100 } }] with self.assertRaises(RabbitCritical) as excinfo: check_lengths(queues, queue_conf, {}) exc = excinfo.exception self.assertEqual(exc.errors, {'test_foo': ['Wrong queue policy']})
def test_override_prefix_threshold(self): lower_thresholds = { 'warning': self.thresholds['warning'] / 2, 'critical': self.thresholds['critical'] / 2, } lower_warning = lower_thresholds['warning'] + 1 self.assertTrue(lower_warning < self.thresholds['warning']) queue_conf = {'test_foo': lower_thresholds} queue_prefix_conf = {'test_': self.thresholds} queues = [{'name': 'test_foo', 'messages_ready': lower_warning}] with self.assertRaises(RabbitWarning) as excinfo: check_lengths(queues, queue_conf, queue_prefix_conf) exc = excinfo.exception self.assertEqual(exc.errors, {'test_foo': [lower_warning]})
def test_unknown_error(self): queues = {'foo': self.thresholds} client_mock = Mock() client_mock.get_queue_depth.side_effect = HTTPError('', status=500) stats, errors = check_lengths(client_mock, Mock(), queues) self.assertEqual(stats, {'foo': 'Unhandled HTTP error, status: 500'}) self.assertEqual(errors, {'critical': [], 'warning': ['foo']})
def test_network_error(self): queues = {'foo': self.thresholds} client_mock = Mock() client_mock.get_queue_depth.side_effect = NetworkError() stats, errors = check_lengths(client_mock, Mock(), queues) self.assertEqual(stats, {'foo': 'Can not communicate with RabbitMQ.'}) self.assertEqual(errors, {'critical': [], 'warning': ['foo']})
def test_401(self): queues = {'foo': self.thresholds} client_mock = Mock() client_mock.get_queue_depth.side_effect = HTTPError('', status=401) stats, errors = check_lengths(client_mock, Mock(), queues) self.assertEqual(stats, {'foo': 'Unauthorized.'}) self.assertEqual(errors, {'critical': [], 'warning': ['foo']})
def test_criticals_take_precedence_over_warnings(self): queue_conf = {'foo': self.thresholds, 'bar': self.thresholds} queue_prefix_conf = {} queues = [ { 'name': 'foo', 'messages_ready': self.warning }, { 'name': 'bar', 'messages_ready': self.critical }, ] with self.assertRaises(RabbitCritical) as excinfo: check_lengths(queues, queue_conf, queue_prefix_conf) exc = excinfo.exception self.assertEqual(exc.errors, {'bar': [self.critical]})
def test_ok(self): queues = {'foo': self.thresholds} client_mock = Mock() client_mock.get_queue_depth.return_value = self.normal stats, errors = check_lengths(client_mock, Mock(), queues) self.assertEqual(stats, {'foo': client_mock.get_queue_depth.return_value}) self.assertEqual(errors, {'critical': [], 'warning': []})
def test_unknown_error(self): queues = {'foo': self.thresholds} client_mock = Mock() client_mock.get_queue_depth.side_effect = HTTPError('', status=500) stats, errors = check_lengths(client_mock, Mock(), queues) self.assertEqual( stats, {'foo': 'Unhandled HTTP error, status: 500'}) self.assertEqual(errors, {'critical': [], 'warning': ['foo']})
def test_401(self): queues = {'foo': self.thresholds} client_mock = Mock() client_mock.get_queue_depth.side_effect = HTTPError('', status=401) stats, errors = check_lengths(client_mock, Mock(), queues) self.assertEqual( stats, {'foo': 'Unauthorized.'}) self.assertEqual(errors, {'critical': [], 'warning': ['foo']})
def test_network_error(self): queues = {'foo': self.thresholds} client_mock = Mock() client_mock.get_queue_depth.side_effect = NetworkError() stats, errors = check_lengths(client_mock, Mock(), queues) self.assertEqual( stats, {'foo': 'Can not communicate with RabbitMQ.'}) self.assertEqual(errors, {'critical': [], 'warning': ['foo']})
def test_ok(self): queues = {'foo': self.thresholds} client_mock = Mock() client_mock.get_queue_depth.return_value = self.normal stats, errors = check_lengths(client_mock, Mock(), queues) self.assertEqual( stats, {'foo': client_mock.get_queue_depth.return_value}) self.assertEqual(errors, {'critical': [], 'warning': []})
def test_critical(self): queue_conf = {'foo': self.thresholds} queue_prefix_conf = {'local_': self.thresholds} queues = [ { 'name': 'foo', 'messages_ready': self.critical }, { 'name': 'local_bar', 'messages_ready': self.critical }, ] with self.assertRaises(RabbitCritical) as excinfo: check_lengths(queues, queue_conf, queue_prefix_conf) exc = excinfo.exception self.assertEqual(exc.errors, { 'foo': [self.critical], 'local_bar': [self.critical] })
def test_ok(self): policy_mock = Mock() conf = copy(self.thresholds) conf['effective_policy_definition'] = policy_mock queue_conf = {'foo': conf} queue_prefix_conf = {} queues = [{ 'name': 'foo', 'messages_ready': self.normal, 'policy': policy_mock }] res = check_lengths(queues, queue_conf, queue_prefix_conf) self.assertEqual(res, {'foo': self.normal})