Remove usage of locals() for formatting from cinder.tests.*
Using of locals() for formatting string is a nasty thing because: 1) It is not so clear as using explicit dicts 2) It could produce hidden errors during refactoring 3) Changing name of variable causes change in message 4) Creating a lot of unused variables Fix bug 1171936 Change-Id: I67aa5bff650b55484ca76adf5be8555f72a4c426
This commit is contained in:
parent
6e90e4089f
commit
729a08a019
|
@ -96,10 +96,9 @@ def fake_execute(*cmd_parts, **kwargs):
|
|||
LOG.debug(_('Faked command raised an exception %s'), e)
|
||||
raise
|
||||
|
||||
stdout = reply[0]
|
||||
stderr = reply[1]
|
||||
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
|
||||
greenthread.sleep(0)
|
||||
|
|
|
@ -31,11 +31,9 @@ class OpenStackApiException(Exception):
|
|||
message = 'Unspecified error'
|
||||
|
||||
if response:
|
||||
_status = response.status
|
||||
_body = response.read()
|
||||
|
||||
message = _('%(message)s\nStatus Code: %(_status)s\n'
|
||||
'Body: %(_body)s') % locals()
|
||||
'Body: %(_body)s') % {'_status': response.status,
|
||||
'_body': response.read()}
|
||||
|
||||
super(OpenStackApiException, self).__init__(message)
|
||||
|
||||
|
@ -101,7 +99,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 +120,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 +147,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:
|
||||
|
|
|
@ -54,8 +54,9 @@ def _get_connect_string(backend,
|
|||
if backend == "postgres":
|
||||
backend = "postgresql+psycopg2"
|
||||
|
||||
return ("%(backend)s://%(user)s:%(passwd)s@localhost/%(database)s"
|
||||
% locals())
|
||||
return ("%(backend)s://%(user)s:%(passwd)s@localhost/%(database)s",
|
||||
{'backend': backend, 'user': user, 'passwd': passwd,
|
||||
'database': database})
|
||||
|
||||
|
||||
def _is_mysql_avail(**kwargs):
|
||||
|
@ -186,10 +187,11 @@ class TestMigrations(test.TestCase):
|
|||
if len(auth_pieces) > 1:
|
||||
if auth_pieces[1].strip():
|
||||
password = "-p\"%s\"" % auth_pieces[1]
|
||||
sql = ("drop database if exists %(database)s; "
|
||||
"create database %(database)s;") % locals()
|
||||
sql = ("drop database if exists %(database)s; create database "
|
||||
"%(database)s;") % {'database': database}
|
||||
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}
|
||||
execute_cmd(cmd)
|
||||
elif conn_string.startswith('postgresql'):
|
||||
database = conn_pieces.path.strip('/')
|
||||
|
@ -212,11 +214,13 @@ class TestMigrations(test.TestCase):
|
|||
# operations there is a special database template1.
|
||||
sqlcmd = ("psql -w -U %(user)s -h %(host)s -c"
|
||||
" '%(sql)s' -d template1")
|
||||
sql = ("drop database if exists %(database)s;") % locals()
|
||||
droptable = sqlcmd % locals()
|
||||
sql = ("drop database if exists %(database)s;") % {'database':
|
||||
database}
|
||||
droptable = sqlcmd % {'user': user, 'host': host, 'sql': sql}
|
||||
execute_cmd(droptable)
|
||||
sql = ("create database %(database)s;") % locals()
|
||||
createtable = sqlcmd % locals()
|
||||
sql = ("create database %(database)s;") % {'database':
|
||||
database}
|
||||
createtable = sqlcmd % {'user': user, 'host': host, 'sql': sql}
|
||||
execute_cmd(createtable)
|
||||
os.unsetenv('PGPASSWORD')
|
||||
os.unsetenv('PGUSER')
|
||||
|
|
Loading…
Reference in New Issue