diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-10-17 15:11:21 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-10-17 15:11:21 +0000 |
commit | 4ffab061b6976970dc2b4a940d5351aca5246409 (patch) | |
tree | 28717ae322f3e4e0adb67c0acba47cbabc07da5d | |
parent | 31da323d14d9d9ad99fa2a1a38a32c929497a8b2 (diff) | |
parent | fdc5a04962bac95724124c247d527316ed8ccd17 (diff) | |
download | nova-4ffab061b6976970dc2b4a940d5351aca5246409.tar.gz |
Merge "Catch DevicePathInUse in attach_volume" into stable/mitaka
-rw-r--r-- | nova/api/openstack/compute/legacy_v2/contrib/volumes.py | 2 | ||||
-rw-r--r-- | nova/api/openstack/compute/volumes.py | 2 | ||||
-rw-r--r-- | nova/tests/unit/api/openstack/compute/test_volumes.py | 20 |
3 files changed, 24 insertions, 0 deletions
diff --git a/nova/api/openstack/compute/legacy_v2/contrib/volumes.py b/nova/api/openstack/compute/legacy_v2/contrib/volumes.py index 70bed0b4bd..eee9804816 100644 --- a/nova/api/openstack/compute/legacy_v2/contrib/volumes.py +++ b/nova/api/openstack/compute/legacy_v2/contrib/volumes.py @@ -325,6 +325,8 @@ class VolumeAttachmentController(wsgi.Controller): raise exc.HTTPNotFound(explanation=e.format_message()) except exception.InstanceIsLocked as e: raise exc.HTTPConflict(explanation=e.format_message()) + except exception.DevicePathInUse as e: + raise exc.HTTPConflict(explanation=e.format_message()) except exception.InstanceInvalidState as state_error: common.raise_http_conflict_for_instance_invalid_state(state_error, 'attach_volume', server_id) diff --git a/nova/api/openstack/compute/volumes.py b/nova/api/openstack/compute/volumes.py index b585bd6b89..27f0bcd91b 100644 --- a/nova/api/openstack/compute/volumes.py +++ b/nova/api/openstack/compute/volumes.py @@ -322,6 +322,8 @@ class VolumeAttachmentController(wsgi.Controller): raise exc.HTTPNotFound(explanation=e.format_message()) except exception.InstanceIsLocked as e: raise exc.HTTPConflict(explanation=e.format_message()) + except exception.DevicePathInUse as e: + raise exc.HTTPConflict(explanation=e.format_message()) except exception.InstanceInvalidState as state_error: common.raise_http_conflict_for_instance_invalid_state(state_error, 'attach_volume', server_id) diff --git a/nova/tests/unit/api/openstack/compute/test_volumes.py b/nova/tests/unit/api/openstack/compute/test_volumes.py index 2468a58e6c..ba47c8fcff 100644 --- a/nova/tests/unit/api/openstack/compute/test_volumes.py +++ b/nova/tests/unit/api/openstack/compute/test_volumes.py @@ -650,6 +650,26 @@ 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', + side_effect=exception.DevicePathInUse(path='/dev/sda')) + def test_attach_volume_device_in_use(self, mock_attach): + + body = { + 'volumeAttachment': { + 'device': '/dev/sda', + 'volumeId': FAKE_UUID_A, + } + } + + 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(webob.exc.HTTPConflict, self.attachments.create, + req, FAKE_UUID, body=body) + def test_attach_volume_without_volumeId(self): self.stubs.Set(compute_api.API, 'attach_volume', |