Add requires_service_type test decorator

Adds the decorator for tests requiring zaqar.

Change-Id: I3a994cf9edfb32ea72090810228a6dac87bfc0f9
Story: #2004107
Task: 27516
This commit is contained in:
Rabi Mishra 2018-10-17 13:11:05 +05:30
parent 77d54cf730
commit d6b253502a
4 changed files with 27 additions and 9 deletions

View File

@ -109,6 +109,29 @@ def requires_resource_type(resource_type):
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 @@ class HeatIntegrationTest(testtools.testcase.WithAttributes,
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."""

View File

@ -19,6 +19,7 @@ from heat_tempest_plugin.common import test
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"

View File

@ -183,6 +183,7 @@ properties:
verify=self.verify_cert)
@test.requires_service_type('messaging')
class ZaqarSignalTransportTest(functional_base.FunctionalTestsBase):
server_template = '''
heat_template_version: "2013-05-23"

View File

@ -16,9 +16,11 @@ from keystoneclient.v3 import client as keystoneclient
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"