Merge "Corrected wrong ethertype exception message" into stable/liberty

This commit is contained in:
Jenkins 2016-04-22 14:17:31 +00:00 committed by Gerrit Code Review
commit 3d2d3c5574
2 changed files with 15 additions and 0 deletions

View File

@ -133,6 +133,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
@ -160,6 +165,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):

View File

@ -1592,3 +1592,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)