components/python/oslo.config/patches/launchpad-1438314.patch
author Devjani Ray <devjani.ray@oracle.com>
Fri, 05 Feb 2016 17:54:17 -0500
changeset 5405 66fd59fecd68
permissions -rw-r--r--
PSARC 2015/535 OpenStack service updates for Kilo PSARC 2015/458 aioeventlet - asyncio event loop scheduling callbacks in eventlet PSARC 2015/460 msgpack - C/Python bindings for MessagePack (de)serializer data PSARC 2015/466 openstackclient - OpenStack Command-line Client PSARC 2015/467 oslo.versionedobjects - Oslo Versioned Objects library PSARC 2015/468 pint - A physical quantities module PSARC 2015/469 pysaml2 - A pure Python implementation of SAML2 PSARC 2015/471 semantic_version - A library implementing the 'SemVer' scheme PSARC 2015/472 testresources - PyUnit extension for managing expensive test resources PSARC 2015/473 testscenarios - Extensions to Python unittest to support scenarios PSARC 2015/474 trollius - Port of the Tulip project (asyncio module, PEP 3156) on Python 2 PSARC 2015/475 urllib3 - HTTP library with thread-safe connection pooling, file post, and more PSARC 2015/520 oslo.concurrency - Oslo Concurrency library PSARC 2015/521 oslo.log - Oslo Logging Configuration library PSARC 2015/529 oslo.policy - Oslo Policy library PSARC 2015/530 psutil - Python system and process utilities PSARC 2015/538 fixtures - Python module to support reusable state for writing clean tests PSARC 2015/539 sqlparse - An SQL parser module for Python PSARC 2016/017 extras - Useful extra utilities for Python PSARC 2016/018 linecache2 - Port of the standard linecache module PSARC 2016/019 python-mimeparse - Basic functions for parsing mime-types PSARC 2016/020 testtools - Extensions to the Python unit testing framework PSARC 2016/021 traceback2 - Port of the standard traceback module PSARC 2016/014 OpenStack Cinder NFS driver for Solaris 22384068 OpenStack service updates for Kilo (Umbrella) 21974208 The Python module msgpack should be added to Userland 22010630 The Python trollius module should be added to Userland 22011755 The Python module pint should be added to Userland 22012256 The Python aioeventlet module should be added to Userland 22012282 The Python oslo.versionedobjects module should be added to Userland 22012317 The Python semantic_version module should be added to Userland 22012321 The Python testresources module should be added to Userland 22012329 The Python testscenarios module should be added to Userland 22012336 The Python urllib3 module should be added to Userland 22012343 The Python openstackclient module should be added to Userland 22299389 The Python oslo.concurrency module should be added to Userland 22299409 The Python oslo.log module should be added to Userland 22299418 The Python oslo.policy module should be added to Userland 22299469 The Python psutil module should be added to Userland 22337793 The Python sqlparse module should be added to Userland 22338325 The Python fixtures module should be added to Userland 22535728 The Python testtools module should be added to Userland 22535739 The Python extras module should be added to Userland 22535748 The Python linecache2 module should be added to Userland 22535753 The Python traceback2 module should be added to Userland 22535760 The Python python-mimeparse module should be added to Userland 18961001 Image filtering does not function as expected 21678935 NFS for Cinder in Solaris OpenStack 22548630 derived manifest should not enforce presence of global when installing from UAR 22629795 problem in SERVICE/KEYSTONE

From 8ddd9180967fae11803b59e92cab0e51faa99cf6 Mon Sep 17 00:00:00 2001
From: Ben Nemec <[email protected]>
Date: Tue, 31 Mar 2015 15:37:25 +0000
Subject: Fix logging of deprecated opts with dest override

When a deprecated opt is used and the new opt name has the dest
property overridden, we were logging the dest property instead of
the actual opt name in the deprecation warning.  This is confusing
because it leads to log messages such as:

Option "username" from group "nova" is deprecated. Use option
"username" from group "nova".

This is nonsense.  In this case the proper new name was "user-name"
but because it had a dest override of "username" that's what was
logged.

Because the deprecation check code does not have access to the
actual opt itself, we need to pass the undeprecated name down from
the opt into the namespace code that does the check.

