Flake8: Fix H501

Fix all occurences of:
H501  Do not use locals() for string formatting

Change-Id: Id221d257975659d31b29ed696345f96525c3b459
Partial-Bug: #1333290
This commit is contained in:
Andreas Jaeger 2014-08-20 19:54:31 +02:00 committed by Andreas Jaeger
parent 8203c51081
commit 1ee54a3144
14 changed files with 64 additions and 30 deletions

View File

@ -335,7 +335,7 @@ def remove_invalid_options(context, search_options, allowed_search_options):
unknown_options = [opt for opt in search_options
if opt not in allowed_search_options]
bad_options = ", ".join(unknown_options)
log_msg = "Removing options '%(bad_options)s' from query" % locals()
LOG.debug(log_msg)
LOG.debug("Removing options '%(bad_options)s' from query" %
{"bad_options": bad_options})
for opt in unknown_options:
del search_options[opt]

View File

@ -287,7 +287,8 @@ class ExtensionManager(object):
self.load_extension(ext_factory)
except Exception as exc:
LOG.warn(_('Failed to load extension %(ext_factory)s: '
'%(exc)s') % locals())
'%(exc)s') %
{"ext_factory": ext_factory, "exc": exc})
class ControllerExtension(object):
@ -355,7 +356,8 @@ def load_standard_extensions(ext_mgr, logger, path, package, ext_list=None):
ext_mgr.load_extension(classpath)
except Exception as exc:
logger.warn(_('Failed to load extension %(classpath)s: '
'%(exc)s') % locals())
'%(exc)s')
% {"classpath": classpath, "exc": exc})
# Now, let's consider any subdirectories we may have...
subdirs = []
@ -379,7 +381,8 @@ def load_standard_extensions(ext_mgr, logger, path, package, ext_list=None):
ext(ext_mgr)
except Exception as exc:
logger.warn(_('Failed to load extension %(ext_name)s: '
'%(exc)s') % locals())
'%(exc)s') %
{"ext_name": ext_name, "exc": exc})
# Update the list of directories we'll explore...
dirnames[:] = subdirs

View File

@ -742,7 +742,10 @@ class MasterTemplate(Template):
slavetag = slave.root.tag
mastertag = self.root.tag
msg = _("Template tree mismatch; adding slave %(slavetag)s "
"to master %(mastertag)s") % locals()
"to master %(mastertag)s") % {
"slavetag": slavetag,
"mastertag": mastertag
}
raise ValueError(msg)
# Make sure slave applies to this template

View File

@ -144,13 +144,14 @@ class FilterScheduler(driver.Scheduler):
if not hosts:
return None
LOG.debug("Filtered share %(hosts)s" % locals())
LOG.debug("Filtered share %(hosts)s" % {"hosts": hosts})
# weighted_host = WeightedHost() ... the best
# host for the job.
weighed_hosts = self.host_manager.get_weighed_hosts(hosts,
filter_properties)
best_host = weighed_hosts[0]
LOG.debug("Choosing for share: %(best_host)s" % locals())
LOG.debug("Choosing for share: %(best_host)s"
% {"best_host": best_host})
# NOTE(rushiagr): updating the available space parameters at same place
best_host.obj.consume_from_share(share_properties)
return best_host
@ -181,7 +182,10 @@ class FilterScheduler(driver.Scheduler):
if retry['num_attempts'] > max_attempts:
msg = _("Exceeded max scheduling attempts %(max_attempts)d for "
"share %(share_id)s") % locals()
"share %(share_id)s") % {
"max_attempts": max_attempts,
"share_id": share_id
}
raise exception.NoValidHost(reason=msg)
def _log_share_error(self, share_id, retry):
@ -198,7 +202,11 @@ class FilterScheduler(driver.Scheduler):
last_host = hosts[-1]
msg = _("Error scheduling %(share_id)s from last share-service: "
"%(last_host)s : %(exc)s") % locals()
"%(last_host)s : %(exc)s") % {
"share_id": share_id,
"last_host": last_host,
"exc": "exc"
}
LOG.error(msg)
def populate_filter_properties_share(self, request_spec,

View File

@ -39,7 +39,8 @@ class RetryFilter(filters.BaseHostFilter):
pass_msg = "passes" if passes else "fails"
LOG.debug("Host %(host)s %(pass_msg)s. Previously tried hosts: "
"%(hosts)s" % locals())
"%(hosts)s" %
{"host": host, "pass_msg": pass_msg, "hosts": hosts})
# Host passes if it's not in the list of previously attempted hosts:
return passes

