Add framework to import queries from json file
Store elastic search queries associated with bugs in json file. Also add a few tests.
This commit is contained in:
parent
d05d8d7f1c
commit
aa79d79946
@ -4,6 +4,7 @@ import gerritlib.gerrit
|
|||||||
from pyelasticsearch import ElasticSearch
|
from pyelasticsearch import ElasticSearch
|
||||||
|
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
class Stream(object):
|
class Stream(object):
|
||||||
@ -26,6 +27,7 @@ class Stream(object):
|
|||||||
event = self.gerrit.getEvent()
|
event = self.gerrit.getEvent()
|
||||||
if event.get('type', '') != 'comment-added':
|
if event.get('type', '') != 'comment-added':
|
||||||
continue
|
continue
|
||||||
|
username = event['author'].get('username', '')
|
||||||
if (event['author']['username'] == 'jenkins' and
|
if (event['author']['username'] == 'jenkins' and
|
||||||
"Build failed. For information on how to proceed" in
|
"Build failed. For information on how to proceed" in
|
||||||
event['comment']):
|
event['comment']):
|
||||||
@ -42,29 +44,35 @@ class Classifier():
|
|||||||
that are mapped to specific bugs.
|
that are mapped to specific bugs.
|
||||||
"""
|
"""
|
||||||
ES_URL = "http://logstash.openstack.org/elasticsearch"
|
ES_URL = "http://logstash.openstack.org/elasticsearch"
|
||||||
#TODO(jogo): make the query below a template that takes a query and
|
template = {
|
||||||
# change and patch number
|
|
||||||
tempest_failed_jobs = {
|
|
||||||
"sort": {
|
"sort": {
|
||||||
"@timestamp": {"order": "desc"}
|
"@timestamp": {"order": "desc"}
|
||||||
},
|
},
|
||||||
"query": {
|
"query": {
|
||||||
"query_string": {
|
"query_string": {
|
||||||
"query": '@tags:"console.html" AND @message:"Finished: FAILURE" AND @fields.build_change:"46396" AND @fields.build_patchset:"1"'
|
"query": '%s AND @fields.build_change:"%s" AND @fields.build_patchset:"%s"'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
queries = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.es = ElasticSearch(self.ES_URL)
|
self.es = ElasticSearch(self.ES_URL)
|
||||||
|
self.queries = json.loads(open('queries.json').read())
|
||||||
|
for x in self.queries:
|
||||||
|
print x['bug']
|
||||||
#TODO(jogo): import a list of queries from a config file
|
#TODO(jogo): import a list of queries from a config file
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
results = self.es.search(self.tempest_failed_jobs, size='10')
|
query = self.template.copy()
|
||||||
|
query['query']['query_string']['query'] = (query['query']['query_string']['query'] %
|
||||||
|
('@tags:"console.html" AND @message:"Finished: FAILURE"', '34825', '3'))
|
||||||
|
results = self.es.search(query, size='10')
|
||||||
for x in results['hits']['hits']:
|
for x in results['hits']['hits']:
|
||||||
try:
|
try:
|
||||||
change = x["_source"]['@fields']['build_change']
|
change = x["_source"]['@fields']['build_change']
|
||||||
patchset = x["_source"]['@fields']['build_patchset']
|
patchset = x["_source"]['@fields']['build_patchset']
|
||||||
|
print "build_name %s" % x["_source"]['@fields']['build_name']
|
||||||
print "https://review.openstack.org/#/c/%(change)s/%(patchset)s" % locals()
|
print "https://review.openstack.org/#/c/%(change)s/%(patchset)s" % locals()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print "build_name %s" % x["_source"]['@fields']['build_name']
|
print "build_name %s" % x["_source"]['@fields']['build_name']
|
||||||
|
10
queries.json
Normal file
10
queries.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"bug": "123",
|
||||||
|
"query": "a query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bug": "1234",
|
||||||
|
"query": "a second query"
|
||||||
|
}
|
||||||
|
]
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
17
tests/test_classifier.py
Normal file
17
tests/test_classifier.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import testtools
|
||||||
|
import elasticRecheck
|
||||||
|
|
||||||
|
|
||||||
|
class TestClassifier(testtools.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestClassifier, self).setUp()
|
||||||
|
self.classifier = elasticRecheck.Classifier()
|
||||||
|
|
||||||
|
def test_read_qeuries_file(self):
|
||||||
|
self.assertNotEqual(self.classifier.queries, None)
|
||||||
|
|
||||||
|
|
||||||
|
def test_elasticSearch(self):
|
||||||
|
self.classifier.test()
|
||||||
|
self.assertFalse(True)
|
Loading…
x
Reference in New Issue
Block a user