Add gerrit reporting to the irc bot.

This adds support to the irc bot for leaving a review on gerrit based
on the ES query. If it finds a match it will leave a link to the bug.
If it fails to find a match it will leave a link to the wiki page for
debugging test failures.

The unit tests depend on gerritlib change: https://review.openstack.org/#/c/47396/1
This commit is contained in:
Matthew Treinish 2013-09-19 11:12:19 -04:00
parent 2c1358c69b
commit 4ede959655
4 changed files with 67 additions and 9 deletions

View File

@ -1,3 +1,4 @@
[DEFAULT]
test_command=${PYTHON:-python} -m subunit.run discover
test_command=${PYTHON:-python} -m subunit.run discover -t ./ ./tests $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

12
bot.py
View File

@ -82,13 +82,14 @@ class RecheckWatchBot(irc.bot.SingleServerIRCBot):
class RecheckWatch(threading.Thread):
def __init__(self, ircbot, channel_config, username, queries):
def __init__(self, ircbot, channel_config, username, queries, host):
threading.Thread.__init__(self)
self.ircbot = ircbot
self.channel_config = channel_config
self.log = logging.getLogger('recheckwatchbot')
self.username = username
self.queries = queries
self.host = host
self.connected = False
def new_error(self, channel, data):
@ -118,17 +119,21 @@ class RecheckWatch(threading.Thread):
def run(self):
classifier = Classifier(self.queries)
stream = Stream(self.username)
stream = Stream(self.username, self.host)
while True:
event = stream.get_failed_tempest()
change = event['change']['number']
rev = event['patchSet']['number']
change_id = "%s,%s" % (change, rev)
project = event['change']['project']
bug_number = classifier.classify(change, rev, event['comment'])
if bug_number is None:
self._read(event)
stream.leave_comment(project, change_id)
else:
event['bug_number'] = bug_number
self._read(event)
stream.leave_comment(project, change_id, bug_number)
class ChannelConfig(object):
@ -170,7 +175,8 @@ def _main():
config.get('ircbot', 'server_password'))
recheck = RecheckWatch(bot, channel_config,
config.get('gerrit', 'user'),
config.get('gerrit', 'query_file'))
config.get('gerrit', 'query_file'),
config.get('gerrit', 'host', 'review.openstack.org'))
recheck.start()
bot.start()

View File

@ -34,11 +34,11 @@ class Stream(object):
Monitors gerrit stream looking for tempest-devstack failures.
"""
def __init__(self, user):
host = 'review.openstack.org'
def __init__(self, user, host, thread=True):
port = 29418
self.gerrit = gerritlib.gerrit.Gerrit(host, user, port)
self.gerrit.startWatching()
if thread:
self.gerrit.startWatching()
def get_failed_tempest(self):
while True:
@ -60,6 +60,17 @@ class Stream(object):
return event
continue
def leave_comment(self, project, commit, bug=None):
if bug:
bug_url = 'https://bugs.launchpad.net/bugs/%s' % bug
message = ("I noticed tempest failed, I think you hit bug %s" %
bug_url)
else:
message = ("I noticed tempest failed, refer to: "
"https://wiki.openstack.org/wiki/"
"GerritJenkinsGithub#Test_Failures")
self.gerrit.review(project, commit, message)
class Classifier():
"""Classify failed tempest-devstack jobs based.
@ -236,9 +247,10 @@ def main():
config_path = 'elasticRecheck.conf'
config.read(config_path)
user = config.get('gerrit', 'user', 'jogo')
host = config.get('gerrit', 'host', 'review.openstack.org')
queries = config.get('gerrit', 'query_file', 'queries.json')
classifier = Classifier(queries)
stream = Stream(user)
stream = Stream(user, host)
while True:
event = stream.get_failed_tempest()
change = event['change']['number']

View File

@ -0,0 +1,39 @@
import ConfigParser
import gerritlib
import testtools
import elasticRecheck
class TestGerritComment(testtools.TestCase):
def setUp(self):
super(TestGerritComment, self).setUp()
config = ConfigParser.ConfigParser({'server_password': None})
config.read('elasticRecheck.conf')
self.user = config.get('gerrit', 'user')
host = 'review-dev.openstack.org'
self.stream = elasticRecheck.Stream(self.user, host, thread=False)
port = 29418
self.gerrit = gerritlib.gerrit.Gerrit(host, self.user, port)
def test_bug_found(self):
bug_number = '1223158'
project = 'gtest-org/test'
commit_id = '434,1'
commit = '434'
self.stream.leave_comment(project, commit_id, bug_number)
result = self.gerrit.query(commit, comments=True)
comments = result.get('comments')
comment = comments[-1]
self.assertIn("I noticed tempest failed, I think you hit bug https://bugs.launchpad.net/bugs/1223158", comment.get('message'))
def test_bug_not_found(self):
project = 'gtest-org/test'
commit_id = '434,1'
commit = '434'
self.stream.leave_comment(project, commit_id)
result = self.gerrit.query(commit, comments=True)
comments = result.get('comments')
comment = comments[-1]
self.assertIn("https://wiki.openstack.org/wiki/GerritJenkinsGithub#Test_Failures", comment.get('message'))