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
- [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
-------------------

View File

@ -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):

View File

@ -1752,7 +1752,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):

View File

@ -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)

View File

@ -60,7 +60,7 @@ 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 '
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.'))
@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -318,7 +318,7 @@ 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 "
LOG.warning(_LW("Cannot resize multiple ephemeral disks for "
"instance."), instance=instance)
for index, eph in enumerate(ephemerals):

View File

@ -3063,7 +3063,7 @@ class LibvirtDriver(driver.ComputeDriver):
files)
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)
# Lookup the filesystem type if required
@ -4296,7 +4296,7 @@ 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 "
LOG.warning(_LW("uefi support is without some kind of "
"functional testing and therefore "
"considered experimental."))
uefi_logged = True

View File

@ -54,7 +54,7 @@ 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, "
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,7 +253,7 @@ 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,"
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(
@ -283,7 +283,7 @@ 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, "
LOG.warning(_LW("Failed to delete bridge for vif %(if)s, "
"exception:%(exception)s"),
{'if': vif, 'exception': e}, instance=instance)
raise exception.VirtualInterfaceUnplugException(
@ -420,7 +420,7 @@ 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, "
LOG.warning(_LW("Failed to create interim network for vif %(if)s, "
"exception:%(exception)s"),
{'if': vif, 'exception': e})
raise exception.VirtualInterfacePlugException(

View File

@ -614,7 +614,7 @@ 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'),
LOG.warning(_LW('Timeout waiting for vif plugging callback'),
instance=instance)
if CONF.vif_plugging_is_fatal:
raise exception.VirtualInterfaceCreateException()
@ -627,7 +627,7 @@ 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'),
LOG.warning(_LW('Neutron Reported failure on event %(event)s'),
{'event': event_name}, instance=instance)
if CONF.vif_plugging_is_fatal:
raise exception.VirtualInterfaceCreateException()