Skip to content

Commit

Permalink
cinder/.: replace 'locals()' with explicit values
Browse files Browse the repository at this point in the history
Help bring source code into compliance with the Cinder Style Commandments:
https://github.com/openstack/cinder/blob/master/HACKING.rst

This change covers all affected source directly in the top-level directory
of the cinder module, i.e. cinder/*.py

Partially fixes: bug #1190748

Change-Id: Ice5efc5eda7189969af6a9b722344fad7aa49ff0
  • Loading branch information
Andrew Forrest committed Jun 17, 2013
1 parent b1b06e3 commit 77be276
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
8 changes: 7 additions & 1 deletion cinder/exception.py
Expand Up @@ -66,7 +66,13 @@ def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None,
exit_code = '-'
message = _('%(description)s\nCommand: %(cmd)s\n'
'Exit code: %(exit_code)s\nStdout: %(stdout)r\n'
'Stderr: %(stderr)r') % locals()
'Stderr: %(stderr)r') % {
'description': description,
'cmd': cmd,
'exit_code': exit_code,
'stdout': stdout,
'stderr': stderr,
}
IOError.__init__(self, message)


Expand Down
7 changes: 3 additions & 4 deletions cinder/quota.py
Expand Up @@ -702,7 +702,7 @@ def reserve(self, context, expire=None, project_id=None, **deltas):
expire=expire,
project_id=project_id)

LOG.debug(_("Created reservations %(reservations)s") % locals())
LOG.debug(_("Created reservations %s") % reservations)

return reservations

Expand All @@ -724,8 +724,7 @@ def commit(self, context, reservations, project_id=None):
# usage resynchronization and the reservation expiration
# mechanisms will resolve the issue. The exception is
# logged, however, because this is less than optimal.
LOG.exception(_("Failed to commit reservations "
"%(reservations)s") % locals())
LOG.exception(_("Failed to commit reservations %s") % reservations)

def rollback(self, context, reservations, project_id=None):
"""Roll back reservations.
Expand All @@ -746,7 +745,7 @@ def rollback(self, context, reservations, project_id=None):
# mechanisms will resolve the issue. The exception is
# logged, however, because this is less than optimal.
LOG.exception(_("Failed to roll back reservations "
"%(reservations)s") % locals())
"%s") % reservations)

def destroy_all_by_project(self, context, project_id):
"""
Expand Down
11 changes: 7 additions & 4 deletions cinder/service.py
Expand Up @@ -270,10 +270,12 @@ def _wait_child(self):
code = 0
if os.WIFSIGNALED(status):
sig = os.WTERMSIG(status)
LOG.info(_('Child %(pid)d killed by signal %(sig)d'), locals())
LOG.info(_('Child %(pid)d killed by signal %(sig)d'),
{'pid': pid, 'sig': sig})
else:
code = os.WEXITSTATUS(status)
LOG.info(_('Child %(pid)d exited with status %(code)d'), locals())
LOG.info(_('Child %(pid)d exited with status %(code)d'),
{'pid': pid, 'code': code})

if pid not in self.children:
LOG.warning(_('pid %d not in child list'), pid)
Expand Down Expand Up @@ -613,9 +615,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(_('%s : FLAG SET ') % 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:
Expand Down
19 changes: 14 additions & 5 deletions cinder/test.py
Expand Up @@ -223,7 +223,8 @@ def raise_assertion(msg):
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())
Expand All @@ -232,7 +233,8 @@ def raise_assertion(msg):
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]
Expand All @@ -254,22 +256,29 @@ def raise_assertion(msg):
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."""
def raise_assertion(msg):
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,
Expand Down
3 changes: 2 additions & 1 deletion cinder/utils.py
Expand Up @@ -530,7 +530,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'):
Expand Down

0 comments on commit 77be276

Please sign in to comment.