Browse Source

Fix string interpolation to delayed by logging

String interpolation should be delayed to be handled by the logging
code, rather than being done at the point of the logging call.

See the oslo i18n guideline.
* http://docs.openstack.org/developer/oslo.i18n/guidelines.html

References: https://review.openstack.org/#/c/339268

Change-Id: Iace952cfcf8dec76f0a6bfe11693d175fa07c640
Closes-Bug: #1596829
tags/3.0.0
Aman Kumar 3 years ago
parent
commit
9300f62e12

+ 16
- 16
networking_vsphere/agent/dvs_neutron_agent.py View File

@@ -100,9 +100,9 @@ class DVSAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
100 100
             dvs = self._lookup_dvs_for_context(segment)
101 101
         except (exceptions.NoDVSForPhysicalNetwork,
102 102
                 exceptions.NotSupportedNetworkType) as e:
103
-            LOG.info(_LI('Network %(id)s not created. Reason: %(reason)s') % {
104
-                'id': current['id'],
105
-                'reason': e.message})
103
+            LOG.info(_LI('Network %(id)s not created. Reason: %(reason)s'),
104
+                     {'id': current['id'],
105
+                      'reason': e.message})
106 106
         except exceptions.InvalidNetwork:
107 107
             pass
108 108
         else:
@@ -114,9 +114,9 @@ class DVSAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
114 114
             dvs = self._lookup_dvs_for_context(segment)
115 115
         except (exceptions.NoDVSForPhysicalNetwork,
116 116
                 exceptions.NotSupportedNetworkType) as e:
117
-            LOG.info(_LI('Network %(id)s not deleted. Reason: %(reason)s') % {
118
-                'id': current['id'],
119
-                'reason': e.message})
117
+            LOG.info(_LI('Network %(id)s not deleted. Reason: %(reason)s'),
118
+                     {'id': current['id'],
119
+                      'reason': e.message})
120 120
         except exceptions.InvalidNetwork:
121 121
             pass
122 122
         else:
@@ -128,9 +128,9 @@ class DVSAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
128 128
             dvs = self._lookup_dvs_for_context(segment)
129 129
         except (exceptions.NoDVSForPhysicalNetwork,
130 130
                 exceptions.NotSupportedNetworkType) as e:
131
-            LOG.info(_LI('Network %(id)s not updated. Reason: %(reason)s') % {
132
-                'id': current['id'],
133
-                'reason': e.message})
131
+            LOG.info(_LI('Network %(id)s not updated. Reason: %(reason)s'),
132
+                     {'id': current['id'],
133
+                      'reason': e.message})
134 134
         except exceptions.InvalidNetwork:
135 135
             pass
136 136
         else:
@@ -159,9 +159,9 @@ class DVSAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
159 159
                 self.added_ports.add(current['id'])
160 160
                 self.booked_ports.discard(current['id'])
161 161
         except exceptions.NotSupportedNetworkType as e:
162
-            LOG.info(_LI('Port %(id)s not updated. Reason: %(reason)s') % {
163
-                'id': current['id'],
164
-                'reason': e.message})
162
+            LOG.info(_LI('Port %(id)s not updated. Reason: %(reason)s'),
163
+                     {'id': current['id'],
164
+                      'reason': e.message})
165 165
         except exceptions.NoDVSForPhysicalNetwork:
