Handle log message interpolation by the logger part 6

The following directories were fixed in this commit:
  - datastore/
  - db/
  - dns/
  - instance/

According to OpenStack Guideline[1], logged string message should be
interpolated by the logger.

[1]: http://docs.openstack.org/developer/oslo.i18n/guidelines.html#adding-variables-to-log-messages

Change-Id: Idd22bd5b561198eb02a03383d0ef53bd900bdcf9
Related-Bug: #1642552
This commit is contained in:
Gábor Antal 2017-02-14 19:21:24 +01:00
parent 3d3181f56f
commit 0956c1e134
10 changed files with 31 additions and 30 deletions

View File

@ -134,7 +134,7 @@ class Capabilities(object):
self.capabilities = [override(obj) for obj in capability_defaults]
LOG.debug('Capabilities for datastore %(ds_id)s: %(capabilities)s' %
LOG.debug('Capabilities for datastore %(ds_id)s: %(capabilities)s',
{'ds_id': self.datastore_version_id,
'capabilities': self.capabilities})

View File

@ -59,14 +59,14 @@ class DatabaseModelBase(models.ModelBase):
if not self.is_valid():
raise exception.InvalidModelError(errors=self.errors)
self['updated'] = utils.utcnow()
LOG.debug("Saving %(name)s: %(dict)s" %
LOG.debug("Saving %(name)s: %(dict)s",
{'name': self.__class__.__name__,
'dict': strutils.mask_dict_password(self.__dict__)})
return self.db_api.save(self)
def delete(self):
self['updated'] = utils.utcnow()
LOG.debug("Deleting %(name)s: %(dict)s" %
LOG.debug("Deleting %(name)s: %(dict)s",
{'name': self.__class__.__name__,
'dict': strutils.mask_dict_password(self.__dict__)})
@ -105,13 +105,12 @@ class DatabaseModelBase(models.ModelBase):
if ((context and not context.is_admin and hasattr(model, 'tenant_id')
and model.tenant_id != context.tenant)):
msg = _("Tenant %(s_tenant)s tried to access "
"%(s_name)s, owned by %(s_owner)s.")
LOG.error(msg % (
{"s_tenant": context.tenant, "s_name": cls.__name__,
"s_owner": model.tenant_id}))
raise exception.ModelNotFoundError(
_("Tenant %(s_tenant)s cannot access %(s_name)s") % (
{"s_tenant": context.tenant, "s_name": cls.__name__}))
"%(s_name)s, owned by %(s_owner)s.") % {
"s_tenant": context.tenant, "s_name": cls.__name__,
"s_owner": model.tenant_id}
LOG.error(msg)
raise exception.ModelNotFoundError(msg)
return model

View File

@ -65,13 +65,13 @@ class Float(sqlalchemy.types.Float):
def create_tables(tables):
for table in tables:
logger.info("creating table %(table)s" % {'table': table})
logger.info("creating table %(table)s", {'table': table})
table.create()
def drop_tables(tables):
for table in tables:
logger.info("dropping table %(table)s" % {'table': table})
logger.info("dropping table %(table)s", {'table': table})
table.drop()

View File

@ -59,7 +59,7 @@ def upgrade(options, version=None, repo_path=None):
repo_path = get_migrate_repo_path(repo_path)
sql_connection = options['database']['connection']
version_str = version or 'latest'
logger.info("Upgrading %(sql_connection)s to version %(version_str)s" %
logger.info("Upgrading %(sql_connection)s to version %(version_str)s",
{'sql_connection': sql_connection, 'version_str': version_str})
return versioning_api.upgrade(sql_connection, repo_path, version)

View File

@ -88,8 +88,8 @@ def _create_facade(options):
LOG.warning(_('Configuration option "query_log" has been '
'depracated. Use "connection_debug" '
'instead. Setting connection_debug = '
'%(debug_level)s instead.')
% conf.get('connection_debug'))
'%(debug_level)s instead.'),
conf.get('connection_debug'))
# TODO(mvandijk): once query_log is removed,
# use enginefacade.from_config() instead
database_opts = dict(CONF.database)

View File

@ -87,7 +87,7 @@ class DesignateDriver(driver.DnsDriver):
raise TypeError(_("The entry's dns_zone must have an ID "
"specified."))
name = entry.name
LOG.debug("Creating DNS entry %s." % name)
LOG.debug("Creating DNS entry %s.", name)
client = self.dns_client
# Record name has to end with a '.' by dns standard
record = Record(name=entry.name + '.',
@ -105,7 +105,7 @@ class DesignateDriver(driver.DnsDriver):
if rec.name == name + '.' and rec.type == type]
if not matching_record:
raise exception.DnsRecordNotFound(name)
LOG.debug("Deleting DNS entry %s." % name)
LOG.debug("Deleting DNS entry %s.", name)
self.dns_client.records.delete(dns_zone.id, matching_record[0].id)
def get_entries_by_content(self, content, dns_zone=None):

View File

@ -51,10 +51,10 @@ class DnsManager(object):
"""
entry = self.entry_factory.create_entry(instance_id)
if entry:
LOG.debug("Creating entry address %s." % str(entry))
LOG.debug("Creating entry address %s.", str(entry))
self.driver.create_entry(entry, content)
else:
LOG.debug("Entry address not found for instance %s" % instance_id)
LOG.debug("Entry address not found for instance %s", instance_id)
def delete_instance_entry(self, instance_id, content=None):
"""Removes a DNS entry associated to an instance.
@ -64,7 +64,7 @@ class DnsManager(object):
"""
entry = self.entry_factory.create_entry(instance_id)
LOG.debug("Deleting instance entry with %s" % str(entry))
LOG.debug("Deleting instance entry with %s", str(entry))
if entry:
self.driver.delete_entry(entry.name, entry.type)

View File

@ -53,12 +53,12 @@ class DnsRecord(ModelBase):
def save(self):
if not self.is_valid():
raise exception.InvalidModelError(errors=self.errors)
LOG.debug("Saving %(name)s: %(dict)s" %
LOG.debug("Saving %(name)s: %(dict)s",
{'name': self.__class__.__name__, 'dict': self.__dict__})
return get_db_api().save(self)
def delete(self):
LOG.debug("Deleting %(name)s: %(dict)s" %
LOG.debug("Deleting %(name)s: %(dict)s",
{'name': self.__class__.__name__, 'dict': self.__dict__})
return get_db_api().delete(self)

View File

@ -982,8 +982,8 @@ class Instance(BuiltInstance):
except exception.ModelNotFoundError:
LOG.exception(
_("Cannot create a replica of %(id)s "
"as that instance could not be found.")
% {'id': slave_of_id})
"as that instance could not be found."),
{'id': slave_of_id})
raise exception.NotFound(uuid=slave_of_id)
elif replica_count and replica_count != 1:
raise exception.Forbidden(_(
@ -1516,7 +1516,7 @@ class Instances(object):
except exception.NotFound:
# The instance may be gone if we're in the middle of a
# shrink operation, so just log and continue
LOG.debug("Instance %s is no longer available, skipping." %
LOG.debug("Instance %s is no longer available, skipping.",
db_instance.id)
return db_insts
@ -1591,7 +1591,7 @@ class DBInstance(dbmodels.DatabaseModelBase):
kwargs["encrypted_key"] = cu.encode_data(cu.encrypt_data(
key, CONF.inst_rpc_key_encr_key))
LOG.debug("Generated unique RPC encryption key for "
"instance. key = %s" % key)
"instance. key = %s", key)
else:
kwargs["encrypted_key"] = None

View File

@ -193,7 +193,7 @@ class InstanceController(wsgi.Controller):
with StartNotification(context, instance_id=instance.id):
instance.reset_status()
LOG.debug("Failing backups for instance %s." % instance.id)
LOG.debug("Failing backups for instance %s.", instance.id)
backup_model.fail_for_instance(instance.id)
return wsgi.Result(None, 202)
@ -470,7 +470,7 @@ class InstanceController(wsgi.Controller):
def guest_log_list(self, req, tenant_id, id):
"""Return all information about all logs for an instance."""
LOG.debug("Listing logs for tenant %s" % tenant_id)
LOG.debug("Listing logs for tenant %s", tenant_id)
context = req.environ[wsgi.CONTEXT_KEY]
instance = models.Instance.load(context, id)
if not instance:
@ -559,6 +559,8 @@ class InstanceController(wsgi.Controller):
context, instance_id=id, module_id=module_id)
for instance_module in instance_modules:
module_models.InstanceModule.delete(context, instance_module)
LOG.debug("Deleted IM record %s (instance %s, module %s)." %
(instance_module.id, id, module_id))
LOG.debug("Deleted IM record %(instance_module_id)s "
"(instance %(id)s, module %(module_id)s).",
{'instance_module_id': instance_module.id, 'id': id,
'module_id': module_id})
return wsgi.Result(None, 200)