Merge "Delete quota API"

This commit is contained in:
Zuul 2020-02-03 12:14:54 +00:00 committed by Gerrit Code Review
commit 39a894634b
5 changed files with 68 additions and 0 deletions

View File

@ -82,3 +82,10 @@ class QuotasController(rest.RestController):
quotas = [Quota.from_db_model(i) for i in db_quotas]
return Quotas(project_id=project_id, quotas=quotas)
@wsme_pecan.wsexpose(None, str, status_code=204)
def delete(self, project_id):
"""Delete quotas for the given project."""
rbac.enforce('delete_quotas', pecan.request.headers,
pecan.request.enforcer, {})
pecan.request.storage.delete_quotas(project_id)

View File

@ -166,6 +166,17 @@ rules = [
'method': 'POST'
}
]
),
policy.DocumentedRuleDefault(
name="telemetry:delete_quotas",
check_str=RULE_CONTEXT_IS_ADMIN,
description='Delete resources quotas for project.',
operations=[
{
'path': '/v2/quotas/{project_id}',
'method': 'DELETE'
}
]
)
]

View File

@ -215,3 +215,8 @@ class Connection(object):
"""Set resource quota for the given user."""
raise aodh.NotImplementedError('Setting resource quota not '
'implemented')
@staticmethod
def delete_quotas(project_id):
raise aodh.NotImplementedError('Deleting resource quota not '
'implemented')

View File

@ -475,3 +475,8 @@ class Connection(base.Connection):
filters = {'project_id': project_id}
query = session.query(models.Quota).filter_by(**filters)
return self._retrieve_quotas(query)
def delete_quotas(self, project_id):
filters = {'project_id': project_id}
session = self._engine_facade.get_session()
session.query(models.Quota).filter_by(**filters).delete()

View File

@ -190,3 +190,43 @@ class TestQuotas(v2.FunctionalTest):
self.assertIn('Value should be one of',
resp.json['error_message']['faultstring'])
def test_delete_project_quota_by_admin(self):
auth_headers = copy.copy(self.auth_headers)
auth_headers['X-Roles'] = 'admin'
self.post_json(
'/quotas',
{
"project_id": self.other_project,
"quotas": [
{
"resource": "alarms",
"limit": 30
}
]
},
headers=auth_headers,
status=201
)
resp = self.get_json('/quotas?project_id=%s' % self.other_project,
headers=auth_headers,
status=200)
self.assert_single_item(resp['quotas'], resource='alarms',
limit=30)
self.delete('/quotas/%s' % self.other_project, headers=auth_headers,
status=204)
resp = self.get_json('/quotas?project_id=%s' % self.other_project,
headers=auth_headers,
status=200)
self.assert_multiple_items(resp['quotas'], 0, resource='alarms',
limit=30)
def test_delete_project_quota_by_user_failed(self):
self.delete('/quotas/%s' % self.other_project,
headers=self.auth_headers,
expect_errors=True,
status=403)