From ba78db0b4b559dcc3b22c37834e430d8b27c45ae Mon Sep 17 00:00:00 2001 From: xuhaigang Date: Thu, 25 May 2017 14:30:37 +0800 Subject: [PATCH] add a log when the option in conf can't be identitied When the option is unknown to auth_token and it's value can't be converted, this patch adds a warning log. Change-Id: I818708cc19488030b80daa2b01b9f8622632f7eb --- keystonemiddleware/_common/config.py | 6 ++++-- .../tests/unit/auth_token/test_auth_token_middleware.py | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/keystonemiddleware/_common/config.py b/keystonemiddleware/_common/config.py index 883d3776..0d5b2907 100644 --- a/keystonemiddleware/_common/config.py +++ b/keystonemiddleware/_common/config.py @@ -13,6 +13,7 @@ import pkg_resources from oslo_config import cfg +from oslo_log import log as logging import pbr import six @@ -21,6 +22,7 @@ CONF = cfg.CONF _NOT_SET = object() +_LOG = logging.getLogger(__name__) def _conf_values_type_convert(group_name, all_options, conf): @@ -53,8 +55,8 @@ def _conf_values_type_convert(group_name, all_options, conf): v = type_(v) except KeyError: # nosec # This option is not known to auth_token. v is not converted. - # FIXME(jamielennox): This should probably log a warning. - pass + _LOG.warning( + 'The option "%s" in conf is not known to auth_token', k) except ValueError as e: raise exceptions.ConfigurationError( _('Unable to convert the value of %(key)s option into correct ' diff --git a/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py b/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py index 21656601..1899cb07 100644 --- a/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py +++ b/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py @@ -491,6 +491,14 @@ def test_deprecated_conf_values(self): middleware = auth_token.AuthProtocol(self.fake_app, conf) self.assertEqual([servers], middleware._conf.get('memcached_servers')) + def test_conf_values_type_convert_with_wrong_key(self): + conf = { + 'wrong_key': '123' + } + log = 'The option "wrong_key" in conf is not known to auth_token' + auth_token.AuthProtocol(self.fake_app, conf) + self.assertThat(self.logger.output, matchers.Contains(log)) + def test_conf_values_type_convert_with_wrong_value(self): conf = { 'include_service_catalog': '123',