Update quotas API
Change-Id: I36016050c94cf8baf7bbfa73cd9073f86fab76bc
This commit is contained in:
parent
bbba25a0fc
commit
1281a8b4db
|
@ -460,9 +460,8 @@ class ArtifactsController(api_versioning.VersionedResource):
|
|||
|
||||
:param req: user request
|
||||
:param values: list with quota values to set
|
||||
:return: definition of created quota
|
||||
"""
|
||||
return self.engine.set_quotas(req.context, values)
|
||||
self.engine.set_quotas(req.context, values)
|
||||
|
||||
@supported_versions(min_ver='1.1')
|
||||
@log_request_progress
|
||||
|
@ -476,7 +475,7 @@ class ArtifactsController(api_versioning.VersionedResource):
|
|||
|
||||
@supported_versions(min_ver='1.1')
|
||||
@log_request_progress
|
||||
def list_project_quotas(self, req, project_id):
|
||||
def list_project_quotas(self, req, project_id=None):
|
||||
"""Get detailed info about project quotas.
|
||||
|
||||
:param req: user request
|
||||
|
@ -599,32 +598,27 @@ class ResponseSerializer(api_versioning.VersionedResource,
|
|||
def _serialize_quota(quotas):
|
||||
res = []
|
||||
for project_id, project_quotas in quotas.items():
|
||||
qouta_list = []
|
||||
for qouta_name, quota_value in project_quotas.items():
|
||||
qouta_list.append({
|
||||
'quota_name': qouta_name,
|
||||
quota_list = []
|
||||
for quota_name, quota_value in project_quotas.items():
|
||||
quota_list.append({
|
||||
'quota_name': quota_name,
|
||||
'quota_value': quota_value,
|
||||
})
|
||||
res.append({
|
||||
'project_id': project_id,
|
||||
'project_quotas': qouta_list
|
||||
'project_quotas': quota_list
|
||||
})
|
||||
return res
|
||||
|
||||
@supported_versions(min_ver='1.1')
|
||||
def set_quotas(self, response, quota):
|
||||
quota = self._serialize_quota(quota)
|
||||
self._prepare_json_response(response, quota)
|
||||
def list_all_quotas(self, response, quotas):
|
||||
quotas['quotas'] = self._serialize_quota(quotas['quotas'])
|
||||
self._prepare_json_response(response, quotas)
|
||||
|
||||
@supported_versions(min_ver='1.1')
|
||||
def list_all_quotas(self, response, quota):
|
||||
quota = self._serialize_quota(quota)
|
||||
self._prepare_json_response(response, quota)
|
||||
|
||||
@supported_versions(min_ver='1.1')
|
||||
def list_project_quotas(self, response, quota):
|
||||
quota = self._serialize_quota(quota)
|
||||
self._prepare_json_response(response, quota)
|
||||
def list_project_quotas(self, response, quotas):
|
||||
quotas = self._serialize_quota(quotas)
|
||||
self._prepare_json_response(response, quotas)
|
||||
|
||||
|
||||
def create_resource():
|
||||
|
|
|
@ -116,12 +116,21 @@ class API(wsgi.Router):
|
|||
action='reject',
|
||||
allowed_methods='PUT, GET')
|
||||
|
||||
mapper.connect('/quotas/{project_id}',
|
||||
mapper.connect('/project-quotas',
|
||||
controller=glare_resource,
|
||||
action='list_project_quotas',
|
||||
conditions={'method': ['GET']},
|
||||
body_reject=True)
|
||||
mapper.connect('/quotas/{project_id}',
|
||||
mapper.connect('/project-quotas',
|
||||
controller=reject_method_resource,
|
||||
action='reject',
|
||||
allowed_methods='GET')
|
||||
mapper.connect('/project-quotas/{project_id}',
|
||||
controller=glare_resource,
|
||||
action='list_project_quotas',
|
||||
conditions={'method': ['GET']},
|
||||
body_reject=True)
|
||||
mapper.connect('/project-quotas/{project_id}',
|
||||
controller=reject_method_resource,
|
||||
action='reject',
|
||||
allowed_methods='GET')
|
||||
|
|
|
@ -641,8 +641,6 @@ def set_quotas(values, session):
|
|||
# save all quotas
|
||||
session.flush()
|
||||
|
||||
return values
|
||||
|
||||
|
||||
@retry(retry_on_exception=_retry_on_deadlock, wait_fixed=500,
|
||||
stop_max_attempt_number=50)
|
||||
|
|
|
@ -62,7 +62,7 @@ class Engine(object):
|
|||
|
||||
# generate all schemas and quotas
|
||||
self.schemas = {}
|
||||
self.quotas = {
|
||||
self.config_quotas = {
|
||||
'max_artifact_number': CONF.max_artifact_number,
|
||||
'max_uploaded_data': CONF.max_uploaded_data
|
||||
}
|
||||
|
@ -72,10 +72,10 @@ class Engine(object):
|
|||
get_artifact_type(type_name).gen_schemas()
|
||||
type_conf_section = getattr(CONF, 'artifact_type:' + type_name)
|
||||
if type_conf_section.max_artifact_number is not None:
|
||||
self.quotas['max_artifact_number:' + type_name] = \
|
||||
self.config_quotas['max_artifact_number:' + type_name] = \
|
||||
type_conf_section.max_artifact_number
|
||||
if type_conf_section.max_uploaded_data is not None:
|
||||
self.quotas['max_uploaded_data:' + type_name] = \
|
||||
self.config_quotas['max_uploaded_data:' + type_name] = \
|
||||
type_conf_section.max_uploaded_data
|
||||
|
||||
lock_engine = locking.LockEngine(artifact_api.ArtifactLockApi())
|
||||
|
@ -691,13 +691,11 @@ class Engine(object):
|
|||
|
||||
:param context: user request context
|
||||
:param values: list with quota values to set
|
||||
:return: definition of created quotas
|
||||
"""
|
||||
action_name = "artifact:set_quotas"
|
||||
policy.authorize(action_name, {}, context)
|
||||
qs = quota.set_quotas(values)
|
||||
Notifier.notify(context, action_name, qs)
|
||||
return qs
|
||||
|
||||
def list_all_quotas(self, context):
|
||||
"""Get detailed info about all available quotas.
|
||||
|
@ -707,19 +705,21 @@ class Engine(object):
|
|||
"""
|
||||
action_name = "artifact:list_all_quotas"
|
||||
policy.authorize(action_name, {}, context)
|
||||
qs = quota.list_quotas()
|
||||
qs[None] = self.quotas
|
||||
return qs
|
||||
return {
|
||||
'quotas': quota.list_quotas(),
|
||||
'global_quotas': self.config_quotas
|
||||
}
|
||||
|
||||
def list_project_quotas(self, context, project_id):
|
||||
def list_project_quotas(self, context, project_id=None):
|
||||
"""Get detailed info about project quotas.
|
||||
|
||||
:param context: user request context
|
||||
:param project_id: id of the project for which to show quotas
|
||||
:return: definition of requested quotas for the project
|
||||
"""
|
||||
project_id = project_id or context.tenant
|
||||
action_name = "artifact:list_project_quotas"
|
||||
policy.authorize(action_name, {'project_id': project_id}, context)
|
||||
qs = self.quotas.copy()
|
||||
qs = self.config_quotas.copy()
|
||||
qs.update(quota.list_quotas(project_id)[project_id])
|
||||
return {project_id: qs}
|
||||
|
|
|
@ -127,7 +127,7 @@ def verify_uploaded_data_amount(context, type_name, data_amount=None):
|
|||
|
||||
def set_quotas(values):
|
||||
session = api.get_session()
|
||||
return api.set_quotas(values, session)
|
||||
api.set_quotas(values, session)
|
||||
|
||||
|
||||
def list_quotas(project_id=None):
|
||||
|
|
|
@ -74,7 +74,9 @@ class TestArtifact(functional.FunctionalTest):
|
|||
super(TestArtifact, self).tearDown()
|
||||
|
||||
def _url(self, path):
|
||||
if path.startswith('/schemas') or path.startswith('/quotas'):
|
||||
if path.startswith('/schemas') or \
|
||||
path.startswith('/quotas') or \
|
||||
path.startswith('/project-quotas'):
|
||||
return 'http://127.0.0.1:%d%s' % (self.glare_port, path)
|
||||
else:
|
||||
return 'http://127.0.0.1:%d/artifacts%s' % (self.glare_port, path)
|
||||
|
|
|
@ -243,12 +243,11 @@ max_artifact_number = 100
|
|||
|
||||
url = '/quotas'
|
||||
# define several quotas
|
||||
res = self._deserialize_quotas(self.put(url=url, data=values))
|
||||
self.assertEqual(self._deserialize_quotas(values), res)
|
||||
self.put(url=url, data=values)
|
||||
|
||||
# get all quotas
|
||||
res = self._deserialize_quotas(self.get(url=url))
|
||||
global_quotas = res.pop(None)
|
||||
res = self.get(url=url)
|
||||
global_quotas = res['global_quotas']
|
||||
self.assertEqual({
|
||||
'max_artifact_number': 150,
|
||||
'max_artifact_number:heat_templates': 150,
|
||||
|
@ -258,11 +257,12 @@ max_artifact_number = 100
|
|||
'max_uploaded_data:images': 15000,
|
||||
'max_uploaded_data:murano_packages': 10000,
|
||||
'max_uploaded_data:sample_artifact': 3000}, global_quotas)
|
||||
self.assertEqual(self._deserialize_quotas(values), res)
|
||||
self.assertEqual(self._deserialize_quotas(values),
|
||||
self._deserialize_quotas(res['quotas']))
|
||||
|
||||
# get user1 quotas
|
||||
res = self._deserialize_quotas(self.get(
|
||||
url='/quotas/' + user1_tenant_id))
|
||||
url='/project-quotas/' + user1_tenant_id))
|
||||
self.assertEqual({user1_tenant_id: {
|
||||
'max_artifact_number': 10,
|
||||
'max_artifact_number:heat_templates': 15,
|
||||
|
@ -274,8 +274,7 @@ max_artifact_number = 100
|
|||
'max_uploaded_data:sample_artifact': 3000}}, res)
|
||||
|
||||
# get admin quotas
|
||||
res = self._deserialize_quotas(self.get(
|
||||
url='/quotas/' + admin_tenant_id))
|
||||
res = self._deserialize_quotas(self.get(url='/project-quotas'))
|
||||
self.assertEqual({admin_tenant_id: {
|
||||
'max_artifact_number': 10,
|
||||
'max_artifact_number:heat_templates': 150,
|
||||
|
@ -292,8 +291,7 @@ max_artifact_number = 100
|
|||
self.get(url=url, status=403)
|
||||
|
||||
# user1 can get his quotas
|
||||
res = self._deserialize_quotas(self.get(
|
||||
url='/quotas/' + user1_tenant_id))
|
||||
res = self._deserialize_quotas(self.get(url='/project-quotas'))
|
||||
self.assertEqual({user1_tenant_id: {
|
||||
'max_artifact_number': 10,
|
||||
'max_artifact_number:heat_templates': 15,
|
||||
|
@ -305,7 +303,7 @@ max_artifact_number = 100
|
|||
'max_uploaded_data:sample_artifact': 3000}}, res)
|
||||
|
||||
# user1 can't get user2 quotas
|
||||
self.get(url=url + '/' + user2_tenant_id, status=403)
|
||||
self.get(url='/project-quotas/' + user2_tenant_id, status=403)
|
||||
|
||||
|
||||
class TestStaticQuotas(base.TestArtifact):
|
||||
|
|
|
@ -146,8 +146,7 @@ class TestQuotaFunctions(base.BaseTestArtifactAPI):
|
|||
}
|
||||
}
|
||||
|
||||
res = api.set_quotas(values, self.session)
|
||||
self.assertEqual(values, res)
|
||||
api.set_quotas(values, self.session)
|
||||
|
||||
res = api.get_all_quotas(self.session)
|
||||
self.assertEqual(values, res)
|
||||
|
@ -163,8 +162,7 @@ class TestQuotaFunctions(base.BaseTestArtifactAPI):
|
|||
"project2": {},
|
||||
}
|
||||
|
||||
res = api.set_quotas(new_values, self.session)
|
||||
self.assertEqual(new_values, res)
|
||||
api.set_quotas(new_values, self.session)
|
||||
|
||||
# project3 should remain unchanged
|
||||
new_values['project3'] = {"max_uploaded_data": 1000}
|
||||
|
|
Loading…
Reference in New Issue