diff --git a/HACKING.rst b/HACKING.rst index 721326db4ec6..8f61c0086281 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -62,6 +62,7 @@ Nova Specific Commandments - [N349] Check for closures in tests which are not used - [N350] Policy registration should be in the central location ``nova/policies/`` - [N351] Do not use the oslo_policy.policy.Enforcer.enforce() method. +- [N352] LOG.warn is deprecated. Enforce use of LOG.warning. Creating Unit Tests ------------------- diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index 9bb903bc0383..049a3de46b75 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -38,7 +38,7 @@ _DEPRECATION_MESSAGE = ('The in tree EC2 API has been removed in Mitaka. ' class DeprecatedMiddleware(wsgi.Middleware): def __init__(self, *args, **kwargs): super(DeprecatedMiddleware, self).__init__(args[0]) - LOG.warn(_LW(_DEPRECATED_MIDDLEWARE % type(self).__name__)) # noqa + LOG.warning(_LW(_DEPRECATED_MIDDLEWARE % type(self).__name__)) # noqa @webob.dec.wsgify(RequestClass=wsgi.Request) def __call__(self, req): diff --git a/nova/compute/api.py b/nova/compute/api.py index 1da2add560a2..85b93323989a 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1751,7 +1751,7 @@ class API(base.Base): self.volume_api.delete(context, bdm.volume_id) except Exception as exc: err_str = _LW("Ignoring volume cleanup failure due to %s") - LOG.warn(err_str % exc, instance=instance) + LOG.warning(err_str % exc, instance=instance) bdm.destroy() def _local_delete(self, context, instance, bdms, delete_type, cb): diff --git a/nova/hacking/checks.py b/nova/hacking/checks.py index f850991b1ee3..1c2b05fc09e3 100644 --- a/nova/hacking/checks.py +++ b/nova/hacking/checks.py @@ -802,6 +802,20 @@ def no_os_popen(logical_line): 'Replace it using subprocess module. ') +def no_log_warn(logical_line): + """Disallow 'LOG.warn(' + + Deprecated LOG.warn(), instead use LOG.warning + https://bugs.launchpad.net/senlin/+bug/1508442 + + N352 + """ + + msg = ("N352: LOG.warn is deprecated, please use LOG.warning!") + if "LOG.warn(" in logical_line: + yield (0, msg) + + def factory(register): register(import_no_db_in_virt) register(no_db_session_in_public_api) @@ -839,4 +853,5 @@ def factory(register): register(check_python3_no_itervalues) register(cfg_help_with_enough_text) register(no_os_popen) + register(no_log_warn) register(CheckForUncalledTestClosure) diff --git a/nova/scheduler/weights/affinity.py b/nova/scheduler/weights/affinity.py index 33b3ea42eba0..e9a4b9511912 100644 --- a/nova/scheduler/weights/affinity.py +++ b/nova/scheduler/weights/affinity.py @@ -60,10 +60,10 @@ class ServerGroupSoftAffinityWeigher(_SoftAffinityWeigherBase): def weight_multiplier(self): if (CONF.soft_affinity_weight_multiplier < 0 and not self.warning_sent): - LOG.warn(_LW('For the soft_affinity_weight_multiplier only a ' - 'positive value is meaningful as a negative value ' - 'would mean that the affinity weigher would ' - 'prefer non-collocating placement.')) + LOG.warning(_LW('For the soft_affinity_weight_multiplier only a ' + 'positive value is meaningful as a negative value ' + 'would mean that the affinity weigher would ' + 'prefer non-collocating placement.')) self.warning_sent = True return CONF.soft_affinity_weight_multiplier @@ -76,10 +76,10 @@ class ServerGroupSoftAntiAffinityWeigher(_SoftAffinityWeigherBase): def weight_multiplier(self): if (CONF.soft_anti_affinity_weight_multiplier < 0 and not self.warning_sent): - LOG.warn(_LW('For the soft_anti_affinity_weight_multiplier only a ' - 'positive value is meaningful as a negative value ' - 'would mean that the anti-affinity weigher would ' - 'prefer collocating placement.')) + LOG.warning(_LW('For the soft_anti_affinity_weight_multiplier ' + 'only a positive value is meaningful as a ' + 'negative value would mean that the anti-affinity ' + 'weigher would prefer collocating placement.')) self.warning_sent = True return CONF.soft_anti_affinity_weight_multiplier diff --git a/nova/tests/unit/scheduler/weights/test_weights_affinity.py b/nova/tests/unit/scheduler/weights/test_weights_affinity.py index ace8ad599eec..873066c70002 100644 --- a/nova/tests/unit/scheduler/weights/test_weights_affinity.py +++ b/nova/tests/unit/scheduler/weights/test_weights_affinity.py @@ -112,7 +112,7 @@ class SoftAffinityWeigherTestCase(SoftWeigherTestBase): self._do_test(policy='soft-affinity', expected_weight=0.0, expected_host='host3') - self.assertEqual(1, mock_log.warn.call_count) + self.assertEqual(1, mock_log.warning.call_count) class SoftAntiAffinityWeigherTestCase(SoftWeigherTestBase): @@ -150,4 +150,4 @@ class SoftAntiAffinityWeigherTestCase(SoftWeigherTestBase): self._do_test(policy='soft-anti-affinity', expected_weight=0.0, expected_host='host2') - self.assertEqual(1, mock_log.warn.call_count) + self.assertEqual(1, mock_log.warning.call_count) diff --git a/nova/tests/unit/test_hacking.py b/nova/tests/unit/test_hacking.py index f7cc11809011..31a0bc176ca6 100644 --- a/nova/tests/unit/test_hacking.py +++ b/nova/tests/unit/test_hacking.py @@ -747,6 +747,18 @@ class HackingTestCase(test.NoDBTestCase): self._assert_has_errors(code, checks.no_os_popen, expected_errors=errors) + def test_no_log_warn(self): + code = """ + LOG.warn("LOG.warn is deprecated") + """ + errors = [(1, 0, 'N352')] + 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) + def test_uncalled_closures(self): checker = checks.CheckForUncalledTestClosure diff --git a/nova/tests/unit/virt/hyperv/test_migrationops.py b/nova/tests/unit/virt/hyperv/test_migrationops.py index e4b581290b11..ff09f7ddd063 100644 --- a/nova/tests/unit/virt/hyperv/test_migrationops.py +++ b/nova/tests/unit/virt/hyperv/test_migrationops.py @@ -444,7 +444,7 @@ class MigrationOpsTestCase(test_base.HyperVBaseTestCase): mock.sentinel.image_meta, True, bdi, True) @mock.patch.object(migrationops.MigrationOps, '_check_resize_vhd') - @mock.patch.object(migrationops.LOG, 'warn') + @mock.patch.object(migrationops.LOG, 'warning') def test_check_ephemeral_disks_multiple_eph_warn(self, mock_warn, mock_check_resize_vhd): mock_instance = fake_instance.fake_instance_obj(self.context) diff --git a/nova/virt/hyperv/migrationops.py b/nova/virt/hyperv/migrationops.py index 9c64dd366316..251226ed4a3c 100644 --- a/nova/virt/hyperv/migrationops.py +++ b/nova/virt/hyperv/migrationops.py @@ -318,8 +318,8 @@ class MigrationOps(object): elif sum(eph['size'] for eph in ephemerals) != new_eph_gb: # New ephemeral size is different from the original ephemeral size # and there are multiple ephemerals. - LOG.warn(_LW("Cannot resize multiple ephemeral disks for " - "instance."), instance=instance) + LOG.warning(_LW("Cannot resize multiple ephemeral disks for " + "instance."), instance=instance) for index, eph in enumerate(ephemerals): eph_name = "eph%s" % index diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 8a7a413ec8d4..7325573c7482 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -3063,8 +3063,8 @@ class LibvirtDriver(driver.ComputeDriver): files) elif need_inject: - LOG.warn(_LW('File injection into a boot from volume ' - 'instance is not supported'), instance=instance) + LOG.warning(_LW('File injection into a boot from volume ' + 'instance is not supported'), instance=instance) # Lookup the filesystem type if required os_type_with_default = disk.get_fs_type_for_os_type(instance.os_type) @@ -4296,9 +4296,9 @@ class LibvirtDriver(driver.ComputeDriver): if self._has_uefi_support(): global uefi_logged if not uefi_logged: - LOG.warn(_LW("uefi support is without some kind of " - "functional testing and therefore " - "considered experimental.")) + LOG.warning(_LW("uefi support is without some kind of " + "functional testing and therefore " + "considered experimental.")) uefi_logged = True guest.os_loader = DEFAULT_UEFI_LOADER_PATH[ caps.host.cpu.arch] diff --git a/nova/virt/xenapi/vif.py b/nova/virt/xenapi/vif.py index 48293091496d..369c2ba7939c 100644 --- a/nova/virt/xenapi/vif.py +++ b/nova/virt/xenapi/vif.py @@ -54,8 +54,8 @@ class XenVIFDriver(object): try: vif_ref = self._session.call_xenapi('VIF.create', vif_rec) except Exception as e: - LOG.warn(_LW("Failed to create vif, exception:%(exception)s, " - "vif:%(vif)s"), {'exception': e, 'vif': vif}) + LOG.warning(_LW("Failed to create vif, exception:%(exception)s, " + "vif:%(vif)s"), {'exception': e, 'vif': vif}) raise exception.NovaException( reason=_("Failed to create vif %s") % vif) @@ -74,7 +74,7 @@ class XenVIFDriver(object): return self._session.call_xenapi('VIF.destroy', vif_ref) except Exception as e: - LOG.warn( + LOG.warning( _LW("Fail to unplug vif:%(vif)s, exception:%(exception)s"), {'vif': vif, 'exception': e}, instance=instance) raise exception.NovaException( @@ -253,9 +253,9 @@ class XenAPIOpenVswitchDriver(XenVIFDriver): # delete the patch port pair self._ovs_del_port(bridge_name, patch_port1) except Exception as e: - LOG.warn(_LW("Failed to delete patch port pair for vif %(if)s," - " exception:%(exception)s"), - {'if': vif, 'exception': e}, instance=instance) + LOG.warning(_LW("Failed to delete patch port pair for vif %(if)s," + " exception:%(exception)s"), + {'if': vif, 'exception': e}, instance=instance) raise exception.VirtualInterfaceUnplugException( reason=_("Failed to delete patch port pair")) @@ -283,9 +283,9 @@ class XenAPIOpenVswitchDriver(XenVIFDriver): self._delete_linux_bridge(qbr_name) self._ovs_del_port(CONF.xenserver.ovs_integration_bridge, qvo_name) except Exception as e: - LOG.warn(_LW("Failed to delete bridge for vif %(if)s, " - "exception:%(exception)s"), - {'if': vif, 'exception': e}, instance=instance) + LOG.warning(_LW("Failed to delete bridge for vif %(if)s, " + "exception:%(exception)s"), + {'if': vif, 'exception': e}, instance=instance) raise exception.VirtualInterfaceUnplugException( reason=_("Failed to delete bridge")) @@ -420,9 +420,9 @@ class XenAPIOpenVswitchDriver(XenVIFDriver): try: network_ref = self._session.network.create(network_rec) except Exception as e: - LOG.warn(_LW("Failed to create interim network for vif %(if)s, " - "exception:%(exception)s"), - {'if': vif, 'exception': e}) + LOG.warning(_LW("Failed to create interim network for vif %(if)s, " + "exception:%(exception)s"), + {'if': vif, 'exception': e}) raise exception.VirtualInterfacePlugException( _("Failed to create the interim network for vif")) return network_ref diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index acc7a332b981..20378dff0271 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -614,8 +614,8 @@ class VMOps(object): def _handle_neutron_event_timeout(self, instance, undo_mgr): # We didn't get callback from Neutron within given time - LOG.warn(_LW('Timeout waiting for vif plugging callback'), - instance=instance) + LOG.warning(_LW('Timeout waiting for vif plugging callback'), + instance=instance) if CONF.vif_plugging_is_fatal: raise exception.VirtualInterfaceCreateException() @@ -627,8 +627,8 @@ class VMOps(object): self._update_last_dom_id(vm_ref) def _neutron_failed_callback(self, event_name, instance): - LOG.warn(_LW('Neutron Reported failure on event %(event)s'), - {'event': event_name}, instance=instance) + LOG.warning(_LW('Neutron Reported failure on event %(event)s'), + {'event': event_name}, instance=instance) if CONF.vif_plugging_is_fatal: raise exception.VirtualInterfaceCreateException()