Merge "Enhance versionutils.deprecated to work with classes"

This commit is contained in:
Jenkins 2014-07-23 11:19:56 +00:00 committed by Gerrit Code Review
commit bbeef169a8
3 changed files with 57 additions and 5 deletions

View File

@ -14,6 +14,12 @@
import string
from openstack_dashboard.openstack.common import log
from muranodashboard.openstack.common import versionutils
LOG = log.getLogger(__name__)
def ensure_python_obj(obj):
mappings = {'True': True, 'False': False, 'None': None}
@ -54,3 +60,31 @@ class BlankFormatter(string.Formatter):
return kwargs.get(key, self.default)
else:
return string.Formatter.get_value(self, key, args, kwargs)
class deprecated(versionutils.deprecated):
"""A decorator to mark both functions and classes as deprecated."""
JUNO = 'J'
_RELEASES = {
'F': 'Folsom',
'G': 'Grizzly',
'H': 'Havana',
'I': 'Icehouse',
'J': 'Juno'
}
def __call__(self, func_or_cls):
if hasattr(func_or_cls, 'func_code'):
return super(deprecated, self).__call__(func_or_cls)
else:
if not self.what:
self.what = func_or_cls.__name__ + '()'
msg, details = self._build_message()
class cls(func_or_cls):
def __init__(self, *args, **kwargs):
LOG.deprecated(msg, details)
super(cls, self).__init__(*args, **kwargs)
return cls

View File

@ -36,8 +36,8 @@ import yaql
from muranoclient.common import exceptions as muranoclient_exc
from muranodashboard.api import packages as pkg_api
from muranodashboard.common import utils
from muranodashboard.environments import api as env_api
from muranodashboard.openstack.common import versionutils
LOG = logging.getLogger(__name__)
@ -553,8 +553,8 @@ class BooleanField(forms.BooleanField, CustomPropertiesField):
super(BooleanField, self).__init__(*args, **kwargs)
@versionutils.deprecated(
as_of=versionutils.deprecated.ICEHOUSE,
@utils.deprecated(
as_of=utils.deprecated.JUNO,
in_favor_of='type boolean (regular BooleanField)',
remove_in=1)
class FloatingIpBooleanField(BooleanField):
@ -712,8 +712,8 @@ def make_select_cls(fqns):
return DynamicSelect
@versionutils.deprecated(
as_of=versionutils.deprecated.ICEHOUSE,
@utils.deprecated(
as_of=utils.deprecated.JUNO,
in_favor_of='type io.murano.windows.ActiveDirectory with a custom '
'emptyValueMessage attribute',
remove_in=1)

View File

@ -14,6 +14,8 @@
import testtools
import mock
from muranodashboard.common import utils
@ -67,3 +69,19 @@ class BunchTests(testtools.TestCase):
del obj['two']
self.assertNotIn('two', obj)
class DeprecatedDecoratorTests(testtools.TestCase):
@mock.patch('muranodashboard.common.utils.LOG')
def test_decorating_class(self, LOG):
dec = utils.deprecated(utils.deprecated.JUNO,
in_favor_of='some class yet to be designed',
remove_in=1)
@dec
class SampleClass(object):
pass
SampleClass()
self.assertEqual(type, SampleClass.__class__)
LOG.deprecated.assert_called_once_with(*dec._build_message())