From 77be2761dc4407fd8aa292a2ee4bb9df6dccd31d Mon Sep 17 00:00:00 2001 From: Andrew Forrest Date: Sat, 15 Jun 2013 11:09:33 -0700 Subject: [PATCH] cinder/.: replace 'locals()' with explicit values 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 --- cinder/exception.py | 8 +++++++- cinder/quota.py | 7 +++---- cinder/service.py | 11 +++++++---- cinder/test.py | 19 ++++++++++++++----- cinder/utils.py | 3 ++- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/cinder/exception.py b/cinder/exception.py index c668e1404..a028a5686 100644 --- a/cinder/exception.py +++ b/cinder/exception.py @@ -66,7 +66,13 @@ class ProcessExecutionError(IOError): 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) diff --git a/cinder/quota.py b/cinder/quota.py index 3f9b174ec..59b03bf01 100644 --- a/cinder/quota.py +++ b/cinder/quota.py @@ -702,7 +702,7 @@ class QuotaEngine(object): expire=expire, project_id=project_id) - LOG.debug(_("Created reservations %(reservations)s") % locals()) + LOG.debug(_("Created reservations %s") % reservations) return reservations @@ -724,8 +724,7 @@ class QuotaEngine(object): # 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. @@ -746,7 +745,7 @@ class QuotaEngine(object): # 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): """ diff --git a/cinder/service.py b/cinder/service.py index 3ffd7f892..c8d374895 100644 --- a/cinder/service.py +++ b/cinder/service.py @@ -270,10 +270,12 @@ class ProcessLauncher(object): 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) @@ -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: diff --git a/cinder/test.py b/cinder/test.py index bebe950a8..59d3bacdb 100644 --- a/cinder/test.py +++ b/cinder/test.py @@ -223,7 +223,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()) @@ -232,7 +233,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] @@ -254,7 +256,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.""" @@ -262,14 +269,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, diff --git a/cinder/utils.py b/cinder/utils.py index b2464d414..c9c33bf5a 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -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'): -- 2.45.2