Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 IBM Corp. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
| 17 | import re |
| 18 | |
| 19 | |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 20 | PYTHON_CLIENTS = ['cinder', 'glance', 'keystone', 'nova', 'swift', 'quantum'] |
| 21 | |
| 22 | SKIP_DECORATOR_RE = re.compile(r'\s*@testtools.skip\((.*)\)') |
| 23 | SKIP_STR_RE = re.compile(r'.*Bug #\d+.*') |
| 24 | PYTHON_CLIENT_RE = re.compile('import (%s)client' % '|'.join(PYTHON_CLIENTS)) |
Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame] | 25 | |
| 26 | |
| 27 | def skip_bugs(physical_line): |
| 28 | """Check skip lines for proper bug entries |
| 29 | |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 30 | T101: skips must contain "Bug #<bug_number>" |
Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame] | 31 | """ |
| 32 | |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 33 | res = SKIP_DECORATOR_RE.match(physical_line) |
| 34 | if res: |
| 35 | content = res.group(1) |
| 36 | res = SKIP_STR_RE.match(content) |
| 37 | if not res: |
| 38 | return (physical_line.find(content), |
| 39 | 'T101: skips must contain "Bug #<bug_number>"') |
Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame] | 40 | |
Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame] | 41 | |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 42 | def import_no_clients_in_api(physical_line, filename): |
| 43 | """Check for client imports from tempest/api tests |
Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame] | 44 | |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 45 | T102: Cannot import OpenStack python clients |
| 46 | """ |
Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame] | 47 | |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 48 | if "tempest/api" in filename: |
| 49 | res = PYTHON_CLIENT_RE.match(physical_line) |
| 50 | if res: |
| 51 | return (physical_line.find(res.group(1)), |
| 52 | ("T102: python clients import not allowed" |
| 53 | " in tempest/api/* tests")) |
Giampaolo Lauria | d50c27d | 2013-05-23 15:23:12 -0400 | [diff] [blame] | 54 | |
| 55 | |
Sean Dague | b2e48c8 | 2013-06-06 12:43:26 -0400 | [diff] [blame] | 56 | def import_no_files_in_tests(physical_line, filename): |
| 57 | """Check for merges that try to land into tempest/tests |
| 58 | |
| 59 | T103: tempest/tests directory is deprecated |
| 60 | """ |
| 61 | |
| 62 | if "tempest/tests" in filename: |
| 63 | return (0, ("T103: tempest/tests is deprecated")) |
| 64 | |
| 65 | |
Giampaolo Lauria | d50c27d | 2013-05-23 15:23:12 -0400 | [diff] [blame] | 66 | def factory(register): |
| 67 | register(skip_bugs) |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 68 | register(import_no_clients_in_api) |