api: Handle invalid volume UUIDs during spawn

If a user requests an invalid volume UUID when creating an instance,
a 'VolumeNotFound' exception will be raised. This is not currently
handled. Correct this.

Change-Id: I6137dc1b6b51321fee1c080bf4b85197b19bf223
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Closes-Bug: #1930448
This commit is contained in:
Stephen Finucane 2021-06-01 17:21:58 +01:00
parent eca7606251
commit 9cdecc81fb
2 changed files with 9 additions and 0 deletions

View File

@ -731,6 +731,7 @@ class ServersController(wsgi.Controller):
exception.FlavorNotFound,
exception.InvalidMetadata,
exception.InvalidVolume,
exception.VolumeNotFound,
exception.MismatchVolumeAZException,
exception.MultiplePortsNotApplicable,
exception.InvalidFixedIpAndMaxCountRequest,

View File

@ -6957,6 +6957,14 @@ class ServersControllerCreateTestWithMock(test.TestCase):
self.assertRaises(webob.exc.HTTPBadRequest,
self._test_create_extra, {})
@mock.patch.object(
compute_api.API, 'create',
side_effect=exception.VolumeNotFound(volume_id='foo'))
def test_create_instance_with_volume_not_found_error(self, create_mock):
# Tests that InvalidVolume is translated to a 400 error.
self.assertRaises(
webob.exc.HTTPBadRequest, self._test_create_extra, {})
class ServersViewBuilderTest(test.TestCase):
project_id = fakes.FAKE_PROJECT_ID