Commit da8e59df authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Fix plankton ItemNotFound exception

Plankton backend raised AssertionError when an Image was not found.
Change this to raise faults.ItemNotFound error. Temporary commit
until common API decorator is implemented.

Refs #3356
parent 45b56769
......@@ -56,6 +56,7 @@ import warnings
from operator import itemgetter
from time import gmtime, strftime
from functools import wraps, partial
from synnefo.api import faults
from django.conf import settings
......@@ -284,7 +285,8 @@ class ImageBackend(object):
@handle_backend_exceptions
def add_user(self, image_id, user):
image = self.get_image(image_id)
assert image, "Image not found"
if not image:
raise faults.ItemNotFound
location = image['location']
permissions = self._get_permissions(location)
......@@ -394,7 +396,8 @@ class ImageBackend(object):
def list_users(self, image_id):
image = self.get_image(image_id)
assert image, "Image not found"
if not image:
raise faults.ItemNotFound
permissions = self._get_permissions(image['location'])
return [user for user in permissions.get('read', []) if user != '*']
......@@ -471,7 +474,8 @@ class ImageBackend(object):
@handle_backend_exceptions
def remove_user(self, image_id, user):
image = self.get_image(image_id)
assert image, "Image not found"
if not image:
raise faults.ItemNotFound
location = image['location']
permissions = self._get_permissions(location)
......@@ -484,7 +488,8 @@ class ImageBackend(object):
@handle_backend_exceptions
def replace_users(self, image_id, users):
image = self.get_image(image_id)
assert image, "Image not found"
if not image:
raise faults.ItemNotFound
location = image['location']
permissions = self._get_permissions(location)
......@@ -497,6 +502,8 @@ class ImageBackend(object):
def update(self, image_id, params):
image = self.get_image(image_id)
assert image, "Image not found"
if not image:
raise faults.ItemNotFound
location = image['location']
is_public = params.pop('is_public', None)
......@@ -521,7 +528,8 @@ class ImageBackend(object):
def unregister(self, image_id):
"""Unregister an image."""
image = self.get_image(image_id)
assert image, "Image not found"
if not image:
raise faults.ItemNotFound
location = image["location"]
# Unregister the image by removing all metadata from domain
......
......@@ -42,6 +42,7 @@ from django.http import (HttpResponse, HttpResponseBadRequest,
from synnefo.lib.astakos import get_user
from synnefo.plankton.backend import (ImageBackend, BackendException,
NotAllowedError)
from synnefo.api import faults
log = getLogger('synnefo.plankton')
......@@ -63,6 +64,8 @@ def plankton_method(method):
return HttpResponseBadRequest(message)
except NotAllowedError:
return HttpResponseForbidden()
except faults.Fault, fault:
return HttpResponse(status=fault.code)
except Exception as e:
if settings.DEBUG:
message = format_exc(e)
......
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