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
diff --git a/tempest/hacking/checks.py b/tempest/hacking/checks.py
index 06ca09b..936fbe8 100644
--- a/tempest/hacking/checks.py
+++ b/tempest/hacking/checks.py
@@ -30,6 +30,9 @@
 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 @@
                "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 @@
     register(no_hyphen_at_end_of_rand_name)
     register(no_mutable_default_args)
     register(no_testtools_skip_decorator)
+    register(get_resources_on_service_clients)