Add InvalidInput handling for attach-volume
If attaching the already attached volume to a server, Cinder returns HTTP400 response to Nova but Nova didn't except the response. Then Nova returned HTTP500 response to a client. Tempest test I594566704b9794457d224031802d9cbf132e765f reproduces this error case. Closes-Bug: #1632513 Change-Id: I6718883cb6b42d9b816e3799324a166cbfe92b40
This commit is contained in:
parent
6e1a9fa7b3
commit
21961e7bc5
|
@ -335,7 +335,7 @@ class VolumeAttachmentController(wsgi.Controller):
|
|||
common.raise_http_conflict_for_instance_invalid_state(state_error,
|
||||
'attach_volume', server_id)
|
||||
except (exception.InvalidVolume,
|
||||
exception.InvalidDevicePath) as e:
|
||||
exception.InvalidDevicePath, exception.InvalidInput) as e:
|
||||
raise exc.HTTPBadRequest(explanation=e.format_message())
|
||||
|
||||
# The attach is async
|
||||
|
|
|
@ -689,6 +689,23 @@ class VolumeAttachTestsV21(test.NoDBTestCase):
|
|||
self.assertRaises(self.validation_error, self.attachments.create,
|
||||
req, FAKE_UUID, body=body)
|
||||
|
||||
@mock.patch.object(compute_api.API, 'attach_volume')
|
||||
def test_attach_volume_with_invalid_input(self, mock_attach):
|
||||
mock_attach.side_effect = exception.InvalidInput(
|
||||
reason='Invalid volume')
|
||||
|
||||
body = {'volumeAttachment': {'volumeId': FAKE_UUID_A,
|
||||
'device': '/dev/fake'}}
|
||||
|
||||
req = fakes.HTTPRequest.blank('/v2/servers/id/os-volume_attachments')
|
||||
req.method = 'POST'
|
||||
req.body = jsonutils.dump_as_bytes({})
|
||||
req.headers['content-type'] = 'application/json'
|
||||
req.environ['nova.context'] = self.context
|
||||
|
||||
self.assertRaises(exc.HTTPBadRequest, self.attachments.create,
|
||||
req, FAKE_UUID, body=body)
|
||||
|
||||
def _test_swap(self, attachments, uuid=FAKE_UUID_A,
|
||||
fake_func=None, body=None):
|
||||
fake_func = fake_func or fake_swap_volume
|
||||
|
|
Loading…
Reference in New Issue