Skip to content

Commit

Permalink
Add requires_service_type test decorator
Browse files Browse the repository at this point in the history
Adds the decorator for tests requiring zaqar.

Change-Id: I3a994cf9edfb32ea72090810228a6dac87bfc0f9
Story: #2004107
Task: 27516
  • Loading branch information
rabi committed Oct 17, 2018
1 parent 77d54cf commit d6b2535
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
32 changes: 23 additions & 9 deletions heat_tempest_plugin/common/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ def decorator(test_method):
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.
Expand Down Expand Up @@ -246,15 +269,6 @@ def is_network_extension_supported(self, extension_alias):
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."""
Expand Down
1 change: 1 addition & 0 deletions heat_tempest_plugin/tests/functional/test_event_sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def signal_deployments(self, stack_identifier):
verify=self.verify_cert)


@test.requires_service_type('messaging')
class ZaqarSignalTransportTest(functional_base.FunctionalTestsBase):
server_template = '''
heat_template_version: "2013-05-23"
Expand Down
2 changes: 2 additions & 0 deletions heat_tempest_plugin/tests/functional/test_waitcondition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d6b2535

Please sign in to comment.