From aeec4d11b2dae769bfe020dcd95ec607afaeed55 Mon Sep 17 00:00:00 2001 From: Kevin_Zheng Date: Fri, 23 Dec 2016 17:38:57 +0800 Subject: [PATCH] Fix "Message object do not support addition". In the 7.0.0 Novaclient release we added some warning log about user should using "endpoint_type" rather than "interface" when init novaclient: https://github.com/openstack/python-novaclient/blob/master/novaclient/client.py#L312-L327 https://github.com/openstack/python-novaclient/blob/master/novaclient/client.py#L249-L272 This is now causing a lot jenkins failures acroos projects that is using novaclient with enable_lazy set to False. As in this kind of scenario the warning message is a message object instead of unicode sting and it cannot be added: http://git.openstack.org/cgit/openstack/oslo.i18n/tree/oslo_i18n/_message.py#n227 and "Message object do not support addition" will raise. Related Jenkins Error: Ceilometer: http://logs.openstack.org/29/333129/3/check/gate-ceilometer-python27-ubuntu-xenial/bd125e7/ Closes-bug: #1652414 Change-Id: I11a490f759fdac9707c1321c9659da2605196a94 --- novaclient/client.py | 23 ++++++++++++++++------- novaclient/v2/contrib/__init__.py | 16 ++++++++-------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/novaclient/client.py b/novaclient/client.py index 282054f70..06f68e366 100644 --- a/novaclient/client.py +++ b/novaclient/client.py @@ -253,19 +253,28 @@ def _check_arguments(kwargs, release, deprecated_name, right_name=None): message, renames key to right one it needed. """ if deprecated_name in kwargs: - msg = _LW("The '%(old)s' argument is deprecated in %(release)s and " - "its use may result in errors in future releases.") % { - "old": deprecated_name, "release": release} if right_name: if right_name in kwargs: - msg += _LW(" As '%(new)s' is provided, the '%(old)s' argument " - "will be ignored.") % {"old": deprecated_name, - "new": right_name} + msg = _LW("The '%(old)s' argument is deprecated in " + "%(release)s and its use may result in errors " + "in future releases. As '%(new)s' is provided, " + "the '%(old)s' argument will be ignored.") % { + "old": deprecated_name, "release": release, + "new": right_name} kwargs.pop(deprecated_name) else: - msg += _LW(" Use '%s' instead.") % right_name + msg = _LW("The '%(old)s' argument is deprecated in " + "%(release)s and its use may result in errors in " + "future releases. Use '%(right)s' instead.") % { + "old": deprecated_name, "release": release, + "right": right_name} kwargs[right_name] = kwargs.pop(deprecated_name) + else: + msg = _LW("The '%(old)s' argument is deprecated in %(release)s " + "and its use may result in errors in future " + "releases.") % { + "old": deprecated_name, "release": release} # just ignore it kwargs.pop(deprecated_name) diff --git a/novaclient/v2/contrib/__init__.py b/novaclient/v2/contrib/__init__.py index b419ae0c2..80acf65f5 100644 --- a/novaclient/v2/contrib/__init__.py +++ b/novaclient/v2/contrib/__init__.py @@ -35,17 +35,17 @@ def warn(alternative=True): frm = inspect.stack()[1] module_name = inspect.getmodule(frm[0]).__name__ if module_name.startswith("novaclient.v2.contrib."): - msg = (_LW("Module `%s` is deprecated as of OpenStack Ocata") % - module_name) if alternative: new_module_name = module_name.replace("contrib.", "") - msg += _LW(" in favor of `%s`") % new_module_name - - msg += (_LW(" and will be removed after OpenStack Pike.")) + msg = _LW("Module `%(module)s` is deprecated as of OpenStack " + "Ocata in favor of `%(new_module)s` and will be " + "removed after OpenStack Pike.") % { + "module": module_name, "new_module": new_module_name} if not alternative: - msg += _LW(" All shell commands were moved to " - "`novaclient.v2.shell` and will be automatically " - "loaded.") + msg = _LW("Module `%s` is deprecated as of OpenStack Ocata " + "All shell commands were moved to " + "`novaclient.v2.shell` and will be automatically " + "loaded.") % module_name warnings.warn(msg)