Add config flags for data source configuration

This commit adds options to the config file for the elastic recheck
bot configuration file. This enables users to specify how to connect
to an elastic recheck server and a subunit2sql database, but things
will still default to using the openstack-infra servers to prevent
breaking the running service.

Change-Id: I10db1a568cc01e137e5f4d8a8814b17201c4c438
This commit is contained in:
Matthew Treinish 2015-08-17 14:24:38 -04:00
parent 59545fea4f
commit 48ebc14283
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177
3 changed files with 28 additions and 9 deletions

View File

@ -11,3 +11,7 @@ user=treinish
host=review.openstack.org
query_file=/home/mtreinish/elasticRecheck/queries
key=/home/mtreinish/.ssh/id_rsa
[data_source]
es_url=http://logstash.openstack.org/elasticsearch
db_uri=mysql+pymysql://query:query@logstash.openstack.org/subunit2sql

View File

@ -27,6 +27,10 @@ channel_config=/path/to/yaml/config
[gerrit]
user=gerrit2
[data_source[
es_url=URLofELASTICSEARCH
db_uri=SQLALCHEMY_URI_TO_SUBUNIT2SQL
"""
# The yaml channel config should look like:
@ -108,7 +112,8 @@ class RecheckWatchBot(irc.bot.SingleServerIRCBot):
class RecheckWatch(threading.Thread):
def __init__(self, ircbot, channel_config, msgs, username,
queries, host, key, commenting=True):
queries, host, key, commenting=True, es_url=None,
db_uri=None):
super(RecheckWatch, self).__init__()
self.ircbot = ircbot
self.channel_config = channel_config
@ -124,6 +129,8 @@ class RecheckWatch(threading.Thread):
'production',
LPCACHEDIR,
timeout=60)
self.es_url = es_url
self.db_uri = db_uri
def display(self, channel, event):
display = False
@ -193,8 +200,8 @@ class RecheckWatch(threading.Thread):
def run(self):
# Import here because it needs to happen after daemonization
import elastic_recheck.elasticRecheck as er
classifier = er.Classifier(self.queries)
stream = er.Stream(self.username, self.host, self.key)
classifier = er.Classifier(self.queries, self.es_url, self.db_uri)
stream = er.Stream(self.username, self.host, self.key, self.es_url)
while True:
try:
event = stream.get_failed_tempest()
@ -308,7 +315,12 @@ def _main(args, config):
config.get('gerrit', 'query_file'),
config.get('gerrit', 'host', 'review.openstack.org'),
config.get('gerrit', 'key'),
not args.nocomment
not args.nocomment,
config.get('data_source', 'es_url',
'http://logstash.openstack.org/elasticsearch'),
config.get('data_source, db_uri',
'mysql+pymysql://query:query@logstash.openstack.org/'
'subunit2sql'),
)
recheck.start()

View File

@ -195,10 +195,11 @@ class Stream(object):
log = logging.getLogger("recheckwatchbot")
def __init__(self, user, host, key, thread=True):
def __init__(self, user, host, key, thread=True, es_url=None):
self.es_url = es_url or ES_URL
port = 29418
self.gerrit = gerritlib.gerrit.Gerrit(host, user, port, key)
self.es = results.SearchEngine(ES_URL)
self.es = results.SearchEngine(self.es_url)
if thread:
self.gerrit.startWatching()
@ -370,8 +371,10 @@ class Classifier(object):
queries = None
def __init__(self, queries_dir):
self.es = results.SearchEngine(ES_URL)
def __init__(self, queries_dir, es_url=None, db_uri=None):
self.es_url = es_url or ES_URL
self.db_uri = db_uri or DB_URI
self.es = results.SearchEngine(self.es_url)
self.queries_dir = queries_dir
self.queries = loader.load(self.queries_dir)
@ -398,7 +401,7 @@ class Classifier(object):
# Reload each time
self.queries = loader.load(self.queries_dir)
bug_matches = []
engine = sqlalchemy.create_engine(DB_URI)
engine = sqlalchemy.create_engine(self.db_uri)
Session = orm.sessionmaker(bind=engine)
session = Session()
for x in self.queries: