Enable H904 check

H904 allows the logging package to skip creating the formatted log
message if the message is not going to be emitted because of the
current log level.

Change-Id: Ib736990696cdcbec360303e744aab9fa4cf82c91
See: https://docs.openstack.org/oslo.i18n/latest/user/guidelines.html#adding-variables-to-log-messages
This commit is contained in:
Ngo Quoc Cuong 2017-07-06 03:17:45 -04:00
parent d06b1adbb9
commit b5530677f4
7 changed files with 19 additions and 15 deletions

View File

@ -349,9 +349,11 @@ class AmbariClient(object):
context.sleep(20)
while True:
status = self.check_request_status(cluster_name, request_id)
LOG.debug("Task %s in %s state. Completed %.1f%%" % (
status["request_context"], status["request_status"],
status["progress_percent"]))
LOG.debug("Task %(context)s in %(status)s state. "
"Completed %(percent).1f%%",
{'context': status["request_context"],
'status': status["request_status"],
'percent': status["progress_percent"]})
if status["request_status"] == "COMPLETED":
return
if status["request_status"] in ["IN_PROGRESS", "PENDING"]:

View File

@ -577,9 +577,9 @@ def restart_service(cluster, service_name):
@cpo.event_wrapper(True, step=_("Remove hosts"), param=('cluster', 0))
def remove_services_from_hosts(cluster, instances):
for inst in instances:
LOG.debug("Stopping and removing processes from host %s" % inst.fqdn())
LOG.debug("Stopping and removing processes from host %s", inst.fqdn())
_remove_services_from_host(cluster, inst)
LOG.debug("Removing the host %s" % inst.fqdn())
LOG.debug("Removing the host %s", inst.fqdn())
_remove_host(cluster, inst)
@ -587,12 +587,12 @@ def _remove_services_from_host(cluster, instance):
with _get_ambari_client(cluster) as client:
hdp_processes = client.list_host_processes(cluster.name, instance)
for proc in hdp_processes:
LOG.debug("Stopping process %s on host %s " %
(proc, instance.fqdn()))
LOG.debug("Stopping process %(proc)s on host %(fqdn)s ",
{'proc': proc, 'fqdn': instance.fqdn()})
client.stop_process_on_host(cluster.name, instance, proc)
LOG.debug("Removing process %s from host %s " %
(proc, instance.fqdn()))
LOG.debug("Removing process %(proc)s from host %(fqdn)s ",
{'proc': proc, 'fqdn': instance.fqdn()})
client.remove_process_from_host(cluster.name, instance, proc)
_wait_all_processes_removed(cluster, instance)

View File

@ -209,7 +209,7 @@ class LabelHandler(object):
if plb.get('deprecated', {}).get('status', False):
LOG.warning("Plugin %s is deprecated and can be removed in "
"the next release" % plugin_name)
"the next release", plugin_name)
vlb = details.get(VERSION_LABELS_SCOPE, {}).get(version, {})
if not vlb.get('enabled', {}).get('status'):
@ -219,5 +219,5 @@ class LabelHandler(object):
if vlb.get('deprecated', {}).get('status', False):
LOG.warning("Using version %(version)s of plugin %(plugin)s is "
"deprecated and can removed in next release"
% {'version': version, 'plugin': plugin_name})
"deprecated and can removed in next release",
{'version': version, 'plugin': plugin_name})

View File

@ -118,7 +118,7 @@ class Service(object):
def _set_service_dir_owner(self, cluster_context, instances):
service_instances = cluster_context.filter_instances(instances,
service=self)
LOG.debug("Changing %s service dir owner" % self.ui_name)
LOG.debug("Changing %s service dir owner", self.ui_name)
for instance in service_instances:
cmd.chown(instance, 'mapr:mapr', self.service_dir(cluster_context))

View File

@ -147,7 +147,7 @@ class AllInstancesAccessible(BasicHealthCheck):
if inst_ips_or_names:
insts = ', '.join(inst_ips_or_names)
LOG.exception(
"Instances (%s) are not available in the cluster" % insts)
"Instances (%s) are not available in the cluster", insts)
raise RedHealthError(
_("Instances (%s) are not available in the cluster.") % insts)
return _("All instances are available")

View File

@ -240,7 +240,7 @@ def _make_periodic_tasks():
api.update_cluster(cluster.id, start_dict)
except vb.CannotVerifyError:
LOG.debug("Skipping running verification "
"on the cluster %s" % cluster.name)
"on the cluster %s", cluster.name)
return SaharaPeriodicTasks()

View File

@ -99,6 +99,8 @@ commands = bandit -c bandit.yaml -r sahara -n5 -p sahara_default -x tests
show-source = true
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools
# [H904] Delay string interpolations at logging calls.
enable-extensions=H904
[hacking]
import_exceptions = sahara.i18n