Replace deprecated LOG.warn with LOG.warning

LOG.warn is deprecated. It is still used in few modules.
Replaced with non-deprecated LOG.warning.

Change-Id: Ia6acc11eca60c652844175a5742f626732e295e3
Closes-Bug: #1508442
This commit is contained in:
yatin karel 2016-07-16 17:50:48 +05:30 committed by yatinkarel
parent 9d43891099
commit ecb24c5f1b
12 changed files with 64 additions and 36 deletions

View File

@ -62,6 +62,7 @@ Nova Specific Commandments
- [N349] Check for closures in tests which are not used - [N349] Check for closures in tests which are not used
- [N350] Policy registration should be in the central location ``nova/policies/`` - [N350] Policy registration should be in the central location ``nova/policies/``
- [N351] Do not use the oslo_policy.policy.Enforcer.enforce() method. - [N351] Do not use the oslo_policy.policy.Enforcer.enforce() method.
- [N352] LOG.warn is deprecated. Enforce use of LOG.warning.
Creating Unit Tests Creating Unit Tests
------------------- -------------------

View File

@ -38,7 +38,7 @@ _DEPRECATION_MESSAGE = ('The in tree EC2 API has been removed in Mitaka. '
class DeprecatedMiddleware(wsgi.Middleware): class DeprecatedMiddleware(wsgi.Middleware):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(DeprecatedMiddleware, self).__init__(args[0]) 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) @webob.dec.wsgify(RequestClass=wsgi.Request)
def __call__(self, req): def __call__(self, req):

View File

@ -1752,7 +1752,7 @@ class API(base.Base):
self.volume_api.delete(context, bdm.volume_id) self.volume_api.delete(context, bdm.volume_id)
except Exception as exc: except Exception as exc:
err_str = _LW("Ignoring volume cleanup failure due to %s") 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() bdm.destroy()
def _local_delete(self, context, instance, bdms, delete_type, cb): def _local_delete(self, context, instance, bdms, delete_type, cb):

View File

@ -802,6 +802,20 @@ def no_os_popen(logical_line):
'Replace it using subprocess module. ') '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): def factory(register):
register(import_no_db_in_virt) register(import_no_db_in_virt)
register(no_db_session_in_public_api) register(no_db_session_in_public_api)
@ -839,4 +853,5 @@ def factory(register):
register(check_python3_no_itervalues) register(check_python3_no_itervalues)
register(cfg_help_with_enough_text) register(cfg_help_with_enough_text)
register(no_os_popen) register(no_os_popen)
register(no_log_warn)
register(CheckForUncalledTestClosure) register(CheckForUncalledTestClosure)

View File

@ -60,10 +60,10 @@ class ServerGroupSoftAffinityWeigher(_SoftAffinityWeigherBase):
def weight_multiplier(self): def weight_multiplier(self):
if (CONF.soft_affinity_weight_multiplier < 0 and if (CONF.soft_affinity_weight_multiplier < 0 and
not self.warning_sent): not self.warning_sent):
LOG.warn(_LW('For the soft_affinity_weight_multiplier only a ' LOG.warning(_LW('For the soft_affinity_weight_multiplier only a '
'positive value is meaningful as a negative value ' 'positive value is meaningful as a negative value '
'would mean that the affinity weigher would ' 'would mean that the affinity weigher would '
'prefer non-collocating placement.')) 'prefer non-collocating placement.'))
self.warning_sent = True self.warning_sent = True
return CONF.soft_affinity_weight_multiplier return CONF.soft_affinity_weight_multiplier
@ -76,10 +76,10 @@ class ServerGroupSoftAntiAffinityWeigher(_SoftAffinityWeigherBase):
def weight_multiplier(self): def weight_multiplier(self):
if (CONF.soft_anti_affinity_weight_multiplier < 0 and if (CONF.soft_anti_affinity_weight_multiplier < 0 and
not self.warning_sent): not self.warning_sent):
LOG.warn(_LW('For the soft_anti_affinity_weight_multiplier only a ' LOG.warning(_LW('For the soft_anti_affinity_weight_multiplier '
'positive value is meaningful as a negative value ' 'only a positive value is meaningful as a '
'would mean that the anti-affinity weigher would ' 'negative value would mean that the anti-affinity '
'prefer collocating placement.')) 'weigher would prefer collocating placement.'))
self.warning_sent = True self.warning_sent = True
return CONF.soft_anti_affinity_weight_multiplier return CONF.soft_anti_affinity_weight_multiplier

