Merge "Audit error logging"
This commit is contained in:
commit
454a346b5a
@ -29,6 +29,7 @@ from webob.exc import (HTTPError,
|
|||||||
HTTPBadRequest,
|
HTTPBadRequest,
|
||||||
HTTPForbidden,
|
HTTPForbidden,
|
||||||
HTTPRequestEntityTooLarge,
|
HTTPRequestEntityTooLarge,
|
||||||
|
HTTPInternalServerError,
|
||||||
HTTPServiceUnavailable)
|
HTTPServiceUnavailable)
|
||||||
|
|
||||||
from glance.api import common
|
from glance.api import common
|
||||||
@ -273,7 +274,7 @@ class Controller(controller.BaseController):
|
|||||||
if source.lower().startswith(scheme):
|
if source.lower().startswith(scheme):
|
||||||
return source
|
return source
|
||||||
msg = _("External sourcing not supported for store %s") % source
|
msg = _("External sourcing not supported for store %s") % source
|
||||||
LOG.error(msg)
|
LOG.debug(msg)
|
||||||
raise HTTPBadRequest(explanation=msg,
|
raise HTTPBadRequest(explanation=msg,
|
||||||
request=req,
|
request=req,
|
||||||
content_type="text/plain")
|
content_type="text/plain")
|
||||||
@ -363,20 +364,20 @@ class Controller(controller.BaseController):
|
|||||||
except exception.Duplicate:
|
except exception.Duplicate:
|
||||||
msg = (_("An image with identifier %s already exists") %
|
msg = (_("An image with identifier %s already exists") %
|
||||||
image_meta['id'])
|
image_meta['id'])
|
||||||
LOG.error(msg)
|
LOG.debug(msg)
|
||||||
raise HTTPConflict(explanation=msg,
|
raise HTTPConflict(explanation=msg,
|
||||||
request=req,
|
request=req,
|
||||||
content_type="text/plain")
|
content_type="text/plain")
|
||||||
except exception.Invalid, e:
|
except exception.Invalid, e:
|
||||||
msg = (_("Failed to reserve image. Got error: %(e)s") % locals())
|
msg = (_("Failed to reserve image. Got error: %(e)s") % locals())
|
||||||
for line in msg.split('\n'):
|
for line in msg.split('\n'):
|
||||||
LOG.error(line)
|
LOG.debug(line)
|
||||||
raise HTTPBadRequest(explanation=msg,
|
raise HTTPBadRequest(explanation=msg,
|
||||||
request=req,
|
request=req,
|
||||||
content_type="text/plain")
|
content_type="text/plain")
|
||||||
except exception.Forbidden:
|
except exception.Forbidden:
|
||||||
msg = _("Forbidden to reserve image.")
|
msg = _("Forbidden to reserve image.")
|
||||||
LOG.error(msg)
|
LOG.debug(msg)
|
||||||
raise HTTPForbidden(explanation=msg,
|
raise HTTPForbidden(explanation=msg,
|
||||||
request=req,
|
request=req,
|
||||||
content_type="text/plain")
|
content_type="text/plain")
|
||||||
@ -403,7 +404,7 @@ class Controller(controller.BaseController):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._safe_kill(req, image_meta['id'])
|
self._safe_kill(req, image_meta['id'])
|
||||||
msg = _("Copy from external source failed: %s") % e
|
msg = _("Copy from external source failed: %s") % e
|
||||||
LOG.error(msg)
|
LOG.debug(msg)
|
||||||
return
|
return
|
||||||
image_meta['size'] = image_size or image_meta['size']
|
image_meta['size'] = image_size or image_meta['size']
|
||||||
else:
|
else:
|
||||||
@ -412,7 +413,7 @@ class Controller(controller.BaseController):
|
|||||||
except exception.InvalidContentType:
|
except exception.InvalidContentType:
|
||||||
self._safe_kill(req, image_meta['id'])
|
self._safe_kill(req, image_meta['id'])
|
||||||
msg = _("Content-Type must be application/octet-stream")
|
msg = _("Content-Type must be application/octet-stream")
|
||||||
LOG.error(msg)
|
LOG.debug(msg)
|
||||||
raise HTTPBadRequest(explanation=msg)
|
raise HTTPBadRequest(explanation=msg)
|
||||||
|
|
||||||
image_data = req.body_file
|
image_data = req.body_file
|
||||||
@ -443,7 +444,7 @@ class Controller(controller.BaseController):
|
|||||||
"checksum generated from uploaded image "
|
"checksum generated from uploaded image "
|
||||||
"(%(checksum)s) did not match. Setting image "
|
"(%(checksum)s) did not match. Setting image "
|
||||||
"status to 'killed'.") % locals()
|
"status to 'killed'.") % locals()
|
||||||
LOG.error(msg)
|
LOG.debug(msg)
|
||||||
self._safe_kill(req, image_id)
|
self._safe_kill(req, image_id)
|
||||||
raise HTTPBadRequest(explanation=msg,
|
raise HTTPBadRequest(explanation=msg,
|
||||||
content_type="text/plain",
|
content_type="text/plain",
|
||||||
@ -465,13 +466,13 @@ class Controller(controller.BaseController):
|
|||||||
|
|
||||||
except exception.Duplicate, e:
|
except exception.Duplicate, e:
|
||||||
msg = _("Attempt to upload duplicate image: %s") % e
|
msg = _("Attempt to upload duplicate image: %s") % e
|
||||||
LOG.error(msg)
|
LOG.debug(msg)
|
||||||
self._safe_kill(req, image_id)
|
self._safe_kill(req, image_id)
|
||||||
raise HTTPConflict(explanation=msg, request=req)
|
raise HTTPConflict(explanation=msg, request=req)
|
||||||
|
|
||||||
except exception.Forbidden, e:
|
except exception.Forbidden, e:
|
||||||
msg = _("Forbidden upload attempt: %s") % e
|
msg = _("Forbidden upload attempt: %s") % e
|
||||||
LOG.error(msg)
|
LOG.debug(msg)
|
||||||
self._safe_kill(req, image_id)
|
self._safe_kill(req, image_id)
|
||||||
raise HTTPForbidden(explanation=msg,
|
raise HTTPForbidden(explanation=msg,
|
||||||
request=req,
|
request=req,
|
||||||
@ -508,16 +509,9 @@ class Controller(controller.BaseController):
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
tb_info = traceback.format_exc()
|
LOG.exception(_("Failed to upload image"))
|
||||||
LOG.error(tb_info)
|
|
||||||
|
|
||||||
self._safe_kill(req, image_id)
|
self._safe_kill(req, image_id)
|
||||||
|
raise HTTPInternalServerError(request=req)
|
||||||
msg = _("Error uploading image: (%(class_name)s): "
|
|
||||||
"%(exc)s") % ({'class_name': e.__class__.__name__,
|
|
||||||
'exc': str(e)})
|
|
||||||
|
|
||||||
raise HTTPBadRequest(explanation=msg, request=req)
|
|
||||||
|
|
||||||
def _activate(self, req, image_id, location):
|
def _activate(self, req, image_id, location):
|
||||||
"""
|
"""
|
||||||
@ -541,8 +535,7 @@ class Controller(controller.BaseController):
|
|||||||
except exception.Invalid, e:
|
except exception.Invalid, e:
|
||||||
msg = (_("Failed to activate image. Got error: %(e)s")
|
msg = (_("Failed to activate image. Got error: %(e)s")
|
||||||
% locals())
|
% locals())
|
||||||
for line in msg.split('\n'):
|
LOG.debug(msg)
|
||||||
LOG.error(line)
|
|
||||||
raise HTTPBadRequest(explanation=msg,
|
raise HTTPBadRequest(explanation=msg,
|
||||||
request=req,
|
request=req,
|
||||||
content_type="text/plain")
|
content_type="text/plain")
|
||||||
@ -770,8 +763,7 @@ class Controller(controller.BaseController):
|
|||||||
except exception.Invalid, e:
|
except exception.Invalid, e:
|
||||||
msg = (_("Failed to update image metadata. Got error: %(e)s")
|
msg = (_("Failed to update image metadata. Got error: %(e)s")
|
||||||
% locals())
|
% locals())
|
||||||
for line in msg.split('\n'):
|
LOG.debug(msg)
|
||||||
LOG.error(line)
|
|
||||||
raise HTTPBadRequest(explanation=msg,
|
raise HTTPBadRequest(explanation=msg,
|
||||||
request=req,
|
request=req,
|
||||||
content_type="text/plain")
|
content_type="text/plain")
|
||||||
@ -879,8 +871,8 @@ class Controller(controller.BaseController):
|
|||||||
try:
|
try:
|
||||||
return get_store_from_scheme(request.context, scheme)
|
return get_store_from_scheme(request.context, scheme)
|
||||||
except exception.UnknownScheme:
|
except exception.UnknownScheme:
|
||||||
msg = _("Store for scheme %s not found")
|
msg = _("Store for scheme %s not found") % scheme
|
||||||
LOG.error(msg % scheme)
|
LOG.debug(msg)
|
||||||
raise HTTPBadRequest(explanation=msg,
|
raise HTTPBadRequest(explanation=msg,
|
||||||
request=request,
|
request=request,
|
||||||
content_type='text/plain')
|
content_type='text/plain')
|
||||||
|
@ -42,7 +42,7 @@ class Store(object):
|
|||||||
except exception.BadStoreConfiguration:
|
except exception.BadStoreConfiguration:
|
||||||
msg = _("Failed to configure store correctly. "
|
msg = _("Failed to configure store correctly. "
|
||||||
"Disabling add method.")
|
"Disabling add method.")
|
||||||
LOG.error(msg)
|
LOG.info(msg)
|
||||||
self.add = self.add_disabled
|
self.add = self.add_disabled
|
||||||
|
|
||||||
def configure(self):
|
def configure(self):
|
||||||
|
@ -63,7 +63,7 @@ class StoreLocation(glance.store.location.StoreLocation):
|
|||||||
path = (pieces.netloc + pieces.path).strip()
|
path = (pieces.netloc + pieces.path).strip()
|
||||||
if path == '':
|
if path == '':
|
||||||
reason = _("No path specified in URI: %s") % uri
|
reason = _("No path specified in URI: %s") % uri
|
||||||
LOG.error(reason)
|
LOG.debug(reason)
|
||||||
raise exception.BadStoreUri('No path specified')
|
raise exception.BadStoreUri('No path specified')
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
|
@ -81,13 +81,13 @@ class StoreLocation(glance.store.location.StoreLocation):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
reason = (_("Credentials '%s' not well-formatted.")
|
reason = (_("Credentials '%s' not well-formatted.")
|
||||||
% "".join(creds))
|
% "".join(creds))
|
||||||
LOG.error(reason)
|
LOG.debug(reason)
|
||||||
raise exception.BadStoreUri()
|
raise exception.BadStoreUri()
|
||||||
else:
|
else:
|
||||||
self.user = None
|
self.user = None
|
||||||
if netloc == '':
|
if netloc == '':
|
||||||
reason = _("No address specified in HTTP URL")
|
reason = _("No address specified in HTTP URL")
|
||||||
LOG.error(reason)
|
LOG.debug(reason)
|
||||||
raise exception.BadStoreUri(message=reason)
|
raise exception.BadStoreUri(message=reason)
|
||||||
self.netloc = netloc
|
self.netloc = netloc
|
||||||
self.path = path
|
self.path = path
|
||||||
|
@ -93,14 +93,14 @@ class StoreLocation(glance.store.location.StoreLocation):
|
|||||||
prefix = 'rbd://'
|
prefix = 'rbd://'
|
||||||
if not uri.startswith(prefix):
|
if not uri.startswith(prefix):
|
||||||
reason = _('URI must start with rbd://')
|
reason = _('URI must start with rbd://')
|
||||||
LOG.error(_("Invalid URI: %(uri)s: %(reason)s") % locals())
|
LOG.debug(_("Invalid URI: %(uri)s: %(reason)s") % locals())
|
||||||
raise exception.BadStoreUri(message=reason)
|
raise exception.BadStoreUri(message=reason)
|
||||||
# convert to ascii since librbd doesn't handle unicode
|
# convert to ascii since librbd doesn't handle unicode
|
||||||
try:
|
try:
|
||||||
ascii_uri = str(uri)
|
ascii_uri = str(uri)
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
reason = _('URI contains non-ascii characters')
|
reason = _('URI contains non-ascii characters')
|
||||||
LOG.error(_("Invalid URI: %(uri)s: %(reason)s") % locals())
|
LOG.debug(_("Invalid URI: %(uri)s: %(reason)s") % locals())
|
||||||
raise exception.BadStoreUri(message=reason)
|
raise exception.BadStoreUri(message=reason)
|
||||||
pieces = ascii_uri[len(prefix):].split('/')
|
pieces = ascii_uri[len(prefix):].split('/')
|
||||||
if len(pieces) == 1:
|
if len(pieces) == 1:
|
||||||
@ -111,11 +111,11 @@ class StoreLocation(glance.store.location.StoreLocation):
|
|||||||
map(urllib.unquote, pieces)
|
map(urllib.unquote, pieces)
|
||||||
else:
|
else:
|
||||||
reason = _('URI must have exactly 1 or 4 components')
|
reason = _('URI must have exactly 1 or 4 components')
|
||||||
LOG.error(_("Invalid URI: %(uri)s: %(reason)s") % locals())
|
LOG.debug(_("Invalid URI: %(uri)s: %(reason)s") % locals())
|
||||||
raise exception.BadStoreUri(message=reason)
|
raise exception.BadStoreUri(message=reason)
|
||||||
if any(map(lambda p: p == '', pieces)):
|
if any(map(lambda p: p == '', pieces)):
|
||||||
reason = _('URI cannot contain empty components')
|
reason = _('URI cannot contain empty components')
|
||||||
LOG.error(_("Invalid URI: %(uri)s: %(reason)s") % locals())
|
LOG.debug(_("Invalid URI: %(uri)s: %(reason)s") % locals())
|
||||||
raise exception.BadStoreUri(message=reason)
|
raise exception.BadStoreUri(message=reason)
|
||||||
|
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ class Store(glance.store.base.Store):
|
|||||||
except rbd.ImageBusy:
|
except rbd.ImageBusy:
|
||||||
log_msg = _("snapshot %s@%s could not be "
|
log_msg = _("snapshot %s@%s could not be "
|
||||||
"unprotected because it is in use")
|
"unprotected because it is in use")
|
||||||
LOG.error(log_msg % (loc.image, loc.snapshot))
|
LOG.debug(log_msg % (loc.image, loc.snapshot))
|
||||||
raise exception.InUseByStore()
|
raise exception.InUseByStore()
|
||||||
image.remove_snap(loc.snapshot)
|
image.remove_snap(loc.snapshot)
|
||||||
try:
|
try:
|
||||||
@ -291,5 +291,5 @@ class Store(glance.store.base.Store):
|
|||||||
except rbd.ImageBusy:
|
except rbd.ImageBusy:
|
||||||
log_msg = _("image %s could not be removed"
|
log_msg = _("image %s could not be removed"
|
||||||
"because it is in use")
|
"because it is in use")
|
||||||
LOG.error(log_msg % loc.image)
|
LOG.debug(log_msg % loc.image)
|
||||||
raise exception.InUseByStore()
|
raise exception.InUseByStore()
|
||||||
|
@ -110,7 +110,7 @@ class StoreLocation(glance.store.location.StoreLocation):
|
|||||||
"s3+https:// scheme, like so: "
|
"s3+https:// scheme, like so: "
|
||||||
"s3+https://accesskey:secretkey@"
|
"s3+https://accesskey:secretkey@"
|
||||||
"s3.amazonaws.com/bucket/key-id")
|
"s3.amazonaws.com/bucket/key-id")
|
||||||
LOG.error(_("Invalid store uri %(uri)s: %(reason)s") % locals())
|
LOG.debug(_("Invalid store uri %(uri)s: %(reason)s") % locals())
|
||||||
raise exception.BadStoreUri(message=reason)
|
raise exception.BadStoreUri(message=reason)
|
||||||
|
|
||||||
pieces = urlparse.urlparse(uri)
|
pieces = urlparse.urlparse(uri)
|
||||||
@ -137,7 +137,7 @@ class StoreLocation(glance.store.location.StoreLocation):
|
|||||||
self.secretkey = secret_key
|
self.secretkey = secret_key
|
||||||
except IndexError:
|
except IndexError:
|
||||||
reason = _("Badly formed S3 credentials %s") % creds
|
reason = _("Badly formed S3 credentials %s") % creds
|
||||||
LOG.error(reason)
|
LOG.debug(reason)
|
||||||
raise exception.BadStoreUri()
|
raise exception.BadStoreUri()
|
||||||
else:
|
else:
|
||||||
self.accesskey = None
|
self.accesskey = None
|
||||||
@ -153,7 +153,7 @@ class StoreLocation(glance.store.location.StoreLocation):
|
|||||||
raise exception.BadStoreUri()
|
raise exception.BadStoreUri()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
reason = _("Badly formed S3 URI: %s") % uri
|
reason = _("Badly formed S3 URI: %s") % uri
|
||||||
LOG.error(reason)
|
LOG.debug(reason)
|
||||||
raise exception.BadStoreUri()
|
raise exception.BadStoreUri()
|
||||||
|
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ class Store(glance.store.base.Store):
|
|||||||
if not result:
|
if not result:
|
||||||
reason = _("Could not find %(param)s in configuration "
|
reason = _("Could not find %(param)s in configuration "
|
||||||
"options.") % locals()
|
"options.") % locals()
|
||||||
LOG.error(reason)
|
LOG.debug(reason)
|
||||||
raise exception.BadStoreConfiguration(store_name="s3",
|
raise exception.BadStoreConfiguration(store_name="s3",
|
||||||
reason=reason)
|
reason=reason)
|
||||||
return result
|
return result
|
||||||
@ -448,7 +448,7 @@ def get_bucket(conn, bucket_id):
|
|||||||
bucket = conn.get_bucket(bucket_id)
|
bucket = conn.get_bucket(bucket_id)
|
||||||
if not bucket:
|
if not bucket:
|
||||||
msg = _("Could not find bucket with ID %(bucket_id)s") % locals()
|
msg = _("Could not find bucket with ID %(bucket_id)s") % locals()
|
||||||
LOG.error(msg)
|
LOG.debug(msg)
|
||||||
raise exception.NotFound(msg)
|
raise exception.NotFound(msg)
|
||||||
|
|
||||||
return bucket
|
return bucket
|
||||||
@ -512,7 +512,7 @@ def get_key(bucket, obj):
|
|||||||
key = bucket.get_key(obj)
|
key = bucket.get_key(obj)
|
||||||
if not key or not key.exists():
|
if not key or not key.exists():
|
||||||
msg = _("Could not find key %(obj)s in bucket %(bucket)s") % locals()
|
msg = _("Could not find key %(obj)s in bucket %(bucket)s") % locals()
|
||||||
LOG.error(msg)
|
LOG.debug(msg)
|
||||||
raise exception.NotFound(msg)
|
raise exception.NotFound(msg)
|
||||||
return key
|
return key
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ class StoreLocation(glance.store.location.StoreLocation):
|
|||||||
", you need to change it to use the "
|
", you need to change it to use the "
|
||||||
"swift+http:// scheme, like so: "
|
"swift+http:// scheme, like so: "
|
||||||
"swift+http://user:pass@authurl.com/v1/container/obj")
|
"swift+http://user:pass@authurl.com/v1/container/obj")
|
||||||
LOG.error(_("Invalid store uri %(uri)s: %(reason)s") % locals())
|
LOG.debug(_("Invalid store uri %(uri)s: %(reason)s") % locals())
|
||||||
raise exception.BadStoreUri(message=reason)
|
raise exception.BadStoreUri(message=reason)
|
||||||
|
|
||||||
pieces = urlparse.urlparse(uri)
|
pieces = urlparse.urlparse(uri)
|
||||||
@ -162,7 +162,7 @@ class StoreLocation(glance.store.location.StoreLocation):
|
|||||||
if len(cred_parts) != 2:
|
if len(cred_parts) != 2:
|
||||||
reason = (_("Badly formed credentials '%(creds)s' in Swift "
|
reason = (_("Badly formed credentials '%(creds)s' in Swift "
|
||||||
"URI") % locals())
|
"URI") % locals())
|
||||||
LOG.error(reason)
|
LOG.debug(reason)
|
||||||
raise exception.BadStoreUri()
|
raise exception.BadStoreUri()
|
||||||
user, key = cred_parts
|
user, key = cred_parts
|
||||||
self.user = urllib.unquote(user)
|
self.user = urllib.unquote(user)
|
||||||
@ -180,7 +180,7 @@ class StoreLocation(glance.store.location.StoreLocation):
|
|||||||
self.auth_or_store_url = '/'.join(path_parts)
|
self.auth_or_store_url = '/'.join(path_parts)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
reason = _("Badly formed Swift URI: %s") % uri
|
reason = _("Badly formed Swift URI: %s") % uri
|
||||||
LOG.error(reason)
|
LOG.debug(reason)
|
||||||
raise exception.BadStoreUri()
|
raise exception.BadStoreUri()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -338,7 +338,7 @@ class Store(glance.store.base.Store):
|
|||||||
storage_url=loc.swift_url, token=self.token)
|
storage_url=loc.swift_url, token=self.token)
|
||||||
else:
|
else:
|
||||||
reason = (_("Location is missing user:password information."))
|
reason = (_("Location is missing user:password information."))
|
||||||
LOG.error(reason)
|
LOG.debug(reason)
|
||||||
raise exception.BadStoreUri(message=reason)
|
raise exception.BadStoreUri(message=reason)
|
||||||
|
|
||||||
def _make_swift_connection(self, auth_url, user, key, region=None,
|
def _make_swift_connection(self, auth_url, user, key, region=None,
|
||||||
@ -368,7 +368,7 @@ class Store(glance.store.base.Store):
|
|||||||
if len(tenant_user) != 2:
|
if len(tenant_user) != 2:
|
||||||
reason = (_("Badly formed tenant:user '%(tenant_user)s' in "
|
reason = (_("Badly formed tenant:user '%(tenant_user)s' in "
|
||||||
"Swift URI") % locals())
|
"Swift URI") % locals())
|
||||||
LOG.error(reason)
|
LOG.debug(reason)
|
||||||
raise exception.BadStoreUri()
|
raise exception.BadStoreUri()
|
||||||
(tenant_name, user) = tenant_user
|
(tenant_name, user) = tenant_user
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user