def run(self): # Import here because it needs to happen after daemonization import elastic_recheck.elasticRecheck as er classifier = er.Classifier(self.queries, config=self.config) stream = er.Stream(self.username, self.host, self.key, config=self.config) while True: try: event = stream.get_failed_tempest() for job in event.failed_jobs: job.bugs = set(classifier.classify( event.change, event.rev, job.build_short_uuid, recent=True)) if not event.get_all_bugs(): self._read(event) else: self._read(event) stream.leave_comment( event, self.msgs, debug=not self.commenting) except er.ResultTimedOut as e: self.log.warning(e.message) self._read(msg=e.message) except Exception: self.log.exception("Uncaught exception processing event.")
def setUp(self): super(TestGerritComment, self).setUp() config = ConfigParser.ConfigParser({'server_password': None}) config.read('elasticRecheck.conf') self.user = config.get('gerrit', 'user') key = config.get('gerrit', 'key') host = 'review-dev.openstack.org' self.stream = elasticRecheck.Stream(self.user, host, key, thread=False) port = 29418 self.gerrit = gerritlib.gerrit.Gerrit(host, self.user, port)
def test_error_found(self): self.useFixture( fixtures.MonkeyPatch('elastic_recheck.bot.RecheckWatch.print_msg', self.fake_print)) self.useFixture( fixtures.MonkeyPatch('elastic_recheck.bot.RecheckWatch.display', self.fake_display)) with mock.patch.object(elasticRecheck.Stream, '_does_es_have_data') as mock_data: mock_data.return_value = True stream = elasticRecheck.Stream("", "", "") event = stream.get_failed_tempest() self.assertIsNone(event.bug_urls_map()) # Add bugs for job in event.failed_jobs: if job.name == 'gate-keystone-python26': job.bugs = ['123456'] self.assertTrue(self.recheck_watch.display('channel', event)) self.recheck_watch.error_found('channel', event)
def test_gerrit_stream(self): """Tests that we can use our mock gerrit to process events.""" with mock.patch.object(elasticRecheck.Stream, '_does_es_have_data') as mock_data: mock_data.return_value = True stream = elasticRecheck.Stream("", "", "") # there are currently 10 events in the stream, 3 are # failures event = stream.get_failed_tempest() self.assertEqual(event.change, 64750) self.assertEqual(event.rev, 6) self.assertEqual(event.project, "openstack/keystone") self.assertEqual(event.name(), "64750,6") self.assertEqual(event.url, "https://review.opendev.org/64750") self.assertEqual(sorted(event.build_short_uuids()), ["5dd41fe", "d3fd328"]) self.assertTrue(event.is_included_job()) self.assertEqual(event.queue(), "gate") self.assertEqual(event.bug_urls(), None) self.assertEqual(event.bug_urls_map(), None) self.assertEqual( sorted(event.failed_job_names()), ['gate-keystone-python26', 'gate-keystone-python27']) self.assertEqual(event.get_all_bugs(), None) self.assertTrue(event.is_fully_classified()) event = stream.get_failed_tempest() self.assertEqual(event.change, 64749) self.assertEqual(event.rev, 6) self.assertEqual(event.project, "openstack/keystone") self.assertEqual(event.name(), "64749,6") self.assertEqual(event.url, "https://review.opendev.org/64749") self.assertEqual(sorted(event.build_short_uuids()), ["5dd41fe", "d3fd328"]) self.assertTrue(event.is_included_job()) self.assertEqual(event.queue(), "check") self.assertEqual(event.bug_urls(), None) self.assertEqual(event.bug_urls_map(), None) self.assertEqual( sorted(event.failed_job_names()), ['gate-keystone-python26', 'gate-keystone-python27']) self.assertEqual(event.get_all_bugs(), None) self.assertTrue(event.is_fully_classified()) event = stream.get_failed_tempest() self.assertEqual(event.change, 63078) self.assertEqual(event.rev, 19) self.assertEqual(event.project, "openstack/horizon") self.assertEqual(event.name(), "63078,19") self.assertEqual(event.url, "https://review.opendev.org/63078") self.assertEqual(event.build_short_uuids(), ["ab07162"]) event = stream.get_failed_tempest() self.assertEqual(event.change, 65361) self.assertEqual(event.rev, 2) self.assertEqual(event.project, "openstack/requirements") self.assertEqual(event.name(), "65361,2") self.assertEqual(event.url, "https://review.opendev.org/65361") self.assertEqual(event.build_short_uuids(), ["8209fb4"]) self.assertRaises(fg.GerritDone, stream.get_failed_tempest)
def test_event(self): with mock.patch.object(elasticRecheck.Stream, '_does_es_have_data') as mock_data: mock_data.return_value = True stream = elasticRecheck.Stream("", "", "") event = stream.get_failed_tempest() # Add bugs for job in event.failed_jobs: if job.name == 'gate-keystone-python26': job.bugs = ['123456'] self.assertEqual(event.change, 64750) self.assertEqual(event.rev, 6) self.assertEqual(event.project, "openstack/keystone") self.assertEqual(event.name(), "64750,6") self.assertEqual(event.url, "https://review.opendev.org/64750") self.assertEqual(sorted(event.build_short_uuids()), ["5dd41fe", "d3fd328"]) self.assertTrue(event.is_included_job()) self.assertEqual(event.queue(), "gate") self.assertEqual(event.bug_urls(), ['https://bugs.launchpad.net/bugs/123456']) errors = [ 'gate-keystone-python27: unrecognized error', 'gate-keystone-python26: ' 'https://bugs.launchpad.net/bugs/123456' ] bug_map = event.bug_urls_map() for error in errors: self.assertIn(error, bug_map) self.assertEqual( sorted(event.failed_job_names()), ['gate-keystone-python26', 'gate-keystone-python27']) self.assertEqual(event.get_all_bugs(), ['123456']) self.assertFalse(event.is_fully_classified()) event = stream.get_failed_tempest() # Add bugs for job in event.failed_jobs: if job.name == 'gate-keystone-python26': job.bugs = ['123456'] self.assertEqual(event.change, 64749) self.assertEqual(event.rev, 6) self.assertEqual(event.project, "openstack/keystone") self.assertEqual(event.name(), "64749,6") self.assertEqual(event.url, "https://review.opendev.org/64749") self.assertEqual(sorted(event.build_short_uuids()), ["5dd41fe", "d3fd328"]) self.assertTrue(event.is_included_job()) self.assertEqual(event.queue(), "check") self.assertEqual(event.bug_urls(), ['https://bugs.launchpad.net/bugs/123456']) self.assertEqual(event.bug_urls_map(), [ 'gate-keystone-python26: ' 'https://bugs.launchpad.net/bugs/123456', 'gate-keystone-python27: unrecognized error' ]) self.assertEqual( sorted(event.failed_job_names()), ['gate-keystone-python26', 'gate-keystone-python27']) self.assertEqual(event.get_all_bugs(), ['123456']) self.assertFalse(event.is_fully_classified())