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 | |
Mark McClain | f2982e8 | 2013-07-06 17:48:03 -0400 | [diff] [blame] | 20 | PYTHON_CLIENTS = ['cinder', 'glance', 'keystone', 'nova', 'swift', 'neutron'] |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 21 | |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 22 | PYTHON_CLIENT_RE = re.compile('import (%s)client' % '|'.join(PYTHON_CLIENTS)) |
Matthew Treinish | 6ba951a | 2013-09-09 22:06:18 +0000 | [diff] [blame] | 23 | TEST_DEFINITION = re.compile(r'^\s*def test.*') |
| 24 | SCENARIO_DECORATOR = re.compile(r'\s*@.*services\(') |
Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame] | 25 | |
| 26 | |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 27 | def import_no_clients_in_api(physical_line, filename): |
| 28 | """Check for client imports from tempest/api tests |
Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame] | 29 | |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 30 | T102: Cannot import OpenStack python clients |
| 31 | """ |
Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame] | 32 | |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 33 | 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 Lauria | d50c27d | 2013-05-23 15:23:12 -0400 | [diff] [blame] | 39 | |
| 40 | |
Matthew Treinish | 6ba951a | 2013-09-09 22:06:18 +0000 | [diff] [blame] | 41 | def 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 Lauria | d50c27d | 2013-05-23 15:23:12 -0400 | [diff] [blame] | 55 | def factory(register): |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 56 | register(import_no_clients_in_api) |
Matthew Treinish | 6ba951a | 2013-09-09 22:06:18 +0000 | [diff] [blame] | 57 | register(scenario_tests_need_service_tags) |