Fix port comparison in port range validation
Ports are compared as integers. Change-Id: Icfe0c101f5095a779580ea3794d2e7c939b12af5 Closes-Bug: #1738371
This commit is contained in:
parent
628f970048
commit
4c49003bb8
@ -950,7 +950,7 @@ def validate_port_range_or_none(data, valid_values=None):
|
|||||||
msg = _("Invalid port: %s.") % p
|
msg = _("Invalid port: %s.") % p
|
||||||
LOG.debug(msg)
|
LOG.debug(msg)
|
||||||
return msg
|
return msg
|
||||||
if len(ports) > 1 and ports[0] > ports[1]:
|
if len(ports) > 1 and int(ports[0]) > int(ports[1]):
|
||||||
msg = _("First port in a port range must be lower than the second "
|
msg = _("First port in a port range must be lower than the second "
|
||||||
"port.")
|
"port.")
|
||||||
LOG.debug(msg)
|
LOG.debug(msg)
|
||||||
|
@ -1125,7 +1125,9 @@ class TestPortRangeValidation(base.BaseTestCase):
|
|||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_valid_range(self):
|
def test_valid_range(self):
|
||||||
result = validators.validate_port_range_or_none("80:8888")
|
# NOTE(huntxu): This case would fail when ports are compared as
|
||||||
|
# strings, since '9' > '1111'.
|
||||||
|
result = validators.validate_port_range_or_none("9:1111")
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_port_too_high(self):
|
def test_port_too_high(self):
|
||||||
@ -1145,7 +1147,9 @@ class TestPortRangeValidation(base.BaseTestCase):
|
|||||||
self.assertEqual(u"Invalid port: -1.", result)
|
self.assertEqual(u"Invalid port: -1.", result)
|
||||||
|
|
||||||
def test_range_wrong_way(self):
|
def test_range_wrong_way(self):
|
||||||
result = validators.validate_port_range_or_none("8888:80")
|
# 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 "
|
self.assertEqual(u"First port in a port range must be lower than the "
|
||||||
"second port.", result)
|
"second port.", result)
|
||||||
|
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- Bug `1738371 <https://bugs.launchpad.net/neutron/+bug/1738371>`_ is fixed
|
||||||
|
by comparing min port and max port in port range specification as integers
|
||||||
|
instead of strings, during port range validation.
|
Loading…
x
Reference in New Issue
Block a user