validate: launcher: Allow checking if bugs linked to blacklist is fixed

This commit is contained in:
Thibault Saunier 2016-11-16 10:47:21 -03:00
parent 615fab620a
commit 2857eaf2ad
3 changed files with 103 additions and 9 deletions

View file

@ -41,7 +41,8 @@ from .loggable import Loggable
import xml.etree.cElementTree as ET
from .utils import mkdir, Result, Colors, printc, DEFAULT_TIMEOUT, GST_SECOND, \
Protocols, look_for_file_in_source_dir, get_data_file, BackTraceGenerator
Protocols, look_for_file_in_source_dir, get_data_file, BackTraceGenerator, \
check_bugs_resolution
# The factor by which we increase the hard timeout when running inside
# Valgrind
@ -208,7 +209,7 @@ class Test(Loggable):
if not stack_trace:
return
info = "\n\n== Segfault informations: == \n%s" % stack_trace
info = "\n\n== Stack trace: == \n%s" % stack_trace
if self.options.redirect_logs:
print(info)
else:
@ -997,6 +998,7 @@ class TestsManager(Loggable):
self.check_testslist = True
self.all_tests = None
self.expected_failures = {}
self.blacklisted_tests = []
def init(self):
return False
@ -1058,12 +1060,7 @@ class TestsManager(Loggable):
self.blacklisted_tests_patterns.append(re.compile(pattern))
def set_default_blacklist(self, default_blacklist):
msg = "\nCurrently 'hardcoded' %s blacklisted tests:\n\n" % self.name
for name, bug in default_blacklist:
self._add_blacklist(name)
msg += " + %s \n --> bug: %s\n" % (name, bug)
printc(msg, Colors.FAIL, True)
self.blacklisted_tests += default_blacklist
def add_options(self, parser):
""" Add more arguments. """
@ -1089,6 +1086,23 @@ class TestsManager(Loggable):
for patterns in options.blacklisted_tests:
self._add_blacklist(patterns)
def set_blacklists(self):
if self.blacklisted_tests:
printc("\nCurrently 'hardcoded' %s blacklisted tests:\n"
"--------------------------------------------" % self.name,
Colors.WARNING)
if self.options.check_bugs_status:
if not check_bugs_resolution(self.blacklisted_tests):
return False
for name, bug in self.blacklisted_tests:
self._add_blacklist(name)
if not self.options.check_bugs_status:
print(" + %s \n --> bug: %s\n" % (name, bug))
return True
def _check_blacklisted(self, test):
for pattern in self.blacklisted_tests_patterns:
if pattern.findall(test.classname):
@ -1380,6 +1394,11 @@ class _TestsLauncher(Loggable):
if not options.config and options.testsuites:
if self._setup_testsuites() is False:
return False
for tester in self.testers:
if not tester.set_blacklists():
return False
return True
def _check_tester_has_other_testsuite(self, testsuite, tester):

View file

@ -219,6 +219,7 @@ class LauncherConfig(Loggable):
self.sync = False
self.force_sync = False
self.sync_all = False
self.check_bugs_status = False
def cleanup(self):
"""
@ -399,6 +400,11 @@ Note that all testsuite should be inside python modules, so the directory should
parser.add_argument("-b", "--blacklisted-tests", dest="blacklisted_tests",
action="append",
help="Define the tests not to execute, it can be a regex.")
parser.add_argument("--check-bugs", dest="check_bugs_status",
action="store_true",
help="Check if the bug linked to blacklisted tests has"
" been marked as resolved. (only work with bugzilla "
"for the time being).")
parser.add_argument("-L", "--list-tests",
dest="list_tests",
action="store_true",

View file

@ -31,12 +31,12 @@ import sys
import tempfile
import time
import urllib.request
import urllib.parse
import urllib.error
import urllib.parse
from .loggable import Loggable
from operator import itemgetter
from xml.etree import ElementTree
GST_SECOND = int(1000000000)
@ -362,3 +362,72 @@ class BackTraceGenerator(Loggable):
return info
return None
def check_bugs_resolution(bugs_definitions):
bugz = {}
regexes = {}
for regex, bug in bugs_definitions:
url = urllib.parse.urlparse(bug)
if "bugzilla" not in url.netloc:
printc(" + %s \n --> bug: %s\n --> Status: Not a bugzilla report\n" % (regex, bug),
Colors.WARNING)
continue
query = urllib.parse.parse_qs(url.query)
_id = query.get('id')
if not _id:
printc(" + '%s' -- Can't check bug '%s'\n" % (regex, bug), Colors.WARNING)
continue
if isinstance(_id, list):
_id = _id[0]
regexes[_id] = (regex, bug)
url_parts = tuple(list(url)[:3] + ['', '', ''])
ids = bugz.get(url_parts, [])
ids.append(_id)
bugz[url_parts] = ids
res = True
for url_parts, ids in bugz.items():
url_parts = list(url_parts)
query = {'id': ','.join(ids)}
query['ctype'] = 'xml'
url_parts[4] = urllib.parse.urlencode(query)
try:
res = urllib.request.urlopen(urllib.parse.urlunparse(url_parts))
except Exception as e:
printc(" + Could not properly check bugs status for: %s (%s)\n"
% (urllib.parse.urlunparse(url_parts), e), Colors.FAIL)
continue
root = ElementTree.fromstring(res.read())
bugs = root.findall('./bug')
if len(bugs) != len(ids):
printc(" + Could not properly check bugs status on server %s\n" %
urllib.parse.urlunparse(url_parts), Colors.FAIL)
continue
for bugelem in bugs:
status = bugelem.findtext('./bug_status')
bugid = bugelem.findtext('./bug_id')
regex, bug = regexes[bugid]
desc = bugelem.findtext('./short_desc')
if not status:
printc(" + %s \n --> bug: %s\n --> Status: UNKNOWN\n" % (regex, bug),
Colors.WARNING)
continue
if not status.lower() in ['new', 'verified']:
printc(" + %s \n --> bug: #%s: '%s'\n ==> Bug CLOSED already (status: %s)\n" % (
regex, bugid, desc, status), Colors.WARNING)
res = False
printc(" + %s \n --> bug: #%s: '%s'\n --> Status: %s\n" % (
regex, bugid, desc, status), Colors.OKGREEN)
return res