Improve secgroup create error message
Fixes secgroup create API so that when it is passed a name or description field which is an empty string the error message specifies which field is of the incorrect format. Change-Id: Ieff67438965a735f2328390125bb4e66aec5e83d Closes-Bug: 1369358
This commit is contained in:
parent
eb860c2f21
commit
a3437851b9
|
@ -3717,8 +3717,8 @@ class SecurityGroupAPI(base.Base, security_group_base.SecurityGroupBase):
|
|||
except AttributeError:
|
||||
msg = _("Security group %s is not a string or unicode") % property
|
||||
self.raise_invalid_property(msg)
|
||||
|
||||
utils.check_string_length(val, min_length=1, max_length=255)
|
||||
utils.check_string_length(val, name=property, min_length=1,
|
||||
max_length=255)
|
||||
|
||||
if allowed and not re.match(allowed, val):
|
||||
# Some validation to ensure that values match API spec.
|
||||
|
|
|
@ -92,6 +92,10 @@ class TestNeutronSecurityGroups(
|
|||
# Neutron's security group description field is optional.
|
||||
pass
|
||||
|
||||
def test_create_security_group_with_empty_description(self):
|
||||
# Neutron's security group description field is optional.
|
||||
pass
|
||||
|
||||
def test_create_security_group_with_blank_name(self):
|
||||
# Neutron's security group name field is optional.
|
||||
pass
|
||||
|
|
|
@ -180,6 +180,21 @@ class TestSecurityGroups(test.TestCase):
|
|||
|
||||
self._assert_no_security_groups_reserved(req.environ['nova.context'])
|
||||
|
||||
def test_create_security_group_with_empty_description(self):
|
||||
sg = security_group_template()
|
||||
sg['description'] = ""
|
||||
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups')
|
||||
try:
|
||||
self.controller.create(req, {'security_group': sg})
|
||||
self.fail('Should have raised BadRequest exception')
|
||||
except webob.exc.HTTPBadRequest as exc:
|
||||
self.assertEqual('description has a minimum character requirement'
|
||||
' of 1.', exc.explanation)
|
||||
except exception.InvalidInput as exc:
|
||||
self.fail('Should have raised BadRequest exception instead of')
|
||||
self._assert_no_security_groups_reserved(req.environ['nova.context'])
|
||||
|
||||
def test_create_security_group_with_blank_name(self):
|
||||
sg = security_group_template(name='')
|
||||
|
||||
|
|
Loading…
Reference in New Issue