Fix string interpolation to delay by logging

String interpolation should be delayed to be handled
by the logging code, rather than being done
at the point of the logging call.

See the oslo i18n guideline.

* http://docs.openstack.org/developer/oslo.i18n/guidelines.html

Change-Id: I400a38a61e1ed6288296e8572218c7642795cbd4
Closes-Bug: #1596829
This commit is contained in:
weiweigu 2016-07-14 15:48:23 +08:00 committed by Sean McGinnis
parent 6bdaac00bb
commit 4889dc1814
9 changed files with 24 additions and 25 deletions

View File

@ -117,8 +117,8 @@ def get_remaining_quota(context, db_api, image_id=None):
if not match: if not match:
LOG.error(_LE("Invalid value for option user_storage_quota: " LOG.error(_LE("Invalid value for option user_storage_quota: "
"%(users_quota)s") "%(users_quota)s"),
% {'users_quota': users_quota}) {'users_quota': users_quota})
raise exception.InvalidOptionValue(option='user_storage_quota', raise exception.InvalidOptionValue(option='user_storage_quota',
value=users_quota) value=users_quota)
@ -166,8 +166,8 @@ def check_quota(context, image_size, db_api, image_id=None):
if remaining <= 0: if remaining <= 0:
LOG.warn(_LW("User %(user)s attempted to upload an image of" LOG.warn(_LW("User %(user)s attempted to upload an image of"
" unknown size that will exceed the quota." " unknown size that will exceed the quota."
" %(remaining)d bytes remaining.") " %(remaining)d bytes remaining."),
% {'user': user, 'remaining': remaining}) {'user': user, 'remaining': remaining})
raise exception.StorageQuotaFull(image_size=image_size, raise exception.StorageQuotaFull(image_size=image_size,
remaining=remaining) remaining=remaining)
return return
@ -175,8 +175,8 @@ def check_quota(context, image_size, db_api, image_id=None):
if image_size > remaining: if image_size > remaining:
LOG.warn(_LW("User %(user)s attempted to upload an image of size" LOG.warn(_LW("User %(user)s attempted to upload an image of size"
" %(size)d that will exceed the quota. %(remaining)d" " %(size)d that will exceed the quota. %(remaining)d"
" bytes remaining.") " bytes remaining."),
% {'user': user, 'size': image_size, 'remaining': remaining}) {'user': user, 'size': image_size, 'remaining': remaining})
raise exception.StorageQuotaFull(image_size=image_size, raise exception.StorageQuotaFull(image_size=image_size,
remaining=remaining) remaining=remaining)

View File

@ -272,7 +272,7 @@ class CacheFilter(wsgi.Middleware):
try: try:
process_response_method = getattr(self, method_str) process_response_method = getattr(self, method_str)
except AttributeError: except AttributeError:
LOG.error(_LE('could not find %s') % method_str) LOG.error(_LE('could not find %s'), method_str)
# Nothing to do here, move along # Nothing to do here, move along
return resp return resp
else: else:

View File

@ -73,7 +73,7 @@ def safe_kill(req, image_id, from_state):
try: try:
_kill(req, image_id, from_state) _kill(req, image_id, from_state)
except Exception: except Exception:
LOG.exception(_LE("Unable to kill image %(id)s: ") % {'id': image_id}) LOG.exception(_LE("Unable to kill image %(id)s: "), {'id': image_id})
def upload_data_to_store(req, image_meta, image_data, store, notifier): def upload_data_to_store(req, image_meta, image_data, store, notifier):
@ -172,7 +172,7 @@ def upload_data_to_store(req, image_meta, image_data, store, notifier):
# Delete image data due to possible token expiration. # Delete image data due to possible token expiration.
LOG.debug("Authentication error - the token may have " LOG.debug("Authentication error - the token may have "
"expired during file upload. Deleting image data for " "expired during file upload. Deleting image data for "
" %s " % image_id) " %s", image_id)
initiate_deletion(req, location_data, image_id) initiate_deletion(req, location_data, image_id)
raise webob.exc.HTTPUnauthorized(explanation=e.msg, request=req) raise webob.exc.HTTPUnauthorized(explanation=e.msg, request=req)
except exception.ImageNotFound: except exception.ImageNotFound:

View File

@ -82,8 +82,8 @@ def _load_strategies():
modules[strategy_name] = mgr.driver modules[strategy_name] = mgr.driver
except Exception as e: except Exception as e:
LOG.error(_LE("Failed to load location strategy module " LOG.error(_LE("Failed to load location strategy module "
"%(module)s: %(e)s") % {'module': module_name, "%(module)s: %(e)s"), {'module': module_name,
'e': e}) 'e': e})
return modules return modules

View File

