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 ef677539b..4347c2c8f 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": [], "volume_extension:volume_manage": [["rule:admin_api"]], "volume_extension:volume_unmanage": [["rule:admin_api"]],