Return HTTP 400 on boot for invalid availability zone
Currently 'nova boot' fails with 500 InternalServerError if you pass invalid availability zone. Caught InvalidInput exception and raised HTTPBadRequest exception to return 400 status code. APIImpact: Return 400 status code for invalid availability zone. Change-Id: I7b730e71abbcbcf9ee1f537a84646243e9a2da7c Closes-Bug: #1580467
This commit is contained in:
parent
be22885793
commit
26dcd0675a
nova
@ -574,7 +574,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')
|
||||
|
||||
|
@ -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'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user