Merge "Return HTTP 400 on boot for invalid availability zone"

This commit is contained in:
Jenkins 2016-05-18 15:35:42 +00:00 committed by Gerrit Code Review
commit 8b162eb7be
2 changed files with 11 additions and 1 deletions

View File

@ -589,7 +589,11 @@ class ServersController(wsgi.Controller):
# TODO(Shao He, Feng) move this policy check to os-availabilty-zone
# extension after refactor it.
parse_az = self.compute_api.parse_availability_zone
availability_zone, host, node = parse_az(context, availability_zone)
try:
availability_zone, host, node = parse_az(context,
availability_zone)
except exception.InvalidInput as err:
raise exc.HTTPBadRequest(explanation=six.text_type(err))
if host or node:
authorize(context, {}, 'create:forced_host')

View File

@ -3321,6 +3321,12 @@ class ServersControllerCreateTest(test.TestCase):
self.controller.create,
self.req, body=self.body)
def test_create_instance_invalid_availability_zone(self):
self.body['server']['availability_zone'] = 'invalid::::zone'
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create,
self.req, body=self.body)
@mock.patch.object(compute_api.API, 'create',
side_effect=exception.FixedIpNotFoundForAddress(
address='dummy'))