Modify variable's using method in Log Messages

String interpolation should be delayed to be handled by the logging code,
rather than being done at the point of the logging call.
Ref:http://docs.openstack.org/developer/oslo.i18n/guidelines.html#log-translation
For example:
LOG.info(_LI('some message: variable=%s') % variable)
LOG.info(_LI('some message: variable=%s'), variable)

Change-Id: Ifaf1dfe589615732e412c4e640cf46679abc9023
Closes-Bug: #1643463
This commit is contained in:
melissaml 2017-01-04 15:11:33 +08:00
parent 1d1096ce54
commit 2ee054c1f5
4 changed files with 17 additions and 17 deletions

View File

@ -103,8 +103,8 @@ class KeystoneClientV3(object):
LOG.warning(_LW('Auth plugin and its options for service user ' LOG.warning(_LW('Auth plugin and its options for service user '
'must be provided in [%(new)s] section. ' 'must be provided in [%(new)s] section. '
'Using values from [%(old)s] section is ' 'Using values from [%(old)s] section is '
'deprecated.') % {'new': ksconf.CFG_GROUP, 'deprecated.'), {'new': ksconf.CFG_GROUP,
'old': ksconf.CFG_LEGACY_GROUP}) 'old': ksconf.CFG_LEGACY_GROUP})
conf = getattr(CONF, ksconf.CFG_LEGACY_GROUP) conf = getattr(CONF, ksconf.CFG_LEGACY_GROUP)

View File

@ -123,7 +123,7 @@ class BayClient(client.MagnumClient):
lambda: self.does_bay_exist(bay_id), 10, 1800) lambda: self.does_bay_exist(bay_id), 10, 1800)
except Exception: except Exception:
# In error state. Clean up the bay id if desired # In error state. Clean up the bay id if desired
self.LOG.error(_LE('Bay %s entered an exception state.') % bay_id) self.LOG.error(_LE('Bay %s entered an exception state.'), bay_id)
if delete_on_error: if delete_on_error:
self.LOG.error(_LE('We will attempt to delete bays now.')) self.LOG.error(_LE('We will attempt to delete bays now.'))
self.delete_bay(bay_id) self.delete_bay(bay_id)
@ -139,35 +139,35 @@ class BayClient(client.MagnumClient):
resp, model = self.get_bay(bay_id) resp, model = self.get_bay(bay_id)
if model.status in ['CREATED', 'CREATE_COMPLETE', if model.status in ['CREATED', 'CREATE_COMPLETE',
'ERROR', 'CREATE_FAILED']: 'ERROR', 'CREATE_FAILED']:
self.LOG.info(_LI('Bay %s succeeded.') % bay_id) self.LOG.info(_LI('Bay %s succeeded.'), bay_id)
return True return True
else: else:
return False return False
except exceptions.NotFound: except exceptions.NotFound:
self.LOG.warning(_LW('Bay %s is not found.') % bay_id) self.LOG.warning(_LW('Bay %s is not found.'), bay_id)
return False return False
def does_bay_exist(self, bay_id): def does_bay_exist(self, bay_id):
try: try:
resp, model = self.get_bay(bay_id) resp, model = self.get_bay(bay_id)
if model.status in ['CREATED', 'CREATE_COMPLETE']: if model.status in ['CREATED', 'CREATE_COMPLETE']:
self.LOG.info(_LI('Bay %s is created.') % bay_id) self.LOG.info(_LI('Bay %s is created.'), bay_id)
return True return True
elif model.status in ['ERROR', 'CREATE_FAILED']: elif model.status in ['ERROR', 'CREATE_FAILED']:
self.LOG.error(_LE('Bay %s is in fail state.') % bay_id) self.LOG.error(_LE('Bay %s is in fail state.'), bay_id)
raise exceptions.ServerFault( raise exceptions.ServerFault(
"Got into an error condition: %s for %s" % "Got into an error condition: %s for %s" %
(model.status, bay_id)) (model.status, bay_id))
else: else:
return False return False
except exceptions.NotFound: except exceptions.NotFound:
self.LOG.warning(_LW('Bay %s is not found.') % bay_id) self.LOG.warning(_LW('Bay %s is not found.'), bay_id)
return False return False
def does_bay_not_exist(self, bay_id): def does_bay_not_exist(self, bay_id):
try: try:
self.get_bay(bay_id) self.get_bay(bay_id)
except exceptions.NotFound: except exceptions.NotFound:
self.LOG.warning(_LW('Bay %s is not found.') % bay_id) self.LOG.warning(_LW('Bay %s is not found.'), bay_id)
return True return True
return False return False

