From 4e615d6da64d583f4023ad5ea8f3a24edb20931e Mon Sep 17 00:00:00 2001 From: Ngo Quoc Cuong Date: Wed, 5 Jul 2017 03:39:22 -0400 Subject: [PATCH] Enable H904 check H904 String interpolation should be delayed to be handled by the logging code, rather than being done at the point of the logging call. Use ',' instead of '%'. See: https://docs.openstack.org/oslo.i18n/latest/user/guidelines.html#adding-variables-to-log-messages Change-Id: I66ea69fe877fa57a54e06c22221cdd1f3414ef16 Related-Bug: #1596829 --- glare/api/middleware/keycloak_auth.py | 6 ++---- glare/common/store_api.py | 4 ++-- glare/db/sqlalchemy/api.py | 2 +- glare/scrubber.py | 4 ++-- tox.ini | 3 ++- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/glare/api/middleware/keycloak_auth.py b/glare/api/middleware/keycloak_auth.py index 91fe702..455a152 100644 --- a/glare/api/middleware/keycloak_auth.py +++ b/glare/api/middleware/keycloak_auth.py @@ -98,10 +98,8 @@ class KeycloakAuthMiddleware(base_middleware.Middleware): time=CONF.keycloak_oidc.token_cache_time) info = resp.json() - LOG.debug( - "HTTP response from OIDC provider: %s" % - pprint.pformat(info) - ) + LOG.debug("HTTP response from OIDC provider: %s", + pprint.pformat(info)) return info diff --git a/glare/common/store_api.py b/glare/common/store_api.py index 9be224e..9e9223d 100644 --- a/glare/common/store_api.py +++ b/glare/common/store_api.py @@ -73,14 +73,14 @@ def save_blob_to_store(blob_id, blob, context, max_size, store_type = None data = utils.LimitingReader(utils.CooperativeReader(blob), max_size) - LOG.debug('Start uploading blob %s.' % blob_id) + LOG.debug('Start uploading blob %s.', blob_id) if store_type == 'database': location = database_api.add_to_backend( blob_id, data, context, verifier) else: (location, size, md5checksum, __) = backend.add_to_backend( CONF, blob_id, data, 0, store_type, context, verifier) - LOG.debug('Uploading of blob %s is finished.' % blob_id) + LOG.debug('Uploading of blob %s is finished.', blob_id) checksums = {"md5": data.md5.hexdigest(), "sha1": data.sha1.hexdigest(), diff --git a/glare/db/sqlalchemy/api.py b/glare/db/sqlalchemy/api.py index 6eb12d6..966e99d 100644 --- a/glare/db/sqlalchemy/api.py +++ b/glare/db/sqlalchemy/api.py @@ -167,7 +167,7 @@ def _create_or_update(context, artifact_id, values, session): artifact.update(values) LOG.debug('Sending request to the database. ' - 'New values are %s' % values) + 'New values are %s', values) artifact.save(session=session) LOG.debug('Response from the database was received.') diff --git a/glare/scrubber.py b/glare/scrubber.py index 52d81b4..2b34b46 100644 --- a/glare/scrubber.py +++ b/glare/scrubber.py @@ -155,7 +155,7 @@ class Scrubber(object): @staticmethod def _scrub_artifact(af): - LOG.info("Begin scrubbing of artifact %s" % af.id) + LOG.info("Begin scrubbing of artifact %s", af.id) for blob in af.blobs: if not blob.external: try: @@ -168,4 +168,4 @@ class Scrubber(object): # delete artifact itself db_api.delete(context, af.id, db_api.get_session()) - LOG.info("Artifact %s was scrubbed" % af.id) + LOG.info("Artifact %s was scrubbed", af.id) diff --git a/tox.ini b/tox.ini index 37e0d56..6b72fb1 100644 --- a/tox.ini +++ b/tox.ini @@ -66,7 +66,8 @@ commands = bandit -c bandit.yaml -r glare -n5 -p gate # H405 multi line docstring summary not separated with an empty line ignore = H404,H405 exclude = .venv,.git,.tox,dist,doc,etc,*glare/locale*,*lib/python*,*egg,build -enable-extensions = H106,H203 +# H904 Delay string interpolations at logging calls. +enable-extensions = H106,H203,H904 [hacking] local-check-factory = glare.hacking.checks.factory