From c017947f582eb582b538ab08c06be2d64777a2b1 Mon Sep 17 00:00:00 2001 From: Valeriy Ponomaryov Date: Wed, 22 Jul 2015 14:49:50 +0300 Subject: [PATCH] Make config opt 'enabled_share_protocols' verification case insensitive Make opt 'enabled_share_protocols' expect share protocol names using any case. Also, remove concatenation of translated messages and make explicit unicode-transformation or these messages that is required when lazy translation is enabled. That is case of Manila. See http://docs.openstack.org/developer/oslo.i18n/usage.html#lazy-translation Change-Id: Iadf41abd5ac62fcce0c0f63cd9a376a2c6eadd6e Closes-Bug: #1475668 --- manila/common/config.py | 22 ++++++++++++---------- manila/tests/common/test_config.py | 3 ++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/manila/common/config.py b/manila/common/config.py index 2d5398b3..3e9d6b0d 100644 --- a/manila/common/config.py +++ b/manila/common/config.py @@ -163,20 +163,22 @@ def verify_share_protocols(): """Perfom verification of 'enabled_share_protocols'.""" msg = None supported_protocols = constants.SUPPORTED_SHARE_PROTOCOLS - data = dict(supported=six.text_type(supported_protocols)) + data = dict(supported=', '.join(supported_protocols)) if CONF.enabled_share_protocols: for share_proto in CONF.enabled_share_protocols: - if share_proto not in supported_protocols: + if share_proto.upper() not in supported_protocols: data.update({'share_proto': share_proto}) - msg = _("Unsupported share protocol '%(share_proto)s' " - "is set as enabled. Available values are " - "%(supported)s. ") + msg = ("Unsupported share protocol '%(share_proto)s' " + "is set as enabled. Available values are " + "%(supported)s. ") break else: - msg = _("No share protocols were specified as enabled. " - "Available values are %(supported)s. ") + msg = ("No share protocols were specified as enabled. " + "Available values are %(supported)s. ") if msg: - msg += _("Please specify one or more protocols using " - "configuration option 'enabled_share_protocols.") - msg = msg % data + msg += ("Please specify one or more protocols using " + "configuration option 'enabled_share_protocols'.") + # NOTE(vponomaryov): use translation to unicode explicitly, + # because of 'lazy' translations. + msg = six.text_type(_(msg) % data) # noqa H701 raise exception.ManilaException(message=msg) diff --git a/manila/tests/common/test_config.py b/manila/tests/common/test_config.py index a6fcc96a..52526e6b 100644 --- a/manila/tests/common/test_config.py +++ b/manila/tests/common/test_config.py @@ -21,7 +21,8 @@ from manila import exception from manila import test from manila.tests import utils as test_utils -VALID_CASES = [proto for proto in constants.SUPPORTED_SHARE_PROTOCOLS] +VALID_CASES = [proto.lower() for proto in constants.SUPPORTED_SHARE_PROTOCOLS] +VALID_CASES.extend([proto.upper() for proto in VALID_CASES]) VALID_CASES.append(','.join(case for case in VALID_CASES))