]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Don't convert numeric protocol values to int
authorRalf Haferkamp <rhafer@suse.de>
Wed, 18 Jun 2014 15:01:26 +0000 (17:01 +0200)
committerRalf Haferkamp <rhafer@suse.de>
Mon, 23 Jun 2014 09:18:14 +0000 (11:18 +0200)
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

neutron/extensions/securitygroup.py
neutron/tests/unit/test_extension_security_group.py

index 5f004af48c3d1082d37c7086d3887bf30cff2ebf..5ebb9de6914593ff10b1655cd7530e0d510b2bdc 100644 (file)
@@ -116,7 +116,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):
index 4a38f6da2f11f4d48fff6a848790feac3847bced..efd7e3edb42205713ef297cd8526ae1208ce8f91 100644 (file)
@@ -1427,5 +1427,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'