View File

@ -112,7 +112,7 @@ class SoftAffinityWeigherTestCase(SoftWeigherTestBase):
self._do_test(policy='soft-affinity', self._do_test(policy='soft-affinity',
expected_weight=0.0, expected_weight=0.0,
expected_host='host3') expected_host='host3')
self.assertEqual(1, mock_log.warn.call_count) self.assertEqual(1, mock_log.warning.call_count)
class SoftAntiAffinityWeigherTestCase(SoftWeigherTestBase): class SoftAntiAffinityWeigherTestCase(SoftWeigherTestBase):
@ -150,4 +150,4 @@ class SoftAntiAffinityWeigherTestCase(SoftWeigherTestBase):
self._do_test(policy='soft-anti-affinity', self._do_test(policy='soft-anti-affinity',
expected_weight=0.0, expected_weight=0.0,
expected_host='host2') expected_host='host2')
self.assertEqual(1, mock_log.warn.call_count) self.assertEqual(1, mock_log.warning.call_count)

View File

@ -747,6 +747,18 @@ class HackingTestCase(test.NoDBTestCase):
self._assert_has_errors(code, checks.no_os_popen, self._assert_has_errors(code, checks.no_os_popen,
expected_errors=errors) 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): def test_uncalled_closures(self):
checker = checks.CheckForUncalledTestClosure checker = checks.CheckForUncalledTestClosure

View File

@ -444,7 +444,7 @@ class MigrationOpsTestCase(test_base.HyperVBaseTestCase):
mock.sentinel.image_meta, True, bdi, True) mock.sentinel.image_meta, True, bdi, True)
@mock.patch.object(migrationops.MigrationOps, '_check_resize_vhd') @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, def test_check_ephemeral_disks_multiple_eph_warn(self, mock_warn,
mock_check_resize_vhd): mock_check_resize_vhd):
mock_instance = fake_instance.fake_instance_obj(self.context) mock_instance = fake_instance.fake_instance_obj(self.context)

View File

@ -318,8 +318,8 @@ class MigrationOps(object):
elif sum(eph['size'] for eph in ephemerals) != new_eph_gb: elif sum(eph['size'] for eph in ephemerals) != new_eph_gb:
# New ephemeral size is different from the original ephemeral size # New ephemeral size is different from the original ephemeral size
# and there are multiple ephemerals. # and there are multiple ephemerals.
LOG.warn(_LW("Cannot resize multiple ephemeral disks for " LOG.warning(_LW("Cannot resize multiple ephemeral disks for "
"instance."), instance=instance) "instance."), instance=instance)
for index, eph in enumerate(ephemerals): for index, eph in enumerate(ephemerals):
eph_name = "eph%s" % index eph_name = "eph%s" % index

View File

@ -3063,8 +3063,8 @@ class LibvirtDriver(driver.ComputeDriver):
files) files)
elif need_inject: elif need_inject:
LOG.warn(_LW('File injection into a boot from volume ' LOG.warning(_LW('File injection into a boot from volume '
'instance is not supported'), instance=instance) 'instance is not supported'), instance=instance)
# Lookup the filesystem type if required # Lookup the filesystem type if required
os_type_with_default = disk.get_fs_type_for_os_type(instance.os_type) 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(): if self._has_uefi_support():
global uefi_logged global uefi_logged
if not uefi_logged: if not uefi_logged:
LOG.warn(_LW("uefi support is without some kind of " LOG.warning(_LW("uefi support is without some kind of "
"functional testing and therefore " "functional testing and therefore "
"considered experimental.")) "considered experimental."))
uefi_logged = True uefi_logged = True
guest.os_loader = DEFAULT_UEFI_LOADER_PATH[ guest.os_loader = DEFAULT_UEFI_LOADER_PATH[
caps.host.cpu.arch] caps.host.cpu.arch]

View File

