diff --git a/HACKING.rst b/HACKING.rst index 4a35d3d33..5dbcda3bc 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -9,6 +9,7 @@ Tacker Specific Commandments ---------------------------- - [N320] Validate that LOG messages, except debug ones, have translations +- [T301] Log.warn is deprecated. Enforce use of LOG.warning. Creating Unit Tests ------------------- diff --git a/samples/mgmt_driver/kubernetes_mgmt.py b/samples/mgmt_driver/kubernetes_mgmt.py index de2a43fd4..2a22f3cd6 100644 --- a/samples/mgmt_driver/kubernetes_mgmt.py +++ b/samples/mgmt_driver/kubernetes_mgmt.py @@ -274,7 +274,7 @@ class KubernetesMgmtDriver(vnflcm_abstract_driver.VnflcmMgmtAbstractDriver): msg = 'Failed to find specified zone id' \ ' related to Vnfc Resource {} in grant'.format( vnfc_id) - LOG.warn(msg) + LOG.warning(msg) else: for zone in grant.zones: if add_resource_zone_id == zone.id: diff --git a/tacker/conductor/conductor_server.py b/tacker/conductor/conductor_server.py index 6b7f1054c..38f5bd532 100644 --- a/tacker/conductor/conductor_server.py +++ b/tacker/conductor/conductor_server.py @@ -1791,7 +1791,7 @@ class Conductor(manager.Manager, v2_hook.ConductorV2Hook): notification_type=notification.get('notificationType') ) if not vnf_lcm_subscriptions: - LOG.warn( + LOG.warning( "vnf_lcm_subscription not found id[%s]" % notification.get('vnfInstanceId')) return -1 @@ -1851,20 +1851,20 @@ class Conductor(manager.Manager, v2_hook.ConductorV2Hook): "reason": str(e)}) self._retry_check(num) except Exception as e: - LOG.warn("send error[%s]" % str(e)) - LOG.warn(traceback.format_exc()) + LOG.warning("send error[%s]" % str(e)) + LOG.warning(traceback.format_exc()) continue except Exception as e: - LOG.warn("Internal Sever Error[%s]" % str(e)) - LOG.warn(traceback.format_exc()) + LOG.warning("Internal Sever Error[%s]" % str(e)) + LOG.warning(traceback.format_exc()) return -2 return 0 def _retry_check(self, retry_count): time.sleep(CONF.vnf_lcm.retry_wait) if retry_count == CONF.vnf_lcm.retry_num: - LOG.warn( + LOG.warning( "Number of retries exceeded retry count [%s]" % CONF.vnf_lcm.retry_num) diff --git a/tacker/glance_store/store.py b/tacker/glance_store/store.py index 4b234fe51..b362d0eff 100644 --- a/tacker/glance_store/store.py +++ b/tacker/glance_store/store.py @@ -52,8 +52,8 @@ def get_csar_data_iter(body): return data_iter except Exception as e: error = encodeutils.exception_to_unicode(e) - LOG.warn("Failed to open csar URL: %(url)s due to error: %(error)s", - {"url": url, "error": error}) + LOG.warning("Failed to open csar URL: %(url)s due to error: %(error)s", + {"url": url, "error": error}) raise exceptions.VNFPackageURLInvalid(url=url) @@ -73,10 +73,10 @@ def store_csar(context, package_uuid, body): context=context) except Exception as e: error = encodeutils.exception_to_unicode(e) - LOG.warn("Failed to store csar data in glance store for " - "package %(uuid)s due to error: %(error)s", - {"uuid": package_uuid, - "error": error}) + LOG.warning("Failed to store csar data in glance store for " + "package %(uuid)s due to error: %(error)s", + {"uuid": package_uuid, + "error": error}) raise exceptions.UploadFailedToGlanceStore(uuid=package_uuid, error=error) finally: diff --git a/tacker/hacking/checks.py b/tacker/hacking/checks.py index f6d829d61..00a7e584d 100644 --- a/tacker/hacking/checks.py +++ b/tacker/hacking/checks.py @@ -46,3 +46,16 @@ def validate_log_translations(physical_line, logical_line, filename): msg = "N320: Log messages require translations!" if log_translation.match(logical_line): 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) diff --git a/tox.ini b/tox.ini index 2d71d0195..42fb774fd 100644 --- a/tox.ini +++ b/tox.ini @@ -130,6 +130,7 @@ import_exceptions = tacker._i18n [flake8:local-plugins] extension = N320 = checks:validate_log_translations + T301 = checks:no_log_warn paths = ./tacker/hacking [testenv:config-gen]