summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-19 11:53:50 +0000
committerGerrit Code Review <review@openstack.org>2017-06-19 11:53:50 +0000
commite68ec1fbf2dd97008d083ca98f7e3ba063edd5af (patch)
tree052a4f213a0d9906c22511a5e93dc9d2b49f6c28
parent4ce39e5b9fbab3f7f4ac91821fafcfc6b0b21a1c (diff)
parent29a31c152caacdb4d73acb534260443fd07801b0 (diff)
Merge "Make port_range validator accept an integer"
-rw-r--r--neutron_lib/api/validators/__init__.py5
-rw-r--r--neutron_lib/tests/unit/api/validators/test_validators.py6
2 files changed, 6 insertions, 5 deletions
diff --git a/neutron_lib/api/validators/__init__.py b/neutron_lib/api/validators/__init__.py
index e1bcd57..fabc21d 100644
--- a/neutron_lib/api/validators/__init__.py
+++ b/neutron_lib/api/validators/__init__.py
@@ -925,10 +925,7 @@ def validate_port_range_or_none(data, valid_values=None):
925 """ 925 """
926 if data is None: 926 if data is None:
927 return 927 return
928 if validate_string_or_none(data): 928 data = str(data)
929 msg = _("Port range must be a string.")
930 LOG.debug(msg)
931 return msg
932 ports = data.split(':') 929 ports = data.split(':')
933 if len(ports) > 2: 930 if len(ports) > 2:
934 msg = _("Port range must be two integers separated by a colon.") 931 msg = _("Port range must be two integers separated by a colon.")
diff --git a/neutron_lib/tests/unit/api/validators/test_validators.py b/neutron_lib/tests/unit/api/validators/test_validators.py
index ea73f03..a5e1d5d 100644
--- a/neutron_lib/tests/unit/api/validators/test_validators.py
+++ b/neutron_lib/tests/unit/api/validators/test_validators.py
@@ -1102,6 +1102,10 @@ class TestPortRangeValidation(base.BaseTestCase):
1102 result = validators.validate_port_range_or_none("80") 1102 result = validators.validate_port_range_or_none("80")
1103 self.assertIsNone(result) 1103 self.assertIsNone(result)
1104 1104
1105 def test_valid_port_integer(self):
1106 result = validators.validate_port_range_or_none(80)
1107 self.assertIsNone(result)
1108
1105 def test_valid_range(self): 1109 def test_valid_range(self):
1106 result = validators.validate_port_range_or_none("80:8888") 1110 result = validators.validate_port_range_or_none("80:8888")
1107 self.assertIsNone(result) 1111 self.assertIsNone(result)
@@ -1133,7 +1137,7 @@ class TestPortRangeValidation(base.BaseTestCase):
1133 1137
1134 def test_range_bad_input(self): 1138 def test_range_bad_input(self):
1135 result = validators.validate_port_range_or_none(['a', 'b', 'c']) 1139 result = validators.validate_port_range_or_none(['a', 'b', 'c'])
1136 self.assertEqual(u"Port range must be a string.", result) 1140 self.assertEqual(u"Invalid port: ['a', 'b', 'c'].", result)
1137 1141
1138 def test_range_colon(self): 1142 def test_range_colon(self):
1139 result = validators.validate_port_range_or_none(":") 1143 result = validators.validate_port_range_or_none(":")