@ -54,8 +54,8 @@ class XenVIFDriver(object):
try: try:
vif_ref = self._session.call_xenapi('VIF.create', vif_rec) vif_ref = self._session.call_xenapi('VIF.create', vif_rec)
except Exception as e: except Exception as e:
LOG.warn(_LW("Failed to create vif, exception:%(exception)s, " LOG.warning(_LW("Failed to create vif, exception:%(exception)s, "
"vif:%(vif)s"), {'exception': e, 'vif': vif}) "vif:%(vif)s"), {'exception': e, 'vif': vif})
raise exception.NovaException( raise exception.NovaException(
reason=_("Failed to create vif %s") % vif) reason=_("Failed to create vif %s") % vif)
@ -74,7 +74,7 @@ class XenVIFDriver(object):
return return
self._session.call_xenapi('VIF.destroy', vif_ref) self._session.call_xenapi('VIF.destroy', vif_ref)
except Exception as e: except Exception as e:
LOG.warn( LOG.warning(
_LW("Fail to unplug vif:%(vif)s, exception:%(exception)s"), _LW("Fail to unplug vif:%(vif)s, exception:%(exception)s"),
{'vif': vif, 'exception': e}, instance=instance) {'vif': vif, 'exception': e}, instance=instance)
raise exception.NovaException( raise exception.NovaException(
@ -253,9 +253,9 @@ class XenAPIOpenVswitchDriver(XenVIFDriver):
# delete the patch port pair # delete the patch port pair
self._ovs_del_port(bridge_name, patch_port1) self._ovs_del_port(bridge_name, patch_port1)
except Exception as e: except Exception as e:
LOG.warn(_LW("Failed to delete patch port pair for vif %(if)s," LOG.warning(_LW("Failed to delete patch port pair for vif %(if)s,"
" exception:%(exception)s"), " exception:%(exception)s"),
{'if': vif, 'exception': e}, instance=instance) {'if': vif, 'exception': e}, instance=instance)
raise exception.VirtualInterfaceUnplugException( raise exception.VirtualInterfaceUnplugException(
reason=_("Failed to delete patch port pair")) reason=_("Failed to delete patch port pair"))
@ -283,9 +283,9 @@ class XenAPIOpenVswitchDriver(XenVIFDriver):
self._delete_linux_bridge(qbr_name) self._delete_linux_bridge(qbr_name)
self._ovs_del_port(CONF.xenserver.ovs_integration_bridge, qvo_name) self._ovs_del_port(CONF.xenserver.ovs_integration_bridge, qvo_name)
except Exception as e: except Exception as e:
LOG.warn(_LW("Failed to delete bridge for vif %(if)s, " LOG.warning(_LW("Failed to delete bridge for vif %(if)s, "
"exception:%(exception)s"), "exception:%(exception)s"),
{'if': vif, 'exception': e}, instance=instance) {'if': vif, 'exception': e}, instance=instance)
raise exception.VirtualInterfaceUnplugException( raise exception.VirtualInterfaceUnplugException(
reason=_("Failed to delete bridge")) reason=_("Failed to delete bridge"))
@ -420,9 +420,9 @@ class XenAPIOpenVswitchDriver(XenVIFDriver):
try: try:
network_ref = self._session.network.create(network_rec) network_ref = self._session.network.create(network_rec)
except Exception as e: except Exception as e:
LOG.warn(_LW("Failed to create interim network for vif %(if)s, " LOG.warning(_LW("Failed to create interim network for vif %(if)s, "
"exception:%(exception)s"), "exception:%(exception)s"),
{'if': vif, 'exception': e}) {'if': vif, 'exception': e})
raise exception.VirtualInterfacePlugException( raise exception.VirtualInterfacePlugException(
_("Failed to create the interim network for vif")) _("Failed to create the interim network for vif"))
return network_ref return network_ref

View File

@ -614,8 +614,8 @@ class VMOps(object):
def _handle_neutron_event_timeout(self, instance, undo_mgr): def _handle_neutron_event_timeout(self, instance, undo_mgr):
# We didn't get callback from Neutron within given time # We didn't get callback from Neutron within given time
LOG.warn(_LW('Timeout waiting for vif plugging callback'), LOG.warning(_LW('Timeout waiting for vif plugging callback'),
instance=instance) instance=instance)
if CONF.vif_plugging_is_fatal: if CONF.vif_plugging_is_fatal:
raise exception.VirtualInterfaceCreateException() raise exception.VirtualInterfaceCreateException()
@ -627,8 +627,8 @@ class VMOps(object):
self._update_last_dom_id(vm_ref) self._update_last_dom_id(vm_ref)
def _neutron_failed_callback(self, event_name, instance): def _neutron_failed_callback(self, event_name, instance):
LOG.warn(_LW('Neutron Reported failure on event %(event)s'), LOG.warning(_LW('Neutron Reported failure on event %(event)s'),
{'event': event_name}, instance=instance) {'event': event_name}, instance=instance)
if CONF.vif_plugging_is_fatal: if CONF.vif_plugging_is_fatal:
raise exception.VirtualInterfaceCreateException() raise exception.VirtualInterfaceCreateException()