Add hacking rule for "GET /resources"

This patch is a prototype for "GET /resources" hacking rule.
black_list_T110.txt file contains the service client files which
are against this rule. So we need to fix them with removing them
from this file.

Partially implements blueprint consistent-service-method-names

Change-Id: I150fe2ef21d4d4d246a46d9baf2fb14cc7d79ee5
This commit is contained in:
Ken'ichi Ohmichi 2015-11-11 12:33:48 +00:00
parent f8512379dc
commit c0d96bec35
3 changed files with 58 additions and 0 deletions

View File

@ -17,6 +17,7 @@ Tempest Specific Commandments
- [T108] Check no hyphen at the end of rand_name() argument
- [T109] Cannot use testtools.skip decorator; instead use
decorators.skip_because from tempest-lib
- [T110] Check that service client names of GET should be consistent
- [N322] Method's default argument shouldn't be mutable
Test Data/Configuration

View File

@ -30,6 +30,9 @@ VI_HEADER_RE = re.compile(r"^#\s+vim?:.+")
RAND_NAME_HYPHEN_RE = re.compile(r".*rand_name\(.+[\-\_][\"\']\)")
mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])")
TESTTOOLS_SKIP_DECORATOR = re.compile(r'\s*@testtools\.skip\((.*)\)')
METHOD = re.compile(r"^ def .+")
METHOD_GET_RESOURCE = re.compile(r"^\s*def (list|show)\_.+")
CLASS = re.compile(r"^class .+")
def import_no_clients_in_api_and_scenario_tests(physical_line, filename):
@ -143,6 +146,45 @@ def no_testtools_skip_decorator(logical_line):
"decorators.skip_because from tempest-lib")
def get_resources_on_service_clients(logical_line, physical_line, filename,
line_number, lines):
"""Check that service client names of GET should be consistent
T110
"""
if 'tempest/services/' not in filename:
return
ignored_list = []
with open('tempest/hacking/ignored_list_T110.txt') as f:
for line in f:
ignored_list.append(line.strip())
if filename in ignored_list:
return
if not METHOD.match(physical_line):
return
if pep8.noqa(physical_line):
return
for line in lines[line_number:]:
if METHOD.match(line) or CLASS.match(line):
# the end of a method
return
if 'self.get(' not in line:
continue
if METHOD_GET_RESOURCE.match(logical_line):
return
msg = ("T110: [GET /resources] methods should be list_<resource name>s"
" or show_<resource name>")
yield (0, msg)
def factory(register):
register(import_no_clients_in_api_and_scenario_tests)
register(scenario_tests_need_service_tags)
@ -152,3 +194,4 @@ def factory(register):
register(no_hyphen_at_end_of_rand_name)
register(no_mutable_default_args)
register(no_testtools_skip_decorator)
register(get_resources_on_service_clients)

View File

@ -0,0 +1,14 @@
./tempest/services/compute/json/server_groups_client.py
./tempest/services/compute/json/servers_client.py
./tempest/services/database/json/flavors_client.py
./tempest/services/identity/v3/json/credentials_client.py
./tempest/services/identity/v3/json/identity_client.py
./tempest/services/identity/v3/json/policy_client.py
./tempest/services/identity/v3/json/region_client.py
./tempest/services/messaging/json/messaging_client.py
./tempest/services/object_storage/object_client.py
./tempest/services/telemetry/json/telemetry_client.py
./tempest/services/volume/json/qos_client.py
./tempest/services/volume/json/backups_client.py
./tempest/services/image/v2/json/image_client.py
./tempest/services/baremetal/base.py