View File

@ -124,7 +124,7 @@ class ClusterClient(client.MagnumClient):
lambda: self.does_cluster_exist(cluster_id), 10, 1800) lambda: self.does_cluster_exist(cluster_id), 10, 1800)
except Exception: except Exception:
# In error state. Clean up the cluster id if desired # In error state. Clean up the cluster id if desired
self.LOG.error(_LE('Cluster %s entered an exception state.') % self.LOG.error(_LE('Cluster %s entered an exception state.'),
cluster_id) cluster_id)
if delete_on_error: if delete_on_error:
self.LOG.error(_LE('We will attempt to delete clusters now.')) self.LOG.error(_LE('We will attempt to delete clusters now.'))
@ -141,22 +141,22 @@ class ClusterClient(client.MagnumClient):
resp, model = self.get_cluster(cluster_id) resp, model = self.get_cluster(cluster_id)
if model.status in ['CREATED', 'CREATE_COMPLETE', if model.status in ['CREATED', 'CREATE_COMPLETE',
'ERROR', 'CREATE_FAILED']: 'ERROR', 'CREATE_FAILED']:
self.LOG.info(_LI('Cluster %s succeeded.') % cluster_id) self.LOG.info(_LI('Cluster %s succeeded.'), cluster_id)
return True return True
else: else:
return False return False
except exceptions.NotFound: except exceptions.NotFound:
self.LOG.warning(_LW('Cluster %s is not found.') % cluster_id) self.LOG.warning(_LW('Cluster %s is not found.'), cluster_id)
return False return False
def does_cluster_exist(self, cluster_id): def does_cluster_exist(self, cluster_id):
try: try:
resp, model = self.get_cluster(cluster_id) resp, model = self.get_cluster(cluster_id)
if model.status in ['CREATED', 'CREATE_COMPLETE']: if model.status in ['CREATED', 'CREATE_COMPLETE']:
self.LOG.info(_LI('Cluster %s is created.') % cluster_id) self.LOG.info(_LI('Cluster %s is created.'), cluster_id)
return True return True
elif model.status in ['ERROR', 'CREATE_FAILED']: elif model.status in ['ERROR', 'CREATE_FAILED']:
self.LOG.error(_LE('Cluster %s is in fail state.') % self.LOG.error(_LE('Cluster %s is in fail state.'),
cluster_id) cluster_id)
raise exceptions.ServerFault( raise exceptions.ServerFault(
"Got into an error condition: %s for %s" % "Got into an error condition: %s for %s" %
@ -164,13 +164,13 @@ class ClusterClient(client.MagnumClient):
else: else:
return False return False
except exceptions.NotFound: except exceptions.NotFound:
self.LOG.warning(_LW('Cluster %s is not found.') % cluster_id) self.LOG.warning(_LW('Cluster %s is not found.'), cluster_id)
return False return False
def does_cluster_not_exist(self, cluster_id): def does_cluster_not_exist(self, cluster_id):
try: try:
self.get_cluster(cluster_id) self.get_cluster(cluster_id)
except exceptions.NotFound: except exceptions.NotFound:
self.LOG.warning(_LW('Cluster %s is not found.') % cluster_id) self.LOG.warning(_LW('Cluster %s is not found.'), cluster_id)
return True return True
return False return False

View File

@ -303,7 +303,7 @@ extendedKeyUsage = clientAuth
nodes = self._get_nodes_from_stack() nodes = self._get_nodes_from_stack()
if not [x for x in nodes if x]: if not [x for x in nodes if x]:
self.LOG.info(_LI("the list of nodes from stack is empty")) self.LOG.info(_LI("the list of nodes from stack is empty"))
self.LOG.info(_LI("Nodes are: %s") % nodes) self.LOG.info(_LI("Nodes are: %s"), nodes)
return nodes return nodes
def _get_nodes_from_cluster(self): def _get_nodes_from_cluster(self):