From: Sergio Cazzolato Date: Wed, 19 Feb 2014 18:53:49 +0000 (-0300) Subject: Quota delete operation in cinder X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=515ccb9451940032fa6f296be63698d7f2615e0f;p=openstack-build%2Fcinder-build.git Quota delete operation in cinder 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 --- diff --git a/cinder/api/contrib/quotas.py b/cinder/api/contrib/quotas.py index ae56ca48b..739eb1e2e 100644 --- a/cinder/api/contrib/quotas.py +++ b/cinder/api/contrib/quotas.py @@ -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.""" diff --git a/cinder/tests/api/contrib/test_quotas.py b/cinder/tests/api/contrib/test_quotas.py index 2b44ebe1f..cc485de0d 100644 --- a/cinder/tests/api/contrib/test_quotas.py +++ b/cinder/tests/api/contrib/test_quotas.py @@ -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): diff --git a/cinder/tests/policy.json b/cinder/tests/policy.json index 78ee5f1ae..d1d72c49e 100644 --- a/cinder/tests/policy.json +++ b/cinder/tests/policy.json @@ -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": [],