Remove periods at the end of validator and converter messages

Messages fixed in this commit are wrapped at the end of other messages,
where the outer messages themselves have periods at the end. Thus the
extra periods of these messages should be removed to avoid duplication
in user facing messages.

An example for reference:

$ openstack firewall group rule create --source-port BEEF --protocol tcp
Invalid input for source_port. Reason: Invalid port: BEEF..

TrivialFix

Change-Id: I76bfed5a91cb569119e1e83ee3bf3917bb526e79
This commit is contained in:
Hunt Xu 2017-12-15 18:44:52 +08:00
parent e2a9c397f7
commit 5f6a1259de
3 changed files with 16 additions and 16 deletions

View File

@ -96,7 +96,7 @@ def convert_to_positive_float_or_none(val):
if val < 0:
raise ValueError()
except (ValueError, TypeError):
msg = _("'%s' must be a non negative decimal.") % val
msg = _("'%s' must be a non negative decimal") % val
raise n_exc.InvalidInput(error_message=msg)
return val

View File

@ -808,7 +808,7 @@ def _validate_dict_item(key, key_validator, data):
try:
val_func = validators[k]
except KeyError:
msg = _("Validator '%s' does not exist.") % k
msg = _("Validator '%s' does not exist") % k
LOG.debug(msg)
return msg
val_params = v
@ -938,21 +938,21 @@ def validate_port_range_or_none(data, valid_values=None):
data = str(data)
ports = data.split(':')
if len(ports) > 2:
msg = _("Port range must be two integers separated by a colon.")
msg = _("Port range must be two integers separated by a colon")
LOG.debug(msg)
return msg
for p in ports:
if len(p) == 0:
msg = _("Port range must be two integers separated by a colon.")
msg = _("Port range must be two integers separated by a colon")
LOG.debug(msg)
return msg
if not netutils.is_valid_port(p):
msg = _("Invalid port: %s.") % p
msg = _("Invalid port: %s") % p
LOG.debug(msg)
return msg
if len(ports) > 1 and int(ports[0]) > int(ports[1]):
msg = _("First port in a port range must be lower than the second "
"port.")
"port")
LOG.debug(msg)
return msg

View File

@ -880,7 +880,7 @@ class TestAttributeValidation(base.BaseTestCase):
constraints['key1'] = {'type:unsupported': None, 'required': True}
msg = validators.validate_dict(dictionary, constraints)
self.assertEqual("Validator 'type:unsupported' does not exist.", msg)
self.assertEqual("Validator 'type:unsupported' does not exist", msg)
def test_validate_dict_not_required_keys(self):
dictionary, constraints = self._construct_dict_and_constraints()
@ -1132,44 +1132,44 @@ class TestPortRangeValidation(base.BaseTestCase):
def test_port_too_high(self):
result = validators.validate_port_range_or_none("99999")
self.assertEqual(u"Invalid port: 99999.", result)
self.assertEqual(u"Invalid port: 99999", result)
def test_port_too_low(self):
result = validators.validate_port_range_or_none("-1")
self.assertEqual(u"Invalid port: -1.", result)
self.assertEqual(u"Invalid port: -1", result)
def test_range_too_high(self):
result = validators.validate_port_range_or_none("80:99999")
self.assertEqual(u"Invalid port: 99999.", result)
self.assertEqual(u"Invalid port: 99999", result)
def test_range_too_low(self):
result = validators.validate_port_range_or_none("-1:8888")
self.assertEqual(u"Invalid port: -1.", result)
self.assertEqual(u"Invalid port: -1", result)
def test_range_wrong_way(self):
# NOTE(huntxu): This case would fail when ports are compared as
# strings, since '1111' < '9'.
result = validators.validate_port_range_or_none("1111:9")
self.assertEqual(u"First port in a port range must be lower than the "
"second port.", result)
"second port", result)
def test_range_invalid(self):
result = validators.validate_port_range_or_none("DEAD:BEEF")
self.assertEqual(u"Invalid port: DEAD.", result)
self.assertEqual(u"Invalid port: DEAD", result)
def test_range_bad_input(self):
result = validators.validate_port_range_or_none(['a', 'b', 'c'])
self.assertEqual(u"Invalid port: ['a', 'b', 'c'].", result)
self.assertEqual(u"Invalid port: ['a', 'b', 'c']", result)
def test_range_colon(self):
result = validators.validate_port_range_or_none(":")
self.assertEqual(u"Port range must be two integers separated by a "
"colon.", result)
"colon", result)
def test_too_many_colons(self):
result = validators.validate_port_range_or_none("80:888:8888")
self.assertEqual(u"Port range must be two integers separated by a "
"colon.", result)
"colon", result)
class TestAnyKeySpecs(base.BaseTestCase):