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

Related-Bug: #1596829
Change-Id: If986ca58517876d65e04b5e63ba8bb0c19793f01
This commit is contained in:
Ngo Quoc Cuong 2017-07-05 03:29:56 -04:00
parent d0bd3a418f
commit 5904cc2457
10 changed files with 59 additions and 63 deletions

View File

@ -63,7 +63,8 @@ commands =
[flake8]
show-source = True
enable-extensions = H203,H106
# [H904] Delay string interpolations at logging calls.
enable-extensions = H203,H106,H904
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build

View File

@ -373,7 +373,7 @@ class ContainersController(base.Controller):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:stop")
utils.validate_container_state(container, 'stop')
LOG.debug('Calling compute.container_stop with %s' %
LOG.debug('Calling compute.container_stop with %s',
container.uuid)
context = pecan.request.context
compute_api = pecan.request.compute_api
@ -387,7 +387,7 @@ class ContainersController(base.Controller):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:reboot")
utils.validate_container_state(container, 'reboot')
LOG.debug('Calling compute.container_reboot with %s' %
LOG.debug('Calling compute.container_reboot with %s',
container.uuid)
context = pecan.request.context
compute_api = pecan.request.compute_api
@ -400,7 +400,7 @@ class ContainersController(base.Controller):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:pause")
utils.validate_container_state(container, 'pause')
LOG.debug('Calling compute.container_pause with %s' %
LOG.debug('Calling compute.container_pause with %s',
container.uuid)
context = pecan.request.context
compute_api = pecan.request.compute_api
@ -413,7 +413,7 @@ class ContainersController(base.Controller):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:unpause")
utils.validate_container_state(container, 'unpause')
LOG.debug('Calling compute.container_unpause with %s' %
LOG.debug('Calling compute.container_unpause with %s',
container.uuid)
context = pecan.request.context
compute_api = pecan.request.compute_api
@ -436,8 +436,7 @@ class ContainersController(base.Controller):
msg = _('Valid stdout, stderr and timestamps values are ''true'', '
'"false", True, False, 0 and 1, yes and no')
raise exception.InvalidValue(msg)
LOG.debug('Calling compute.container_logs with %s' %
container.uuid)
LOG.debug('Calling compute.container_logs with %s', container.uuid)
context = pecan.request.context
compute_api = pecan.request.compute_api
return compute_api.container_logs(context, container, stdout, stderr,
@ -457,8 +456,9 @@ class ContainersController(base.Controller):
except ValueError:
msg = _('Valid run values are true, false, 0, 1, yes and no')
raise exception.InvalidValue(msg)
LOG.debug('Calling compute.container_exec with %s command %s'
% (container.uuid, kwargs['command']))
LOG.debug('Calling compute.container_exec with %(uuid)s command '
'%(command)s',
{'uuid': container.uuid, 'command': kwargs['command']})
context = pecan.request.context
compute_api = pecan.request.compute_api
return compute_api.container_exec(context, container,
@ -488,9 +488,10 @@ class ContainersController(base.Controller):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:kill")
utils.validate_container_state(container, 'kill')
LOG.debug('Calling compute.container_kill with %s signal %s'
% (container.uuid,
kwargs.get('signal', kwargs.get('signal'))))
LOG.debug('Calling compute.container_kill with %(uuid)s '
'signal %(signal)s',
{'uuid': container.uuid,
'signal': kwargs.get('signal', kwargs.get('signal'))})
context = pecan.request.context
compute_api = pecan.request.compute_api
compute_api.container_kill(context, container, kwargs.get('signal'))
@ -502,8 +503,7 @@ class ContainersController(base.Controller):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:attach")
utils.validate_container_state(container, 'attach')
LOG.debug('Checking the status for attach with %s' %
container.uuid)
LOG.debug('Checking the status for attach with %s', container.uuid)
if container.interactive:
context = pecan.request.context
compute_api = pecan.request.compute_api
@ -520,7 +520,7 @@ class ContainersController(base.Controller):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:resize")
utils.validate_container_state(container, 'resize')
LOG.debug('Calling tty resize with %s ' % (container.uuid))
LOG.debug('Calling tty resize with %s ', container.uuid)
context = pecan.request.context
compute_api = pecan.request.compute_api
compute_api.container_resize(context, container, kwargs.get('h', None),
@ -533,8 +533,7 @@ class ContainersController(base.Controller):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:top")
utils.validate_container_state(container, 'top')
LOG.debug('Calling compute.container_top with %s' %
container.uuid)
LOG.debug('Calling compute.container_top with %s', container.uuid)
context = pecan.request.context
compute_api = pecan.request.compute_api
return compute_api.container_top(context, container, ps_args)
@ -545,8 +544,9 @@ class ContainersController(base.Controller):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:get_archive")
utils.validate_container_state(container, 'get_archive')
LOG.debug('Calling compute.container_get_archive with %s path %s'
% (container.uuid, kwargs['path']))
LOG.debug('Calling compute.container_get_archive with %(uuid)s '
'path %(path)s',
{'uuid': container.uuid, 'path': kwargs['path']})
context = pecan.request.context
compute_api = pecan.request.compute_api
data, stat = compute_api.container_get_archive(
@ -559,8 +559,9 @@ class ContainersController(base.Controller):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:put_archive")
utils.validate_container_state(container, 'put_archive')
LOG.debug('Calling compute.container_put_archive with %s path %s'
% (container.uuid, kwargs['path']))
LOG.debug('Calling compute.container_put_archive with %(uuid)s '
'path %(path)s',
{'uuid': container.uuid, 'path': kwargs['path']})
context = pecan.request.context
compute_api = pecan.request.compute_api
compute_api.container_put_archive(context, container,
@ -572,8 +573,7 @@ class ContainersController(base.Controller):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:stats")
utils.validate_container_state(container, 'stats')
LOG.debug('Calling compute.container_stats with %s'
% (container.uuid))
LOG.debug('Calling compute.container_stats with %s', container.uuid)
context = pecan.request.context
compute_api = pecan.request.compute_api
return compute_api.container_stats(context, container)
@ -585,7 +585,7 @@ class ContainersController(base.Controller):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:commit")
utils.validate_container_state(container, 'commit')
LOG.debug('Calling compute.container_commit %s ' % (container.uuid))
LOG.debug('Calling compute.container_commit %s ', container.uuid)
context = pecan.request.context
compute_api = pecan.request.compute_api
pecan.response.status = 202

View File

@ -123,8 +123,7 @@ class ImagesController(base.Controller):
context = pecan.request.context
policy.enforce(context, "image:search",
action="image:search")
LOG.debug('Calling compute.image_search with %s' %
image)
LOG.debug('Calling compute.image_search with %s', image)
try:
exact_match = strutils.bool_from_string(exact_match, strict=True)
except ValueError:

View File

@ -117,7 +117,7 @@ def wrap_controller_exception(func, func_server_error, func_client_error):
# log the error message with its associated
# correlation id
log_correlation_id = uuidutils.generate_uuid()
LOG.exception("%(correlation_id)s:%(excp)s" %
LOG.exception("%(correlation_id)s:%(excp)s",
{'correlation_id': log_correlation_id,
'excp': str(excp)})
# raise a client error with an obfuscated message
@ -194,8 +194,8 @@ class ZunException(Exception):
except KeyError:
# kwargs doesn't match a variable in the message
# log the issue and the kwargs
LOG.exception(('Exception in string format operation, '
'kwargs: %s') % kwargs)
LOG.exception('Exception in string format operation, '
'kwargs: %s', kwargs)
try:
ferr = CONF.fatal_exception_format_errors
except cfg.NoSuchOptError:

View File

@ -574,7 +574,7 @@ class Manager(object):
LOG.error("Error occurred while calling docker commit API: %s",
six.text_type(e))
raise
LOG.debug('Upload image %s to glance' % container_image_id)
LOG.debug('Upload image %s to glance', container_image_id)
self._do_container_image_upload(context, snapshot_image,
container_image, tag)

View File

@ -86,12 +86,12 @@ class DockerDriver(driver.ContainerDriver):
def inspect_image(self, image):
with docker_utils.docker_client() as docker:
LOG.debug('Inspecting image %s' % image)
LOG.debug('Inspecting image %s', image)
image_dict = docker.inspect_image(image)
return image_dict
def get_image(self, name):
LOG.debug('Obtaining image %s' % name)
LOG.debug('Obtaining image %s', name)
with docker_utils.docker_client() as docker:
response = docker.get_image(name)
return response
@ -105,8 +105,8 @@ class DockerDriver(driver.ContainerDriver):
with docker_utils.docker_client() as docker:
name = container.name
image = container.image
LOG.debug('Creating container with image %s name %s'
% (image, name))
LOG.debug('Creating container with image %(image)s name %(name)s',
{'image': image, 'name': name})
kwargs = {
'name': self.get_container_name(container),
@ -779,8 +779,7 @@ class NovaDockerDriver(DockerDriver):
novaclient = nova.NovaClient(elevated)
server_name = self._find_server_by_container_id(sandbox_id)
if not server_name:
LOG.warning("Cannot find server name for sandbox %s" %
sandbox_id)
LOG.warning("Cannot find server name for sandbox %s", sandbox_id)
return
server_id = novaclient.delete_server(server_name)
@ -791,8 +790,7 @@ class NovaDockerDriver(DockerDriver):
novaclient = nova.NovaClient(elevated)
server_name = self._find_server_by_container_id(sandbox_id)
if not server_name:
LOG.warning("Cannot find server name for sandbox %s" %
sandbox_id)
LOG.warning("Cannot find server name for sandbox %s", sandbox_id)
return
novaclient.stop_server(server_name)

View File

@ -36,13 +36,13 @@ class DockerDriver(driver.ContainerImageDriver):
def _search_image_on_host(self, repo, tag):
with docker_utils.docker_client() as docker:
image = repo + ":" + tag
LOG.debug('Inspecting image locally %s' % image)
LOG.debug('Inspecting image locally %s', image)
try:
image_dict = docker.inspect_image(image)
if image_dict:
return {'image': repo, 'path': None}
except errors.NotFound:
LOG.debug('Image %s not found locally' % image)
LOG.debug('Image %s not found locally', image)
return None
def _pull_image(self, repo, tag):
@ -57,7 +57,7 @@ class DockerDriver(driver.ContainerImageDriver):
image = self._search_image_on_host(repo, tag)
if not utils.should_pull_image(image_pull_policy, bool(image)):
if image:
LOG.debug('Image %s present locally' % repo)
LOG.debug('Image %s present locally', repo)
return image, image_loaded
else:
message = _('Image %s not present with pull policy of Never'
@ -65,19 +65,18 @@ class DockerDriver(driver.ContainerImageDriver):
raise exception.ImageNotFound(message)
try:
LOG.debug('Pulling image from docker %s,'
' context %s' % (repo, context))
LOG.debug('Pulling image from docker %(repo)s,'
' context %(context)s',
{'repo': repo, 'context': context})
self._pull_image(repo, tag)
return {'image': repo, 'path': None}, image_loaded
except exception.ImageNotFound:
with excutils.save_and_reraise_exception():
LOG.error(
'Image %s was not found in docker repo' % repo)
LOG.error('Image %s was not found in docker repo', repo)
except exception.DockerError:
with excutils.save_and_reraise_exception():
LOG.error(
'Docker API error occurred during downloading\
image %s' % repo)
LOG.error('Docker API error occurred during downloading '
'image %s', repo)
except Exception as e:
msg = _('Cannot download image from docker: {0}')
raise exception.ZunException(msg.format(e))

View File

@ -36,7 +36,7 @@ class GlanceDriver(driver.ContainerImageDriver):
super(GlanceDriver, self).__init__()
def _search_image_on_host(self, context, repo):
LOG.debug('Searching for image %s locally' % repo)
LOG.debug('Searching for image %s locally', repo)
images_directory = CONF.glance.images_directory
try:
# TODO(mkrai): Change this to search image entry in zun db
@ -78,7 +78,7 @@ class GlanceDriver(driver.ContainerImageDriver):
if not common_utils.should_pull_image(image_pull_policy, bool(image)):
if image:
LOG.debug('Image %s present locally' % repo)
LOG.debug('Image %s present locally', repo)
image_loaded = True
return image, image_loaded
else:
@ -86,15 +86,14 @@ class GlanceDriver(driver.ContainerImageDriver):
) % repo
raise exception.ImageNotFound(message)
LOG.debug('Pulling image from glance %s' % repo)
LOG.debug('Pulling image from glance %s', repo)
try:
glance = utils.create_glanceclient(context)
image_meta = utils.find_image(context, repo)
LOG.debug('Image %s was found in glance, downloading now...'
% repo)
LOG.debug('Image %s was found in glance, downloading now...', repo)
image_chunks = glance.images.data(image_meta.id)
except exception.ImageNotFound:
LOG.error('Image %s was not found in glance' % repo)
LOG.error('Image %s was not found in glance', repo)
raise
except Exception as e:
msg = _('Cannot download image from glance: {0}')
@ -109,14 +108,14 @@ class GlanceDriver(driver.ContainerImageDriver):
except Exception as e:
msg = _('Error occurred while writing image: {0}')
raise exception.ZunException(msg.format(e))
LOG.debug('Image %s was downloaded to path : %s'
% (repo, out_path))
LOG.debug('Image %(repo)s was downloaded to path : %(path)s',
{'repo': repo, 'path': out_path})
return {'image': repo, 'path': out_path}, image_loaded
def search_image(self, context, repo, tag, exact_match):
# TODO(mkrai): glance driver does not handle tags
# once metadata is stored in db then handle tags
LOG.debug('Searching image in glance %s' % repo)
LOG.debug('Searching image in glance %s', repo)
try:
# TODO(hongbin): find image by both repo and tag
images = utils.find_images(context, repo, exact_match)
@ -126,7 +125,7 @@ class GlanceDriver(driver.ContainerImageDriver):
def create_image(self, context, image_name):
"""Create an image."""
LOG.debug('Creating a new image in glance %s' % image_name)
LOG.debug('Creating a new image in glance %s', image_name)
try:
img = utils.create_image(context, image_name)
return img
@ -136,7 +135,7 @@ class GlanceDriver(driver.ContainerImageDriver):
def update_image(self, context, img_id, disk_format='qcow2',
container_format='docker', tag=None):
"""Update an image."""
LOG.debug('Updating an image %s in glance' % img_id)
LOG.debug('Updating an image %s in glance', img_id)
try:
if tag is not None:
tags = []
@ -151,7 +150,7 @@ class GlanceDriver(driver.ContainerImageDriver):
def upload_image_data(self, context, img_id, data):
"""Update an image."""
LOG.debug('Uploading an image to glance %s' % img_id)
LOG.debug('Uploading an image to glance %s', img_id)
try:
img = utils.upload_image_data(context, img_id, data)
return img

View File

@ -35,7 +35,7 @@ def create_glanceclient(context):
def find_image(context, image_ident):
matches = find_images(context, image_ident, exact_match=True)
LOG.debug('Found matches %s ' % matches)
LOG.debug('Found matches %s ', matches)
if len(matches) == 0:
raise exception.ImageNotFound(image=image_ident)
if len(matches) > 1:
@ -93,7 +93,7 @@ def update_image_tags(context, img_id, tags):
def upload_image_data(context, img_id, data):
"""Upload an image."""
LOG.debug('Upload image %s ' % img_id)
LOG.debug('Upload image %s ', img_id)
glance = create_glanceclient(context)
img = glance.images.upload(img_id, data)
return img

View File

@ -199,7 +199,7 @@ class KuryrNetwork(network.Network):
updated_port = {'security_groups': port['security_groups']}
try:
LOG.info("Adding security group %(security_group_ids)s "
"to port %(port_id)s" %
"to port %(port_id)s",
{'security_group_ids': security_group_ids,
'port_id': port['id']})
self.neutron.update_port(port['id'],