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
This commit is contained in:
Valeriy Ponomaryov 2015-07-22 14:49:50 +03:00
parent 51a2bbefe1
commit c017947f58
2 changed files with 14 additions and 11 deletions

View File

@ -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)

View File

@ -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))