Delay string interpolation in logs
It's a known good practice to avoid unnecessary string interpolation overhead, especially in debug logs. Enable H904 check to catch any direct interpolation in the future. Change-Id: I060fb0d140d0da09488f6abd44b4fb1d79555d35 Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
1 parent
db36c51d5b
commit
33c603ccba
14 files changed
+30
-31
No files matched your search
@@ -87,7 +87,7 @@ class MariaBackupIncremental(MariaBackup):
|
||||
'--backup --stream=xbstream --incremental-lsn=%(lsn)s ' +
|
||||
self.user_and_pass
|
||||
)
|
||||
LOG.info('cmd:{}'.format(cmd))
|
||||
LOG.debug('cmd: %s', cmd)
|
||||
return cmd
|
||||
|
||||
def get_metadata(self):
|
||||
|
||||
@@ -137,7 +137,7 @@ class MySQLBaseRunner(base.BaseRunner):
|
||||
LOG.info("Restoring back to full backup.")
|
||||
command = self.restore_command
|
||||
|
||||
LOG.debug("command:{}".format(command))
|
||||
LOG.debug("command: %s", command)
|
||||
|
||||
self.restore_content_length += self.unpack(location, checksum, command)
|
||||
self.incremental_prepare(incremental_dir)
|
||||
|
||||
@@ -152,8 +152,8 @@ class PgBasebackup(base.BaseRunner):
|
||||
"""
|
||||
def _metadata_found():
|
||||
backup_file = self.get_backup_file()
|
||||
LOG.info("backup_file: %s" % [backup_file])
|
||||
LOG.info("Doing backup Postgres in read-only mode: %s" %
|
||||
LOG.info("backup_file: %s", [backup_file])
|
||||
LOG.info("Doing backup Postgres in read-only mode: %s",
|
||||
self.is_read_only)
|
||||
if not backup_file and self.is_read_only:
|
||||
return True
|
||||
|
||||
@@ -63,7 +63,7 @@ ignore-path = .venv,.tox,.git,dist,doc,*egg-info,tools,etc,build,*.po,*.pot,inte
|
||||
[flake8]
|
||||
show-source = True
|
||||
ignore = E402,E731,F601,H301,H404,H405,H501,W503,W504,W605
|
||||
enable-extensions = H203,H106,H213
|
||||
enable-extensions = H203,H106,H213,H904
|
||||
import-order-style = pep8
|
||||
builtins = _
|
||||
# add *.yaml for playbooks/trove-devstack-base.yaml, as it will be matched by
|
||||
|
||||
@@ -62,10 +62,10 @@ class TenantBasedAuth(object):
|
||||
match_for_tenant = self.tenant_scoped_url.match(request.path_info)
|
||||
if (match_for_tenant and
|
||||
tenant_id == match_for_tenant.group('tenant_id')):
|
||||
LOG.debug(strutils.mask_password(
|
||||
("Authorized tenant '%(tenant_id)s' request: "
|
||||
"%(request)s") %
|
||||
{'tenant_id': tenant_id, 'request': req_to_text(request)}))
|
||||
LOG.debug(
|
||||
"Authorized tenant '%(tenant_id)s' request: %(request)s",
|
||||
{'tenant_id': tenant_id,
|
||||
'request': strutils.mask_password(req_to_text(request))})
|
||||
return True
|
||||
|
||||
log_fmt = "User with tenant id %s cannot access this resource."
|
||||
|
||||
@@ -149,7 +149,7 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
def report_root(self, context, instance_id, user=None):
|
||||
if user is not None:
|
||||
LOG.debug("calling report_root with a username: %s, "
|
||||
"is deprecated now!" % user)
|
||||
"is deprecated now!", user)
|
||||
common_models.RootHistory.create(context, instance_id)
|
||||
|
||||
def notify_end(self, context, serialized_notification, notification_args):
|
||||
|
||||
@@ -967,7 +967,7 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
# Freeze FS
|
||||
operating_system.fsfreeze(mount_point)
|
||||
except Exception as e:
|
||||
LOG.error("Run pre_create_backup failed, error: %s" % str(e))
|
||||
LOG.error("Run pre_create_backup failed, error: %s", e)
|
||||
|
||||
return {}
|
||||
|
||||
@@ -980,6 +980,6 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
mount_point = CONF.get(CONF.datastore_manager).mount_point
|
||||
operating_system.fsunfreeze(mount_point)
|
||||
except Exception as e:
|
||||
LOG.error("Run post_create_backup failed, error: %s" % str(e))
|
||||
LOG.error("Run post_create_backup failed, error: %s", e)
|
||||
|
||||
return {}
|
||||
@@ -79,7 +79,7 @@ class Manager(manager.MySqlManager):
|
||||
operating_system.sync(mount_point)
|
||||
operating_system.fsfreeze(mount_point)
|
||||
except Exception as e:
|
||||
LOG.error("Run pre_create_backup failed, error: %s" % str(e))
|
||||
LOG.error("Run pre_create_backup failed, error: %s", e)
|
||||
raise exception.BackupCreationError(str(e))
|
||||
return status
|
||||
|
||||
@@ -139,7 +139,6 @@ class Manager(manager.MySqlManager):
|
||||
)
|
||||
docker_utils.remove_container(self.app.docker_client)
|
||||
except Exception as err:
|
||||
LOG.error('Failed to remove container. error: %s',
|
||||
str(err))
|
||||
LOG.error('Failed to remove container. error: %s', err)
|
||||
pass
|
||||
LOG.info('Finished to reset password for restore')
|
||||
@@ -61,7 +61,7 @@ class Manager(manager.MySqlManager):
|
||||
operating_system.sync(mount_point)
|
||||
operating_system.fsfreeze(mount_point)
|
||||
except Exception as e:
|
||||
LOG.error("Run pre_create_backup failed, error: %s" % str(e))
|
||||
LOG.error("Run pre_create_backup failed, error: %s", e)
|
||||
raise exception.BackupCreationError(str(e))
|
||||
|
||||
return status
|
||||
@@ -326,8 +326,8 @@ class MySqlManager(manager.Manager):
|
||||
command = self.get_start_db_params(data_dir)
|
||||
self.app.start_db(ds_version=ds_version, command=command)
|
||||
except Exception as e:
|
||||
LOG.error(f"Failed to restore database service after rebuild, "
|
||||
f"error: {str(e)}")
|
||||
LOG.error("Failed to restore database service after rebuild, "
|
||||
"error: %s", e)
|
||||
self.prepare_error = True
|
||||
raise
|
||||
finally:
|
||||
@@ -341,6 +341,6 @@ class MySqlManager(manager.Manager):
|
||||
mount_point = CONF.get(CONF.datastore_manager).mount_point
|
||||
operating_system.fsunfreeze(mount_point)
|
||||
except Exception as e:
|
||||
LOG.error("Run post_create_backup failed, error: %s" % str(e))
|
||||
LOG.error("Run post_create_backup failed, error: %s", e)
|
||||
|
||||
return {}
|
||||
@@ -332,8 +332,8 @@ class PostgresManager(manager.Manager):
|
||||
command = f"postgres -c config_file={service.CONFIG_FILE}"
|
||||
self.app.start_db(ds_version=ds_version, command=command)
|
||||
except Exception as e:
|
||||
LOG.error(f"Failed to restore database service after rebuild, "
|
||||
f"error: {str(e)}")
|
||||
LOG.error("Failed to restore database service after rebuild, "
|
||||
"error: %s", e)
|
||||
self.prepare_error = True
|
||||
raise
|
||||
finally:
|
||||
@@ -380,7 +380,7 @@ class PostgresManager(manager.Manager):
|
||||
operating_system.sync(mount_point)
|
||||
operating_system.fsfreeze(mount_point)
|
||||
except Exception as e:
|
||||
LOG.error("Run pre_create_backup failed, error: %s" % str(e))
|
||||
LOG.error("Run pre_create_backup failed, error: %s", e)
|
||||
raise exception.BackupCreationError(str(e))
|
||||
return {}
|
||||
|
||||
@@ -400,7 +400,7 @@ class PostgresManager(manager.Manager):
|
||||
|
||||
self.app.adm.pquery(command)
|
||||
except Exception as e:
|
||||
LOG.error("Run _stop_backup failed, error: %s" % str(e))
|
||||
LOG.error("Run _stop_backup failed, error: %s", e)
|
||||
finally:
|
||||
self.app.adm.close_pconnection()
|
||||
|
||||
@@ -408,7 +408,7 @@ class PostgresManager(manager.Manager):
|
||||
mount_point = CONF.get(CONF.datastore_manager).mount_point
|
||||
operating_system.fsunfreeze(mount_point)
|
||||
except Exception as e:
|
||||
LOG.warning('Failed to run post_create_backup %s' % e)
|
||||
LOG.warning('Failed to run post_create_backup %s', e)
|
||||
raise exception.BackupCreationError(str(e))
|
||||
_stop_backup()
|
||||
return {}
|
||||
|
||||
@@ -341,10 +341,10 @@ class VolumeMountPoint(object):
|
||||
if not operating_system.exists(self.mount_point, is_directory=True,
|
||||
as_root=True):
|
||||
operating_system.ensure_directory(self.mount_point, as_root=True)
|
||||
LOG.debug("Mounting volume. Device path:{0}, mount_point:{1}, "
|
||||
"volume_type:{2}, mount options:{3}".format(
|
||||
self.device_path, self.mount_point, self.volume_fstype,
|
||||
self.mount_options))
|
||||
LOG.debug("Mounting volume. Device path:%s, mount_point:%s, "
|
||||
"volume_type:%s, mount options:%s",
|
||||
self.device_path, self.mount_point, self.volume_fstype,
|
||||
self.mount_options)
|
||||
try:
|
||||
utils.execute("mount", "-t", self.volume_fstype,
|
||||
"-o", self.mount_options,
|
||||
|
||||
@@ -1722,13 +1722,13 @@ class SnapshotTasks(object):
|
||||
self.instance.guest.post_create_backup()
|
||||
LOG.info("Completed backup %s.", self.backup_id)
|
||||
except GuestError as err:
|
||||
LOG.error("Failed to create backup %s: %s" % (self.backup_id, err))
|
||||
LOG.error("Failed to create backup %s: %s", self.backup_id, err)
|
||||
backup_state.update({
|
||||
'success': False,
|
||||
'state': BackupState.FAILED,
|
||||
})
|
||||
except Exception as e:
|
||||
LOG.error("Failed to create backup %s: %s" % (self.backup_id, e))
|
||||
LOG.error("Failed to create backup %s: %s", self.backup_id, e)
|
||||
backup_state.update({
|
||||
'success': False,
|
||||
'state': BackupState.FAILED,
|
||||
|
||||
@@ -47,7 +47,7 @@ def retry(expected_exception_cls, retries=3, delay_fun=lambda n: 3 * n):
|
||||
delay = delay_fun(retries - remaining_attempts)
|
||||
LOG.exception(
|
||||
"Retrying in %(delay)d seconds "
|
||||
"(remaining attempts: %(remaining)d)..." %
|
||||
"(remaining attempts: %(remaining)d)...",
|
||||
{'delay': delay, 'remaining': remaining_attempts})
|
||||
time.sleep(delay)
|
||||
return f(*args, **kwargs)
|
||||
|
||||
Reference in new issue
Block a user