Merge "Use LOG.warning instead of deprecated LOG.warn"

This commit is contained in:
Zuul 2021-12-15 09:05:34 +00:00 committed by Gerrit Code Review
commit 1e19534563
6 changed files with 28 additions and 13 deletions

View File

@ -9,6 +9,7 @@ Tacker Specific Commandments
---------------------------- ----------------------------
- [N320] Validate that LOG messages, except debug ones, have translations - [N320] Validate that LOG messages, except debug ones, have translations
- [T301] Log.warn is deprecated. Enforce use of LOG.warning.
Creating Unit Tests Creating Unit Tests
------------------- -------------------

View File

@ -274,7 +274,7 @@ class KubernetesMgmtDriver(vnflcm_abstract_driver.VnflcmMgmtAbstractDriver):
msg = 'Failed to find specified zone id' \ msg = 'Failed to find specified zone id' \
' related to Vnfc Resource {} in grant'.format( ' related to Vnfc Resource {} in grant'.format(
vnfc_id) vnfc_id)
LOG.warn(msg) LOG.warning(msg)
else: else:
for zone in grant.zones: for zone in grant.zones:
if add_resource_zone_id == zone.id: if add_resource_zone_id == zone.id:

View File

@ -1791,7 +1791,7 @@ class Conductor(manager.Manager, v2_hook.ConductorV2Hook):
notification_type=notification.get('notificationType') notification_type=notification.get('notificationType')
) )
if not vnf_lcm_subscriptions: if not vnf_lcm_subscriptions:
LOG.warn( LOG.warning(
"vnf_lcm_subscription not found id[%s]" % "vnf_lcm_subscription not found id[%s]" %
notification.get('vnfInstanceId')) notification.get('vnfInstanceId'))
return -1 return -1
@ -1851,20 +1851,20 @@ class Conductor(manager.Manager, v2_hook.ConductorV2Hook):
"reason": str(e)}) "reason": str(e)})
self._retry_check(num) self._retry_check(num)
except Exception as e: except Exception as e:
LOG.warn("send error[%s]" % str(e)) LOG.warning("send error[%s]" % str(e))
LOG.warn(traceback.format_exc()) LOG.warning(traceback.format_exc())
continue continue
except Exception as e: except Exception as e:
LOG.warn("Internal Sever Error[%s]" % str(e)) LOG.warning("Internal Sever Error[%s]" % str(e))
LOG.warn(traceback.format_exc()) LOG.warning(traceback.format_exc())
return -2 return -2
return 0 return 0
def _retry_check(self, retry_count): def _retry_check(self, retry_count):
time.sleep(CONF.vnf_lcm.retry_wait) time.sleep(CONF.vnf_lcm.retry_wait)
if retry_count == CONF.vnf_lcm.retry_num: if retry_count == CONF.vnf_lcm.retry_num:
LOG.warn( LOG.warning(
"Number of retries exceeded retry count [%s]" % "Number of retries exceeded retry count [%s]" %
CONF.vnf_lcm.retry_num) CONF.vnf_lcm.retry_num)

View File

@ -52,8 +52,8 @@ def get_csar_data_iter(body):
return data_iter return data_iter
except Exception as e: except Exception as e:
error = encodeutils.exception_to_unicode(e) error = encodeutils.exception_to_unicode(e)
LOG.warn("Failed to open csar URL: %(url)s due to error: %(error)s", LOG.warning("Failed to open csar URL: %(url)s due to error: %(error)s",
{"url": url, "error": error}) {"url": url, "error": error})
raise exceptions.VNFPackageURLInvalid(url=url) raise exceptions.VNFPackageURLInvalid(url=url)
@ -73,10 +73,10 @@ def store_csar(context, package_uuid, body):
context=context) context=context)
except Exception as e: except Exception as e:
error = encodeutils.exception_to_unicode(e) error = encodeutils.exception_to_unicode(e)
LOG.warn("Failed to store csar data in glance store for " LOG.warning("Failed to store csar data in glance store for "
"package %(uuid)s due to error: %(error)s", "package %(uuid)s due to error: %(error)s",
{"uuid": package_uuid, {"uuid": package_uuid,
"error": error}) "error": error})
raise exceptions.UploadFailedToGlanceStore(uuid=package_uuid, raise exceptions.UploadFailedToGlanceStore(uuid=package_uuid,
error=error) error=error)
finally: finally:

View File

@ -46,3 +46,16 @@ def validate_log_translations(physical_line, logical_line, filename):
msg = "N320: Log messages require translations!" msg = "N320: Log messages require translations!"
if log_translation.match(logical_line): if log_translation.match(logical_line):
yield (0, msg) yield (0, msg)
@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 = ("T301: LOG.warn is deprecated, please use LOG.warning!")
if "LOG.warn(" in logical_line:
yield (0, msg)

View File

@ -130,6 +130,7 @@ import_exceptions = tacker._i18n
[flake8:local-plugins] [flake8:local-plugins]
extension = extension =
N320 = checks:validate_log_translations N320 = checks:validate_log_translations
T301 = checks:no_log_warn
paths = ./tacker/hacking paths = ./tacker/hacking
[testenv:config-gen] [testenv:config-gen]