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