Browse Source

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
tags/14.0.0.0b3
yatin karel 3 years ago
parent
commit
ecb24c5f1b

+ 1
- 0
HACKING.rst View File

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

+ 1
- 1
nova/api/ec2/__init__.py View File

@@ -38,7 +38,7 @@ _DEPRECATION_MESSAGE = ('The in tree EC2 API has been removed in Mitaka. '
38 38
 class DeprecatedMiddleware(wsgi.Middleware):
39 39
     def __init__(self, *args, **kwargs):
40 40
         super(DeprecatedMiddleware, self).__init__(args[0])
41
-        LOG.warn(_LW(_DEPRECATED_MIDDLEWARE % type(self).__name__))  # noqa
41
+        LOG.warning(_LW(_DEPRECATED_MIDDLEWARE % type(self).__name__))  # noqa
42 42
 
43 43
     @webob.dec.wsgify(RequestClass=wsgi.Request)
44 44
     def __call__(self, req):

+ 1
- 1
nova/compute/api.py View File

@@ -1752,7 +1752,7 @@ class API(base.Base):
1752 1752
                         self.volume_api.delete(context, bdm.volume_id)
1753 1753
                 except Exception as exc:
1754 1754
                     err_str = _LW("Ignoring volume cleanup failure due to %s")
1755
-                    LOG.warn(err_str % exc, instance=instance)
1755
+                    LOG.warning(err_str % exc, instance=instance)
1756 1756
             bdm.destroy()
1757 1757
 
1758 1758
     def _local_delete(self, context, instance, bdms, delete_type, cb):

+ 15
- 0
nova/hacking/checks.py View File

@@ -802,6 +802,20 @@ def no_os_popen(logical_line):
802 802
                  'Replace it using subprocess module. ')
803 803
 
804 804
 
805
+def no_log_warn(logical_line):
806
+    """Disallow 'LOG.warn('
807
+
808
+    Deprecated LOG.warn(), instead use LOG.warning
809
+    https://bugs.launchpad.net/senlin/+bug/1508442
810
+
811
+    N352
812
+    """
813
+
814
+    msg = ("N352: LOG.warn is deprecated, please use LOG.warning!")
815
+    if "LOG.warn(" in logical_line:
816
+        yield (0, msg)
817
+
818
+
805 819
 def factory(register):
806 820
     register(import_no_db_in_virt)
807 821
     register(no_db_session_in_public_api)
@@ -839,4 +853,5 @@ def factory(register):
839 853
     register(check_python3_no_itervalues)
840 854
     register(cfg_help_with_enough_text)
841 855
     register(no_os_popen)
856
+    register(no_log_warn)
842 857
     register(CheckForUncalledTestClosure)

+ 8
- 8
nova/scheduler/weights/affinity.py View File

@@ -60,10 +60,10 @@ class ServerGroupSoftAffinityWeigher(_SoftAffinityWeigherBase):
60 60
     def weight_multiplier(self):
61 61
         if (CONF.soft_affinity_weight_multiplier < 0 and
62 62
                 not self.warning_sent):
63
-            LOG.warn(_LW('For the soft_affinity_weight_multiplier only a '
64
-                         'positive value is meaningful as a negative value '
65
-                         'would mean that the affinity weigher would '
66
-                         'prefer non-collocating placement.'))
63
+            LOG.warning(_LW('For the soft_affinity_weight_multiplier only a '
64
+                            'positive value is meaningful as a negative value '
65
+                            'would mean that the affinity weigher would '
66
+                            'prefer non-collocating placement.'))
67 67
             self.warning_sent = True
68 68
 
69 69
         return CONF.soft_affinity_weight_multiplier
@@ -76,10 +76,10 @@ class ServerGroupSoftAntiAffinityWeigher(_SoftAffinityWeigherBase):
76 76
     def weight_multiplier(self):
77 77
         if (CONF.soft_anti_affinity_weight_multiplier < 0 and
78 78
                 not self.warning_sent):
