Skip to content

Commit

Permalink
Audit error logging
Browse files Browse the repository at this point in the history
Reduce log level from error to info/debug in several cases
where users do something silly. The operator of Glance
does not need to be alerted with an ERROR log in these
cases.

Fixes bug 1079211.

Change-Id: I09d86c8727530cf58f22446493ef9c4789d5d6cb
  • Loading branch information
bcwaldon committed Nov 17, 2012
1 parent 6d57df0 commit d576f89
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 45 deletions.
40 changes: 16 additions & 24 deletions glance/api/v1/images.py
Expand Up @@ -29,6 +29,7 @@
HTTPBadRequest,
HTTPForbidden,
HTTPRequestEntityTooLarge,
HTTPInternalServerError,
HTTPServiceUnavailable)

from glance.api import common
Expand Down Expand Up @@ -273,7 +274,7 @@ def _validate_source(source, req):
if source.lower().startswith(scheme):
return source
msg = _("External sourcing not supported for store %s") % source
LOG.error(msg)
LOG.debug(msg)
raise HTTPBadRequest(explanation=msg,
request=req,
content_type="text/plain")
Expand Down Expand Up @@ -363,20 +364,20 @@ def _reserve(self, req, image_meta):
except exception.Duplicate:
msg = (_("An image with identifier %s already exists") %
image_meta['id'])
LOG.error(msg)
LOG.debug(msg)
raise HTTPConflict(explanation=msg,
request=req,
content_type="text/plain")
except exception.Invalid, e:
msg = (_("Failed to reserve image. Got error: %(e)s") % locals())
for line in msg.split('\n'):
LOG.error(line)
LOG.debug(line)
raise HTTPBadRequest(explanation=msg,
request=req,
content_type="text/plain")
except exception.Forbidden:
msg = _("Forbidden to reserve image.")
LOG.error(msg)
LOG.debug(msg)
raise HTTPForbidden(explanation=msg,
request=req,
content_type="text/plain")
Expand All @@ -403,7 +404,7 @@ def _upload(self, req, image_meta):
except Exception as e:
self._safe_kill(req, image_meta['id'])
msg = _("Copy from external source failed: %s") % e
LOG.error(msg)
LOG.debug(msg)
return
image_meta['size'] = image_size or image_meta['size']
else:
Expand All @@ -412,7 +413,7 @@ def _upload(self, req, image_meta):
except exception.InvalidContentType:
self._safe_kill(req, image_meta['id'])
msg = _("Content-Type must be application/octet-stream")
LOG.error(msg)
LOG.debug(msg)
raise HTTPBadRequest(explanation=msg)

