From d576f897bcf4877a478ced10af05e3c79455e02a Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Fri, 16 Nov 2012 16:23:34 -0800 Subject: [PATCH] Audit error logging 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 --- glance/api/v1/images.py | 40 +++++++++++++++----------------------- glance/store/base.py | 2 +- glance/store/filesystem.py | 2 +- glance/store/http.py | 4 ++-- glance/store/rbd.py | 12 ++++++------ glance/store/s3.py | 12 ++++++------ glance/store/swift.py | 10 +++++----- 7 files changed, 37 insertions(+), 45 deletions(-) diff --git a/glance/api/v1/images.py b/glance/api/v1/images.py index cd3cf35cfd..4ebc5d01db 100644 --- a/glance/api/v1/images.py +++ b/glance/api/v1/images.py @@ -29,6 +29,7 @@ from webob.exc import (HTTPError, HTTPBadRequest, HTTPForbidden, HTTPRequestEntityTooLarge, + HTTPInternalServerError, HTTPServiceUnavailable) from glance.api import common @@ -273,7 +274,7 @@ class Controller(controller.BaseController): 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") @@ -363,20 +364,20 @@ class Controller(controller.BaseController): 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") @@ -403,7 +404,7 @@ class Controller(controller.BaseController): 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: @@ -412,7 +413,7 @@ class Controller(controller.BaseController): 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 @@ -443,7 +444,7 @@ class Controller(controller.BaseController): "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", @@ -465,13 +466,13 @@ class Controller(controller.BaseController): 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, @@ -508,16 +509,9 @@ class Controller(controller.BaseController): 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): """ @@ -541,8 +535,7 @@ class Controller(controller.BaseController): 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") @@ -770,8 +763,7 @@ class Controller(controller.BaseController): 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") @@ -879,8 +871,8 @@ class Controller(controller.BaseController): 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') diff --git a/glance/store/base.py b/glance/store/base.py index 992bed632f..4e659cbdd0 100644 --- a/glance/store/base.py +++ b/glance/store/base.py @@ -42,7 +42,7 @@ class Store(object): 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): diff --git a/glance/store/filesystem.py b/glance/store/filesystem.py index 1e08c7a13f..c3d6f17f28 100644 --- a/glance/store/filesystem.py +++ b/glance/store/filesystem.py @@ -63,7 +63,7 @@ class StoreLocation(glance.store.location.StoreLocation): 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 diff --git a/glance/store/http.py b/glance/store/http.py index 26778ca4d5..9585733a68 100644 --- a/glance/store/http.py +++ b/glance/store/http.py @@ -81,13 +81,13 @@ class StoreLocation(glance.store.location.StoreLocation): 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 diff --git a/glance/store/rbd.py b/glance/store/rbd.py index 389ee10cb9..8330ff2308 100644 --- a/glance/store/rbd.py +++ b/glance/store/rbd.py @@ -93,14 +93,14 @@ class StoreLocation(glance.store.location.StoreLocation): 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: @@ -111,11 +111,11 @@ class StoreLocation(glance.store.location.StoreLocation): 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) @@ -280,7 +280,7 @@ class Store(glance.store.base.Store): 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: @@ -291,5 +291,5 @@ class Store(glance.store.base.Store): 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() diff --git a/glance/store/s3.py b/glance/store/s3.py index f924caec26..a454928c1c 100644 --- a/glance/store/s3.py +++ b/glance/store/s3.py @@ -110,7 +110,7 @@ class StoreLocation(glance.store.location.StoreLocation): "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) @@ -137,7 +137,7 @@ class StoreLocation(glance.store.location.StoreLocation): 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 @@ -153,7 +153,7 @@ class StoreLocation(glance.store.location.StoreLocation): raise exception.BadStoreUri() except IndexError: reason = _("Badly formed S3 URI: %s") % uri - LOG.error(reason) + LOG.debug(reason) raise exception.BadStoreUri() @@ -240,7 +240,7 @@ class Store(glance.store.base.Store): 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 @@ -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 @@ -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 diff --git a/glance/store/swift.py b/glance/store/swift.py index 984af34377..5c4bb440d3 100644 --- a/glance/store/swift.py +++ b/glance/store/swift.py @@ -134,7 +134,7 @@ class StoreLocation(glance.store.location.StoreLocation): ", 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) @@ -162,7 +162,7 @@ class StoreLocation(glance.store.location.StoreLocation): 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) @@ -180,7 +180,7 @@ class StoreLocation(glance.store.location.StoreLocation): 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 @@ -338,7 +338,7 @@ class Store(glance.store.base.Store): 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, @@ -368,7 +368,7 @@ class Store(glance.store.base.Store): 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