Browse Source

Python 3 deprecated the logger.warn method in favor of warning

Python 3 deprecated the logger.warn method, see:
https://docs.python.org/3/library/logging.html#logging.warning, so we
prefer to use warning to avoid DeprecationWarning.

Closes-Bug: 1508442
Change-Id: I245d24b30e783f1c6dcec1b425d78d271edff49b
tags/2.0.0
Wanlong Gao 3 years ago
parent
commit
6ac4ce2eb1

+ 3
- 3
magnum/common/cert_manager/local_cert_manager.py View File

@@ -89,7 +89,7 @@ class CertManager(cert_manager.CertManager):
89 89
         cert_ref = str(uuid.uuid4())
90 90
         filename_base = os.path.join(CONF.certificates.storage_path, cert_ref)
91 91
 
92
-        LOG.warn(_LW(
92
+        LOG.warning(_LW(
93 93
             "Storing certificate data on the local filesystem. "
94 94
             "CertManager type 'local' should be used for testing purpose."
95 95
         ))
@@ -127,7 +127,7 @@ class CertManager(cert_manager.CertManager):
127 127
                  representation of the certificate data
128 128
         :raises CertificateStorageException: if certificate retrieval fails
129 129
         """
130
-        LOG.warn(_LW(
130
+        LOG.warning(_LW(
131 131
             "Loading certificate {0} from the local filesystem. "
132 132
             "CertManager type 'local' should be used for testing purpose."
133 133
         ).format(cert_ref))
@@ -188,7 +188,7 @@ class CertManager(cert_manager.CertManager):
188 188
 
189 189
         :raises CertificateStorageException: if certificate deletion fails
190 190
         """
191
-        LOG.warn(_LW(
191
+        LOG.warning(_LW(
192 192
             "Deleting certificate {0} from the local filesystem. "
193 193
             "CertManager type 'local' should be used for testing purpose."
194 194
         ).format(cert_ref))

+ 1
- 1
magnum/common/keystone.py View File

@@ -92,7 +92,7 @@ class KeystoneClientV3(object):
92 92
         elif self.context.auth_token_info:
93 93
             kwargs['token'] = self.context.auth_token
94 94
             if self._is_v2_valid(self.context.auth_token_info):
95
-                LOG.warn('Keystone v2 is deprecated.')
95
+                LOG.warning('Keystone v2 is deprecated.')
96 96
                 kwargs['auth_ref'] = self.context.auth_token_info['access']
97 97
                 kwargs['auth_ref']['version'] = 'v2.0'
98 98
             elif self._is_v3_valid(self.context.auth_token_info):

+ 11
- 9
magnum/common/utils.py View File

@@ -406,8 +406,8 @@ def unlink_without_raise(path):
406 406
         if e.errno == errno.ENOENT:
407 407
             return
408 408
         else:
409
-            LOG.warn(_LW("Failed to unlink %(path)s, error: %(e)s"),
410
-                     {'path': path, 'e': e})
409
+            LOG.warning(_LW("Failed to unlink %(path)s, error: %(e)s"),
410
+                        {'path': path, 'e': e})
411 411
 
412 412
 
413 413
 def rmtree_without_raise(path):
@@ -415,8 +415,8 @@ def rmtree_without_raise(path):
415 415
         if os.path.isdir(path):
416 416
             shutil.rmtree(path)
417 417
     except OSError as e:
418
-        LOG.warn(_LW("Failed to remove dir %(path)s, error: %(e)s"),
419
-                 {'path': path, 'e': e})
418
+        LOG.warning(_LW("Failed to remove dir %(path)s, error: %(e)s"),
419
+                    {'path': path, 'e': e})
420 420
 
421 421
 
422 422
 def write_to_file(path, contents):
@@ -431,9 +431,9 @@ def create_link_without_raise(source, link):
431 431
         if e.errno == errno.EEXIST:
432 432
             return
433 433
         else:
434
-            LOG.warn(_LW("Failed to create symlink from %(source)s to %(link)s"
435
-                         ", error: %(e)s"),
436
-                     {'source': source, 'link': link, 'e': e})
434
+            LOG.warning(_LW("Failed to create symlink from %(source)s to "
435
+                            "%(link)s, error: %(e)s"),
436
+                        {'source': source, 'link': link, 'e': e})
437 437
 
438 438
 
439 439
 def safe_rstrip(value, chars=None):
@@ -445,8 +445,10 @@ def safe_rstrip(value, chars=None):
445 445
 
446 446
     """
447 447
     if not isinstance(value, six.string_types):
448
-        LOG.warn(_LW("Failed to remove trailing character. Returning original "
449
-                     "object. Supplied object is not a string: %s,"), value)
448
+        LOG.warning(_LW(
449
+            "Failed to remove trailing character. Returning original object. "
450
+            "Supplied object is not a string: %s,"
451
+        ), value)
450 452
         return value
451 453
 
452 454
     return value.rstrip(chars) or value

+ 1
- 1
magnum/conductor/handlers/common/cert_manager.py View File

@@ -150,4 +150,4 @@ def delete_certificates_from_bay(bay):
150 150
                 cert_manager.get_backend().CertManager.delete_cert(
151 151
                     cert_ref, resource_ref=bay.uuid)
152 152
         except Exception:
153
-            LOG.warn(_LW("Deleting cert is failed: %s") % cert_ref)
153
+            LOG.warning(_LW("Deleting cert is failed: %s") % cert_ref)

+ 4
- 4
magnum/conductor/swarm_monitor.py View File

@@ -51,10 +51,10 @@ class SwarmMonitor(MonitorBase):
51 51
                 try:
52 52
                     container = docker.inspect_container(container['Id'])
53 53
                 except Exception as e:
54
-                    LOG.warn(_LW("Ignore error [%(e)s] when inspecting "
55
-                                 "container %(container_id)s."),
56
-                             {'e': e, 'container_id': container['Id']},
57
-                             exc_info=True)
54
+                    LOG.warning(_LW("Ignore error [%(e)s] when inspecting "
55
+                                    "container %(container_id)s."),
56
+                                {'e': e, 'container_id': container['Id']},
57
+                                exc_info=True)
58 58
                 containers.append(container)
59 59
             self.data['containers'] = containers
60 60
 

+ 9
- 8
magnum/service/periodic.py View File

@@ -98,8 +98,9 @@ class MagnumPeriodicTasks(periodic_task.PeriodicTasks):
98 98
                 self._sync_missing_heat_stack(bay)
99 99
 
100 100
         except Exception as e:
101
-            LOG.warn(_LW("Ignore error [%s] when syncing up bay status."), e,
102
-                     exc_info=True)
101
+            LOG.warning(_LW(
102
+                "Ignore error [%s] when syncing up bay status."
103
+            ), e, exc_info=True)
103 104
 
104 105
     def _sync_existing_bay(self, bay, stack):
105 106
         if bay.status != stack.stack_status:
@@ -158,9 +159,9 @@ class MagnumPeriodicTasks(periodic_task.PeriodicTasks):
158 159
             try:
159 160
                 monitor.pull_data()
160 161
             except Exception as e:
161
-                LOG.warn(_LW("Skip pulling data from bay %(bay)s due to "
162
-                             "error: %(e)s"),
163
-                         {'e': e, 'bay': bay.uuid}, exc_info=True)
162
+                LOG.warning(_LW("Skip pulling data from bay %(bay)s due to "
163
+                                "error: %(e)s"),
164
+                            {'e': e, 'bay': bay.uuid}, exc_info=True)
164 165
                 continue
165 166
 
166 167
             metrics = list()
@@ -173,9 +174,9 @@ class MagnumPeriodicTasks(periodic_task.PeriodicTasks):
173 174
                     }
174 175
                     metrics.append(metric)
175 176
                 except Exception as e:
176
-                    LOG.warn(_LW("Skip adding metric %(name)s due to "
177
-                                 "error: %(e)s"),
178
-                             {'e': e, 'name': name}, exc_info=True)
177
+                    LOG.warning(_LW("Skip adding metric %(name)s due to "
178
+                                    "error: %(e)s"),
179
+                                {'e': e, 'name': name}, exc_info=True)
179 180
 
180 181
             message = dict(metrics=metrics,
181 182
                            user_id=bay.user_id,

Loading…
Cancel
Save