79
-            LOG.warn(_LW('For the soft_anti_affinity_weight_multiplier only a '
80
-                         'positive value is meaningful as a negative value '
81
-                         'would mean that the anti-affinity weigher would '
82
-                         'prefer collocating placement.'))
79
+            LOG.warning(_LW('For the soft_anti_affinity_weight_multiplier '
80
+                            'only a positive value is meaningful as a '
81
+                            'negative value would mean that the anti-affinity '
82
+                            'weigher would prefer collocating placement.'))
83 83
             self.warning_sent = True
84 84
 
85 85
         return CONF.soft_anti_affinity_weight_multiplier

+ 2
- 2
nova/tests/unit/scheduler/weights/test_weights_affinity.py View File

@@ -112,7 +112,7 @@ class SoftAffinityWeigherTestCase(SoftWeigherTestBase):
112 112
         self._do_test(policy='soft-affinity',
113 113
                       expected_weight=0.0,
114 114
                       expected_host='host3')
115
-        self.assertEqual(1, mock_log.warn.call_count)
115
+        self.assertEqual(1, mock_log.warning.call_count)
116 116
 
117 117
 
118 118
 class SoftAntiAffinityWeigherTestCase(SoftWeigherTestBase):
@@ -150,4 +150,4 @@ class SoftAntiAffinityWeigherTestCase(SoftWeigherTestBase):
150 150
         self._do_test(policy='soft-anti-affinity',
151 151
                       expected_weight=0.0,
152 152
                       expected_host='host2')
153
-        self.assertEqual(1, mock_log.warn.call_count)
153
+        self.assertEqual(1, mock_log.warning.call_count)

+ 12
- 0
nova/tests/unit/test_hacking.py View File

@@ -747,6 +747,18 @@ class HackingTestCase(test.NoDBTestCase):
747 747
         self._assert_has_errors(code, checks.no_os_popen,
748 748
                                 expected_errors=errors)
749 749
 
750
+    def test_no_log_warn(self):
751
+        code = """
752
+                  LOG.warn("LOG.warn is deprecated")
753
+               """
754
+        errors = [(1, 0, 'N352')]
755
+        self._assert_has_errors(code, checks.no_log_warn,
756
+                                expected_errors=errors)
757
+        code = """
758
+                  LOG.warning("LOG.warn is deprecated")
759
+               """
760
+        self._assert_has_no_errors(code, checks.no_log_warn)
761
+
750 762
     def test_uncalled_closures(self):
751 763
 
752 764
         checker = checks.CheckForUncalledTestClosure

+ 1
- 1
nova/tests/unit/virt/hyperv/test_migrationops.py View File

@@ -444,7 +444,7 @@ class MigrationOpsTestCase(test_base.HyperVBaseTestCase):
444 444
                           mock.sentinel.image_meta, True, bdi, True)
445 445
 
446 446
     @mock.patch.object(migrationops.MigrationOps, '_check_resize_vhd')
447
-    @mock.patch.object(migrationops.LOG, 'warn')
447
+    @mock.patch.object(migrationops.LOG, 'warning')
448 448
     def test_check_ephemeral_disks_multiple_eph_warn(self, mock_warn,
449 449
                                                      mock_check_resize_vhd):
450 450
         mock_instance = fake_instance.fake_instance_obj(self.context)

+ 2
- 2
nova/virt/hyperv/migrationops.py View File

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

+ 5
- 5
nova/virt/libvirt/driver.py View File

@@ -3063,8 +3063,8 @@ class LibvirtDriver(driver.ComputeDriver):
3063 3063
                                   files)
3064 3064
 
3065 3065
         elif need_inject:
3066
-            LOG.warn(_LW('File injection into a boot from volume '
3067
-                         'instance is not supported'), instance=instance)
3066
+            LOG.warning(_LW('File injection into a boot from volume '
3067
+                            'instance is not supported'), instance=instance)
3068 3068
 
3069 3069
         # Lookup the filesystem type if required
3070 3070
         os_type_with_default = disk.get_fs_type_for_os_type(instance.os_type)
@@ -4296,9 +4296,9 @@ class LibvirtDriver(driver.ComputeDriver):
4296 4296
                 if self._has_uefi_support():
4297 4297
                     global uefi_logged
4298 4298
                     if not uefi_logged:
