From ce1fb989f3c230e15251c3ea154b14a51934f715 Mon Sep 17 00:00:00 2001
From: Scott DAngelo <scott.dangelo@hp.com>
Date: Tue, 25 Jun 2013 13:19:51 +0000
Subject: [PATCH]         cinder.[brick,db,image] Replace 'locals()'

        Replace use of '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 soruce in the
        cinder brick, db, and image modules, i.e.
        cinder/brick/*.py and subdirectories
        cinder/db/*.py and subdirectories
        cinder/image/*.py and subdirectories

        Partially fixes: bug #1190758

Change-Id: Ibc111ab5ef53a2316e868c9cba8b94b323ba31c0
---
 cinder/brick/iscsi/iscsi.py | 11 +++++++----
 cinder/db/sqlalchemy/api.py | 12 ++++++------
 cinder/image/glance.py      | 17 ++++++++++++++---
 cinder/image/image_utils.py |  5 ++++-
 4 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/cinder/brick/iscsi/iscsi.py b/cinder/brick/iscsi/iscsi.py
index c212771d0..027e2019f 100644
--- a/cinder/brick/iscsi/iscsi.py
+++ b/cinder/brick/iscsi/iscsi.py
@@ -184,7 +184,10 @@ class TgtAdm(TargetAdmin):
         if tid is None:
             LOG.error(_("Failed to create iscsi target for volume "
                         "id:%(vol_id)s. Please ensure your tgtd config file "
-                        "contains 'include %(volumes_dir)s/*'") % locals())
+                        "contains 'include %(volumes_dir)s/*'") % {
+                            'vol_id': vol_id,
+                            'volumes_dir': volumes_dir,
+                        })
             raise exception.NotFound()
 
         if old_persist_file is not None and os.path.exists(old_persist_file):
@@ -404,7 +407,7 @@ class LioAdm(TargetAdmin):
             self._execute(*command_args, run_as_root=True)
         except exception.ProcessExecutionError as e:
                 LOG.error(_("Failed to create iscsi target for volume "
-                            "id:%(vol_id)s.") % locals())
+                            "id:%s.") % vol_id)
                 LOG.error("%s" % str(e))
 
                 raise exception.ISCSITargetCreateFailed(volume_id=vol_id)
@@ -413,7 +416,7 @@ class LioAdm(TargetAdmin):
         tid = self._get_target(iqn)
         if tid is None:
             LOG.error(_("Failed to create iscsi target for volume "
-                        "id:%(vol_id)s.") % locals())
+                        "id:%s.") % vol_id)
             raise exception.NotFound()
 
         return tid
@@ -430,7 +433,7 @@ class LioAdm(TargetAdmin):
                           run_as_root=True)
         except exception.ProcessExecutionError as e:
             LOG.error(_("Failed to remove iscsi target for volume "
-                        "id:%(vol_id)s.") % locals())
+                        "id:%s.") % vol_id)
             LOG.error("%s" % str(e))
             raise exception.ISCSITargetRemoveFailed(volume_id=vol_id)
 
diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py
index c5735fc85..2f08c31b0 100644
--- a/cinder/db/sqlalchemy/api.py
+++ b/cinder/db/sqlalchemy/api.py
@@ -811,7 +811,7 @@ def quota_reserve(context, resources, quotas, deltas, expire,
 
     if unders:
         LOG.warning(_("Change will make usage less than 0 for the following "
-                      "resources: %(unders)s") % locals())
+                      "resources: %s") % unders)
     if overs:
         usages = dict((k, dict(in_use=v['in_use'], reserved=v['reserved']))
                       for k, v in usages.items())
@@ -1829,7 +1829,7 @@ def sm_backend_conf_update(context, sm_backend_id, values):
 
         if not backend_conf:
             raise exception.NotFound(
-                _("No backend config with id %(sm_backend_id)s") % locals())
+                _("No backend config with id %s") % sm_backend_id)
 
         backend_conf.update(values)
         backend_conf.save(session=session)
@@ -1856,7 +1856,7 @@ def sm_backend_conf_get(context, sm_backend_id):
 
     if not result:
         raise exception.NotFound(_("No backend config with id "
-                                   "%(sm_backend_id)s") % locals())
+                                   "%s") % sm_backend_id)
 
     return result
 
@@ -1912,7 +1912,7 @@ def sm_flavor_get(context, sm_flavor_label):
 
     if not result:
         raise exception.NotFound(
-            _("No sm_flavor called %(sm_flavor)s") % locals())
+            _("No sm_flavor called %s") % sm_flavor_label)
 
     return result
 
@@ -1956,7 +1956,7 @@ def sm_volume_get(context, volume_id):
 
     if not result:
         raise exception.NotFound(
-            _("No sm_volume with id %(volume_id)s") % locals())
+            _("No sm_volume with id %s") % volume_id)
 
     return result
 
@@ -2019,7 +2019,7 @@ def backup_update(context, backup_id, values):
 
         if not backup:
             raise exception.BackupNotFound(
-                _("No backup with id %(backup_id)s") % locals())
+                _("No backup with id %s") % backup_id)
 
         backup.update(values)
         backup.save(session=session)
diff --git a/cinder/image/glance.py b/cinder/image/glance.py
index 80b23911e..f9315e6a8 100644
--- a/cinder/image/glance.py
+++ b/cinder/image/glance.py
@@ -152,13 +152,24 @@ class GlanceClientWrapper(object):
                 extra = "retrying"
                 error_msg = _("Error contacting glance server "
                               "'%(netloc)s' for '%(method)s', "
-                              "%(extra)s.")
+                              "%(extra)s.") % {
+                                  'netloc': netloc,
+                                  'method': method,
+                                  'extra': extra,
+                              }
                 if attempt == num_attempts:
                     extra = 'done trying'
-                    LOG.exception(error_msg, locals())
+                    error_msg = _("Error contacting glance server "
+                                  "'%(netloc)s' for '%(method)s', "
+                                  "%(extra)s.") % {
+                                      'netloc': netloc,
+                                      'method': method,
+                                      'extra': extra,
+                                  }
+                    LOG.exception(error_msg)
                     raise exception.GlanceConnectionFailed(netloc=netloc,
                                                            reason=str(e))
-                LOG.exception(error_msg, locals())
+                LOG.exception(error_msg)
                 time.sleep(1)
 
 
diff --git a/cinder/image/image_utils.py b/cinder/image/image_utils.py
index d9b810a1f..d5179af8a 100644
--- a/cinder/image/image_utils.py
+++ b/cinder/image/image_utils.py
@@ -238,7 +238,10 @@ def fetch_to_raw(context, image_service,
             raise exception.ImageUnacceptable(
                 image_id=image_id,
                 reason=_("fmt=%(fmt)s backed by:"
-                         "%(backing_file)s") % locals())
+                         "%(backing_file)s") % {
+                             'fmt': fmt,
+                             'backing_file': backing_file,
+                         })
 
         # NOTE(jdg): I'm using qemu-img convert to write
         # to the volume regardless if it *needs* conversion or not
-- 
2.45.2