From 92f9e91ff75513af2f6892a34c25f458cd1ee7ad Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Wed, 18 Jun 2014 17:01:26 +0200 Subject: [PATCH] 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 --- neutron/extensions/securitygroup.py | 2 +- neutron/tests/unit/test_extension_security_group.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/neutron/extensions/securitygroup.py b/neutron/extensions/securitygroup.py index 5f004af48c..5ebb9de691 100644 --- a/neutron/extensions/securitygroup.py +++ b/neutron/extensions/securitygroup.py @@ -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): diff --git a/neutron/tests/unit/test_extension_security_group.py b/neutron/tests/unit/test_extension_security_group.py index 4a38f6da2f..efd7e3edb4 100644 --- a/neutron/tests/unit/test_extension_security_group.py +++ b/neutron/tests/unit/test_extension_security_group.py @@ -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'