Add requires_service_type test decorator

Adds the decorator for tests requiring zaqar.

Change-Id: I3a994cf9edfb32ea72090810228a6dac87bfc0f9
Story: #2004107
Task: 27516
diff --git a/heat_tempest_plugin/common/test.py b/heat_tempest_plugin/common/test.py
index cbf4abb..ccbc12a 100644
--- a/heat_tempest_plugin/common/test.py
+++ b/heat_tempest_plugin/common/test.py
@@ -109,6 +109,29 @@
     return decorator
 
 
+def requires_service_type(service_type):
+    '''Decorator for tests requiring a specific service being available.
+
+    The decorated test will be skipped when a service is not available.
+    '''
+    def decorator(test_method):
+        conf = getattr(config.CONF, 'heat_plugin', None)
+        if not conf or conf.auth_url is None:
+            return test_method
+
+        manager = clients.ClientManager(conf)
+        try:
+            manager.identity_client.get_endpoint_url(
+                service_type, conf.region, conf.endpoint_type)
+        except kc_exceptions.EndpointNotFound:
+            skipper = testtools.skip(
+                "%s service not available, skipping test." % service_type)
+            return skipper(test_method)
+        else:
+            return test_method
+    return decorator
+
+
 def requires_feature(feature):
     '''Decorator for tests requring specific feature.
 
@@ -246,15 +269,6 @@
             return False
         return True
 
-    def is_service_available(self, service_type):
-        try:
-            self.identity_client.get_endpoint_url(
-                service_type, self.conf.region, self.conf.endpoint_type)
-        except kc_exceptions.EndpointNotFound:
-            return False
-        else:
-            return True
-
     @staticmethod
     def _stack_output(stack, output_key, validate_errors=True):
         """Return a stack output value for a given key."""