View File

@ -238,7 +238,7 @@ class HostManager(object):
return
LOG.debug("Received %(service_name)s service update from "
"%(host)s." % locals())
"%(host)s." % {"service_name": service_name, "host": host})
# Copy the capabilities, so we don't modify the original dict
capab_copy = dict(capabilities)

View File

@ -89,7 +89,8 @@ class SchedulerManager(manager.Manager):
def _set_share_error_state_and_notify(self, method, context, ex,
request_spec):
LOG.warning(_("Failed to schedule_%(method)s: %(ex)s") % locals())
LOG.warning(_("Failed to schedule_%(method)s: %(ex)s") %
{"method": method, "ex": ex})
share_state = {'status': 'error'}
properties = request_spec.get('share_properties', {})

View File

@ -67,7 +67,8 @@ class SchedulerOptions(object):
return os.path.getmtime(filename)
except os.error as e:
LOG.exception(_("Could not stat scheduler options file "
"%(filename)s: '%(e)s'"), locals())
"%(filename)s: '%(e)s'") %
{"filename": filename, "e": e})
raise
def _load_file(self, handle):
@ -76,7 +77,7 @@ class SchedulerOptions(object):
return jsonutils.load(handle)
except ValueError as e:
LOG.exception(_("Could not decode scheduler options: "
"'%(e)s'") % locals())
"'%(e)s'") % {"e": e})
return {}
def _get_time_now(self):

View File

@ -607,9 +607,10 @@ def wait():
# should use secret flag when switch over to openstack-common
if ("_password" in flag or "_key" in flag or
(flag == "sql_connection" and "mysql:" in flag_get)):
LOG.debug('%(flag)s : FLAG SET ' % locals())
LOG.debug('%(flag)s : FLAG SET ' % {"flag": flag})
else:
LOG.debug('%(flag)s : %(flag_get)s' % locals())
LOG.debug('%(flag)s : %(flag_get)s' %
{"flag": flag, "flag_get": flag_get})
try:
_launcher.wait()
except KeyboardInterrupt:

View File

