]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
Catch exception.OverQuota when create image for volume backed instance
authorKevin_Zheng <zhengzhenyu@huawei.com>
Mon, 15 May 2017 07:02:00 +0000 (15:02 +0800)
committerZhenyu Zheng <zhengzhenyu@huawei.com>
Tue, 23 May 2017 06:28:00 +0000 (06:28 +0000)
When create image for a volume backed instance, nova will
create snapshots for all volumes attached to the instance
in Cinder, and if quota exceed in Cinder, HTTP 500 will
raise, we should capture this error and raise 403.

Change-Id: Ic62478e22a7477cfaefac3e63c383082d66bd635
Closes-Bug: #1689284
(cherry picked from commit 29c8ae3cd9653b310c3fac803e6295e5fa885d15)

nova/api/openstack/compute/servers.py
nova/tests/unit/api/openstack/compute/test_server_actions.py

index 91c2a221d4ecc1f8bdcec725d546178f11247e54..44e0bcf5a4792305e1524ae530aa57909760e0eb 100644 (file)
@@ -1105,6 +1105,8 @@ class ServersController(wsgi.Controller):
                         'createImage', id)
         except exception.Invalid as err:
             raise exc.HTTPBadRequest(explanation=err.format_message())
+        except exception.OverQuota as e:
+            raise exc.HTTPForbidden(explanation=e.format_message())
 
         # build location of newly-created image entity
         image_id = str(image['id'])
index 5d09bd13faa098f5e41a2430dc1d063effebdca1..f97c51bf9efa34438ca4c3518dd22944672e212b 100644 (file)
@@ -913,7 +913,8 @@ class ServerActionsControllerTestV21(test.TestCase):
                           self.controller._action_create_image, self.req,
                           FAKE_UUID, body=body)
 
-    def _do_test_create_volume_backed_image(self, extra_properties):
+    def _do_test_create_volume_backed_image(
+            self, extra_properties, mock_vol_create_side_effect=None):
 
         def _fake_id(x):
             return '%s-%s-%s-%s' % (x * 8, x * 4, x * 4, x * 12)
@@ -976,6 +977,9 @@ class ServerActionsControllerTestV21(test.TestCase):
                               return_value=snapshot),
         ) as (mock_quiesce, mock_vol_get, mock_vol_create):
 
+            if mock_vol_create_side_effect:
+                mock_vol_create.side_effect = mock_vol_create_side_effect
+
             response = self.controller._action_create_image(self.req,
                 FAKE_UUID, body=body)
 
@@ -1014,6 +1018,13 @@ class ServerActionsControllerTestV21(test.TestCase):
         self._do_test_create_volume_backed_image(dict(ImageType='Gold',
                                                       ImageVersion='2.0'))
 
+    def test_create_volume_backed_image_cinder_over_quota(self):
+        self.assertRaises(
+            webob.exc.HTTPForbidden,
+            self._do_test_create_volume_backed_image, {},
+            mock_vol_create_side_effect=exception.OverQuota(
+                overs='snapshot'))
+
     def _test_create_volume_backed_image_with_metadata_from_volume(
             self, extra_metadata=None):