def test_graphite_run(self): checkresults = self.graphite_check.statuscheckresult_set.all() custom_check_types = add_custom_check_plugins() self.assertEqual(len(custom_check_types), 0) self.assertEqual(len(checkresults), 2) custom_check_types = add_custom_check_plugins() self.assertEqual(len(custom_check_types), 0) self.graphite_check.utcnow = 1387818601 # see graphite_response.json for this magic timestamp self.graphite_check.run() checkresults = self.graphite_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 3) # Most recent check failed self.assertFalse(self.graphite_check.last_result().succeeded) self.assertEqual(self.graphite_check.calculated_status, Service.CALCULATED_FAILING_STATUS) # This should now pass self.graphite_check.value = '11.0' self.graphite_check.save() checkresults = self.graphite_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 3) self.graphite_check.run() checkresults = self.graphite_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 4) self.assertEqual(self.graphite_check.calculated_status, Service.CALCULATED_PASSING_STATUS) # As should this - passing but failures allowed self.graphite_check.allowed_num_failures = 2 self.graphite_check.save() self.graphite_check.run() checkresults = self.graphite_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 5) self.assertEqual(self.graphite_check.calculated_status, Service.CALCULATED_PASSING_STATUS) # As should this - failing but 1 failure allowed # (in test data, one data series is entirely below 9 and one goes above) self.graphite_check.value = '9.0' self.graphite_check.allowed_num_failures = 1 self.graphite_check.save() self.graphite_check.run() checkresults = self.graphite_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 6) self.assertEqual(self.graphite_check.calculated_status, Service.CALCULATED_PASSING_STATUS, list(checkresults)[-1].error) # And it will fail if we don't allow failures self.graphite_check.allowed_num_failures = 0 self.graphite_check.save() self.graphite_check.run() checkresults = self.graphite_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 7) self.assertEqual(self.graphite_check.calculated_status, Service.CALCULATED_FAILING_STATUS) result = checkresults.order_by('-time')[0] self.assertEqual(result.error, u'PROD: 9.16092 > 9.0')
def test_jenkins_blocked_build(self): checkresults = self.jenkins_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 0) custom_check_types = add_custom_check_plugins() self.assertEqual(len(custom_check_types), 0) self.jenkins_check.run() checkresults = self.jenkins_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 1) self.assertFalse(self.jenkins_check.last_result().succeeded)
def test_graphite_timing(self): checkresults = self.graphite_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 2) custom_check_types = add_custom_check_plugins() self.assertEqual(len(custom_check_types), 0) self.graphite_check.run() checkresults = self.graphite_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 3) self.assertTrue(self.graphite_check.last_result().succeeded) self.assertGreater(list(checkresults)[-1].took, 0.0)
def test_timeout_handling_in_http(self): checkresults = self.http_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 0) custom_check_types = add_custom_check_plugins() self.assertEqual(len(custom_check_types), 0) self.http_check.run() checkresults = self.http_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 1) self.assertFalse(self.http_check.last_result().succeeded) self.assertIn(u'Request error occurred: фиктивная ошибка innit', self.http_check.last_result().error)
def test_timeout_handling_in_jenkins(self): checkresults = self.jenkins_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 0) custom_check_types = add_custom_check_plugins() self.assertEqual(len(custom_check_types), 0) self.jenkins_check.run() checkresults = self.jenkins_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 1) self.assertTrue(self.jenkins_check.last_result().succeeded) self.assertIn(u'Error fetching from Jenkins - фиктивная ошибка', self.jenkins_check.last_result().error)
def test_graphite_empty_run(self): checkresults = self.graphite_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 2) custom_check_types = add_custom_check_plugins() self.assertEqual(len(custom_check_types), 0) self.graphite_check.run() checkresults = self.graphite_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 3) self.assertTrue(self.graphite_check.last_result().succeeded) self.assertEqual(self.graphite_check.calculated_status, Service.CALCULATED_PASSING_STATUS) self.graphite_check.expected_num_hosts = 1 self.graphite_check.save() self.graphite_check.run() checkresults = self.graphite_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 4) self.assertFalse(self.graphite_check.last_result().succeeded) self.assertEqual(self.graphite_check.calculated_status, Service.CALCULATED_FAILING_STATUS)
def test_http_run(self): checkresults = self.http_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 0) custom_check_types = add_custom_check_plugins() self.assertEqual(len(custom_check_types), 0) self.http_check.run() checkresults = self.http_check.statuscheckresult_set.all() self.assertEqual(len(checkresults), 1) self.assertTrue(self.http_check.last_result().succeeded) self.assertEqual(self.http_check.calculated_status, Service.CALCULATED_PASSING_STATUS) self.http_check.text_match = u'blah blah' self.http_check.save() self.http_check.run() self.assertFalse(self.http_check.last_result().succeeded) self.assertEqual(self.http_check.calculated_status, Service.CALCULATED_FAILING_STATUS) # Unicode self.http_check.text_match = u'как закалялась сталь' self.http_check.save() self.http_check.run() self.assertFalse(self.http_check.last_result().succeeded) self.assertEqual(self.http_check.calculated_status, Service.CALCULATED_FAILING_STATUS)
def test_with_check_plugins(self): result = add_custom_check_plugins() self.assertEqual(result, [{ 'creation_url': 'create-skeleton-check', 'check_name': 'skeleton' }])
def test_without_check_plugins(self): result = add_custom_check_plugins() self.assertEqual(result, [])