blob: 2e499a2b17e6a8350812186e66e5d6afe3416ecf [file] [log] [blame]
Giampaolo Lauria1b837ce2013-05-01 11:22:07 -04001# Copyright 2013 IBM Corp.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import re
16
17
Mark McClainf2982e82013-07-06 17:48:03 -040018PYTHON_CLIENTS = ['cinder', 'glance', 'keystone', 'nova', 'swift', 'neutron']
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040019
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040020PYTHON_CLIENT_RE = re.compile('import (%s)client' % '|'.join(PYTHON_CLIENTS))
Matthew Treinish6ba951a2013-09-09 22:06:18 +000021TEST_DEFINITION = re.compile(r'^\s*def test.*')
Matthew Treinishecf212c2013-12-06 18:23:54 +000022SETUPCLASS_DEFINITION = re.compile(r'^\s*def setUpClass')
Matthew Treinish6ba951a2013-09-09 22:06:18 +000023SCENARIO_DECORATOR = re.compile(r'\s*@.*services\(')
Giampaolo Lauria1b837ce2013-05-01 11:22:07 -040024
25
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040026def import_no_clients_in_api(physical_line, filename):
27 """Check for client imports from tempest/api tests
Giampaolo Lauria1b837ce2013-05-01 11:22:07 -040028
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040029 T102: Cannot import OpenStack python clients
30 """
Giampaolo Lauria1b837ce2013-05-01 11:22:07 -040031
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040032 if "tempest/api" in filename:
33 res = PYTHON_CLIENT_RE.match(physical_line)
34 if res:
35 return (physical_line.find(res.group(1)),
36 ("T102: python clients import not allowed"
37 " in tempest/api/* tests"))
Giampaolo Lauriad50c27d2013-05-23 15:23:12 -040038
39
Matthew Treinish6ba951a2013-09-09 22:06:18 +000040def scenario_tests_need_service_tags(physical_line, filename,
41 previous_logical):
42 """Check that scenario tests have service tags
43
44 T104: Scenario tests require a services decorator
45 """
46
47 if 'tempest/scenario' in filename:
48 if TEST_DEFINITION.match(physical_line):
49 if not SCENARIO_DECORATOR.match(previous_logical):
50 return (physical_line.find('def'),
51 "T104: Scenario tests require a service decorator")
52
53
Matthew Treinishecf212c2013-12-06 18:23:54 +000054def no_setupclass_for_unit_tests(physical_line, filename):
55 if 'tempest/tests' in filename:
56 if SETUPCLASS_DEFINITION.match(physical_line):
57 return (physical_line.find('def'),
58 "T105: setUpClass can not be used with unit tests")
59
60
Giampaolo Lauriad50c27d2013-05-23 15:23:12 -040061def factory(register):
Giampaolo Lauriab8424eb2013-05-23 15:56:21 -040062 register(import_no_clients_in_api)
Matthew Treinish6ba951a2013-09-09 22:06:18 +000063 register(scenario_tests_need_service_tags)
Matthew Treinishecf212c2013-12-06 18:23:54 +000064 register(no_setupclass_for_unit_tests)