]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Corrected wrong ethertype exception message
authorSreekumar S <sreesiv@gmail.com>
Wed, 16 Dec 2015 21:04:33 +0000 (02:34 +0530)
committerSreekumar S <sreesiv@gmail.com>
Mon, 21 Dec 2015 07:43:10 +0000 (13:13 +0530)
This patch resolves the issue where wrong message was being
shown when ethertype input parameter was not amongst one of
the types supported. New message made akin to other input
parameters like 'protocol'.

Change-Id: I5636f3582c9d9877dad4d091a374284b656923f4
Closes-Bug: #1508106

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

index e1c8d45ad507830c20885c345f37e2e284e64e35..9ae3806da245b1cc4ef7903b91a229a8d429f35c 100644 (file)
@@ -134,6 +134,11 @@ class SecurityGroupConflict(nexception.Conflict):
     message = _("Error %(reason)s while attempting the operation.")
 
 
+class SecurityGroupRuleInvalidEtherType(nexception.InvalidInput):
+    message = _("Security group rule for ethertype '%(ethertype)s' not "
+                "supported. Allowed values are %(values)s.")
+
+
 def convert_protocol(value):
     if value is None:
         return
@@ -161,6 +166,8 @@ def convert_ethertype_to_case_insensitive(value):
         for ethertype in sg_supported_ethertypes:
             if ethertype.lower() == value.lower():
                 return ethertype
+    raise SecurityGroupRuleInvalidEtherType(
+        ethertype=value, values=sg_supported_ethertypes)
 
 
 def convert_validate_port_value(port):
index 6ff3ed0f3324f04a62d8365446c17cd8224317c7..c7195803b9d214477c5bad874547f51db774432c 100644 (file)
@@ -1559,3 +1559,11 @@ class TestConvertProtocol(base.BaseTestCase):
 
     def test_convert_numeric_protocol_to_string(self):
         self.assertIsInstance(ext_sg.convert_protocol(2), str)
+
+
+class TestConvertEtherType(base.BaseTestCase):
+    def test_convert_unsupported_ethertype(self):
+        for val in ['ip', 'ip4', 'ip6', '']:
+            self.assertRaises(ext_sg.SecurityGroupRuleInvalidEtherType,
+                              ext_sg.convert_ethertype_to_case_insensitive,
+                              val)