diff options
author | jichenjc <jichenjc@cn.ibm.com> | 2016-09-07 04:41:06 +0800 |
---|---|---|
committer | Tony Breeds <tony@bakeyournoodle.com> | 2016-10-16 23:46:54 +0000 |
commit | fdc5a04962bac95724124c247d527316ed8ccd17 (patch) | |
tree | c18ba13cc99d262abd8914afa9fe1018083574ce | |
parent | 63f3d99819137315b9cb8475614b86314733b1d7 (diff) | |
download | nova-fdc5a04962bac95724124c247d527316ed8ccd17.tar.gz |
Catch DevicePathInUse in attach_volume
DevicePathInUse might be raised in attach action,
we didn't catch it so a 500 error might be returned
to end user.
NOTE: mitaka also includes the legacy_v2 API so this needs to
be patched there to.
Change-Id: Ic9f0979b5adef28bb47756e7fc2ce5a3d6493298
Closes-Bug: 1621452
(cherry picked from commit 6051499a856659290c381e1a80328e48fe8a2199)
(cherry picked from commit 1ef4b725f1df54bc45f6d50a02d9aa65d3bff338)
-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 6b0e9966e2..ce53d5996c 100644 --- a/nova/api/openstack/compute/legacy_v2/contrib/volumes.py +++ b/nova/api/openstack/compute/legacy_v2/contrib/volumes.py @@ -323,6 +323,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 7dc2caaebe..fc1a3f52a2 100644 --- a/nova/api/openstack/compute/volumes.py +++ b/nova/api/openstack/compute/volumes.py @@ -320,6 +320,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 42745aa100..32cc1c3e12 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', |