Sync latest versionutils to let us add warning for deprecated class in
Kilo. This also syncs its dependency module log and _i18n.
versionutils:
5d40e14 Remove code that moved to oslo.i18n
1c3ecfc Enhance versionutils.deprecated to work with classes
9a46271 Add Kilo release name to versionutils
a2ad3a2 Allow deprecated decorator to specify no plan for removal
05ae498 Add JUNO as a target to versionutils module
de4adbc pep8: fixed multiple violations
log:
ac4330d Make use_syslog=True log to syslog via /dev/log
df774ff Import PublishErrorsHandler from oslo.messaging
a3220c5 add list_opts to all modules with configuration options
6c706c5 Delete graduated serialization files
5d40e14 Remove code that moved to oslo.i18n
6ff6b4b Switch oslo-incubator to use oslo.utils and remove old modules
aa74411 log: add missing space in error message
Change-Id: I9c1911e666e603d306685ff8bea390830c656256
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-import six
-
-
-six.add_move(six.MovedModule('mox', 'mox', 'mox3.mox'))
--- /dev/null
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""oslo.i18n integration module.
+
+See http://docs.openstack.org/developer/oslo.i18n/usage.html
+
+"""
+
+try:
+ import oslo.i18n
+
+ # NOTE(dhellmann): This reference to o-s-l-o will be replaced by the
+ # application name when this module is synced into the separate
+ # repository. It is OK to have more than one translation function
+ # using the same domain, since there will still only be one message
+ # catalog.
+ _translators = oslo.i18n.TranslatorFactory(domain='cinder')
+
+ # The primary translation function using the well-known name "_"
+ _ = _translators.primary
+
+ # Translators for log levels.
+ #
+ # The abbreviated names are meant to reflect the usual use of a short
+ # name like '_'. The "L" is for "log" and the other letter comes from
+ # the level.
+ _LI = _translators.log_info
+ _LW = _translators.log_warning
+ _LE = _translators.log_error
+ _LC = _translators.log_critical
+except ImportError:
+ # NOTE(dims): Support for cases where a project wants to use
+ # code from cinder-incubator, but is not ready to be internationalized
+ # (like tempest)
+ _ = _LI = _LW = _LE = _LC = lambda x: x
"""
+import copy
import inspect
import itertools
import logging
import traceback
from oslo.config import cfg
+from oslo.serialization import jsonutils
+from oslo.utils import importutils
import six
from six import moves
_PY26 = sys.version_info[0:2] == (2, 6)
-from cinder.openstack.common.gettextutils import _
-from cinder.openstack.common import importutils
-from cinder.openstack.common import jsonutils
+from cinder.openstack.common._i18n import _
from cinder.openstack.common import local
-# NOTE(flaper87): Pls, remove when graduating this module
-# from the incubator.
-from cinder.openstack.common.strutils import mask_password # noqa
_DEFAULT_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
CONF.register_opts(generic_log_opts)
CONF.register_opts(log_opts)
+
+def list_opts():
+ """Entry point for oslo.config-generator."""
+ return [(None, copy.deepcopy(common_cli_opts)),
+ (None, copy.deepcopy(logging_cli_opts)),
+ (None, copy.deepcopy(generic_log_opts)),
+ (None, copy.deepcopy(log_opts)),
+ ]
+
+
# our new audit level
# NOTE(jkoelker) Since we synthesized an audit level, make the logging
# module aware of it so it acts like other levels.
log_root.addHandler(streamlog)
if CONF.publish_errors:
- try:
- handler = importutils.import_object(
- "cinder.openstack.common.log_handler.PublishErrorsHandler",
- logging.ERROR)
- except ImportError:
- handler = importutils.import_object(
- "oslo.messaging.notify.log_handler.PublishErrorsHandler",
- logging.ERROR)
+ handler = importutils.import_object(
+ "oslo.messaging.notify.log_handler.PublishErrorsHandler",
+ logging.ERROR)
log_root.addHandler(handler)
datefmt = CONF.log_date_format
# TODO(bogdando) use the format provided by RFCSysLogHandler
# after existing syslog format deprecation in J
if CONF.use_syslog_rfc_format:
- syslog = RFCSysLogHandler(facility=facility)
+ syslog = RFCSysLogHandler(address='/dev/log',
+ facility=facility)
else:
- syslog = logging.handlers.SysLogHandler(facility=facility)
+ syslog = logging.handlers.SysLogHandler(address='/dev/log',
+ facility=facility)
log_root.addHandler(syslog)
except socket.error:
- log_root.error('Unable to add syslog handler. Verify that syslog'
+ log_root.error('Unable to add syslog handler. Verify that syslog '
'is running.')
"""
import functools
+import inspect
+
import pkg_resources
+import six
-from cinder.openstack.common.gettextutils import _
+from cinder.openstack.common._i18n import _
from cinder.openstack.common import log as logging
>>> @deprecated(as_of=deprecated.ICEHOUSE, remove_in=+1)
... def c(): pass
+ 4. Specifying the deprecated functionality will not be removed:
+ >>> @deprecated(as_of=deprecated.ICEHOUSE, remove_in=0)
+ ... def d(): pass
+
+ 5. Specifying a replacement, deprecated functionality will not be removed:
+ >>> @deprecated(as_of=deprecated.ICEHOUSE, in_favor_of='f()', remove_in=0)
+ ... def e(): pass
+
"""
+ # NOTE(morganfainberg): Bexar is used for unit test purposes, it is
+ # expected we maintain a gap between Bexar and Folsom in this list.
+ BEXAR = 'B'
FOLSOM = 'F'
GRIZZLY = 'G'
HAVANA = 'H'
ICEHOUSE = 'I'
+ JUNO = 'J'
+ KILO = 'K'
_RELEASES = {
+ # NOTE(morganfainberg): Bexar is used for unit test purposes, it is
+ # expected we maintain a gap between Bexar and Folsom in this list.
+ 'B': 'Bexar',
'F': 'Folsom',
'G': 'Grizzly',
'H': 'Havana',
'I': 'Icehouse',
+ 'J': 'Juno',
+ 'K': 'Kilo',
}
_deprecated_msg_with_alternative = _(
'%(what)s is deprecated as of %(as_of)s and may be '
'removed in %(remove_in)s. It will not be superseded.')
+ _deprecated_msg_with_alternative_no_removal = _(
+ '%(what)s is deprecated as of %(as_of)s in favor of %(in_favor_of)s.')
+
+ _deprecated_msg_with_no_alternative_no_removal = _(
+ '%(what)s is deprecated as of %(as_of)s. It will not be superseded.')
+
def __init__(self, as_of, in_favor_of=None, remove_in=2, what=None):
"""Initialize decorator
self.remove_in = remove_in
self.what = what
- def __call__(self, func):
+ def __call__(self, func_or_cls):
if not self.what:
- self.what = func.__name__ + '()'
-
- @functools.wraps(func)
- def wrapped(*args, **kwargs):
- msg, details = self._build_message()
- LOG.deprecated(msg, details)
- return func(*args, **kwargs)
- return wrapped
+ self.what = func_or_cls.__name__ + '()'
+ msg, details = self._build_message()
+
+ if inspect.isfunction(func_or_cls):
+
+ @six.wraps(func_or_cls)
+ def wrapped(*args, **kwargs):
+ LOG.deprecated(msg, details)
+ return func_or_cls(*args, **kwargs)
+ return wrapped
+ elif inspect.isclass(func_or_cls):
+ orig_init = func_or_cls.__init__
+
+ # TODO(tsufiev): change `functools` module to `six` as
+ # soon as six 1.7.4 (with fix for passing `assigned`
+ # argument to underlying `functools.wraps`) is released
+ # and added to the cinder-incubator requrements
+ @functools.wraps(orig_init, assigned=('__name__', '__doc__'))
+ def new_init(self, *args, **kwargs):
+ LOG.deprecated(msg, details)
+ orig_init(self, *args, **kwargs)
+ func_or_cls.__init__ = new_init
+ return func_or_cls
+ else:
+ raise TypeError('deprecated can be used only with functions or '
+ 'classes')
def _get_safe_to_remove_release(self, release):
# TODO(dstanek): this method will have to be reimplemented once
if self.in_favor_of:
details['in_favor_of'] = self.in_favor_of
- msg = self._deprecated_msg_with_alternative
+ if self.remove_in > 0:
+ msg = self._deprecated_msg_with_alternative
+ else:
+ # There are no plans to remove this function, but it is
+ # now deprecated.
+ msg = self._deprecated_msg_with_alternative_no_removal
else:
- msg = self._deprecated_msg_no_alternative
+ if self.remove_in > 0:
+ msg = self._deprecated_msg_no_alternative
+ else:
+ # There are no plans to remove this function, but it is
+ # now deprecated.
+ msg = self._deprecated_msg_with_no_alternative_no_removal
return msg, details