Add queries test

Add test to make sure all queries in queries.json are valid and have
hits in logstash.
This commit is contained in:
Joe Gordon 2013-09-19 17:13:39 -07:00
parent e3853ce537
commit a641bb30af
3 changed files with 32 additions and 3 deletions

View File

@ -54,6 +54,7 @@ class Stream(object):
for line in event['comment'].split('\n'):
if "FAILURE" in line and ("python2" in line or "pep8" in line):
# Unit Test Failure
print "SKIPPING %s" % line
found = False
break
if "FAILURE" in line and "tempest-devstack" in line:
@ -265,7 +266,6 @@ class RequiredFiles(object):
def main():
#classifier.test()
config = ConfigParser.ConfigParser()
if len(sys.argv) is 2:
config_path = sys.argv[1]

View File

@ -9,7 +9,7 @@
},
{
"bug": "1227915",
"query": "\"already exists in volume group\" AND @fields.build_status:\"FAILURE\" AND @fields.loglevel:\"ERROR\" AND @fields.filename:\"logs/screen-c-vol.txt\""
"query": "@message:\"already exists in volume group\" AND @fields.build_status:\"FAILURE\" AND @fields.loglevel:\"ERROR\" AND @fields.filename:\"logs/screen-c-vol.txt\""
},
{
@ -18,7 +18,7 @@
},
{
"bug": "1226791",
"query": "@message:\"KeyError: 'nova'\" AND @fields.filename:\"logs/screen-n-api.txt\" AND @fields.build_status:\"FAILURE\" AND \"_describe_availability_zones_verbose\""
"query": "@message:\"KeyError: 'nova'\" AND @fields.filename:\"logs/screen-n-api.txt\" AND @fields.build_status:\"FAILURE\" AND @message:\"_describe_availability_zones_verbose\""
},
{
"bug": "1225664",

29
tests/test_queries.py Normal file
View File

@ -0,0 +1,29 @@
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import elasticRecheck
import testtools
class TestQueries(testtools.TestCase):
def setUp(self):
super(TestQueries, self).setUp()
self.classifier = elasticRecheck.Classifier('queries.json')
def test_queries(self):
for x in self.classifier.queries:
print "Looking for bug: https://bugs.launchpad.net/bugs/%s" % x['bug']
query = self.classifier._apply_template(self.classifier.general_template, x['query'])
results = self.classifier.es.search(query, size='10')
self.assertTrue(int(results['hits']['total']) > 0, ("unable to find hits for bug %s" % x['bug']))