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."""
diff --git a/heat_tempest_plugin/tests/functional/test_event_sinks.py b/heat_tempest_plugin/tests/functional/test_event_sinks.py
index 7cb1d7b..dd1accc 100644
--- a/heat_tempest_plugin/tests/functional/test_event_sinks.py
+++ b/heat_tempest_plugin/tests/functional/test_event_sinks.py
@@ -19,6 +19,7 @@
 from heat_tempest_plugin.tests.functional import functional_base
 
 
+@test.requires_service_type('messaging')
 class ZaqarEventSinkTest(functional_base.FunctionalTestsBase):
     template = '''
 heat_template_version: "2013-05-23"
diff --git a/heat_tempest_plugin/tests/functional/test_software_config.py b/heat_tempest_plugin/tests/functional/test_software_config.py
index f034096..ada67f2 100644
--- a/heat_tempest_plugin/tests/functional/test_software_config.py
+++ b/heat_tempest_plugin/tests/functional/test_software_config.py
@@ -183,6 +183,7 @@
                           verify=self.verify_cert)
 
 
+@test.requires_service_type('messaging')
 class ZaqarSignalTransportTest(functional_base.FunctionalTestsBase):
     server_template = '''
 heat_template_version: "2013-05-23"
diff --git a/heat_tempest_plugin/tests/functional/test_waitcondition.py b/heat_tempest_plugin/tests/functional/test_waitcondition.py
index c21b33b..3bffd76 100644
--- a/heat_tempest_plugin/tests/functional/test_waitcondition.py
+++ b/heat_tempest_plugin/tests/functional/test_waitcondition.py
@@ -16,9 +16,11 @@
 from tempest.lib import decorators
 from zaqarclient.queues.v2 import client as zaqarclient
 
+from heat_tempest_plugin.common import test
 from heat_tempest_plugin.tests.functional import functional_base
 
 
+@test.requires_service_type('messaging')
 class ZaqarWaitConditionTest(functional_base.FunctionalTestsBase):
     template = '''
 heat_template_version: "2013-05-23"