blob: 93cf89d43ea1f8fa565e4c2f4e26c1636e1f8b24 [file] [log] [blame]
Giampaolo Lauria1b837ce2013-05-01 11:22:07 -04001# 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
17import re
18
19
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040020PYTHON_CLIENTS = ['cinder', 'glance', 'keystone', 'nova', 'swift', 'quantum']
21
22SKIP_DECORATOR_RE = re.compile(r'\s*@testtools.skip\((.*)\)')
23SKIP_STR_RE = re.compile(r'.*Bug #\d+.*')
24PYTHON_CLIENT_RE = re.compile('import (%s)client' % '|'.join(PYTHON_CLIENTS))
Giampaolo Lauria1b837ce2013-05-01 11:22:07 -040025
26
27def skip_bugs(physical_line):
28 """Check skip lines for proper bug entries
29
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040030 T101: skips must contain "Bug #<bug_number>"
Giampaolo Lauria1b837ce2013-05-01 11:22:07 -040031 """
32
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040033 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 Lauria1b837ce2013-05-01 11:22:07 -040040
Giampaolo Lauria1b837ce2013-05-01 11:22:07 -040041
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040042def import_no_clients_in_api(physical_line, filename):
43 """Check for client imports from tempest/api tests
Giampaolo Lauria1b837ce2013-05-01 11:22:07 -040044
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040045 T102: Cannot import OpenStack python clients
46 """
Giampaolo Lauria1b837ce2013-05-01 11:22:07 -040047
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040048 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 Lauriad50c27d2013-05-23 15:23:12 -040054
55
Sean Dagueb2e48c82013-06-06 12:43:26 -040056def 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 Lauriad50c27d2013-05-23 15:23:12 -040066def factory(register):
67 register(skip_bugs)
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040068 register(import_no_clients_in_api)