Commit d8075556 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

cyclades: Inspect qh NotFound response

Since a user can now specify the project where a resource is assigned,
user-provided data do reach the quotaholder. A NotFound response is
thus not necessarily an internal error; the user may just not be a
member of the input project. Query the quotaholder to find out whether
this is the case and, if so, raise BadRequest.
parent e04bb068
......@@ -74,11 +74,30 @@ class Quotaholder(object):
class AstakosClientExceptionHandler(object):
def __init__(self, *args, **kwargs):
pass
self.user = kwargs.get("user")
self.projects = kwargs.get("projects")
def __enter__(self):
pass
def check_notFound(self):
if not self.user or not self.projects:
return
try:
qh = Quotaholder.get()
user_quota = qh.service_get_quotas(self.user)
except errors.AstakosClientException as e:
log.exception("Unexpected error %s" % e.message)
raise faults.InternalServerError("Unexpected error")
user_quota = user_quota[self.user]
for project in self.projects:
try:
user_quota[project]
except KeyError:
m = "User %s not in project %s" % (self.user, project)
raise faults.BadRequest(m)
def __exit__(self, exc_type, value, traceback):
if value is not None: # exception
if not isinstance(value, errors.AstakosClientException):
......@@ -86,6 +105,8 @@ class AstakosClientExceptionHandler(object):
if exc_type is errors.QuotaLimit:
msg, details = render_overlimit_exception(value)
raise faults.OverLimit(msg, details=details)
if exc_type is errors.NotFound:
self.check_notFound()
log.exception("Unexpected error %s" % value.message)
raise faults.InternalServerError("Unexpected error")
......@@ -111,7 +132,7 @@ def issue_commission(resource, action, name="", force=False, auto_accept=False,
qh = Quotaholder.get()
if True: # placeholder
with AstakosClientExceptionHandler():
with AstakosClientExceptionHandler(user=user, projects=[source]):
serial = qh.issue_one_commission(user, source,
provisions, name=name,
force=force,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment