Don't convert numeric protocol values to int

They are treated as strings everywhere. Converting them to int causes problems
when using postgresql as the database backend because it doesn't automatically
cast them back to integer.

Change-Id: I9f0a5149d24a4c003409728e50376569c97e7325
Closes-bug: 1330490
(cherry picked from commit 3be62f878e)
This commit is contained in:
Ralf Haferkamp 2014-06-18 17:01:26 +02:00 committed by Ihar Hrachyshka
parent d57e3b345c
commit a17a500575
2 changed files with 11 additions and 1 deletions

View File

@ -114,7 +114,7 @@ def convert_protocol(value):
try:
val = int(value)
if val >= 0 and val <= 255:
return val
return value
raise SecurityGroupRuleInvalidProtocol(
protocol=value, values=sg_supported_protocols)
except (ValueError, TypeError):

View File

@ -1421,5 +1421,15 @@ class TestConvertIPPrefixToCIDR(base.BaseTestCase):
self.assertEqual(ext_sg.convert_ip_prefix_to_cidr(addr), addr)
class TestConvertProtocol(base.BaseTestCase):
def test_convert_numeric_protocol(self):
assert(isinstance(ext_sg.convert_protocol('2'), str))
def test_convert_bad_protocol(self):
for val in ['bad', '256', '-1']:
self.assertRaises(ext_sg.SecurityGroupRuleInvalidProtocol,
ext_sg.convert_protocol, val)
class TestSecurityGroupsXML(TestSecurityGroups):
fmt = 'xml'