]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Quota delete operation in cinder
authorSergio Cazzolato <sergio.j.cazzolato@intel.com>
Wed, 19 Feb 2014 18:53:49 +0000 (15:53 -0300)
committerSergio Cazzolato <sergio.j.cazzolato@intel.com>
Wed, 26 Feb 2014 19:47:09 +0000 (16:47 -0300)
This change adds the quota-delete operation to cinder.

It is adding the api and the tests, using the methods already
implemented in the db to destroy all the quotas for a specific
project.

Implements blueprint quota-delete

DocImpact

Change-Id: Ia040a20abb831c311eb13624ddecbbf0f12fdd9f

cinder/api/contrib/quotas.py
cinder/tests/api/contrib/test_quotas.py
cinder/tests/policy.json

index ae56ca48bba36a0abd3d5f80db1b2ee3d5615c12..739eb1e2e0b55d4359e94278c72e8f12ebb8db1e 100644 (file)
@@ -32,6 +32,7 @@ NON_QUOTA_KEYS = ['tenant_id', 'id']
 
 authorize_update = extensions.extension_authorizer('volume', 'quotas:update')
 authorize_show = extensions.extension_authorizer('volume', 'quotas:show')
+authorize_delete = extensions.extension_authorizer('volume', 'quotas:delete')
 
 
 class QuotaTemplate(xmlutil.TemplateBuilder):
@@ -134,6 +135,17 @@ class QuotaSetsController(wsgi.Controller):
         authorize_show(context)
         return self._format_quota_set(id, QUOTAS.get_defaults(context))
 
+    @wsgi.serializers(xml=QuotaTemplate)
+    def delete(self, req, id):
+
+        context = req.environ['cinder.context']
+        authorize_delete(context)
+
+        try:
+            db.quota_destroy_all_by_project(context, id)
+        except exception.AdminRequired:
+            raise webob.exc.HTTPForbidden()
+
 
 class Quotas(extensions.ExtensionDescriptor):
     """Quota management support."""
index 2b44ebe1f44809dae431f95de9042f33a1b351d7..cc485de0d2c08938adb6d64c15dee2353fe3215e 100644 (file)
@@ -110,6 +110,25 @@ class QuotaSetsControllerTest(test.TestCase):
         self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
                           self.req, 'foo', body)
 
+    def test_delete(self):
+        result_show = self.controller.show(self.req, 'foo')
+        self.assertDictMatch(result_show, make_body())
+
+        body = make_body(gigabytes=2000, snapshots=15,
+                         volumes=5, tenant_id=None)
+        result_update = self.controller.update(self.req, 'foo', body)
+        self.assertDictMatch(result_update, body)
+
+        self.controller.delete(self.req, 'foo')
+
+        result_show_after = self.controller.show(self.req, 'foo')
+        self.assertDictMatch(result_show, result_show_after)
+
+    def test_delete_no_admin(self):
+        self.req.environ['cinder.context'].is_admin = False
+        self.assertRaises(webob.exc.HTTPForbidden, self.controller.delete,
+                          self.req, 'test')
+
 
 class QuotaSerializerTest(test.TestCase):
 
index 78ee5f1aef3ecd93d97309a28e9b9876497dc0d9..d1d72c49e863826f820abc22291d3463e334cb84 100644 (file)
@@ -56,6 +56,7 @@
     "volume_extension:hosts": [["rule:admin_api"]],
     "volume_extension:quotas:show": [],
     "volume_extension:quotas:update": [],
+    "volume_extension:quotas:delete": [],
     "volume_extension:quota_classes": [],
 
     "limits_extension:used_limits": [],