From d2e40a3e49819dace92975de3e3d7ba3a3fac79d Mon Sep 17 00:00:00 2001 From: Maciej Jozefczyk Date: Fri, 25 May 2018 11:01:58 +0000 Subject: [PATCH] Change exception type while deattaching root device By default it is not possible to deattach volume that is configured as root device for an instance. Previous HTTP 403 reponse pointed that caller don't have permission to deattach the volume instead he's not able to do it. Response 400 suits more for that case. Change-Id: Ife59900448719f78c0505f1b681cb26674fa0306 --- nova/api/openstack/compute/volumes.py | 2 +- nova/tests/unit/api/openstack/compute/test_volumes.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/compute/volumes.py b/nova/api/openstack/compute/volumes.py index 27b9af950293..faa2238e5e7d 100644 --- a/nova/api/openstack/compute/volumes.py +++ b/nova/api/openstack/compute/volumes.py @@ -433,7 +433,7 @@ class VolumeAttachmentController(wsgi.Controller): if bdm.is_root: msg = _("Cannot detach a root device volume") - raise exc.HTTPForbidden(explanation=msg) + raise exc.HTTPBadRequest(explanation=msg) try: self.compute_api.detach_volume(context, instance, volume) diff --git a/nova/tests/unit/api/openstack/compute/test_volumes.py b/nova/tests/unit/api/openstack/compute/test_volumes.py index ef47287a25a4..162d472034a5 100644 --- a/nova/tests/unit/api/openstack/compute/test_volumes.py +++ b/nova/tests/unit/api/openstack/compute/test_volumes.py @@ -541,7 +541,7 @@ class VolumeAttachTestsV21(test.NoDBTestCase): new_callable=mock.PropertyMock) def test_detach_vol_root(self, mock_isroot): mock_isroot.return_value = True - self.assertRaises(exc.HTTPForbidden, + self.assertRaises(exc.HTTPBadRequest, self.attachments.delete, self.req, FAKE_UUID,