blob: 4c1c107651984ff51a9d3a30a44167a486cd7868 [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
Mark McClainf2982e82013-07-06 17:48:03 -040020PYTHON_CLIENTS = ['cinder', 'glance', 'keystone', 'nova', 'swift', 'neutron']
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040021
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040022PYTHON_CLIENT_RE = re.compile('import (%s)client' % '|'.join(PYTHON_CLIENTS))
Matthew Treinish6ba951a2013-09-09 22:06:18 +000023TEST_DEFINITION = re.compile(r'^\s*def test.*')
24SCENARIO_DECORATOR = re.compile(r'\s*@.*services\(')
Giampaolo Lauria1b837ce2013-05-01 11:22:07 -040025
26
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040027def import_no_clients_in_api(physical_line, filename):
28 """Check for client imports from tempest/api tests
Giampaolo Lauria1b837ce2013-05-01 11:22:07 -040029
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040030 T102: Cannot import OpenStack python clients
31 """
Giampaolo Lauria1b837ce2013-05-01 11:22:07 -040032
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040033 if "tempest/api" in filename:
34 res = PYTHON_CLIENT_RE.match(physical_line)
35 if res:
36 return (physical_line.find(res.group(1)),
37 ("T102: python clients import not allowed"
38 " in tempest/api/* tests"))
Giampaolo Lauriad50c27d2013-05-23 15:23:12 -040039
40
Matthew Treinish6ba951a2013-09-09 22:06:18 +000041def scenario_tests_need_service_tags(physical_line, filename,
42 previous_logical):
43 """Check that scenario tests have service tags
44
45 T104: Scenario tests require a services decorator
46 """
47
48 if 'tempest/scenario' in filename:
49 if TEST_DEFINITION.match(physical_line):
50 if not SCENARIO_DECORATOR.match(previous_logical):
51 return (physical_line.find('def'),
52 "T104: Scenario tests require a service decorator")
53
54
Giampaolo Lauriad50c27d2013-05-23 15:23:12 -040055def factory(register):
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040056 register(import_no_clients_in_api)
Matthew Treinish6ba951a2013-09-09 22:06:18 +000057 register(scenario_tests_need_service_tags)