Remove deprecated skip decorators

This patch aims to remove 'skip_unless_config' and 'skip_if_config'
decorators, which marked as deprecated and would be removed in Queens.

Change-Id: I45a0216b7ab34e962b0f4802df77019b0c613d49
This commit is contained in:
jeremy.zhang 2017-09-21 12:37:32 +08:00
parent 991d62df79
commit f92e6d42f0
3 changed files with 5 additions and 169 deletions

View File

@ -0,0 +1,5 @@
---
upgrade:
- |
Remove two deprecated skip decorators in ``config`` module:
``skip_unless_config`` and ``skip_if_config``.

View File

@ -15,15 +15,12 @@
from __future__ import print_function
import functools
import os
import tempfile
import debtcollector.removals
from oslo_concurrency import lockutils
from oslo_config import cfg
from oslo_log import log as logging
import testtools
from tempest.lib import exceptions
from tempest.lib.services import clients
@ -1284,79 +1281,6 @@ class TempestConfigProxy(object):
CONF = TempestConfigProxy()
@debtcollector.removals.remove(
message='use testtools.skipUnless instead', removal_version='Queens')
def skip_unless_config(*args):
"""Decorator to raise a skip if a config opt doesn't exist or is False
:param str group: The first arg, the option group to check
:param str name: The second arg, the option name to check
:param str msg: Optional third arg, the skip msg to use if a skip is raised
:raises testtools.TestCaseskipException: If the specified config option
doesn't exist or it exists and evaluates to False
"""
def decorator(f):
group = args[0]
name = args[1]
@functools.wraps(f)
def wrapper(self, *func_args, **func_kwargs):
if not hasattr(CONF, group):
msg = "Config group %s doesn't exist" % group
raise testtools.TestCase.skipException(msg)
conf_group = getattr(CONF, group)
if not hasattr(conf_group, name):
msg = "Config option %s.%s doesn't exist" % (group,
name)
raise testtools.TestCase.skipException(msg)
value = getattr(conf_group, name)
if not value:
if len(args) == 3:
msg = args[2]
else:
msg = "Config option %s.%s is false" % (group,
name)
raise testtools.TestCase.skipException(msg)
return f(self, *func_args, **func_kwargs)
return wrapper
return decorator
@debtcollector.removals.remove(
message='use testtools.skipIf instead', removal_version='Queens')
def skip_if_config(*args):
"""Raise a skipException if a config exists and is True
:param str group: The first arg, the option group to check
:param str name: The second arg, the option name to check
:param str msg: Optional third arg, the skip msg to use if a skip is raised
:raises testtools.TestCase.skipException: If the specified config option
exists and evaluates to True
"""
def decorator(f):
group = args[0]
name = args[1]
@functools.wraps(f)
def wrapper(self, *func_args, **func_kwargs):
if hasattr(CONF, group):
conf_group = getattr(CONF, group)
if hasattr(conf_group, name):
value = getattr(conf_group, name)
if value:
if len(args) == 3:
msg = args[2]
else:
msg = "Config option %s.%s is false" % (group,
name)
raise testtools.TestCase.skipException(msg)
return f(self, *func_args, **func_kwargs)
return wrapper
return decorator
def service_client_config(service_client_name=None):
"""Return a dict with the parameters to init service clients

View File

@ -176,96 +176,3 @@ class TestRequiresExtDecorator(BaseDecoratorsTest):
self._test_requires_ext_helper,
extension='enabled_ext',
service='bad_service')
class TestConfigDecorators(BaseDecoratorsTest):
def setUp(self):
super(TestConfigDecorators, self).setUp()
cfg.CONF.set_default('nova', True, 'service_available')
cfg.CONF.set_default('glance', False, 'service_available')
def _assert_skip_message(self, func, skip_msg):
try:
func()
self.fail()
except testtools.TestCase.skipException as skip_exc:
self.assertEqual(skip_exc.args[0], skip_msg)
def _test_skip_unless_config(self, expected_to_skip=True, *decorator_args):
class TestFoo(test.BaseTestCase):
@config.skip_unless_config(*decorator_args)
def test_bar(self):
return 0
t = TestFoo('test_bar')
if expected_to_skip:
self.assertRaises(testtools.TestCase.skipException, t.test_bar)
if (len(decorator_args) >= 3):
# decorator_args[2]: skip message specified
self._assert_skip_message(t.test_bar, decorator_args[2])
else:
try:
self.assertEqual(t.test_bar(), 0)
except testtools.TestCase.skipException:
# We caught a skipException but we didn't expect to skip
# this test so raise a hard test failure instead.
raise testtools.TestCase.failureException(
"Not supposed to skip")
def _test_skip_if_config(self, expected_to_skip=True,
*decorator_args):
class TestFoo(test.BaseTestCase):
@config.skip_if_config(*decorator_args)
def test_bar(self):
return 0
t = TestFoo('test_bar')
if expected_to_skip:
self.assertRaises(testtools.TestCase.skipException, t.test_bar)
if (len(decorator_args) >= 3):
# decorator_args[2]: skip message specified
self._assert_skip_message(t.test_bar, decorator_args[2])
else:
try:
self.assertEqual(t.test_bar(), 0)
except testtools.TestCase.skipException:
# We caught a skipException but we didn't expect to skip
# this test so raise a hard test failure instead.
raise testtools.TestCase.failureException(
"Not supposed to skip")
def test_skip_unless_no_group(self):
self._test_skip_unless_config(True, 'fake_group', 'an_option')
def test_skip_unless_no_option(self):
self._test_skip_unless_config(True, 'service_available',
'not_an_option')
def test_skip_unless_false_option(self):
self._test_skip_unless_config(True, 'service_available', 'glance')
def test_skip_unless_false_option_msg(self):
self._test_skip_unless_config(True, 'service_available', 'glance',
'skip message')
def test_skip_unless_true_option(self):
self._test_skip_unless_config(False,
'service_available', 'nova')
def test_skip_if_no_group(self):
self._test_skip_if_config(False, 'fake_group', 'an_option')
def test_skip_if_no_option(self):
self._test_skip_if_config(False, 'service_available', 'not_an_option')
def test_skip_if_false_option(self):
self._test_skip_if_config(False, 'service_available', 'glance')
def test_skip_if_true_option(self):
self._test_skip_if_config(True, 'service_available', 'nova')
def test_skip_if_true_option_msg(self):
self._test_skip_if_config(True, 'service_available', 'nova',
'skip message')