Jay Pipes | 257d3f8 | 2012-07-08 23:01:31 -0400 | [diff] [blame] | 1 | # 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 | """ |
| 19 | Track test skips via launchpadlib API and raise alerts if a bug |
| 20 | is fixed but a skip is still in the Tempest test code |
| 21 | """ |
| 22 | |
| 23 | import logging |
| 24 | import os |
| 25 | import re |
| 26 | |
| 27 | from launchpadlib import launchpad |
| 28 | |
| 29 | BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) |
| 30 | TESTDIR = os.path.join(BASEDIR, 'tempest', 'tests') |
| 31 | LPCACHEDIR = os.path.expanduser('~/.launchpadlib/cache') |
| 32 | |
| 33 | |
| 34 | def info(msg, *args, **kwargs): |
| 35 | logging.info(msg, *args, **kwargs) |
| 36 | |
| 37 | |
| 38 | def debug(msg, *args, **kwargs): |
| 39 | logging.debug(msg, *args, **kwargs) |
| 40 | |
| 41 | |
| 42 | def 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 | |
| 59 | def 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 | |
| 85 | if __name__ == '__main__': |
Jay Pipes | a6aa5f2 | 2012-07-24 19:40:29 -0400 | [diff] [blame] | 86 | logging.basicConfig(format='%(levelname)s: %(message)s', |
| 87 | level=logging.INFO) |
Jay Pipes | 257d3f8 | 2012-07-08 23:01:31 -0400 | [diff] [blame] | 88 | results = find_skips() |
| 89 | unique_bugs = sorted(set([bug for (method, bug) in results])) |
| 90 | unskips = [] |
| 91 | info("Total bug skips found: %d", len(results)) |
| 92 | info("Total unique bugs causing skips: %d", len(unique_bugs)) |
Jay Pipes | a6aa5f2 | 2012-07-24 19:40:29 -0400 | [diff] [blame] | 93 | lp = launchpad.Launchpad.login_anonymously('grabbing bugs', |
| 94 | 'production', |
| 95 | LPCACHEDIR) |
Jay Pipes | 257d3f8 | 2012-07-08 23:01:31 -0400 | [diff] [blame] | 96 | for bug_no in unique_bugs: |
| 97 | bug = lp.bugs[bug_no] |
| 98 | for task in bug.bug_tasks: |
Jay Pipes | a6aa5f2 | 2012-07-24 19:40:29 -0400 | [diff] [blame] | 99 | info("Bug #%7s (%12s - %12s)", bug_no, |
| 100 | task.importance, task.status) |
Jay Pipes | 257d3f8 | 2012-07-08 23:01:31 -0400 | [diff] [blame] | 101 | if task.status in ('Fix Released', 'Fix Committed'): |
| 102 | unskips.append(bug_no) |
| 103 | |
| 104 | if unskips: |
| 105 | print "The following bugs have been fixed and the corresponding skips" |
| 106 | print "should be removed from the test cases:" |
| 107 | print |
| 108 | for bug in unskips: |
| 109 | print " %7s" % bug |