@ -215,7 +215,8 @@ class TestCase(testtools.TestCase):
d1str = str(d1)
d2str = str(d2)
base_msg = ('Dictionaries do not match. %(msg)s d1: %(d1str)s '
'd2: %(d2str)s' % locals())
'd2: %(d2str)s' %
{"msg": msg, "d1str": d1str, "d2str": d2str})
raise AssertionError(base_msg)
d1keys = set(d1.keys())
@ -224,7 +225,8 @@ class TestCase(testtools.TestCase):
d1only = d1keys - d2keys
d2only = d2keys - d1keys
raise_assertion('Keys in d1 and not d2: %(d1only)s. '
'Keys in d2 and not d1: %(d2only)s' % locals())
'Keys in d2 and not d1: %(d2only)s' %
{"d1only": d1only, "d2only": d2only})
for key in d1keys:
d1value = d1[key]
@ -246,7 +248,12 @@ class TestCase(testtools.TestCase):
continue
elif d1value != d2value:
raise_assertion("d1['%(key)s']=%(d1value)s != "
"d2['%(key)s']=%(d2value)s" % locals())
"d2['%(key)s']=%(d2value)s" %
{
"key": key,
"d1value": d1value,
"d2value": d2value
})
def assertDictListMatch(self, L1, L2, approx_equal=False, tolerance=0.001):
"""Assert a list of dicts are equivalent."""
@ -254,14 +261,16 @@ class TestCase(testtools.TestCase):
L1str = str(L1)
L2str = str(L2)
base_msg = ('List of dictionaries do not match: %(msg)s '
'L1: %(L1str)s L2: %(L2str)s' % locals())
'L1: %(L1str)s L2: %(L2str)s' %
{"msg": msg, "L1str": L1str, "L2str": L2str})
raise AssertionError(base_msg)
L1count = len(L1)
L2count = len(L2)
if L1count != L2count:
raise_assertion('Length mismatch: len(L1)=%(L1count)d != '
'len(L2)=%(L2count)d' % locals())
'len(L2)=%(L2count)d' %
{"L1count": L1count, "L2count": L2count})
for d1, d2 in zip(L1, L2):
self.assertDictMatch(d1, d2, approx_equal=approx_equal,

View File

@ -100,7 +100,7 @@ def fake_execute(*cmd_parts, **kwargs):
stdout = reply[0]
stderr = reply[1]
LOG.debug("Reply to faked command is stdout='%(stdout)s' "
"stderr='%(stderr)s'" % locals())
"stderr='%(stderr)s'" % {"stdout": stdout, "stderr": stderr})
# Replicate the sleep call in the real function
greenthread.sleep(0)

View File

@ -35,7 +35,11 @@ class OpenStackApiException(Exception):
_body = response.read()
message = _('%(message)s\nStatus Code: %(_status)s\n'
'Body: %(_body)s') % locals()
'Body: %(_body)s') % {
"message": message,
"_status": _status,
"_body": _body
}
super(OpenStackApiException, self).__init__(message)
@ -101,7 +105,8 @@ class TestOpenStackClient(object):
relative_url = parsed_url.path
if parsed_url.query:
relative_url = relative_url + "?" + parsed_url.query
LOG.info(_("Doing %(method)s on %(relative_url)s") % locals())
LOG.info(_("Doing %(method)s on %(relative_url)s") %
{"method": method, "relative_url": relative_url})
if body:
LOG.info(_("Body: %s") % body)
@ -121,7 +126,8 @@ class TestOpenStackClient(object):
headers=headers)
http_status = response.status
LOG.debug("%(auth_uri)s => code %(http_status)s" % locals())
LOG.debug("%(auth_uri)s => code %(http_status)s" %
{"auth_uri": auth_uri, "http_status": http_status})
if http_status == 401:
raise OpenStackApiAuthenticationException(response=response)
@ -147,7 +153,8 @@ class TestOpenStackClient(object):
response = self.request(full_uri, **kwargs)
http_status = response.status
LOG.debug("%(relative_uri)s => code %(http_status)s" % locals())
LOG.debug("%(relative_uri)s => code %(http_status)s" %
{"relative_uri": relative_uri, "http_status": http_status})
if check_response_status:
if http_status not in check_response_status:

View File

@ -366,7 +366,8 @@ def get_my_linklocal(interface):
% if_str)
except Exception as ex:
raise exception.Error(_("Couldn't get Link Local IP of %(interface)s"
" :%(ex)s") % locals())
" :%(ex)s") %
{"interface": interface, "ex": ex})
def parse_mailmap(mailmap='.mailmap'):

View File

@ -44,12 +44,11 @@ commands = bash tools/lintstack.sh
[flake8]
# TODO: These are not intentionally disabled, reenable when fixed:
# H405: multi line docstring summary not separated with an empty line
# H501: Do not use locals() for string formatting
#
# Following checks are ignored on purpose:
#
# H904 wrap long lines in parentheses instead of a backslash
# reason: removed in hacking (https://review.openstack.org/#/c/101701/)
ignore = H405,H501,H904
ignore = H405,H904
builtins = _
exclude = .venv,.tox,dist,doc,openstack,*egg