image_data = req.body_file
Expand Down Expand Up @@ -443,7 +444,7 @@ def _upload(self, req, image_meta):
"checksum generated from uploaded image "
"(%(checksum)s) did not match. Setting image "
"status to 'killed'.") % locals()
LOG.error(msg)
LOG.debug(msg)
self._safe_kill(req, image_id)
raise HTTPBadRequest(explanation=msg,
content_type="text/plain",
Expand All @@ -465,13 +466,13 @@ def _upload(self, req, image_meta):

except exception.Duplicate, e:
msg = _("Attempt to upload duplicate image: %s") % e
LOG.error(msg)
LOG.debug(msg)
self._safe_kill(req, image_id)
raise HTTPConflict(explanation=msg, request=req)

except exception.Forbidden, e:
msg = _("Forbidden upload attempt: %s") % e
LOG.error(msg)
LOG.debug(msg)
self._safe_kill(req, image_id)
raise HTTPForbidden(explanation=msg,
request=req,
Expand Down Expand Up @@ -508,16 +509,9 @@ def _upload(self, req, image_meta):
raise e

except Exception, e:
tb_info = traceback.format_exc()
LOG.error(tb_info)

LOG.exception(_("Failed to upload image"))
self._safe_kill(req, image_id)

msg = _("Error uploading image: (%(class_name)s): "
"%(exc)s") % ({'class_name': e.__class__.__name__,
'exc': str(e)})

raise HTTPBadRequest(explanation=msg, request=req)
raise HTTPInternalServerError(request=req)

def _activate(self, req, image_id, location):
"""
Expand All @@ -541,8 +535,7 @@ def _activate(self, req, image_id, location):
except exception.Invalid, e:
msg = (_("Failed to activate image. Got error: %(e)s")
% locals())
for line in msg.split('\n'):
LOG.error(line)
LOG.debug(msg)
raise HTTPBadRequest(explanation=msg,
request=req,
content_type="text/plain")
Expand Down Expand Up @@ -770,8 +763,7 @@ def update(self, req, id, image_meta, image_data):
except exception.Invalid, e:
msg = (_("Failed to update image metadata. Got error: %(e)s")
% locals())
for line in msg.split('\n'):
LOG.error(line)
LOG.debug(msg)
raise HTTPBadRequest(explanation=msg,
request=req,
content_type="text/plain")
Expand Down Expand Up @@ -879,8 +871,8 @@ def get_store_or_400(self, request, scheme):
try:
return get_store_from_scheme(request.context, scheme)
except exception.UnknownScheme:
msg = _("Store for scheme %s not found")
LOG.error(msg % scheme)
msg = _("Store for scheme %s not found") % scheme
LOG.debug(msg)
raise HTTPBadRequest(explanation=msg,
request=request,
content_type='text/plain')
Expand Down
2 changes: 1 addition & 1 deletion glance/store/base.py
Expand Up @@ -42,7 +42,7 @@ def __init__(self, context=None):
except exception.BadStoreConfiguration:
msg = _("Failed to configure store correctly. "
"Disabling add method.")
LOG.error(msg)
LOG.info(msg)
self.add = self.add_disabled

def configure(self):
Expand Down
2 changes: 1 addition & 1 deletion glance/store/filesystem.py
Expand Up @@ -63,7 +63,7 @@ def parse_uri(self, uri):
path = (pieces.netloc + pieces.path).strip()
if path == '':
reason = _("No path specified in URI: %s") % uri
LOG.error(reason)
LOG.debug(reason)
raise exception.BadStoreUri('No path specified')
self.path = path

Expand Down
4 changes: 2 additions & 2 deletions glance/store/http.py
Expand Up @@ -81,13 +81,13 @@ def parse_uri(self, uri):
except ValueError:
reason = (_("Credentials '%s' not well-formatted.")
% "".join(creds))
LOG.error(reason)
LOG.debug(reason)
raise exception.BadStoreUri()
else:
self.user = None
if netloc == '':
reason = _("No address specified in HTTP URL")
LOG.error(reason)
LOG.debug(reason)
raise exception.BadStoreUri(message=reason)
self.netloc = netloc
self.path = path
Expand Down
12 changes: 6 additions & 6 deletions glance/store/rbd.py
Expand Up @@ -93,14 +93,14 @@ def parse_uri(self, uri):
prefix = 'rbd://'
if not uri.startswith(prefix):
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)
# convert to ascii since librbd doesn't handle unicode
try:
ascii_uri = str(uri)
except UnicodeError:
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)
pieces = ascii_uri[len(prefix):].split('/')
if len(pieces) == 1:
Expand All @@ -111,11 +111,11 @@ def parse_uri(self, uri):
map(urllib.unquote, pieces)
else:
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)
if any(map(lambda p: p == '', pieces)):
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)


Expand Down Expand Up @@ -280,7 +280,7 @@ def delete(self, location):
except rbd.ImageBusy:
log_msg = _("snapshot %s@%s could not be "
"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()
image.remove_snap(loc.snapshot)
try:
Expand All @@ -291,5 +291,5 @@ def delete(self, location):
except rbd.ImageBusy:
log_msg = _("image %s could not be removed"
"because it is in use")
LOG.error(log_msg % loc.image)
LOG.debug(log_msg % loc.image)
raise exception.InUseByStore()
12 changes: 6 additions & 6 deletions glance/store/s3.py
Expand Up @@ -110,7 +110,7 @@ def parse_uri(self, uri):
"s3+https:// scheme, like so: "
"s3+https://accesskey:secretkey@"
"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)

pieces = urlparse.urlparse(uri)
Expand All @@ -137,7 +137,7 @@ def parse_uri(self, uri):
self.secretkey = secret_key
except IndexError:
reason = _("Badly formed S3 credentials %s") % creds
LOG.error(reason)
LOG.debug(reason)
raise exception.BadStoreUri()
else:
self.accesskey = None
Expand All @@ -153,7 +153,7 @@ def parse_uri(self, uri):
raise exception.BadStoreUri()
except IndexError:
reason = _("Badly formed S3 URI: %s") % uri
LOG.error(reason)
LOG.debug(reason)
raise exception.BadStoreUri()


Expand Down Expand Up @@ -240,7 +240,7 @@ def _option_get(self, param):
if not result:
reason = _("Could not find %(param)s in configuration "
"options.") % locals()
LOG.error(reason)
LOG.debug(reason)
raise exception.BadStoreConfiguration(store_name="s3",
reason=reason)
return result
Expand Down Expand Up @@ -448,7 +448,7 @@ def get_bucket(conn, bucket_id):
bucket = conn.get_bucket(bucket_id)
if not bucket:
msg = _("Could not find bucket with ID %(bucket_id)s") % locals()
LOG.error(msg)
LOG.debug(msg)
raise exception.NotFound(msg)

return bucket
Expand Down Expand Up @@ -512,7 +512,7 @@ def get_key(bucket, obj):
key = bucket.get_key(obj)
if not key or not key.exists():
msg = _("Could not find key %(obj)s in bucket %(bucket)s") % locals()
LOG.error(msg)
LOG.debug(msg)
raise exception.NotFound(msg)
return key

Expand Down
10 changes: 5 additions & 5 deletions glance/store/swift.py
Expand Up @@ -134,7 +134,7 @@ def parse_uri(self, uri):
", you need to change it to use the "
"swift+http:// scheme, like so: "
"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)

pieces = urlparse.urlparse(uri)
Expand Down Expand Up @@ -162,7 +162,7 @@ def parse_uri(self, uri):
if len(cred_parts) != 2:
reason = (_("Badly formed credentials '%(creds)s' in Swift "
"URI") % locals())
LOG.error(reason)
LOG.debug(reason)
raise exception.BadStoreUri()
user, key = cred_parts
self.user = urllib.unquote(user)
Expand All @@ -180,7 +180,7 @@ def parse_uri(self, uri):
self.auth_or_store_url = '/'.join(path_parts)
except IndexError:
reason = _("Badly formed Swift URI: %s") % uri
LOG.error(reason)
LOG.debug(reason)
raise exception.BadStoreUri()

@property
Expand Down Expand Up @@ -338,7 +338,7 @@ def _swift_connection_for_location(self, loc):
storage_url=loc.swift_url, token=self.token)
else:
reason = (_("Location is missing user:password information."))
LOG.error(reason)
LOG.debug(reason)
raise exception.BadStoreUri(message=reason)

def _make_swift_connection(self, auth_url, user, key, region=None,
Expand Down Expand Up @@ -368,7 +368,7 @@ def _make_swift_connection(self, auth_url, user, key, region=None,
if len(tenant_user) != 2:
reason = (_("Badly formed tenant:user '%(tenant_user)s' in "
"Swift URI") % locals())
LOG.error(reason)
LOG.debug(reason)
raise exception.BadStoreUri()
(tenant_name, user) = tenant_user

Expand Down

0 comments on commit d576f89

Please sign in to comment.