Merge "Fix H501: Do not use locals() for string formatting"
This commit is contained in:
commit
d9c52956f5
|
@ -119,7 +119,7 @@ class FileTransfer(xfer_base.TransferBase):
|
||||||
if r not in metadata:
|
if r not in metadata:
|
||||||
url = url_parts.geturl()
|
url = url_parts.geturl()
|
||||||
msg = _('The key %(r)s is required in the location metadata '
|
msg = _('The key %(r)s is required in the location metadata '
|
||||||
'to access the url %(url)s.') % locals()
|
'to access the url %(url)s.') % {'r': r, 'url': url}
|
||||||
LOG.info(msg)
|
LOG.info(msg)
|
||||||
raise exception.ImageDownloadModuleMetaDataError(
|
raise exception.ImageDownloadModuleMetaDataError(
|
||||||
module=str(self), reason=msg)
|
module=str(self), reason=msg)
|
||||||
|
@ -128,8 +128,9 @@ class FileTransfer(xfer_base.TransferBase):
|
||||||
|
|
||||||
def _normalize_destination(self, nova_mount, glance_mount, path):
|
def _normalize_destination(self, nova_mount, glance_mount, path):
|
||||||
if not path.startswith(glance_mount):
|
if not path.startswith(glance_mount):
|
||||||
msg = _('The mount point advertised by glance: %(glance_mount)s, '
|
msg = (_('The mount point advertised by glance: %(glance_mount)s, '
|
||||||
'does not match the URL path: %(path)s') % locals()
|
'does not match the URL path: %(path)s') %
|
||||||
|
{'glance_mount': glance_mount, 'path': path})
|
||||||
raise exception.ImageDownloadModuleMetaDataError(
|
raise exception.ImageDownloadModuleMetaDataError(
|
||||||
module=str(self), reason=msg)
|
module=str(self), reason=msg)
|
||||||
new_path = path.replace(glance_mount, nova_mount, 1)
|
new_path = path.replace(glance_mount, nova_mount, 1)
|
||||||
|
|
|
@ -311,7 +311,7 @@ class GlanceImageService(object):
|
||||||
return None
|
return None
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.error(_("Failed to instantiate the download handler "
|
LOG.error(_("Failed to instantiate the download handler "
|
||||||
"for %(scheme)s") % locals())
|
"for %(scheme)s") % {'scheme': scheme})
|
||||||
return
|
return
|
||||||
|
|
||||||
def download(self, context, image_id, data=None):
|
def download(self, context, image_id, data=None):
|
||||||
|
|
|
@ -140,8 +140,7 @@ class AdminActionsTest(test.TestCase):
|
||||||
req.content_type = 'application/json'
|
req.content_type = 'application/json'
|
||||||
res = req.get_response(app)
|
res = req.get_response(app)
|
||||||
self.assertEqual(res.status_int, 409)
|
self.assertEqual(res.status_int, 409)
|
||||||
self.assertIn("Cannot \'%(_action)s\' while instance" % locals(),
|
self.assertIn("Cannot \'%s\' while instance" % _action, res.body)
|
||||||
res.body)
|
|
||||||
|
|
||||||
def test_admin_api_actions_raise_not_found(self):
|
def test_admin_api_actions_raise_not_found(self):
|
||||||
app = fakes.wsgi_app(init_only=('servers',))
|
app = fakes.wsgi_app(init_only=('servers',))
|
||||||
|
|
|
@ -152,8 +152,7 @@ class AdminActionsTest(test.TestCase):
|
||||||
res = self._make_request('/v3/servers/%s/action' % self.UUID,
|
res = self._make_request('/v3/servers/%s/action' % self.UUID,
|
||||||
{_action: None})
|
{_action: None})
|
||||||
self.assertEqual(res.status_int, 409)
|
self.assertEqual(res.status_int, 409)
|
||||||
self.assertIn("Cannot \'%(_action)s\' while instance" % locals(),
|
self.assertIn("Cannot \'%s\' while instance" % _action, res.body)
|
||||||
res.body)
|
|
||||||
|
|
||||||
def test_admin_api_actions_with_non_existed_instance(self):
|
def test_admin_api_actions_with_non_existed_instance(self):
|
||||||
app = fakes.wsgi_app_v3(init_only=('servers', 'os-admin-actions'))
|
app = fakes.wsgi_app_v3(init_only=('servers', 'os-admin-actions'))
|
||||||
|
|
|
@ -433,7 +433,7 @@ class BaseTrackerTestCase(BaseTestCase):
|
||||||
|
|
||||||
if field not in tracker.compute_node:
|
if field not in tracker.compute_node:
|
||||||
raise test.TestingException(
|
raise test.TestingException(
|
||||||
"'%(field)s' not in compute node." % locals())
|
"'%(field)s' not in compute node." % {'field': field})
|
||||||
x = tracker.compute_node[field]
|
x = tracker.compute_node[field]
|
||||||
|
|
||||||
self.assertEqual(value, x)
|
self.assertEqual(value, x)
|
||||||
|
|
|
@ -86,8 +86,7 @@ def _get_connect_string(backend, user, passwd, database):
|
||||||
else:
|
else:
|
||||||
raise Exception("Unrecognized backend: '%s'" % backend)
|
raise Exception("Unrecognized backend: '%s'" % backend)
|
||||||
|
|
||||||
return ("%(backend)s://%(user)s:%(passwd)s@localhost/%(database)s"
|
return ("%s://%s:%s@localhost/%s" % (backend, user, passwd, database))
|
||||||
% locals())
|
|
||||||
|
|
||||||
|
|
||||||
def _is_backend_avail(backend, user, passwd, database):
|
def _is_backend_avail(backend, user, passwd, database):
|
||||||
|
@ -262,13 +261,14 @@ class BaseMigrationTestCase(test.TestCase):
|
||||||
# operations there is a special database template1.
|
# operations there is a special database template1.
|
||||||
sqlcmd = ("psql -w -U %(user)s -h %(host)s -c"
|
sqlcmd = ("psql -w -U %(user)s -h %(host)s -c"
|
||||||
" '%(sql)s' -d template1")
|
" '%(sql)s' -d template1")
|
||||||
|
sqldict = {'user': user, 'host': host}
|
||||||
|
|
||||||
sql = ("drop database if exists %(database)s;") % locals()
|
sqldict['sql'] = ("drop database if exists %s;") % database
|
||||||
droptable = sqlcmd % locals()
|
droptable = sqlcmd % sqldict
|
||||||
self.execute_cmd(droptable)
|
self.execute_cmd(droptable)
|
||||||
|
|
||||||
sql = ("create database %(database)s;") % locals()
|
sqldict['sql'] = ("create database %s;") % database
|
||||||
createtable = sqlcmd % locals()
|
createtable = sqlcmd % sqldict
|
||||||
self.execute_cmd(createtable)
|
self.execute_cmd(createtable)
|
||||||
|
|
||||||
os.unsetenv('PGPASSWORD')
|
os.unsetenv('PGPASSWORD')
|
||||||
|
@ -294,9 +294,11 @@ class BaseMigrationTestCase(test.TestCase):
|
||||||
(user, password, database, host) = \
|
(user, password, database, host) = \
|
||||||
get_mysql_connection_info(conn_pieces)
|
get_mysql_connection_info(conn_pieces)
|
||||||
sql = ("drop database if exists %(database)s; "
|
sql = ("drop database if exists %(database)s; "
|
||||||
"create database %(database)s;") % locals()
|
"create database %(database)s;"
|
||||||
|
% {'database': database})
|
||||||
cmd = ("mysql -u \"%(user)s\" %(password)s -h %(host)s "
|
cmd = ("mysql -u \"%(user)s\" %(password)s -h %(host)s "
|
||||||
"-e \"%(sql)s\"") % locals()
|
"-e \"%(sql)s\"" % {'user': user,
|
||||||
|
'password': password, 'host': host, 'sql': sql})
|
||||||
self.execute_cmd(cmd)
|
self.execute_cmd(cmd)
|
||||||
elif conn_string.startswith('postgresql'):
|
elif conn_string.startswith('postgresql'):
|
||||||
self._reset_pg(conn_pieces)
|
self._reset_pg(conn_pieces)
|
||||||
|
@ -324,7 +326,7 @@ class BaseMigrationTestCase(test.TestCase):
|
||||||
total = connection.execute("SELECT count(*) "
|
total = connection.execute("SELECT count(*) "
|
||||||
"from information_schema.TABLES "
|
"from information_schema.TABLES "
|
||||||
"where TABLE_SCHEMA='%(database)s'" %
|
"where TABLE_SCHEMA='%(database)s'" %
|
||||||
locals())
|
{'database': database})
|
||||||
self.assertTrue(total.scalar() > 0, "No tables found. Wrong schema?")
|
self.assertTrue(total.scalar() > 0, "No tables found. Wrong schema?")
|
||||||
|
|
||||||
noninnodb = connection.execute("SELECT count(*) "
|
noninnodb = connection.execute("SELECT count(*) "
|
||||||
|
@ -332,7 +334,7 @@ class BaseMigrationTestCase(test.TestCase):
|
||||||
"where TABLE_SCHEMA='%(database)s' "
|
"where TABLE_SCHEMA='%(database)s' "
|
||||||
"and ENGINE!='InnoDB' "
|
"and ENGINE!='InnoDB' "
|
||||||
"and TABLE_NAME!='migrate_version'" %
|
"and TABLE_NAME!='migrate_version'" %
|
||||||
locals())
|
{'database': database})
|
||||||
count = noninnodb.scalar()
|
count = noninnodb.scalar()
|
||||||
self.assertEqual(count, 0, "%d non InnoDB tables created" % count)
|
self.assertEqual(count, 0, "%d non InnoDB tables created" % count)
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
|
@ -96,10 +96,8 @@ def fake_execute(*cmd_parts, **kwargs):
|
||||||
LOG.debug(_('Faked command raised an exception %s'), e)
|
LOG.debug(_('Faked command raised an exception %s'), e)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
stdout = reply[0]
|
|
||||||
stderr = reply[1]
|
|
||||||
LOG.debug(_("Reply to faked command is stdout='%(stdout)s' "
|
LOG.debug(_("Reply to faked command is stdout='%(stdout)s' "
|
||||||
"stderr='%(stderr)s'") % locals())
|
"stderr='%(stderr)s'") % {'stdout': reply[0], 'stderr': reply[1]})
|
||||||
|
|
||||||
# Replicate the sleep call in the real function
|
# Replicate the sleep call in the real function
|
||||||
greenthread.sleep(0)
|
greenthread.sleep(0)
|
||||||
|
|
|
@ -36,8 +36,10 @@ class OpenStackApiException(Exception):
|
||||||
_status = response.status
|
_status = response.status
|
||||||
_body = response.read()
|
_body = response.read()
|
||||||
|
|
||||||
message = _('%(message)s\nStatus Code: %(_status)s\n'
|
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)
|
super(OpenStackApiException, self).__init__(message)
|
||||||
|
|
||||||
|
@ -103,7 +105,8 @@ class TestOpenStackClient(object):
|
||||||
relative_url = parsed_url.path
|
relative_url = parsed_url.path
|
||||||
if parsed_url.query:
|
if parsed_url.query:
|
||||||
relative_url = relative_url + "?" + 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:
|
if body:
|
||||||
LOG.info(_("Body: %s") % body)
|
LOG.info(_("Body: %s") % body)
|
||||||
|
|
||||||
|
@ -123,7 +126,8 @@ class TestOpenStackClient(object):
|
||||||
headers=headers)
|
headers=headers)
|
||||||
|
|
||||||
http_status = response.status
|
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:
|
if http_status == 401:
|
||||||
raise OpenStackApiAuthenticationException(response=response)
|
raise OpenStackApiAuthenticationException(response=response)
|
||||||
|
@ -153,7 +157,8 @@ class TestOpenStackClient(object):
|
||||||
response = self.request(full_uri, **kwargs)
|
response = self.request(full_uri, **kwargs)
|
||||||
|
|
||||||
http_status = response.status
|
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 check_response_status:
|
||||||
if http_status not in check_response_status:
|
if http_status not in check_response_status:
|
||||||
|
|
|
@ -185,7 +185,7 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
||||||
if isinstance(expected, dict):
|
if isinstance(expected, dict):
|
||||||
if not isinstance(result, dict):
|
if not isinstance(result, dict):
|
||||||
raise NoMatch(_('%(result_str)s: %(result)s is not a dict.')
|
raise NoMatch(_('%(result_str)s: %(result)s is not a dict.')
|
||||||
% locals())
|
% {'result_str': result_str, 'result': result})
|
||||||
ex_keys = sorted(expected.keys())
|
ex_keys = sorted(expected.keys())
|
||||||
res_keys = sorted(result.keys())
|
res_keys = sorted(result.keys())
|
||||||
if ex_keys != res_keys:
|
if ex_keys != res_keys:
|
||||||
|
@ -200,8 +200,9 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
||||||
raise NoMatch(
|
raise NoMatch(
|
||||||
_('Dictionary key mismatch:\n'
|
_('Dictionary key mismatch:\n'
|
||||||
'Extra key(s) in template:\n%(ex_delta)s\n'
|
'Extra key(s) in template:\n%(ex_delta)s\n'
|
||||||
'Extra key(s) in %(result_str)s:\n%(res_delta)s\n')
|
'Extra key(s) in %(result_str)s:\n%(res_delta)s\n') %
|
||||||
% locals())
|
{'ex_delta': ex_delta, 'result_str': result_str,
|
||||||
|
'res_delta': res_delta})
|
||||||
for key in ex_keys:
|
for key in ex_keys:
|
||||||
res = self._compare_result(subs, expected[key], result[key],
|
res = self._compare_result(subs, expected[key], result[key],
|
||||||
result_str)
|
result_str)
|
||||||
|
@ -209,7 +210,8 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
||||||
elif isinstance(expected, list):
|
elif isinstance(expected, list):
|
||||||
if not isinstance(result, list):
|
if not isinstance(result, list):
|
||||||
raise NoMatch(
|
raise NoMatch(
|
||||||
_('%(result_str)s: %(result)s is not a list.') % locals())
|
_('%(result_str)s: %(result)s is not a list.') %
|
||||||
|
{'result_str': result_str, 'result': result})
|
||||||
|
|
||||||
expected = expected[:]
|
expected = expected[:]
|
||||||
extra = []
|
extra = []
|
||||||
|
@ -232,8 +234,8 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
||||||
error.extend([repr(o) for o in expected])
|
error.extend([repr(o) for o in expected])
|
||||||
|
|
||||||
if extra:
|
if extra:
|
||||||
error.append(_('Extra list items in %(result_str)s:')
|
error.append(_('Extra list items in %(result_str)s:') %
|
||||||
% locals())
|
{'result_str': result_str})
|
||||||
error.extend([repr(o) for o in extra])
|
error.extend([repr(o) for o in extra])
|
||||||
|
|
||||||
if error:
|
if error:
|
||||||
|
@ -254,8 +256,9 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
||||||
if not match:
|
if not match:
|
||||||
raise NoMatch(
|
raise NoMatch(
|
||||||
_('Values do not match:\n'
|
_('Values do not match:\n'
|
||||||
'Template: %(expected)s\n%(result_str)s: %(result)s')
|
'Template: %(expected)s\n%(result_str)s: %(result)s') %
|
||||||
% locals())
|
{'expected': expected, 'result_str': result_str,
|
||||||
|
'result': result})
|
||||||
try:
|
try:
|
||||||
matched_value = match.group('id')
|
matched_value = match.group('id')
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
@ -269,8 +272,10 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
||||||
if expected != result:
|
if expected != result:
|
||||||
raise NoMatch(
|
raise NoMatch(
|
||||||
_('Values do not match:\n'
|
_('Values do not match:\n'
|
||||||
'Template: %(expected)s\n%(result_str)s: %(result)s')
|
'Template: %(expected)s\n%(result_str)s: '
|
||||||
% locals())
|
'%(result)s') % {'expected': expected,
|
||||||
|
'result_str': result_str,
|
||||||
|
'result': result})
|
||||||
return matched_value
|
return matched_value
|
||||||
|
|
||||||
def generalize_subs(self, subs, vanilla_regexes):
|
def generalize_subs(self, subs, vanilla_regexes):
|
||||||
|
|
|
@ -825,7 +825,8 @@ class PowerVMDriverLparTestCase(test.TestCase):
|
||||||
exp_mac_str = mac[:-2].replace(':', '')
|
exp_mac_str = mac[:-2].replace(':', '')
|
||||||
|
|
||||||
exp_cmd = ('chsyscfg -r lpar -i "name=%(inst_name)s, '
|
exp_cmd = ('chsyscfg -r lpar -i "name=%(inst_name)s, '
|
||||||
'virtual_eth_mac_base_value=%(exp_mac_str)s"') % locals()
|
'virtual_eth_mac_base_value=%(exp_mac_str)s"'
|
||||||
|
% {'inst_name': inst_name, 'exp_mac_str': exp_mac_str})
|
||||||
|
|
||||||
fake_op = self.powervm_connection._powervm
|
fake_op = self.powervm_connection._powervm
|
||||||
self.mox.StubOutWithMock(fake_op._operator, 'run_vios_command')
|
self.mox.StubOutWithMock(fake_op._operator, 'run_vios_command')
|
||||||
|
|
3
tox.ini
3
tox.ini
|
@ -45,9 +45,8 @@ commands = {posargs}
|
||||||
# in sqlalchemy.
|
# in sqlalchemy.
|
||||||
# TODO Hacking 0.6 checks to fix
|
# TODO Hacking 0.6 checks to fix
|
||||||
# H102 Apache 2.0 license header not found
|
# H102 Apache 2.0 license header not found
|
||||||
# H501 Do not use locals() for string formatting
|
|
||||||
|
|
||||||
ignore = E121,E122,E123,E124,E126,E127,E128,E711,E712,H102,H302,H404,F403,H501,F811,F841
|
ignore = E121,E122,E123,E124,E126,E127,E128,E711,E712,H102,H302,H404,F403,F811,F841
|
||||||
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,*plugins/xenserver*,tools
|
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,*plugins/xenserver*,tools
|
||||||
|
|
||||||
[hacking]
|
[hacking]
|
||||||
|
|
Loading…
Reference in New Issue