Fix Bad except clauses order
Invalid is an ancestor class of AutoDiskConfigDisabledByImage. If we catch Invalid before, the user will be see a wrong message "Invalid instance image." instead of "Requested Image has automatic disk resize disabled." Change-Id: Idb021c7da01ad7a1af07585be527773d14ff2d20
This commit is contained in:
parent
a781a392eb
commit
a9a80ad665
|
@ -1194,12 +1194,12 @@ class Controller(wsgi.Controller):
|
|||
msg = _("Image that the instance was started "
|
||||
"with could not be found.")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
except exception.Invalid:
|
||||
msg = _("Invalid instance image.")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
except (exception.NoValidHost,
|
||||
exception.AutoDiskConfigDisabledByImage) as e:
|
||||
raise exc.HTTPBadRequest(explanation=e.format_message())
|
||||
except exception.Invalid:
|
||||
msg = _("Invalid instance image.")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
|
|
|
@ -832,6 +832,10 @@ class ServerActionsControllerTest(test.TestCase):
|
|||
(exception.ImageNotFound(image_id=image_id),
|
||||
webob.exc.HTTPBadRequest),
|
||||
(exception.Invalid, webob.exc.HTTPBadRequest),
|
||||
(exception.NoValidHost(reason='Bad host'),
|
||||
webob.exc.HTTPBadRequest),
|
||||
(exception.AutoDiskConfigDisabledByImage(image=image_id),
|
||||
webob.exc.HTTPBadRequest),
|
||||
]
|
||||
|
||||
raised, expected = map(iter, zip(*exceptions))
|
||||
|
@ -844,9 +848,19 @@ class ServerActionsControllerTest(test.TestCase):
|
|||
|
||||
for call_no in range(len(exceptions)):
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
self.assertRaises(expected.next(),
|
||||
self.controller._action_resize,
|
||||
req, FAKE_UUID, body)
|
||||
next_exception = expected.next()
|
||||
actual = self.assertRaises(next_exception,
|
||||
self.controller._action_resize,
|
||||
req, FAKE_UUID, body)
|
||||
if (isinstance(exceptions[call_no][0],
|
||||
exception.NoValidHost)):
|
||||
self.assertEqual(actual.explanation,
|
||||
'No valid host was found. Bad host')
|
||||
elif (isinstance(exceptions[call_no][0],
|
||||
exception.AutoDiskConfigDisabledByImage)):
|
||||
self.assertEqual(actual.explanation,
|
||||
'Requested image fake_image_id has automatic'
|
||||
' disk resize disabled.')
|
||||
self.assertEqual(self.resize_called, call_no + 1)
|
||||
|
||||
@mock.patch('nova.compute.api.API.resize',
|
||||
|
|
Loading…
Reference in New Issue