From 82b7128f872fa470e5589cc25816d3fb70f21b5f Mon Sep 17 00:00:00 2001 From: rabi Date: Thu, 8 Mar 2018 11:08:36 +0530 Subject: [PATCH] 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 --- heat_tempest_plugin/common/test.py | 24 +++++++++++++++++++ .../test_create_update_neutron_trunk.py | 2 ++ 2 files changed, 26 insertions(+) diff --git a/heat_tempest_plugin/common/test.py b/heat_tempest_plugin/common/test.py index dbd2e27..f75385f 100644 --- a/heat_tempest_plugin/common/test.py +++ b/heat_tempest_plugin/common/test.py @@ -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): diff --git a/heat_tempest_plugin/tests/functional/test_create_update_neutron_trunk.py b/heat_tempest_plugin/tests/functional/test_create_update_neutron_trunk.py index ff5bcaf..bdcb58e 100644 --- a/heat_tempest_plugin/tests/functional/test_create_update_neutron_trunk.py +++ b/heat_tempest_plugin/tests/functional/test_create_update_neutron_trunk.py @@ -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