blob: fd15c1c01a601154fabb361abcf4d73da92dd2e8 [file] [log] [blame]
Jay Pipes257d3f82012-07-08 23:01:31 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18"""
19Track test skips via launchpadlib API and raise alerts if a bug
20is fixed but a skip is still in the Tempest test code
21"""
22
23import logging
24import os
25import re
26
27from launchpadlib import launchpad
28
29BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
30TESTDIR = os.path.join(BASEDIR, 'tempest', 'tests')
31LPCACHEDIR = os.path.expanduser('~/.launchpadlib/cache')
32
33
34def info(msg, *args, **kwargs):
35 logging.info(msg, *args, **kwargs)
36
37
38def debug(msg, *args, **kwargs):
39 logging.debug(msg, *args, **kwargs)
40
41
42def find_skips(start=TESTDIR):
43 """
44 Returns a list of tuples (method, bug) that represent
45 test methods that have been decorated to skip because of
46 a particular bug.
47 """
48 results = []
49 debug("Searching in %s", start)
50 for root, _dirs, files in os.walk(start):
51 for name in files:
52 if name.startswith('test_') and name.endswith('py'):
53 path = os.path.join(root, name)
54 debug("Searching in %s", path)
55 results += find_skips_in_file(path)
56 return results
57
58
59def find_skips_in_file(path):
60 """
61 Return the skip tuples in a test file
62 """
63 BUG_RE = re.compile(r'.*skip\(.*[bB]ug\s*(\d+)')
64 DEF_RE = re.compile(r'.*def (\w+)\(')
65 bug_found = False
66 results = []
67 lines = open(path, 'rb').readlines()
68 for x, line in enumerate(lines):
69 if not bug_found:
70 res = BUG_RE.match(line)
71 if res:
72 bug_no = int(res.group(1))
73 debug("Found bug skip %s on line %d", bug_no, x + 1)
74 bug_found = True
75 else:
76 res = DEF_RE.match(line)
77 if res:
78 method = res.group(1)
79 debug("Found test method %s skips for bug %d", method, bug_no)
80 results.append((method, bug_no))
81 bug_found = False
82 return results
83
84
85if __name__ == '__main__':
86 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
87 results = find_skips()
88 unique_bugs = sorted(set([bug for (method, bug) in results]))
89 unskips = []
90 info("Total bug skips found: %d", len(results))
91 info("Total unique bugs causing skips: %d", len(unique_bugs))
92 lp = launchpad.Launchpad.login_anonymously('grabbing bugs', 'production', LPCACHEDIR)
93 for bug_no in unique_bugs:
94 bug = lp.bugs[bug_no]
95 for task in bug.bug_tasks:
96 info("Bug #%7s (%12s - %12s)", bug_no, task.importance, task.status)
97 if task.status in ('Fix Released', 'Fix Committed'):
98 unskips.append(bug_no)
99
100 if unskips:
101 print "The following bugs have been fixed and the corresponding skips"
102 print "should be removed from the test cases:"
103 print
104 for bug in unskips:
105 print " %7s" % bug