166 166
             raise exceptions.InvalidSystemState(details=_(
167 167
                 'Port %(port_id)s belong to VMWare VM, but there is '
@@ -176,9 +176,9 @@ class DVSAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
176 176
         try:
177 177
             dvs = self._lookup_dvs_for_context(segment)
178 178
         except exceptions.NotSupportedNetworkType as e:
179
-            LOG.info(_LI('Port %(id)s not deleted. Reason: %(reason)s') % {
180
-                'id': current['id'],
181
-                'reason': e.message})
179
+            LOG.info(_LI('Port %(id)s not deleted. Reason: %(reason)s'),
180
+                     {'id': current['id'],
181
+                      'reason': e.message})
182 182
         except exceptions.NoDVSForPhysicalNetwork:
183 183
             raise exceptions.InvalidSystemState(details=_(
184 184
                 'Port %(port_id)s belong to VMWare VM, but there is '
@@ -195,7 +195,7 @@ class DVSAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
195 195
                 return self.network_map[physical_network]
196 196
             except KeyError:
197 197
                 LOG.debug('No dvs mapped for physical '
198
-                          'network: %s' % physical_network)
198
+                          'network: %s', physical_network)
199 199
                 raise exceptions.NoDVSForPhysicalNetwork(
200 200
                     physical_network=physical_network)
201 201
         else:

+ 3
- 3
networking_vsphere/agent/ovsvapp_agent.py View File

@@ -974,7 +974,7 @@ class OVSvAppAgent(agent.Agent, ovs_agent.OVSNeutronAgent):
974 974
                           "provisioning for %(name)s %(uuid)s."),
975 975
                       {'name': event.src_obj.__class__.__name__,
976 976
                        'uuid': event.src_obj.uuid})
977
-            LOG.exception(_LE("Cause of failure: %s.") % str(e))
977
+            LOG.exception(_LE("Cause of failure: %s."), str(e))
978 978
 
979 979
     def _add_ports_to_host_ports(self, ports, hosting=True):
980 980
         for port_id in ports:
@@ -1055,7 +1055,7 @@ class OVSvAppAgent(agent.Agent, ovs_agent.OVSNeutronAgent):
1055 1055
                     ovsvapp_l2pop_lock.acquire()
1056 1056
                     try:
1057 1057
                         LOG.info(_LI("Invoking update_device_binding RPC for "
1058
-                                     "device %s.") % vm.uuid)
1058
+                                     "device %s."), vm.uuid)
1059 1059
                         self.ovsvapp_rpc.update_device_binding(
1060 1060
                             self.context,
1061 1061
                             agent_id=self.agent_id,
@@ -1063,7 +1063,7 @@ class OVSvAppAgent(agent.Agent, ovs_agent.OVSNeutronAgent):
1063 1063
                             host=self.hostname)
1064 1064
                     except Exception as e:
1065 1065
                         LOG.exception(_LE("Failed to handle VM migration "
1066
-                                          "for device: %s.") % vm.uuid)
1066
+                                          "for device: %s."), vm.uuid)
1067 1067
                         raise error.OVSvAppNeutronAgentError(e)
1068 1068
                     finally:
1069 1069
                         ovsvapp_l2pop_lock.release()

+ 4
- 4
networking_vsphere/drivers/manager.py View File