@ -430,7 +430,7 @@ def _image_get(context, image_id, force_show_deleted=False, status=None):
try: try:
image = DATA['images'][image_id] image = DATA['images'][image_id]
except KeyError: except KeyError:
LOG.warn(_LW('Could not find image %s') % image_id) LOG.warn(_LW('Could not find image %s'), image_id)
raise exception.ImageNotFound() raise exception.ImageNotFound()
if image['deleted'] and not (force_show_deleted if image['deleted'] and not (force_show_deleted

View File

@ -46,7 +46,7 @@ class Prefetcher(base.CacheApp):
image_repo = self.gateway.get_repo(ctx) image_repo = self.gateway.get_repo(ctx)
image = image_repo.get(image_id) image = image_repo.get(image_id)
except exception.NotFound: except exception.NotFound:
LOG.warn(_LW("Image '%s' not found") % image_id) LOG.warning(_LW("Image '%s' not found"), image_id)
return False return False
if image.status != 'active': if image.status != 'active':

View File

@ -540,14 +540,13 @@ class ImageProxy(glance.domain.proxy.Image):
return data return data
except Exception as e: except Exception as e:
LOG.warn(_LW('Get image %(id)s data failed: ' LOG.warn(_LW('Get image %(id)s data failed: '
'%(err)s.') '%(err)s.'),
% {'id': self.image.image_id, {'id': self.image.image_id,
'err': encodeutils.exception_to_unicode(e)}) 'err': encodeutils.exception_to_unicode(e)})
err = e err = e
# tried all locations # tried all locations
LOG.error(_LE( LOG.error(_LE('Glance tried all active locations to get data for '
'Glance tried all active locations/stores to get data ' 'image %s but all have failed.'), self.image.image_id)
'for image %s but all have failed.') % self.image.image_id)
raise err raise err

View File

@ -122,12 +122,12 @@ class Controller(object):
v1_mode=True, **params) v1_mode=True, **params)
except exception.ImageNotFound: except exception.ImageNotFound:
LOG.warn(_LW("Invalid marker. Image %(id)s could not be " LOG.warn(_LW("Invalid marker. Image %(id)s could not be "
"found.") % {'id': params.get('marker')}) "found."), {'id': params.get('marker')})
msg = _("Invalid marker. Image could not be found.") msg = _("Invalid marker. Image could not be found.")
raise exc.HTTPBadRequest(explanation=msg) raise exc.HTTPBadRequest(explanation=msg)
except exception.Forbidden: except exception.Forbidden:
LOG.warn(_LW("Access denied to image %(id)s but returning " LOG.warn(_LW("Access denied to image %(id)s but returning "
"'not found'") % {'id': params.get('marker')}) "'not found'"), {'id': params.get('marker')})
msg = _("Invalid marker. Image could not be found.") msg = _("Invalid marker. Image could not be found.")
raise exc.HTTPBadRequest(explanation=msg) raise exc.HTTPBadRequest(explanation=msg)
except Exception: except Exception:
@ -370,7 +370,7 @@ class Controller(object):
" 'not found'"), {'id': id}) " 'not found'"), {'id': id})
raise exc.HTTPNotFound() raise exc.HTTPNotFound()
except Exception: except Exception:
LOG.exception(_LE("Unable to show image %s") % id) LOG.exception(_LE("Unable to show image %s"), id)
raise raise
return dict(image=make_image_dict(image)) return dict(image=make_image_dict(image))
@ -403,7 +403,7 @@ class Controller(object):
LOG.info(_LI("Image %(id)s not found"), {'id': id}) LOG.info(_LI("Image %(id)s not found"), {'id': id})
return exc.HTTPNotFound() return exc.HTTPNotFound()
except Exception: except Exception:
LOG.exception(_LE("Unable to delete image %s") % id) LOG.exception(_LE("Unable to delete image %s"), id)
raise raise
@utils.mutating @utils.mutating
@ -527,7 +527,7 @@ class Controller(object):
request=req, request=req,
content_type='text/plain') content_type='text/plain')
except Exception: except Exception:
LOG.exception(_LE("Unable to update image %s") % id) LOG.exception(_LE("Unable to update image %s"), id)
raise raise

View File

@ -386,7 +386,7 @@ class Scrubber(object):
else: else:
LOG.warn(_LW("One or more image locations couldn't be scrubbed " LOG.warn(_LW("One or more image locations couldn't be scrubbed "
"from backend. Leaving image '%s' in 'pending_delete'" "from backend. Leaving image '%s' in 'pending_delete'"
" status") % image_id) " status"), image_id)
def _delete_image_location_from_backend(self, image_id, loc_id, uri, def _delete_image_location_from_backend(self, image_id, loc_id, uri,
backend=None): backend=None):