4299
-                        LOG.warn(_LW("uefi support is without some kind of "
4300
-                                     "functional testing and therefore "
4301
-                                     "considered experimental."))
4299
+                        LOG.warning(_LW("uefi support is without some kind of "
4300
+                                        "functional testing and therefore "
4301
+                                        "considered experimental."))
4302 4302
                         uefi_logged = True
4303 4303
                     guest.os_loader = DEFAULT_UEFI_LOADER_PATH[
4304 4304
                         caps.host.cpu.arch]

+ 12
- 12
nova/virt/xenapi/vif.py View File

@@ -54,8 +54,8 @@ class XenVIFDriver(object):
54 54
         try:
55 55
             vif_ref = self._session.call_xenapi('VIF.create', vif_rec)
56 56
         except Exception as e:
57
-            LOG.warn(_LW("Failed to create vif, exception:%(exception)s, "
58
-                      "vif:%(vif)s"), {'exception': e, 'vif': vif})
57
+            LOG.warning(_LW("Failed to create vif, exception:%(exception)s, "
58
+                            "vif:%(vif)s"), {'exception': e, 'vif': vif})
59 59
             raise exception.NovaException(
60 60
                 reason=_("Failed to create vif %s") % vif)
61 61
 
@@ -74,7 +74,7 @@ class XenVIFDriver(object):
74 74
                 return
75 75
             self._session.call_xenapi('VIF.destroy', vif_ref)
76 76
         except Exception as e:
77
-            LOG.warn(
77
+            LOG.warning(
78 78
                 _LW("Fail to unplug vif:%(vif)s, exception:%(exception)s"),
79 79
                 {'vif': vif, 'exception': e}, instance=instance)
80 80
             raise exception.NovaException(
@@ -253,9 +253,9 @@ class XenAPIOpenVswitchDriver(XenVIFDriver):
253 253
             # delete the patch port pair
254 254
             self._ovs_del_port(bridge_name, patch_port1)
255 255
         except Exception as e:
256
-            LOG.warn(_LW("Failed to delete patch port pair for vif %(if)s,"
257
-                         " exception:%(exception)s"),
258
-                     {'if': vif, 'exception': e}, instance=instance)
256
+            LOG.warning(_LW("Failed to delete patch port pair for vif %(if)s,"
257
+                            " exception:%(exception)s"),
258
+                        {'if': vif, 'exception': e}, instance=instance)
259 259
             raise exception.VirtualInterfaceUnplugException(
260 260
                 reason=_("Failed to delete patch port pair"))
261 261
 
@@ -283,9 +283,9 @@ class XenAPIOpenVswitchDriver(XenVIFDriver):
283 283
                 self._delete_linux_bridge(qbr_name)
284 284
             self._ovs_del_port(CONF.xenserver.ovs_integration_bridge, qvo_name)
285 285
         except Exception as e:
286
-            LOG.warn(_LW("Failed to delete bridge for vif %(if)s, "
287
-                         "exception:%(exception)s"),
288
-                     {'if': vif, 'exception': e}, instance=instance)
286
+            LOG.warning(_LW("Failed to delete bridge for vif %(if)s, "
287
+                            "exception:%(exception)s"),
288
+                        {'if': vif, 'exception': e}, instance=instance)
289 289
             raise exception.VirtualInterfaceUnplugException(
290 290
                 reason=_("Failed to delete bridge"))
291 291
 
@@ -420,9 +420,9 @@ class XenAPIOpenVswitchDriver(XenVIFDriver):
420 420
         try:
421 421
             network_ref = self._session.network.create(network_rec)
422 422
         except Exception as e:
423
-            LOG.warn(_LW("Failed to create interim network for vif %(if)s, "
424
-                         "exception:%(exception)s"),
425
-                     {'if': vif, 'exception': e})
423
+            LOG.warning(_LW("Failed to create interim network for vif %(if)s, "
424
+                            "exception:%(exception)s"),
425
+                        {'if': vif, 'exception': e})
426 426
             raise exception.VirtualInterfacePlugException(
427 427
                 _("Failed to create the interim network for vif"))
428 428
         return network_ref

+ 4
- 4
nova/virt/xenapi/vmops.py View File

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

Loading…
Cancel
Save