From 144bdc6f73fef1962443379fc2dd34b499a2905e Mon Sep 17 00:00:00 2001 From: Rabi Mishra Date: Thu, 10 Jan 2019 17:00:57 +0530 Subject: [PATCH] Skip tests based on service features disabled in tempest It's not possible to know if services have certain features enabled from the sevice API in certain cases. Let's leverage the service specific feature groups in tempest. If a specific service feature is disabled in tempest config, the decorated tests would be skipped. ex. If tempest.conf contains [volume-feature-enabled] backup = False test_cinder_volume_create_backup_restore scenario test would be skipped. Change-Id: I7a2495182791595c87f8245ff5e13dfd841b013f --- heat_tempest_plugin/common/test.py | 29 ++++++++++++++----- .../tests/scenario/test_volumes.py | 2 ++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/heat_tempest_plugin/common/test.py b/heat_tempest_plugin/common/test.py index ccbc12a..008ac87 100644 --- a/heat_tempest_plugin/common/test.py +++ b/heat_tempest_plugin/common/test.py @@ -132,19 +132,34 @@ def requires_service_type(service_type): return decorator +def _check_require(group, feature, test_method): + features_group = getattr(config.CONF, group, None) + if not features_group: + return test_method + feature_enabled = features_group.get(feature, True) + skipper = testtools.skipUnless(feature_enabled, + "%s - Feature not enabled." % feature) + return skipper(test_method) + + def requires_feature(feature): '''Decorator for tests requring specific feature. The decorated test will be skipped when a specific feature is disabled. ''' def decorator(test_method): - features_group = getattr(config.CONF, 'heat_features_enabled', None) - if not features_group: - return test_method - feature_enabled = config.CONF.heat_features_enabled.get(feature, False) - skipper = testtools.skipUnless(feature_enabled, - "%s - Feature not enabled." % feature) - return skipper(test_method) + return _check_require('heat_features_enabled', feature, test_method) + return decorator + + +def requires_service_feature(service, feature): + '''Decorator for tests requring specific service feature enabled in tempest. + + The decorated test will be skipped when a specific feature is disabled. + ''' + def decorator(test_method): + group = service + '_feature_enabled' + return _check_require(group, feature, test_method) return decorator diff --git a/heat_tempest_plugin/tests/scenario/test_volumes.py b/heat_tempest_plugin/tests/scenario/test_volumes.py index 57d0936..7dfa8bf 100644 --- a/heat_tempest_plugin/tests/scenario/test_volumes.py +++ b/heat_tempest_plugin/tests/scenario/test_volumes.py @@ -17,11 +17,13 @@ import six from tempest.lib import decorators from heat_tempest_plugin.common import exceptions +from heat_tempest_plugin.common import test from heat_tempest_plugin.tests.scenario import scenario_base LOG = logging.getLogger(__name__) +@test.requires_service_feature('volume', 'backup') class VolumeBackupRestoreIntegrationTest(scenario_base.ScenarioTestsBase): """Class is responsible for testing of volume backup."""