From 226557afc42c245e050d84162497f46341407ef7 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Thu, 19 May 2016 18:55:40 -0700 Subject: [PATCH] Turn on H703, so our translators don't punch us Change-Id: I4ce3068f79563e4d4296c6e1078bc12f0cf84c96 Related-Bug: 1559431 --- swift/common/container_sync_realms.py | 11 +++++++---- swift/common/utils.py | 3 ++- swift/common/wsgi.py | 7 ++++--- swift/container/server.py | 11 ++++++----- swift/container/sync.py | 5 +++-- swift/obj/diskfile.py | 5 +++-- swift/obj/expirer.py | 16 ++++++++++------ swift/obj/server.py | 11 ++++++----- swift/obj/updater.py | 6 +++--- tox.ini | 3 +-- 10 files changed, 45 insertions(+), 33 deletions(-) diff --git a/swift/common/container_sync_realms.py b/swift/common/container_sync_realms.py index 7b441da9de..2c4c944add 100644 --- a/swift/common/container_sync_realms.py +++ b/swift/common/container_sync_realms.py @@ -57,7 +57,8 @@ class ContainerSyncRealms(object): log_func = self.logger.debug else: log_func = self.logger.error - log_func(_('Could not load %r: %s'), self.conf_path, err) + log_func(_('Could not load %(conf)r: %(error)s') % { + 'conf': self.conf_path, 'error': err}) else: if mtime != self.conf_path_mtime: self.conf_path_mtime = mtime @@ -66,7 +67,8 @@ class ContainerSyncRealms(object): conf.read(self.conf_path) except configparser.ParsingError as err: self.logger.error( - _('Could not load %r: %s'), self.conf_path, err) + _('Could not load %(conf)r: %(error)s') + % {'conf': self.conf_path, 'error': err}) else: try: self.mtime_check_interval = conf.getint( @@ -79,8 +81,9 @@ class ContainerSyncRealms(object): now + self.mtime_check_interval except (configparser.ParsingError, ValueError) as err: self.logger.error( - _('Error in %r with mtime_check_interval: %s'), - self.conf_path, err) + _('Error in %(conf)r with ' + 'mtime_check_interval: %(error)s') + % {'conf': self.conf_path, 'error': err}) realms = {} for section in conf.sections(): realm = {} diff --git a/swift/common/utils.py b/swift/common/utils.py index 4694f5951e..1d12b96495 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -2674,7 +2674,8 @@ def validate_sync_to(value, allowed_sync_hosts, realms_conf): endpoint = realms_conf.endpoint(realm, cluster) if not endpoint: return ( - _('No cluster endpoint for %r %r') % (realm, cluster), + _('No cluster endpoint for %(realm)r %(cluster)r') + % {'realm': realm, 'cluster': cluster}, None, None, None) return ( None, diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index fdd4a203ed..6676d38358 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -196,9 +196,10 @@ def get_socket(conf): raise sleep(0.1) if not sock: - raise Exception(_('Could not bind to %s:%s ' - 'after trying for %s seconds') % ( - bind_addr[0], bind_addr[1], bind_timeout)) + raise Exception(_('Could not bind to %(addr)s:%(port)s ' + 'after trying for %(timeout)s seconds') % { + 'addr': bind_addr[0], 'port': bind_addr[1], + 'timeout': bind_timeout}) # in my experience, sockets can hang around forever without keepalive sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) diff --git a/swift/container/server.py b/swift/container/server.py index 92bb595e8f..a77dadcd22 100644 --- a/swift/container/server.py +++ b/swift/container/server.py @@ -183,11 +183,12 @@ class ContainerController(BaseStorageServer): if len(account_hosts) != len(account_devices): # This shouldn't happen unless there's a bug in the proxy, # but if there is, we want to know about it. - self.logger.error(_('ERROR Account update failed: different ' - 'numbers of hosts and devices in request: ' - '"%s" vs "%s"') % - (req.headers.get('X-Account-Host', ''), - req.headers.get('X-Account-Device', ''))) + self.logger.error(_( + 'ERROR Account update failed: different ' + 'numbers of hosts and devices in request: ' + '"%(hosts)s" vs "%(devices)s"') % { + 'hosts': req.headers.get('X-Account-Host', ''), + 'devices': req.headers.get('X-Account-Device', '')}) return HTTPBadRequest(req=req) if account_partition: diff --git a/swift/container/sync.py b/swift/container/sync.py index 8fbfe9dba3..1c94d9a679 100644 --- a/swift/container/sync.py +++ b/swift/container/sync.py @@ -237,8 +237,9 @@ class ContainerSync(Daemon): if err.errno != errno.ENOENT: raise raise SystemExit( - _('Unable to load internal client from config: %r (%s)') % - (internal_client_conf_path, err)) + _('Unable to load internal client from config: ' + '%(conf)r (%(error)s)') + % {'conf': internal_client_conf_path, 'error': err}) def run_forever(self, *args, **kwargs): """ diff --git a/swift/obj/diskfile.py b/swift/obj/diskfile.py index f50ca7030e..49deb36f67 100644 --- a/swift/obj/diskfile.py +++ b/swift/obj/diskfile.py @@ -378,8 +378,9 @@ def object_audit_location_generator(devices, mount_check=True, logger=None, base, policy = split_policy_string(dir_) except PolicyError as e: if logger: - logger.warning(_('Directory %r does not map ' - 'to a valid policy (%s)') % (dir_, e)) + logger.warning(_('Directory %(directory)r does not map ' + 'to a valid policy (%(error)s)') % { + 'directory': dir_, 'error': e}) continue datadir_path = os.path.join(devices, device, dir_) diff --git a/swift/obj/expirer.py b/swift/obj/expirer.py index 42855eee77..115920dd6d 100644 --- a/swift/obj/expirer.py +++ b/swift/obj/expirer.py @@ -77,15 +77,17 @@ class ObjectExpirer(Daemon): """ if final: elapsed = time() - self.report_first_time - self.logger.info(_('Pass completed in %ds; %d objects expired') % - (elapsed, self.report_objects)) + self.logger.info(_('Pass completed in %(time)ds; ' + '%(objects)d objects expired') % { + 'time': elapsed, 'objects': self.report_objects}) dump_recon_cache({'object_expiration_pass': elapsed, 'expired_last_pass': self.report_objects}, self.rcache, self.logger) elif time() - self.report_last_time >= self.report_interval: elapsed = time() - self.report_first_time - self.logger.info(_('Pass so far %ds; %d objects expired') % - (elapsed, self.report_objects)) + self.logger.info(_('Pass so far %(time)ds; ' + '%(objects)d objects expired') % { + 'time': elapsed, 'objects': self.report_objects}) self.report_last_time = time() def iter_cont_objs_to_expire(self): @@ -168,8 +170,10 @@ class ObjectExpirer(Daemon): self.logger.debug('Run begin') containers, objects = \ self.swift.get_account_info(self.expiring_objects_account) - self.logger.info(_('Pass beginning; %s possible containers; %s ' - 'possible objects') % (containers, objects)) + self.logger.info(_('Pass beginning; ' + '%(containers)s possible containers; ' + '%(objects)s possible objects') % { + 'containers': containers, 'objects': objects}) for container, obj in self.iter_cont_objs_to_expire(): containers_to_delete.add(container) diff --git a/swift/obj/server.py b/swift/obj/server.py index e59c9fbc38..4a90c6d677 100644 --- a/swift/obj/server.py +++ b/swift/obj/server.py @@ -281,11 +281,12 @@ class ObjectController(BaseStorageServer): if len(conthosts) != len(contdevices): # This shouldn't happen unless there's a bug in the proxy, # but if there is, we want to know about it. - self.logger.error(_('ERROR Container update failed: different ' - 'numbers of hosts and devices in request: ' - '"%s" vs "%s"') % - (headers_in.get('X-Container-Host', ''), - headers_in.get('X-Container-Device', ''))) + self.logger.error(_( + 'ERROR Container update failed: different ' + 'numbers of hosts and devices in request: ' + '"%(hosts)s" vs "%(devices)s"') % { + 'hosts': headers_in.get('X-Container-Host', ''), + 'devices': headers_in.get('X-Container-Device', '')}) return if contpartition: diff --git a/swift/obj/updater.py b/swift/obj/updater.py index 9bf4ef19a3..743cf850dc 100644 --- a/swift/obj/updater.py +++ b/swift/obj/updater.py @@ -160,9 +160,9 @@ class ObjectUpdater(Daemon): try: base, policy = split_policy_string(asyncdir) except PolicyError as e: - self.logger.warning(_('Directory %r does not map ' - 'to a valid policy (%s)') % - (asyncdir, e)) + self.logger.warning(_('Directory %(directory)r does not map ' + 'to a valid policy (%(error)s)') % { + 'directory': asyncdir, 'error': e}) continue for prefix in self._listdir(async_pending): prefix_path = os.path.join(async_pending, prefix) diff --git a/tox.ini b/tox.ini index 68c1f6a0bd..1e79f67b88 100644 --- a/tox.ini +++ b/tox.ini @@ -76,8 +76,7 @@ commands = bandit -c bandit.yaml -r swift bin -n 5 -p gate # H404: multi line docstring should start without a leading new line # H405: multi line docstring summary not separated with an empty line # H501: Do not use self.__dict__ for string formatting -# H703: Multiple positional placeholders -ignore = F812,H101,H202,H233,H301,H306,H401,H403,H404,H405,H501,H703 +ignore = F812,H101,H202,H233,H301,H306,H401,H403,H404,H405,H501 exclude = .venv,.tox,dist,*egg show-source = True