From b9aa042293b36956047d0346ba9c19b585610d93 Mon Sep 17 00:00:00 2001 From: "ting.wang" Date: Sat, 20 Feb 2016 13:36:40 +0800 Subject: [PATCH] Replace string format arguments with function parameters There are files containing string format arguments inside logging messages. Using logging function parameters should be preferred. Change-Id: Id558f66de13146f6ae76a7a69f49721b6c3d6257 Closes-Bug: #1321274 --- magnum/api/controllers/v1/container.py | 12 ++++++------ magnum/cmd/api.py | 6 +++--- magnum/cmd/conductor.py | 2 +- magnum/common/utils.py | 8 ++++---- magnum/conductor/handlers/bay_conductor.py | 4 ++-- magnum/conductor/handlers/common/cert_manager.py | 8 ++++---- magnum/conductor/handlers/docker_conductor.py | 10 +++++----- magnum/conductor/handlers/x509keypair_conductor.py | 2 +- magnum/conductor/k8s_api.py | 2 +- magnum/conductor/monitors.py | 2 +- magnum/conductor/scale_manager.py | 4 ++-- magnum/service/periodic.py | 4 ++-- 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/magnum/api/controllers/v1/container.py b/magnum/api/controllers/v1/container.py index 555d7d498f..57170cd752 100644 --- a/magnum/api/controllers/v1/container.py +++ b/magnum/api/controllers/v1/container.py @@ -177,7 +177,7 @@ class StartController(object): container_uuid = api_utils.get_rpc_resource('Container', container_ident).uuid - LOG.debug('Calling conductor.container_start with %s' % + LOG.debug('Calling conductor.container_start with %s', container_uuid) return pecan.request.rpcapi.container_start(container_uuid) @@ -190,7 +190,7 @@ class StopController(object): % pecan.request.method)) container_uuid = api_utils.get_rpc_resource('Container', container_ident).uuid - LOG.debug('Calling conductor.container_stop with %s' % + LOG.debug('Calling conductor.container_stop with %s', container_uuid) return pecan.request.rpcapi.container_stop(container_uuid) @@ -203,7 +203,7 @@ class RebootController(object): % pecan.request.method)) container_uuid = api_utils.get_rpc_resource('Container', container_ident).uuid - LOG.debug('Calling conductor.container_reboot with %s' % + LOG.debug('Calling conductor.container_reboot with %s', container_uuid) return pecan.request.rpcapi.container_reboot(container_uuid) @@ -216,7 +216,7 @@ class PauseController(object): % pecan.request.method)) container_uuid = api_utils.get_rpc_resource('Container', container_ident).uuid - LOG.debug('Calling conductor.container_pause with %s' % + LOG.debug('Calling conductor.container_pause with %s', container_uuid) return pecan.request.rpcapi.container_pause(container_uuid) @@ -229,7 +229,7 @@ class UnpauseController(object): % pecan.request.method)) container_uuid = api_utils.get_rpc_resource('Container', container_ident).uuid - LOG.debug('Calling conductor.container_unpause with %s' % + LOG.debug('Calling conductor.container_unpause with %s', container_uuid) return pecan.request.rpcapi.container_unpause(container_uuid) @@ -242,7 +242,7 @@ class LogsController(object): % pecan.request.method)) container_uuid = api_utils.get_rpc_resource('Container', container_ident).uuid - LOG.debug('Calling conductor.container_logs with %s' % + LOG.debug('Calling conductor.container_logs with %s', container_uuid) return pecan.request.rpcapi.container_logs(container_uuid) diff --git a/magnum/cmd/api.py b/magnum/cmd/api.py index 5ef7d6586f..3155190b19 100644 --- a/magnum/cmd/api.py +++ b/magnum/cmd/api.py @@ -46,16 +46,16 @@ def main(): host, port = cfg.CONF.api.host, cfg.CONF.api.port srv = simple_server.make_server(host, port, app) - LOG.info(_LI('Starting server in PID %s') % os.getpid()) + LOG.info(_LI('Starting server in PID %s'), os.getpid()) LOG.debug("Configuration:") cfg.CONF.log_opt_values(LOG, logging.DEBUG) if host == '0.0.0.0': LOG.info(_LI('serving on 0.0.0.0:%(port)s, ' - 'view at http://127.0.0.1:%(port)s') % + 'view at http://127.0.0.1:%(port)s'), dict(port=port)) else: - LOG.info(_LI('serving on http://%(host)s:%(port)s') % + LOG.info(_LI('serving on http://%(host)s:%(port)s'), dict(host=host, port=port)) srv.serve_forever() diff --git a/magnum/cmd/conductor.py b/magnum/cmd/conductor.py index 01ff904fe6..ca647ec7db 100644 --- a/magnum/cmd/conductor.py +++ b/magnum/cmd/conductor.py @@ -44,7 +44,7 @@ def main(): gmr.TextGuruMeditation.setup_autorun(version) - LOG.info(_LI('Starting server in PID %s') % os.getpid()) + LOG.info(_LI('Starting server in PID %s'), os.getpid()) LOG.debug("Configuration:") cfg.CONF.log_opt_values(LOG, logging.DEBUG) diff --git a/magnum/common/utils.py b/magnum/common/utils.py index 42e497229e..31fbc0c0e0 100644 --- a/magnum/common/utils.py +++ b/magnum/common/utils.py @@ -99,8 +99,8 @@ def execute(*cmd, **kwargs): result = processutils.execute(*cmd, **kwargs) LOG.debug('Execution completed, command line is "%s"', ' '.join(map(str, cmd))) - LOG.debug('Command stdout is: "%s"' % result[0]) - LOG.debug('Command stderr is: "%s"' % result[1]) + LOG.debug('Command stdout is: "%s"', result[0]) + LOG.debug('Command stderr is: "%s"', result[1]) return result @@ -145,7 +145,7 @@ def ssh_connect(connection): # send TCP keepalive packets every 20 seconds ssh.get_transport().set_keepalive(20) except Exception as e: - LOG.debug("SSH connect failed: %s" % e) + LOG.debug("SSH connect failed: %s", e) raise exception.SSHConnectFailed(host=connection.get('host')) return ssh @@ -320,7 +320,7 @@ def read_cached_file(filename, cache_info, reload_func=None): """ mtime = os.path.getmtime(filename) if not cache_info or mtime != cache_info.get('mtime'): - LOG.debug("Reloading cached file %s" % filename) + LOG.debug("Reloading cached file %s", filename) with open(filename) as fap: cache_info['data'] = fap.read() cache_info['mtime'] = mtime diff --git a/magnum/conductor/handlers/bay_conductor.py b/magnum/conductor/handlers/bay_conductor.py index d0bab93cef..365f1cd5b2 100644 --- a/magnum/conductor/handlers/bay_conductor.py +++ b/magnum/conductor/handlers/bay_conductor.py @@ -208,12 +208,12 @@ class Handler(object): osc.heat().stacks.delete(stack_id) except exc.HTTPNotFound: LOG.info(_LI('The stack %s was not be found during bay' - ' deletion.') % stack_id) + ' deletion.'), stack_id) try: cert_manager.delete_certificates_from_bay(bay) bay.destroy() except exception.BayNotFound: - LOG.info(_LI('The bay %s has been deleted by others.') % uuid) + LOG.info(_LI('The bay %s has been deleted by others.'), uuid) return None except Exception: raise diff --git a/magnum/conductor/handlers/common/cert_manager.py b/magnum/conductor/handlers/common/cert_manager.py index 27b36ebe03..9eb5665c59 100644 --- a/magnum/conductor/handlers/common/cert_manager.py +++ b/magnum/conductor/handlers/common/cert_manager.py @@ -42,7 +42,7 @@ def _generate_ca_cert(issuer_name): private_key_passphrase=ca_password, name=issuer_name, ) - LOG.debug('CA cert is created: %s' % ca_cert_ref) + LOG.debug('CA cert is created: %s', ca_cert_ref) return ca_cert_ref, ca_cert, ca_password @@ -68,7 +68,7 @@ def _generate_client_cert(issuer_name, ca_cert, ca_password): private_key_passphrase=client_password, name=CONDUCTOR_CLIENT_NAME, ) - LOG.debug('Magnum client cert is created: %s' % magnum_cert_ref) + LOG.debug('Magnum client cert is created: %s', magnum_cert_ref) return magnum_cert_ref @@ -89,7 +89,7 @@ def generate_certificates_to_bay(bay): """ issuer_name = _get_issuer_name(bay) - LOG.debug('Start to generate certificates: %s' % issuer_name) + LOG.debug('Start to generate certificates: %s', issuer_name) ca_cert_ref, ca_cert, ca_password = _generate_ca_cert(issuer_name) magnum_cert_ref = _generate_client_cert(issuer_name, ca_cert, ca_password) @@ -159,4 +159,4 @@ def delete_certificates_from_bay(bay): cert_manager.get_backend().CertManager.delete_cert( cert_ref, resource_ref=bay.uuid) except Exception: - LOG.warning(_LW("Deleting cert is failed: %s") % cert_ref) + LOG.warning(_LW("Deleting cert is failed: %s"), cert_ref) diff --git a/magnum/conductor/handlers/docker_conductor.py b/magnum/conductor/handlers/docker_conductor.py index 869110769a..49a7625b0a 100644 --- a/magnum/conductor/handlers/docker_conductor.py +++ b/magnum/conductor/handlers/docker_conductor.py @@ -95,7 +95,7 @@ class Handler(object): @wrap_container_exception def container_delete(self, context, container_uuid): - LOG.debug("container_delete %s" % container_uuid) + LOG.debug("container_delete %s", container_uuid) with docker_utils.docker_for_container(context, container_uuid) as docker: docker_id = self._find_container_by_name(docker, @@ -106,7 +106,7 @@ class Handler(object): @wrap_container_exception def container_show(self, context, container_uuid): - LOG.debug("container_show %s" % container_uuid) + LOG.debug("container_show %s", container_uuid) with docker_utils.docker_for_container(context, container_uuid) as docker: container = objects.Container.get_by_uuid(context, container_uuid) @@ -143,7 +143,7 @@ class Handler(object): @wrap_container_exception def _container_action(self, context, container_uuid, status, docker_func): - LOG.debug("%s container %s ..." % (docker_func, container_uuid)) + LOG.debug("%s container %s ...", (docker_func, container_uuid)) with docker_utils.docker_for_container(context, container_uuid) as docker: docker_id = self._find_container_by_name(docker, @@ -179,7 +179,7 @@ class Handler(object): @wrap_container_exception def container_logs(self, context, container_uuid): - LOG.debug("container_logs %s" % container_uuid) + LOG.debug("container_logs %s", container_uuid) with docker_utils.docker_for_container(context, container_uuid) as docker: docker_id = self._find_container_by_name(docker, @@ -188,7 +188,7 @@ class Handler(object): @wrap_container_exception def container_exec(self, context, container_uuid, command): - LOG.debug("container_exec %s command %s" % + LOG.debug("container_exec %s command %s", (container_uuid, command)) with docker_utils.docker_for_container(context, container_uuid) as docker: diff --git a/magnum/conductor/handlers/x509keypair_conductor.py b/magnum/conductor/handlers/x509keypair_conductor.py index 120d3e3c91..3318192592 100644 --- a/magnum/conductor/handlers/x509keypair_conductor.py +++ b/magnum/conductor/handlers/x509keypair_conductor.py @@ -37,6 +37,6 @@ class Handler(object): return x509keypair def x509keypair_delete(self, context, uuid): - LOG.debug("Deleting x509keypair %s" % uuid) + LOG.debug("Deleting x509keypair %s", uuid) x509keypair = objects.X509KeyPair.get_by_uuid(context, uuid) x509keypair.destroy(context) diff --git a/magnum/conductor/k8s_api.py b/magnum/conductor/k8s_api.py index 3d77b9ad22..8b7e897cf5 100644 --- a/magnum/conductor/k8s_api.py +++ b/magnum/conductor/k8s_api.py @@ -38,7 +38,7 @@ class K8sAPI(apiv_api.ApivApi): tmp.write(content) tmp.flush() except Exception as err: - LOG.error("Error while creating temp file: %s" % err) + LOG.error("Error while creating temp file: %s", err) raise err return tmp diff --git a/magnum/conductor/monitors.py b/magnum/conductor/monitors.py index 0a1bae7131..2d3cd00a00 100644 --- a/magnum/conductor/monitors.py +++ b/magnum/conductor/monitors.py @@ -72,5 +72,5 @@ def create_monitor(context, bay): coe_cls = importutils.import_class(COE_CLASS_PATH[bay.baymodel.coe]) return coe_cls(context, bay) - LOG.debug("Cannot create monitor with bay type '%s'" % bay.baymodel.coe) + LOG.debug("Cannot create monitor with bay type '%s'", bay.baymodel.coe) return None diff --git a/magnum/conductor/scale_manager.py b/magnum/conductor/scale_manager.py index a1ea5d76b7..fb106be261 100644 --- a/magnum/conductor/scale_manager.py +++ b/magnum/conductor/scale_manager.py @@ -53,7 +53,7 @@ class ScaleManager(object): if host in hosts_no_container: hosts_no_container.remove(host) - LOG.debug('List of hosts that has no container: %s' % + LOG.debug('List of hosts that has no container: %s', str(hosts_no_container)) num_of_removal = self._get_num_of_removal() @@ -67,7 +67,7 @@ class ScaleManager(object): 'num_non_empty': num_of_removal - len(hosts_no_container)}) hosts_to_remove = hosts_no_container[0:num_of_removal] - LOG.info(_LI('Require removal of hosts: %s') % hosts_to_remove) + LOG.info(_LI('Require removal of hosts: %s'), hosts_to_remove) return hosts_to_remove diff --git a/magnum/service/periodic.py b/magnum/service/periodic.py index ba4b0b940b..5ef86cc41d 100644 --- a/magnum/service/periodic.py +++ b/magnum/service/periodic.py @@ -125,7 +125,7 @@ class MagnumPeriodicTasks(periodic_task.PeriodicTasks): try: bay.destroy() except exception.BayNotFound: - LOG.info(_LI('The bay %s has been deleted by others.') % bay.uuid) + LOG.info(_LI('The bay %s has been deleted by others.'), bay.uuid) else: LOG.info(_LI("Bay with id %(id)s not found in heat " "with stack id %(sid)s, with status_reason: " @@ -182,7 +182,7 @@ class MagnumPeriodicTasks(periodic_task.PeriodicTasks): user_id=bay.user_id, project_id=bay.project_id, resource_id=bay.uuid) - LOG.debug("About to send notification: '%s'" % message) + LOG.debug("About to send notification: '%s'", message) self.notifier.info(ctx, "magnum.bay.metrics.update", message)