Add decorator to skip tests for a required resource type
Skip tests if a resource type is unavailable. This would help us add tests for new resource plugins that would be skipped for earlier releases. Change-Id: Ia9f08f9148934e80af6ba827e71e110a89a89859
This commit is contained in:
parent
fbae3959fc
commit
82b7128f87
|
@ -34,6 +34,7 @@ from tempest import config
|
|||
|
||||
LOG = logging.getLogger(__name__)
|
||||
_LOG_FORMAT = "%(levelname)8s [%(name)s] %(message)s"
|
||||
_resource_types = None
|
||||
|
||||
|
||||
def call_until_true(duration, sleep_for, func, *args, **kwargs):
|
||||
|
@ -86,6 +87,29 @@ def requires_convergence(test_method):
|
|||
return skipper(test_method)
|
||||
|
||||
|
||||
def requires_resource_type(resource_type):
|
||||
'''Decorator for tests requiring a resource type.
|
||||
|
||||
The decorated test will be skipped when the resource type 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
|
||||
|
||||
global _resource_types
|
||||
if not _resource_types:
|
||||
manager = clients.ClientManager(conf)
|
||||
obj_rtypes = manager.orchestration_client.resource_types.list()
|
||||
_resource_types = list(t.resource_type for t in obj_rtypes)
|
||||
rtype_available = resource_type and resource_type in _resource_types
|
||||
skipper = testtools.skipUnless(
|
||||
rtype_available,
|
||||
"%s resource type not available, skipping test." % resource_type)
|
||||
return skipper(test_method)
|
||||
return decorator
|
||||
|
||||
|
||||
class HeatIntegrationTest(testtools.testcase.WithAttributes,
|
||||
testscenarios.WithScenarios,
|
||||
testtools.TestCase):
|
||||
|
|
|
@ -17,6 +17,7 @@ import yaml
|
|||
|
||||
from tempest.lib import decorators
|
||||
|
||||
from heat_tempest_plugin.common import test
|
||||
from heat_tempest_plugin.tests.functional import functional_base
|
||||
|
||||
|
||||
|
@ -72,6 +73,7 @@ outputs:
|
|||
'''
|
||||
|
||||
|
||||
@test.requires_resource_type('OS::Neutron::Trunk')
|
||||
class UpdateTrunkTest(functional_base.FunctionalTestsBase):
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Reference in New Issue