Make test_queries runnable as gating test
Previously test_queries, tested for: * check if the query has hits * check if the launchpad bug is open This wasn't a good test to gate on because hits can go away and bugs can be closed, so this test can stop working without any code changes, making it a bad gating test. Split out getting launchpad test working to a separate patch, still a few more issues to sort out there. Change-Id: Ic362d89a0ed34bb14864237e4bc5975befc36497
This commit is contained in:
parent
660e1f6402
commit
7ac81a0d48
@ -12,16 +12,13 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
|
||||
import ConfigParser
|
||||
from launchpadlib import launchpad
|
||||
import pyelasticsearch
|
||||
|
||||
from elastic_recheck import elasticRecheck
|
||||
import elastic_recheck.query_builder as qb
|
||||
from elastic_recheck import tests
|
||||
|
||||
LPCACHEDIR = os.path.expanduser('~/.launchpadlib/cache')
|
||||
|
||||
|
||||
class TestQueries(tests.TestCase):
|
||||
"""Make sure queries are valid.
|
||||
@ -38,44 +35,23 @@ class TestQueries(tests.TestCase):
|
||||
self.queries = config.get('gerrit', 'query_file')
|
||||
self.classifier = elasticRecheck.Classifier(self.queries)
|
||||
|
||||
def test_queries(self):
|
||||
def test_elasticsearch_query(self):
|
||||
for x in self.classifier.queries:
|
||||
print("Looking for bug: https://bugs.launchpad.net/bugs/%s"
|
||||
% x['bug'])
|
||||
self.assertTrue(
|
||||
(self._is_valid_ElasticSearch_query(x) or
|
||||
self._is_valid_launchpad_bug(x['bug'])),
|
||||
self._is_valid_ElasticSearch_query(x, x['bug']),
|
||||
("Something is wrong with bug %s" % x['bug']))
|
||||
|
||||
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_ElasticSearch_query(self, x, bug):
|
||||
query = qb.generic(x['query'])
|
||||
try:
|
||||
results = self.classifier.es.search(query, size='10')
|
||||
except pyelasticsearch.ElasticHttpError:
|
||||
self.fail("Failure to process query for bug %s" % bug)
|
||||
|
||||
def _is_valid_launchpad_bug(self, bug):
|
||||
lp = launchpad.Launchpad.login_anonymously('grabbing bugs',
|
||||
'production',
|
||||
LPCACHEDIR)
|
||||
openstack_group = lp.project_groups['openstack']
|
||||
openstack_projects = map(lambda project: project.name,
|
||||
openstack_group.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
|
||||
valid_query = len(results) > 0
|
||||
if not valid_query:
|
||||
print("Didn't find any hits for bug %s" % x['bug'])
|
||||
# don't fail tests if no hits for a bug
|
||||
return True
|
||||
|
3
tox.ini
3
tox.ini
@ -15,6 +15,9 @@ commands = python setup.py testr --slowest --testr-args='{posargs} tests.unit'
|
||||
[testenv:functional]
|
||||
commands = python setup.py testr --slowest --testr-args='{posargs} tests.functional'
|
||||
|
||||
[testenv:queries]
|
||||
commands = python setup.py testr --slowest --testr-args='{posargs} tests.functional.test_queries'
|
||||
|
||||
[testenv:pep8]
|
||||
commands = flake8
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user