Change test_queries from logical AND to OR
Instead of passing if valid query and valid launchpad, change to pass of valid query or valid launchpad. We want to use OR to be extra safe before removing queries. With this change we will keep queries around until there are no valid hits on logstash.openstack.org and the bug is marked as closed in launchpad. Change-Id: I991acb3f0f6a34366a223710c7b25d98919d3751
This commit is contained in:
parent
12835a2d73
commit
5c017932d8
@ -16,7 +16,6 @@ import os
|
||||
|
||||
import ConfigParser
|
||||
from launchpadlib import launchpad
|
||||
import yaml
|
||||
|
||||
from elastic_recheck import elasticRecheck
|
||||
from elastic_recheck import tests
|
||||
@ -25,6 +24,13 @@ LPCACHEDIR = os.path.expanduser('~/.launchpadlib/cache')
|
||||
|
||||
|
||||
class TestQueries(tests.TestCase):
|
||||
"""Make sure queries are valid.
|
||||
|
||||
Make sure all queries are for open OpenStack bugs in Launchpad or have
|
||||
hits in logstash.openstack.org.
|
||||
This test is used to validate any changes to queries.yaml
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestQueries, self).setUp()
|
||||
config = ConfigParser.ConfigParser({'server_password': None})
|
||||
@ -35,27 +41,36 @@ class TestQueries(tests.TestCase):
|
||||
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']))
|
||||
self.assertTrue((self._is_valid_ElasticSearch_query(x) or
|
||||
self._is_valid_launchpad_bug(x['bug'])),
|
||||
("Something is wrong with bug %s" % x['bug']))
|
||||
|
||||
def test_valid_bugs(self):
|
||||
def _is_valid_ElasticSearch_query(self, x):
|
||||
query = self.classifier._apply_template(self.classifier.general_template, x['query'])
|
||||
results = self.classifier.es.search(query, size='10')
|
||||
valid_query = int(results['hits']['total']) > 0
|
||||
if not valid_query:
|
||||
print "Didn't find any hits for bug %s" % x['bug']
|
||||
return valid_query
|
||||
|
||||
def _is_valid_launchpad_bug(self, bug):
|
||||
lp = launchpad.Launchpad.login_anonymously('grabbing bugs',
|
||||
'production',
|
||||
LPCACHEDIR)
|
||||
query_dict = yaml.load(open(self.queries).read())
|
||||
bugs = map(lambda x: x['bug'], query_dict)
|
||||
openstack_group = lp.project_groups['openstack']
|
||||
openstack_projects = map(lambda project: project.name,
|
||||
openstack_group.projects)
|
||||
for bug in bugs:
|
||||
lp_bug = lp.bugs[bug]
|
||||
bug_tasks = lp_bug.bug_tasks
|
||||
bug_complete = map(lambda bug_task: bug_task.is_complete, bug_tasks)
|
||||
projects = map(lambda bug_task: bug_task.bug_target_name, bug_tasks)
|
||||
# Check if all open bug tasks are closed if is_complete is true for all tasks.
|
||||
self.assertNotEquals(len(bug_complete), bug_complete.count(True),
|
||||
"bug %s is closed in launchpad" % bug)
|
||||
# Check that all bug_tasks are targetted to OpenStack Projects
|
||||
for project in projects:
|
||||
self.assertIn(project, openstack_projects)
|
||||
lp_bug = lp.bugs[bug]
|
||||
bug_tasks = lp_bug.bug_tasks
|
||||
bug_complete = map(lambda bug_task: bug_task.is_complete, bug_tasks)
|
||||
projects = map(lambda bug_task: bug_task.bug_target_name, bug_tasks)
|
||||
# Check if all open bug tasks are closed if is_complete is true for all tasks.
|
||||
if len(bug_complete) != bug_complete.count(True):
|
||||
print "bug %s is closed in launchpad" % bug
|
||||
return False
|
||||
# Check that all bug_tasks are targeted to OpenStack Projects
|
||||
for project in projects:
|
||||
if project not in openstack_projects:
|
||||
print "bug target %s not an openstack project" % project
|
||||
return False
|
||||
return True
|
||||
|
Loading…
x
Reference in New Issue
Block a user