From 0a5b5117291ff1fba4838ac873a4cfb7225c8ea7 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 29 Nov 2021 16:37:38 +0900 Subject: [PATCH] Use LOG.warning instead of deprecated LOG.warn The LOG.warn method is deprecated[1] and the LOG.warning method should be used instead. [1] https://docs.python.org/3/library/logging.html#logging.warning Change-Id: Ie0cac63dedf69728392f293f4551e495aebf4d40 --- HACKING.rst | 1 + glance/api/common.py | 16 +++++------ glance/api/middleware/context.py | 2 +- glance/api/v2/image_data.py | 2 +- glance/api/v2/images.py | 18 ++++++------ glance/api/v2/tasks.py | 10 +++---- glance/async_/flows/convert.py | 2 +- glance/async_/flows/ovf_process.py | 15 +++++----- glance/async_/utils.py | 2 +- glance/cmd/replicator.py | 24 ++++++++-------- glance/common/location_strategy/__init__.py | 2 +- glance/common/property_utils.py | 2 +- .../common/scripts/api_image_import/main.py | 6 ++-- glance/common/scripts/image_import/main.py | 7 +++-- glance/common/store_utils.py | 4 +-- glance/common/wsgi.py | 2 +- glance/db/simple/api.py | 28 +++++++++---------- glance/db/sqlalchemy/api.py | 10 +++---- glance/db/sqlalchemy/metadef_api/namespace.py | 2 +- glance/db/sqlalchemy/metadef_api/object.py | 2 +- glance/db/sqlalchemy/metadef_api/property.py | 2 +- glance/db/sqlalchemy/metadef_api/tag.py | 2 +- glance/domain/__init__.py | 2 +- glance/hacking/checks.py | 13 +++++++++ glance/image_cache/__init__.py | 20 ++++++------- glance/image_cache/drivers/sqlite.py | 15 +++++----- glance/image_cache/prefetcher.py | 7 +++-- glance/location.py | 8 +++--- glance/scrubber.py | 6 ++-- glance/tests/test_hacking.py | 12 ++++++++ tox.ini | 1 + 31 files changed, 138 insertions(+), 107 deletions(-) diff --git a/HACKING.rst b/HACKING.rst index b0aa39efe5..202c850882 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -20,3 +20,4 @@ glance Specific Commandments - [G328] Must use a dict comprehension instead of a dict constructor with a sequence of key-value pairs - [G329] Python 3: Do not use xrange. +- [G330] Log.warn is deprecated. Enforce use of LOG.warning. diff --git a/glance/api/common.py b/glance/api/common.py index 00cbd5d23b..c47a065e35 100644 --- a/glance/api/common.py +++ b/glance/api/common.py @@ -170,19 +170,19 @@ def check_quota(context, image_size, db_api, image_id=None): # exception is when there is no room left at all, thus we know # it will not fit if remaining <= 0: - LOG.warn(_LW("User %(user)s attempted to upload an image of" - " unknown size that will exceed the quota." - " %(remaining)d bytes remaining."), - {'user': user, 'remaining': remaining}) + LOG.warning(_LW("User %(user)s attempted to upload an image of" + " unknown size that will exceed the quota." + " %(remaining)d bytes remaining."), + {'user': user, 'remaining': remaining}) raise exception.StorageQuotaFull(image_size=image_size, remaining=remaining) return if image_size > remaining: - LOG.warn(_LW("User %(user)s attempted to upload an image of size" - " %(size)d that will exceed the quota. %(remaining)d" - " bytes remaining."), - {'user': user, 'size': image_size, 'remaining': remaining}) + LOG.warning(_LW("User %(user)s attempted to upload an image of size" + " %(size)d that will exceed the quota. %(remaining)d" + " bytes remaining."), + {'user': user, 'size': image_size, 'remaining': remaining}) raise exception.StorageQuotaFull(image_size=image_size, remaining=remaining) diff --git a/glance/api/middleware/context.py b/glance/api/middleware/context.py index 3e06ebfcec..13d0487352 100644 --- a/glance/api/middleware/context.py +++ b/glance/api/middleware/context.py @@ -73,7 +73,7 @@ class BaseContextMiddleware(wsgi.Middleware): try: request_id = resp.request.context.request_id except AttributeError: - LOG.warn(_LW('Unable to retrieve request id from context')) + LOG.warning(_LW('Unable to retrieve request id from context')) else: # For python 3 compatibility need to use bytes type prefix = b'req-' if isinstance(request_id, bytes) else 'req-' diff --git a/glance/api/v2/image_data.py b/glance/api/v2/image_data.py index 1f8c2519b6..8134838299 100644 --- a/glance/api/v2/image_data.py +++ b/glance/api/v2/image_data.py @@ -189,7 +189,7 @@ class ImageDataController(object): "The image may have been deleted during the " "upload, cleaning up the chunks uploaded.") % image_id) - LOG.warn(msg) + LOG.warning(msg) # NOTE(sridevi): Cleaning up the uploaded chunks. try: image.delete() diff --git a/glance/api/v2/images.py b/glance/api/v2/images.py index 97bae73da1..8c550dbd17 100644 --- a/glance/api/v2/images.py +++ b/glance/api/v2/images.py @@ -116,7 +116,7 @@ class ImagesController(object): LOG.debug("User not permitted to create image") raise webob.exc.HTTPForbidden(explanation=e.msg) except exception.LimitExceeded as e: - LOG.warn(encodeutils.exception_to_unicode(e)) + LOG.warning(encodeutils.exception_to_unicode(e)) raise webob.exc.HTTPRequestEntityTooLarge( explanation=e.msg, request=req, content_type='text/plain') except exception.Duplicate as e: @@ -379,7 +379,7 @@ class ImagesController(object): try: stores = utils.get_stores_from_request(req, body) except glance_store.UnknownScheme as exc: - LOG.warn(exc.msg) + LOG.warning(exc.msg) raise exception.Conflict(exc.msg) # NOTE(abhishekk): If all_stores is specified and import_method is @@ -625,7 +625,7 @@ class ImagesController(object): except exception.StorageQuotaFull as e: msg = (_("Denying attempt to upload image because it exceeds the" " quota: %s") % encodeutils.exception_to_unicode(e)) - LOG.warn(msg) + LOG.warning(msg) raise webob.exc.HTTPRequestEntityTooLarge( explanation=msg, request=req, content_type='text/plain') except exception.LimitExceeded as e: @@ -717,14 +717,14 @@ class ImagesController(object): except castellan_exception.Forbidden: msg = ('Not allowed to delete encryption key %s' % cinder_encryption_key_id) - LOG.warn(msg) + LOG.warning(msg) except (castellan_exception.ManagedObjectNotFoundError, KeyError): msg = 'Could not find encryption key %s' % cinder_encryption_key_id - LOG.warn(msg) + LOG.warning(msg) except castellan_exception.KeyManagerError: msg = ('Failed to delete cinder encryption key %s' % cinder_encryption_key_id) - LOG.warn(msg) + LOG.warning(msg) @utils.mutating def delete_from_store(self, req, store_id, image_id): @@ -910,14 +910,14 @@ class ImagesController(object): except (glance_store.NotFound, exception.NotFound): msg = (_("Failed to find image %(image_id)s to delete") % {'image_id': image_id}) - LOG.warn(msg) + LOG.warning(msg) raise webob.exc.HTTPNotFound(explanation=msg) except glance_store.exceptions.InUseByStore as e: msg = (_("Image %(id)s could not be deleted " "because it is in use: %(exc)s") % {"id": image_id, "exc": e.msg}) - LOG.warn(msg) + LOG.warning(msg) raise webob.exc.HTTPConflict(explanation=msg) except glance_store.exceptions.HasSnapshot as e: raise webob.exc.HTTPConflict(explanation=e.msg) @@ -1926,7 +1926,7 @@ def load_custom_properties(): else: msg = (_LW('Could not find schema properties file %s. Continuing ' 'without custom properties') % filename) - LOG.warn(msg) + LOG.warning(msg) return {} diff --git a/glance/api/v2/tasks.py b/glance/api/v2/tasks.py index 5bc78e58bb..3f5f837a31 100644 --- a/glance/api/v2/tasks.py +++ b/glance/api/v2/tasks.py @@ -92,7 +92,7 @@ class TasksController(object): except exception.Forbidden as e: msg = (_LW("Forbidden to create task. Reason: %(reason)s") % {'reason': encodeutils.exception_to_unicode(e)}) - LOG.warn(msg) + LOG.warning(msg) raise webob.exc.HTTPForbidden(explanation=e.msg) return new_task @@ -119,10 +119,10 @@ class TasksController(object): result['next_marker'] = tasks[-1].task_id except (exception.NotFound, exception.InvalidSortKey, exception.InvalidFilterRangeValue) as e: - LOG.warn(encodeutils.exception_to_unicode(e)) + LOG.warning(encodeutils.exception_to_unicode(e)) raise webob.exc.HTTPBadRequest(explanation=e.msg) except exception.Forbidden as e: - LOG.warn(encodeutils.exception_to_unicode(e)) + LOG.warning(encodeutils.exception_to_unicode(e)) raise webob.exc.HTTPForbidden(explanation=e.msg) result['tasks'] = tasks return result @@ -138,14 +138,14 @@ class TasksController(object): msg = (_LW("Failed to find task %(task_id)s. Reason: %(reason)s") % {'task_id': task_id, 'reason': encodeutils.exception_to_unicode(e)}) - LOG.warn(msg) + LOG.warning(msg) raise webob.exc.HTTPNotFound(explanation=e.msg) except exception.Forbidden as e: msg = (_LW("Forbidden to get task %(task_id)s. Reason:" " %(reason)s") % {'task_id': task_id, 'reason': encodeutils.exception_to_unicode(e)}) - LOG.warn(msg) + LOG.warning(msg) raise webob.exc.HTTPForbidden(explanation=e.msg) return task diff --git a/glance/async_/flows/convert.py b/glance/async_/flows/convert.py index 5dcf5a3bf4..c1faf871df 100644 --- a/glance/async_/flows/convert.py +++ b/glance/async_/flows/convert.py @@ -98,7 +98,7 @@ class _Convert(task.Task): msg = _LW('The conversion format is None, please add a value ' 'for it in the config file for this task to ' 'work: %s') - LOG.warn(msg, self.task_id) + LOG.warning(msg, self.task_id) _Convert.conversion_missing_warned = True return diff --git a/glance/async_/flows/ovf_process.py b/glance/async_/flows/ovf_process.py index 5e2b2e9d24..06b5c8b8c9 100644 --- a/glance/async_/flows/ovf_process.py +++ b/glance/async_/flows/ovf_process.py @@ -252,14 +252,15 @@ class OVAImageExtractor(object): self.interested_properties = properties.get( 'cim_pasd', []) if not self.interested_properties: - LOG.warn(_LW('OVF metadata of interest was not specified ' - 'in ovf-metadata.json config file. Please ' - 'set "cim_pasd" to a list of interested ' - 'CIM_ProcessorAllocationSettingData ' - 'properties.')) + msg = _LW('OVF metadata of interest was not specified ' + 'in ovf-metadata.json config file. Please ' + 'set "cim_pasd" to a list of interested ' + 'CIM_ProcessorAllocationSettingData ' + 'properties.') + LOG.warning(msg) else: - LOG.warn(_LW('OVF properties config file "ovf-metadata.json" was ' - 'not found.')) + LOG.warning(_LW('OVF properties config file "ovf-metadata.json" ' + 'was not found.')) def get_flow(**kwargs): diff --git a/glance/async_/utils.py b/glance/async_/utils.py index 014d06ef17..f4214a6c32 100644 --- a/glance/async_/utils.py +++ b/glance/async_/utils.py @@ -75,5 +75,5 @@ class OptionalTask(task.Task): msg = (_LW("An optional task has failed, " "the failure was: %s") % encodeutils.exception_to_unicode(exc)) - LOG.warn(msg) + LOG.warning(msg) return wrapper diff --git a/glance/cmd/replicator.py b/glance/cmd/replicator.py index 3d46496929..8aef036449 100644 --- a/glance/cmd/replicator.py +++ b/glance/cmd/replicator.py @@ -636,24 +636,24 @@ def replication_compare(options, args): for key in image: if image[key] != headers.get(key): - LOG.warn(_LW('%(image_id)s: field %(key)s differs ' - '(source is %(source_value)s, destination ' - 'is %(target_value)s)') - % {'image_id': image['id'], - 'key': key, - 'source_value': image[key], - 'target_value': headers.get(key, - 'undefined')}) + LOG.warning(_LW('%(image_id)s: field %(key)s differs ' + '(source is %(source_value)s, destination ' + 'is %(target_value)s)') + % {'image_id': image['id'], + 'key': key, + 'source_value': image[key], + 'target_value': headers.get(key, + 'undefined')}) differences[image['id']] = 'diff' else: LOG.debug('%(image_id)s is identical', {'image_id': image['id']}) elif image['status'] == 'active': - LOG.warn(_LW('Image %(image_id)s ("%(image_name)s") ' - 'entirely missing from the destination') - % {'image_id': image['id'], - 'image_name': image.get('name', '--unnamed')}) + LOG.warning(_LW('Image %(image_id)s ("%(image_name)s") ' + 'entirely missing from the destination') + % {'image_id': image['id'], + 'image_name': image.get('name', '--unnamed')}) differences[image['id']] = 'missing' return differences diff --git a/glance/common/location_strategy/__init__.py b/glance/common/location_strategy/__init__.py index dd4bc7b4d6..f7bfe197b8 100644 --- a/glance/common/location_strategy/__init__.py +++ b/glance/common/location_strategy/__init__.py @@ -75,7 +75,7 @@ def _load_strategies(): msg = (_('%(strategy)s is registered as a module twice. ' '%(module)s is not being used.') % {'strategy': strategy_name, 'module': module_name}) - LOG.warn(msg) + LOG.warning(msg) else: # Initialize strategy module mgr.driver.init() diff --git a/glance/common/property_utils.py b/glance/common/property_utils.py index c9befa88dd..928cf1013e 100644 --- a/glance/common/property_utils.py +++ b/glance/common/property_utils.py @@ -164,7 +164,7 @@ class PropertyRules(object): property_dict[operation] = permissions else: property_dict[operation] = [] - LOG.warn( + LOG.warning( _LW('Property protection on operation %(operation)s' ' for rule %(rule)s is not found. No role will be' ' allowed to perform this operation.') % diff --git a/glance/common/scripts/api_image_import/main.py b/glance/common/scripts/api_image_import/main.py index 38d3be055e..5b531d7c89 100644 --- a/glance/common/scripts/api_image_import/main.py +++ b/glance/common/scripts/api_image_import/main.py @@ -125,9 +125,9 @@ def set_image_data(image, uri, task_id, backend=None): image.set_data(data_iter, backend=backend) except Exception as e: with excutils.save_and_reraise_exception(): - LOG.warn("Task %(task_id)s failed with exception %(error)s" % - {"error": encodeutils.exception_to_unicode(e), - "task_id": task_id}) + LOG.warning("Task %(task_id)s failed with exception %(error)s" % + {"error": encodeutils.exception_to_unicode(e), + "task_id": task_id}) LOG.info("Task %(task_id)s: Could not import image file" " %(image_data)s", {"image_data": uri, "task_id": task_id}) diff --git a/glance/common/scripts/image_import/main.py b/glance/common/scripts/image_import/main.py index 9b624920db..b80f738294 100644 --- a/glance/common/scripts/image_import/main.py +++ b/glance/common/scripts/image_import/main.py @@ -152,9 +152,10 @@ def set_image_data(image, uri, task_id, backend=None, set_active=True, image.set_data(data_iter, backend=backend, set_active=set_active) except Exception as e: with excutils.save_and_reraise_exception(): - LOG.warn(_LW("Task %(task_id)s failed with exception %(error)s") % - {"error": encodeutils.exception_to_unicode(e), - "task_id": task_id}) + LOG.warning(_LW("Task %(task_id)s failed with exception " + "%(error)s") % + {"error": encodeutils.exception_to_unicode(e), + "task_id": task_id}) LOG.info(_LI("Task %(task_id)s: Could not import image file" " %(image_data)s"), {"image_data": uri, "task_id": task_id}) diff --git a/glance/common/store_utils.py b/glance/common/store_utils.py index ac5ccbee7a..abde406c1f 100644 --- a/glance/common/store_utils.py +++ b/glance/common/store_utils.py @@ -70,9 +70,9 @@ def safe_delete_from_backend(context, image_id, location): msg = ("The image data for %(iid)s was not found in the store. " "The image record has been updated to reflect " "this." % {'iid': image_id}) - LOG.warn(msg) + LOG.warning(msg) except store_api.StoreDeleteNotSupported as e: - LOG.warn(encodeutils.exception_to_unicode(e)) + LOG.warning(encodeutils.exception_to_unicode(e)) except store_api.UnsupportedBackend: exc_type = sys.exc_info()[0].__name__ msg = (_LE('Failed to delete image %(image_id)s from store: %(exc)s') % diff --git a/glance/common/wsgi.py b/glance/common/wsgi.py index 820e18b598..d6ee9656ff 100644 --- a/glance/common/wsgi.py +++ b/glance/common/wsgi.py @@ -674,7 +674,7 @@ class PosixServer(BaseServer): self.stale_children.remove(pid) LOG.info(_LI('Removed stale child %s'), pid) else: - LOG.warn(_LW('Unrecognised child %s') % pid) + LOG.warning(_LW('Unrecognised child %s') % pid) def _verify_and_respawn_children(self, pid, status): if len(self.stale_children) == 0: diff --git a/glance/db/simple/api.py b/glance/db/simple/api.py index 10f77c48dc..12f0b0b90b 100644 --- a/glance/db/simple/api.py +++ b/glance/db/simple/api.py @@ -432,7 +432,7 @@ def image_set_property_atomic(image_id, name, value): try: image = DATA['images'][image_id] except KeyError: - LOG.warn(_LW('Could not find image %s'), image_id) + LOG.warning(_LW('Could not find image %s'), image_id) raise exception.ImageNotFound() prop = _image_property_format(image_id, @@ -445,7 +445,7 @@ def image_delete_property_atomic(image_id, name, value): try: image = DATA['images'][image_id] except KeyError: - LOG.warn(_LW('Could not find image %s'), image_id) + LOG.warning(_LW('Could not find image %s'), image_id) raise exception.ImageNotFound() for i, prop in enumerate(image['properties']): @@ -460,16 +460,16 @@ def _image_get(context, image_id, force_show_deleted=False, status=None): try: image = DATA['images'][image_id] except KeyError: - LOG.warn(_LW('Could not find image %s'), image_id) + LOG.warning(_LW('Could not find image %s'), image_id) raise exception.ImageNotFound() if image['deleted'] and not (force_show_deleted or context.can_see_deleted): - LOG.warn(_LW('Unable to get deleted image')) + LOG.warning(_LW('Unable to get deleted image')) raise exception.ImageNotFound() if not is_image_visible(context, image): - LOG.warn(_LW('Unable to get unowned image')) + LOG.warning(_LW('Unable to get unowned image')) raise exception.Forbidden("Image not visible to you") return image @@ -676,7 +676,7 @@ def image_location_update(context, image_id, location): if not updated: msg = (_("No location found with ID %(loc)s from image %(img)s") % dict(loc=loc_id, img=image_id)) - LOG.warn(msg) + LOG.warning(msg) raise exception.NotFound(msg) @@ -702,7 +702,7 @@ def image_location_delete(context, image_id, location_id, status, if not deleted: msg = (_("No location found with ID %(loc)s from image %(img)s") % dict(loc=location_id, img=image_id)) - LOG.warn(msg) + LOG.warning(msg) raise exception.NotFound(msg) @@ -990,12 +990,12 @@ def _task_get(context, task_id, force_show_deleted=False): task = DATA['tasks'][task_id] except KeyError: msg = _LW('Could not find task %s') % task_id - LOG.warn(msg) + LOG.warning(msg) raise exception.TaskNotFound(task_id=task_id) if task['deleted'] and not (force_show_deleted or context.can_see_deleted): msg = _LW('Unable to get deleted task %s') % task_id - LOG.warn(msg) + LOG.warning(msg) raise exception.TaskNotFound(task_id=task_id) if not _is_task_visible(context, task): @@ -1171,7 +1171,7 @@ def _task_info_get(task_id): task_info = DATA['task_info'][task_id] except KeyError: msg = _LW('Could not find task info %s') % task_id - LOG.warn(msg) + LOG.warning(msg) raise exception.TaskNotFound(task_id=task_id) return task_info @@ -1257,7 +1257,7 @@ def metadef_namespace_get_by_id(context, namespace_id): except StopIteration: msg = (_("Metadata definition namespace not found for id=%s") % namespace_id) - LOG.warn(msg) + LOG.warning(msg) raise exception.MetadefNamespaceNotFound(msg) if not _is_namespace_visible(context, namespace): @@ -1388,7 +1388,7 @@ def metadef_object_get_by_id(context, namespace_name, object_id): else: msg = (_("Metadata definition object not found for id=%s") % object_id) - LOG.warn(msg) + LOG.warning(msg) raise exception.MetadefObjectNotFound(msg) @@ -1644,7 +1644,7 @@ def metadef_property_get_by_id(context, namespace_name, property_id): else: msg = (_("Metadata definition property not found for id=%s") % property_id) - LOG.warn(msg) + LOG.warning(msg) raise exception.MetadefPropertyNotFound(msg) @@ -1849,7 +1849,7 @@ def metadef_tag_get_by_id(context, namespace_name, id): return tag else: msg = (_("Metadata definition tag not found for id=%s") % id) - LOG.warn(msg) + LOG.warning(msg) raise exception.MetadefTagNotFound(msg) diff --git a/glance/db/sqlalchemy/api.py b/glance/db/sqlalchemy/api.py index 7df5f19697..47eb1038e8 100644 --- a/glance/db/sqlalchemy/api.py +++ b/glance/db/sqlalchemy/api.py @@ -75,7 +75,7 @@ def _retry_on_deadlock(exc): """Decorator to retry a DB API call if Deadlock was received.""" if isinstance(exc, db_exception.DBDeadlock): - LOG.warn(_LW("Deadlock detected. Retrying...")) + LOG.warning(_LW("Deadlock detected. Retrying...")) return True return False @@ -132,7 +132,7 @@ def clear_db_env(): def _check_mutate_authorization(context, image_ref): if not is_image_mutable(context, image_ref): - LOG.warn(_LW("Attempted to modify image user did not own.")) + LOG.warning(_LW("Attempted to modify image user did not own.")) msg = _("You do not own this image") if image_ref.visibility in ['private', 'shared']: exc_class = exception.Forbidden @@ -365,7 +365,7 @@ def _paginate_query(query, model, limit, sort_keys, marker=None, if 'id' not in sort_keys: # TODO(justinsb): If this ever gives a false-positive, check # the actual primary key, rather than assuming its id - LOG.warn(_LW('Id not in sort_keys; is sort_keys unique?')) + LOG.warning(_LW('Id not in sort_keys; is sort_keys unique?')) assert(not (sort_dir and sort_dirs)) # nosec # nosec: This function runs safely if the assertion fails. @@ -1087,7 +1087,7 @@ def image_location_update(context, image_id, location, session=None): except sa_orm.exc.NoResultFound: msg = (_("No location found with ID %(loc)s from image %(img)s") % dict(loc=loc_id, img=image_id)) - LOG.warn(msg) + LOG.warning(msg) raise exception.NotFound(msg) @@ -1113,7 +1113,7 @@ def image_location_delete(context, image_id, location_id, status, except sa_orm.exc.NoResultFound: msg = (_("No location found with ID %(loc)s from image %(img)s") % dict(loc=location_id, img=image_id)) - LOG.warn(msg) + LOG.warning(msg) raise exception.NotFound(msg) diff --git a/glance/db/sqlalchemy/metadef_api/namespace.py b/glance/db/sqlalchemy/metadef_api/namespace.py index 8933751148..cc1e679fcd 100644 --- a/glance/db/sqlalchemy/metadef_api/namespace.py +++ b/glance/db/sqlalchemy/metadef_api/namespace.py @@ -87,7 +87,7 @@ def _get(context, namespace_id, session): except sa_orm.exc.NoResultFound: msg = (_("Metadata definition namespace not found for id=%s") % namespace_id) - LOG.warn(msg) + LOG.warning(msg) raise exc.MetadefNamespaceNotFound(msg) # Make sure they are allowed to view it. diff --git a/glance/db/sqlalchemy/metadef_api/object.py b/glance/db/sqlalchemy/metadef_api/object.py index 48862522fe..49b1a185f8 100644 --- a/glance/db/sqlalchemy/metadef_api/object.py +++ b/glance/db/sqlalchemy/metadef_api/object.py @@ -34,7 +34,7 @@ def _get(context, object_id, session): except sa_orm.exc.NoResultFound: msg = (_("Metadata definition object not found for id=%s") % object_id) - LOG.warn(msg) + LOG.warning(msg) raise exc.MetadefObjectNotFound(msg) return metadef_object diff --git a/glance/db/sqlalchemy/metadef_api/property.py b/glance/db/sqlalchemy/metadef_api/property.py index eba5c0fc30..779c0c3c69 100644 --- a/glance/db/sqlalchemy/metadef_api/property.py +++ b/glance/db/sqlalchemy/metadef_api/property.py @@ -36,7 +36,7 @@ def _get(context, property_id, session): except sa_orm.exc.NoResultFound: msg = (_("Metadata definition property not found for id=%s") % property_id) - LOG.warn(msg) + LOG.warning(msg) raise exc.MetadefPropertyNotFound(msg) return property_rec diff --git a/glance/db/sqlalchemy/metadef_api/tag.py b/glance/db/sqlalchemy/metadef_api/tag.py index 556ef7887f..fac0728b6a 100644 --- a/glance/db/sqlalchemy/metadef_api/tag.py +++ b/glance/db/sqlalchemy/metadef_api/tag.py @@ -34,7 +34,7 @@ def _get(context, id, session): metadef_tag = query.one() except sa_orm.exc.NoResultFound: msg = (_LW("Metadata tag not found for id %s") % id) - LOG.warn(msg) + LOG.warning(msg) raise exc.MetadefTagNotFound(message=msg) return metadef_tag diff --git a/glance/domain/__init__.py b/glance/domain/__init__.py index 3054088d72..92ff071065 100644 --- a/glance/domain/__init__.py +++ b/glance/domain/__init__.py @@ -522,7 +522,7 @@ class TaskExecutorFactory(object): if not TaskExecutorFactory.eventlet_deprecation_warned: msg = _LW("The `eventlet` executor has been deprecated. " "Use `taskflow` instead.") - LOG.warn(msg) + LOG.warning(msg) TaskExecutorFactory.eventlet_deprecation_warned = True task_executor = 'taskflow' diff --git a/glance/hacking/checks.py b/glance/hacking/checks.py index a5cc6222f1..3f4f10a780 100644 --- a/glance/hacking/checks.py +++ b/glance/hacking/checks.py @@ -131,3 +131,16 @@ def check_python3_xrange(logical_line): if re.search(r"\bxrange\s*\(", logical_line): yield(0, "G329: Do not use xrange. Use range, or six.moves.range for " "large loops.") + + +@core.flake8ext +def no_log_warn(logical_line): + """Disallow 'LOG.warn(' + + Use LOG.warning() instead of Deprecated LOG.warn(). + https://docs.python.org/3/library/logging.html#logging.warning + """ + + msg = ("G330: LOG.warn is deprecated, please use LOG.warning!") + if "LOG.warn(" in logical_line: + yield (0, msg) diff --git a/glance/image_cache/__init__.py b/glance/image_cache/__init__.py index 77a11796c9..56b5bc9e97 100644 --- a/glance/image_cache/__init__.py +++ b/glance/image_cache/__init__.py @@ -172,11 +172,11 @@ class ImageCache(object): self.driver_class = importutils.import_class(driver_module) LOG.info(_LI("Image cache loaded driver '%s'."), driver_name) except ImportError as import_err: - LOG.warn(_LW("Image cache driver " - "'%(driver_name)s' failed to load. " - "Got error: '%(import_err)s."), - {'driver_name': driver_name, - 'import_err': import_err}) + LOG.warning(_LW("Image cache driver " + "'%(driver_name)s' failed to load. " + "Got error: '%(import_err)s."), + {'driver_name': driver_name, + 'import_err': import_err}) driver_module = __name__ + '.drivers.sqlite.Driver' LOG.info(_LI("Defaulting to SQLite driver.")) @@ -193,11 +193,11 @@ class ImageCache(object): self.driver.configure() except exception.BadDriverConfiguration as config_err: driver_module = self.driver_class.__module__ - LOG.warn(_LW("Image cache driver " - "'%(driver_module)s' failed to configure. " - "Got error: '%(config_err)s"), - {'driver_module': driver_module, - 'config_err': config_err}) + LOG.warning(_LW("Image cache driver " + "'%(driver_module)s' failed to configure. " + "Got error: '%(config_err)s"), + {'driver_module': driver_module, + 'config_err': config_err}) LOG.info(_LI("Defaulting to SQLite driver.")) default_module = __name__ + '.drivers.sqlite.Driver' self.driver_class = importutils.import_class(default_module) diff --git a/glance/image_cache/drivers/sqlite.py b/glance/image_cache/drivers/sqlite.py index 1fe6d10539..a78889e530 100644 --- a/glance/image_cache/drivers/sqlite.py +++ b/glance/image_cache/drivers/sqlite.py @@ -346,12 +346,13 @@ class Driver(base.Driver): if os.path.exists(incomplete_path): invalid_path = self.get_image_filepath(image_id, 'invalid') - LOG.warn(_LW("Fetch of cache file failed (%(e)s), rolling " - "back by moving '%(incomplete_path)s' to " - "'%(invalid_path)s'") % - {'e': e, - 'incomplete_path': incomplete_path, - 'invalid_path': invalid_path}) + msg = (_LW("Fetch of cache file failed (%(e)s), rolling " + "back by moving '%(incomplete_path)s' to " + "'%(invalid_path)s'") % + {'e': e, + 'incomplete_path': incomplete_path, + 'invalid_path': invalid_path}) + LOG.warning(msg) os.rename(incomplete_path, invalid_path) db.execute("""DELETE FROM cached_images @@ -472,7 +473,7 @@ class Driver(base.Driver): msg = (_LW("Failed to delete file %(path)s. " "Got error: %(e)s"), dict(path=path, e=e)) - LOG.warn(msg) + LOG.warning(msg) def get_queued_images(self): """ diff --git a/glance/image_cache/prefetcher.py b/glance/image_cache/prefetcher.py index a1e37a9671..93e97e4f68 100644 --- a/glance/image_cache/prefetcher.py +++ b/glance/image_cache/prefetcher.py @@ -51,7 +51,8 @@ class Prefetcher(base.CacheApp): return False if image.status != 'active': - LOG.warn(_LW("Image '%s' is not active. Not caching.") % image_id) + LOG.warning(_LW("Image '%s' is not active. Not caching.") % + image_id) return False for loc in image.locations: @@ -85,8 +86,8 @@ class Prefetcher(base.CacheApp): results = pool.map(self.fetch_image_into_cache, images) successes = sum([1 for r in results if r is True]) if successes != num_images: - LOG.warn(_LW("Failed to successfully cache all " - "images in queue.")) + LOG.warning(_LW("Failed to successfully cache all " + "images in queue.")) return False LOG.info(_LI("Successfully cached all %d images"), num_images) diff --git a/glance/location.py b/glance/location.py index 970fb156fc..13e73e21a6 100644 --- a/glance/location.py +++ b/glance/location.py @@ -622,10 +622,10 @@ class ImageProxy(glance.domain.proxy.Image): return data except Exception as e: - LOG.warn(_LW('Get image %(id)s data failed: ' - '%(err)s.'), - {'id': self.image.image_id, - 'err': encodeutils.exception_to_unicode(e)}) + LOG.warning(_LW('Get image %(id)s data failed: ' + '%(err)s.'), + {'id': self.image.image_id, + 'err': encodeutils.exception_to_unicode(e)}) err = e # tried all locations LOG.error(_LE('Glance tried all active locations to get data for ' diff --git a/glance/scrubber.py b/glance/scrubber.py index 410494a0fc..32606c59a2 100644 --- a/glance/scrubber.py +++ b/glance/scrubber.py @@ -384,9 +384,9 @@ class Scrubber(object): {'status': 'deleted'}) LOG.info(_LI("Image %s has been scrubbed successfully"), image_id) else: - LOG.warn(_LW("One or more image locations couldn't be scrubbed " - "from backend. Leaving image '%s' in 'pending_delete'" - " status"), image_id) + LOG.warning(_LW("One or more image locations couldn't be scrubbed " + "from backend. Leaving image '%s' in " + "'pending_delete' status"), image_id) def _delete_image_location_from_backend(self, image_id, loc_id, uri, backend=None): diff --git a/glance/tests/test_hacking.py b/glance/tests/test_hacking.py index 3bd0c00597..b70ae1c1ad 100644 --- a/glance/tests/test_hacking.py +++ b/glance/tests/test_hacking.py @@ -108,3 +108,15 @@ class HackingTestCase(utils.BaseTestCase): self.assertEqual(0, len(list(func('for i in range(10)')))) self.assertEqual(0, len(list(func('for i in six.moves.range(10)')))) self.assertEqual(0, len(list(func('testxrange(10)')))) + + def test_no_log_warn(self): + code = """ + LOG.warn("LOG.warn is deprecated") + """ + errors = [(1, 0, 'G330')] + self._assert_has_errors(code, checks.no_log_warn, + expected_errors=errors) + code = """ + LOG.warning("LOG.warn is deprecated") + """ + self._assert_has_no_errors(code, checks.no_log_warn) diff --git a/tox.ini b/tox.ini index 59e32b56ac..c66202434d 100644 --- a/tox.ini +++ b/tox.ini @@ -142,6 +142,7 @@ extension = G327 = checks:check_no_contextlib_nested G328 = checks:dict_constructor_with_list_copy G329 = checks:check_python3_xrange + G330 = checks:no_log_warn paths = ./glance/hacking [testenv:docs]