I also tried simply adding a (group, name) tuple to the beginning
of the names list, but this subtly broke the CLI opt tests because
there are specific combinations of - and _ variants expected, and
this seems to violate those assumptions.  I did not pursue it any
further because I felt it was better to simply be explicit about
the current name and not mess around with adding non-existent opt
names to the lookup list solely for logging purposes.

Change-Id: Ib1ea8ae2d60a9c508935bad27d7ddc2cdb5ab505
Closes-Bug: #1438314
---
 oslo_config/cfg.py            | 14 +++++++++-----
 oslo_config/tests/test_cfg.py | 16 ++++++++++++++++
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/oslo_config/cfg.py b/oslo_config/cfg.py
index 77fd44d..f472139 100644
--- a/oslo_config/cfg.py
+++ b/oslo_config/cfg.py
@@ -717,6 +717,7 @@ class Opt(object):
         :param group_name: a group name
         """
         names = [(group_name, self.dest)]
+        current_name = (group_name, self.name)
 
         for opt in self.deprecated_opts:
             dname, dgroup = opt.name, opt.group
@@ -724,7 +725,8 @@ class Opt(object):
                 names.append((dgroup if dgroup else group_name,
                               dname if dname else self.dest))
 
-        value = namespace._get_value(names, self.multi, self.positional)
+        value = namespace._get_value(names, self.multi, self.positional,
+                                     current_name)
         # The previous line will raise a KeyError if no value is set in the
         # config file, so we'll only log deprecations for set options.
         if self.deprecated_for_removal and not self._logged_deprecation:
@@ -1469,7 +1471,7 @@ class MultiConfigParser(object):
     def get(self, names, multi=False):
         return self._get(names, multi=multi)
 
-    def _get(self, names, multi=False, normalized=False):
+    def _get(self, names, multi=False, normalized=False, current_name=None):
         """Fetch a config file value from the parsed files.
 
         :param names: a list of (section, name) tuples
@@ -1488,7 +1490,8 @@ class MultiConfigParser(object):
                 if section not in sections:
                     continue
                 if name in sections[section]:
-                    self._check_deprecated((section, name), names[0],
+                    current_name = current_name or names[0]
+                    self._check_deprecated((section, name), current_name,
                                            names[1:])
                     val = sections[section][name]
                     if multi:
@@ -1641,7 +1644,7 @@ class _Namespace(argparse.Namespace):
 
         raise KeyError
 
-    def _get_value(self, names, multi, positional):
+    def _get_value(self, names, multi, positional, current_name):
         """Fetch a value from config files.
 
         Multiple names for a given configuration option may be supplied so
@@ -1658,7 +1661,8 @@ class _Namespace(argparse.Namespace):
             pass
 
         names = [(g if g is not None else 'DEFAULT', n) for g, n in names]
-        values = self._parser._get(names, multi=multi, normalized=True)
+        values = self._parser._get(names, multi=multi, normalized=True,
+                                   current_name=current_name)
         return values if multi else values[-1]
 
 
diff --git a/oslo_config/tests/test_cfg.py b/oslo_config/tests/test_cfg.py
index 5518f53..e007494 100644
--- a/oslo_config/tests/test_cfg.py
+++ b/oslo_config/tests/test_cfg.py
@@ -3724,3 +3724,19 @@ class DeprecationWarningTests(DeprecationWarningTestBase):
                     'removal.  Its value may be silently ignored in the '
                     'future.\n')
         self.assertEqual(expected, self.log_fixture.output)
+
+    def test_deprecated_with_dest(self):
+        self.conf.register_group(cfg.OptGroup('other'))
+        self.conf.register_opt(cfg.StrOpt('foo-bar', deprecated_name='bar',
+                                          dest='foo'),
+                               group='other')
+        content = 'bar=baz'
+        paths = self.create_tempfiles([('test',
+                                        '[other]\n' +
+                                        content + '\n')])
+
+        self.conf(['--config-file', paths[0]])
+        self.assertEqual('baz', self.conf.other.foo)
+        expected = (self._parser_class._deprecated_opt_message %
+                    ('bar', 'other', 'foo-bar', 'other') + '\n')
+        self.assertEqual(expected, self.log_fixture.output)
-- 
cgit v0.11.2