@@ -53,7 +53,7 @@ class VcenterManager(base_manager.DriverManager):
53 53
         """
54 54
         try:
55 55
             cluster_dvs_list = []
56
-            LOG.debug("Parsing cluster_dvs_mapping %s." % entry)
56
+            LOG.debug("Parsing cluster_dvs_mapping %s.", entry)
57 57
             mappings = entry.split(",")
58 58
             for mapping in mappings:
59 59
                 cluster = None
@@ -64,12 +64,12 @@ class VcenterManager(base_manager.DriverManager):
64 64
                     vds = vds.strip()
65 65
                 if not cluster or not vds:
66 66
                     LOG.error(_LE("Invalid value %s for opt "
67
-                                  "cluster_dvs_mapping.") % mapping)
67
+                                  "cluster_dvs_mapping."), mapping)
68 68
                 else:
69 69
                     cluster_dvs_list.append((cluster, vds))
70 70
         except Exception:
71
-            LOG.exception(_LE("Invalid value %s for opt cluster_dvs_mapping.")
72
-                          % entry)
71
+            LOG.exception(_LE("Invalid value %s for opt cluster_dvs_mapping."),
72
+                          entry)
73 73
         return cluster_dvs_list
74 74
 
75 75
     def _add_cluster(self, cluster, vds):

+ 2
- 2
networking_vsphere/monitor/ovsvapp_monitor.py View File

@@ -172,8 +172,8 @@ class AgentMonitor(agents_db.AgentDbMixin, common_db_mixin.CommonDbMixin):
172 172
                               "%(res)s", {'res': response,
173 173
                                           'ip': monitoring_ip})
174 174
                     status = response.json()
175
-                    LOG.info(_LI("ovs status is %(st)s from agent@ %(ip)s")
176
-                             % {'st': status, 'ip': monitoring_ip})
175
+                    LOG.info(_LI("ovs status is %(st)s from agent@ %(ip)s"),
176
+                             {'st': status, 'ip': monitoring_ip})
177 177
                     return (status.get('ovs') == "OK")
178 178
             except Exception:
179 179
                 LOG.exception(_LE("Failed to get OVS status. Will continue "

+ 3
- 3
networking_vsphere/tests/scenario/manager.py View File

@@ -315,7 +315,7 @@ class ESXNetworksTestJSON(base.BaseAdminNetworkTest,
315 315
                 waitsec = (time.time() - start_time)
316 316
                 LOG.info(
317 317
                     _LI('State transition %(oldstatus)s => %(serverstatus)s '
318
-                        'after %(waitsec)d second wait') %
318
+                        'after %(waitsec)d second wait'),
319 319
                     {'oldstatus': oldstatus, 'serverstatus': serverstatus,
320 320
                      'waitsec': waitsec}
321 321
                 )
@@ -418,7 +418,7 @@ class ESXNetworksTestJSON(base.BaseAdminNetworkTest,
418 418
     def check_public_network_connectivity(self, ip_address, username,
419 419
                                           should_connect=True,
420 420
                                           msg=None):
421
-        LOG.debug('checking network connections to IP %s with user: %s' %
421
+        LOG.debug('checking network connections to IP %s with user: %s',
422 422
                   (ip_address, username))
423 423
         try:
424 424
             self.check_vm_connectivity(ip_address,
@@ -580,7 +580,7 @@ class ESXNetworksTestJSON(base.BaseAdminNetworkTest,
580 580
                 self.ping_host(source, dest)
581 581
             except lib_exc.SSHExecCommandFailed:
582 582
                 LOG.warning(_LW('Failed to ping IP: %(dest)s '
583
-                                'via a ssh connection from: %(source)s.') %
583
+                                'via a ssh connection from: %(source)s.'),
584 584
                             {'dest': dest, 'source': source})
585 585
                 return not should_succeed
586 586
             return should_succeed

+ 2
- 2
networking_vsphere/utils/dvs_util.py View File

@@ -105,10 +105,10 @@ class DVSController(object):
105 105
                     'Destroy_Task',
106 106
                     pg_ref)
107 107
                 self.connection.wait_for_task(pg_delete_task)
108
-                LOG.info(_LI('Network %(name)s deleted.') % {'name': name})
108
+                LOG.info(_LI('Network %(name)s deleted.'), {'name': name})
109 109
                 break
110 110
             except exceptions.PortGroupNotFound:
111
-                LOG.debug('Network %s not present in vcenter.' % name)
111
+                LOG.debug('Network %s not present in vcenter.', name)
112 112
                 break
113 113
             except vmware_exceptions.VimException as e:
114 114
                 raise exceptions.wrap_wmvare_vim_exception(e)

+ 5
- 5
networking_vsphere/utils/network_util.py View File

@@ -160,11 +160,11 @@ def wait_until_dvs_portgroup_available(session, vm_ref, pg_name, wait_time):
160 160
                                                  network._type,
161 161
                                                  "config")
162 162
                     if props.name in pg_name:
163
-                        LOG.debug("DistributedVirtualPortgroup created %s "
164
-                                  % pg_name)
163
+                        LOG.debug("DistributedVirtualPortgroup created %s ",
164
+                                  pg_name)
165 165
                         return True
166 166
         LOG.debug("Portgroup %s not created yet. Retrying again "
167
-                  "after 5 seconds" % pg_name)
167
+                  "after 5 seconds", pg_name)
168 168
         greenthread.sleep(5)
169 169
         time_elapsed += 5
170 170
     if time_elapsed >= wait_time:
@@ -335,9 +335,9 @@ def is_valid_dvswitch(session, cluster_mor, dvs_name):
335 335
                 if hostname == cfg.CONF.VMWARE.esx_hostname:
336 336
                     if host.value not in dvs_attached_host_ids:
337 337
                         LOG.error(_LE("DVS not present on"
338
-                                      "host %s") % host.value)
338
+                                      "host %s"), host.value)
339 339
                         return False
340 340
             return hosts_in_cluster
341 341
     else:
342
-        LOG.error(_LE("DVS not present %s") % dvs_name)
342
+        LOG.error(_LE("DVS not present %s"), dvs_name)
343 343
         return False

Loading…
Cancel
Save