From c0d96bec352ff2058258d90247416e09704bb13c Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Wed, 11 Nov 2015 12:33:48 +0000 Subject: [PATCH] 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 --- HACKING.rst | 1 + tempest/hacking/checks.py | 43 +++++++++++++++++++++++++++ tempest/hacking/ignored_list_T110.txt | 14 +++++++++ 3 files changed, 58 insertions(+) create mode 100644 tempest/hacking/ignored_list_T110.txt diff --git a/HACKING.rst b/HACKING.rst index 379904685d..9f7487de1d 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -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 diff --git a/tempest/hacking/checks.py b/tempest/hacking/checks.py index 06ca09b0f6..936fbe816c 100644 --- a/tempest/hacking/checks.py +++ b/tempest/hacking/checks.py @@ -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_s" + " or show_") + 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) diff --git a/tempest/hacking/ignored_list_T110.txt b/tempest/hacking/ignored_list_T110.txt new file mode 100644 index 0000000000..987861faee --- /dev/null +++ b/tempest/hacking/ignored_list_T110.txt @@ -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