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): ...@@ -74,11 +74,30 @@ class Quotaholder(object):
class AstakosClientExceptionHandler(object): class AstakosClientExceptionHandler(object):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
pass self.user = kwargs.get("user")
self.projects = kwargs.get("projects")
def __enter__(self): def __enter__(self):
pass pass
def check_notFound(self):
if not self.user or not self.projects:
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:
except KeyError:
m = "User %s not in project %s" % (self.user, project)
raise faults.BadRequest(m)
def __exit__(self, exc_type, value, traceback): def __exit__(self, exc_type, value, traceback):
if value is not None: # exception if value is not None: # exception
if not isinstance(value, errors.AstakosClientException): if not isinstance(value, errors.AstakosClientException):
...@@ -86,6 +105,8 @@ class AstakosClientExceptionHandler(object): ...@@ -86,6 +105,8 @@ class AstakosClientExceptionHandler(object):
if exc_type is errors.QuotaLimit: if exc_type is errors.QuotaLimit:
msg, details = render_overlimit_exception(value) msg, details = render_overlimit_exception(value)
raise faults.OverLimit(msg, details=details) raise faults.OverLimit(msg, details=details)
if exc_type is errors.NotFound:
log.exception("Unexpected error %s" % value.message) log.exception("Unexpected error %s" % value.message)
raise faults.InternalServerError("Unexpected error") raise faults.InternalServerError("Unexpected error")
...@@ -111,7 +132,7 @@ def issue_commission(resource, action, name="", force=False, auto_accept=False, ...@@ -111,7 +132,7 @@ def issue_commission(resource, action, name="", force=False, auto_accept=False,
qh = Quotaholder.get() qh = Quotaholder.get()
if True: # placeholder if True: # placeholder
with AstakosClientExceptionHandler(): with AstakosClientExceptionHandler(user=user, projects=[source]):
serial = qh.issue_one_commission(user, source, serial = qh.issue_one_commission(user, source,
provisions, name=name, provisions, name=name,
force=force, 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