From 03df827e7870851ddb28add8b6b9cad1a812f81a Mon Sep 17 00:00:00 2001 From: Eugene Nikanorov Date: Thu, 4 Jul 2013 18:06:53 +0400 Subject: [PATCH] Remove locals() from virt directory fixes bug 1171936 Change-Id: Id91f2fd516f57970d3af59c1bae6e8da46c5482c --- nova/virt/baremetal/ipmi.py | 2 +- nova/virt/baremetal/utils.py | 11 +++++++---- nova/virt/disk/api.py | 2 +- nova/virt/disk/mount/api.py | 8 ++++++-- nova/virt/disk/vfs/api.py | 5 +++-- nova/virt/disk/vfs/guestfs.py | 19 +++++++++++-------- nova/virt/disk/vfs/localfs.py | 16 +++++++++------- nova/virt/driver.py | 4 ++-- nova/virt/images.py | 3 ++- 9 files changed, 42 insertions(+), 28 deletions(-) mode change 100755 => 100644 nova/virt/disk/api.py diff --git a/nova/virt/baremetal/ipmi.py b/nova/virt/baremetal/ipmi.py index 73d871e42502..6fe33ad9a30f 100644 --- a/nova/virt/baremetal/ipmi.py +++ b/nova/virt/baremetal/ipmi.py @@ -133,7 +133,7 @@ class IPMI(base.PowerManager): args.extend(command.split(" ")) out, err = utils.execute(*args, attempts=3) LOG.debug(_("ipmitool stdout: '%(out)s', stderr: '%(err)s'"), - locals()) + {'out': out, 'err': err}) return out, err finally: bm_utils.unlink_without_raise(pwfile) diff --git a/nova/virt/baremetal/utils.py b/nova/virt/baremetal/utils.py index 96abcd41b68d..382470050ee3 100644 --- a/nova/virt/baremetal/utils.py +++ b/nova/virt/baremetal/utils.py @@ -39,7 +39,7 @@ def inject_into_image(image, key, net, metadata, admin_password, files, partition, use_cow) except Exception as e: LOG.warn(_("Failed to inject data into image %(image)s. " - "Error: %(e)s") % locals()) + "Error: %(e)s"), {'image': image, 'e': e}) def unlink_without_raise(path): @@ -49,7 +49,8 @@ def unlink_without_raise(path): if e.errno == errno.ENOENT: return else: - LOG.warn(_("Failed to unlink %(path)s, error: %(e)s") % locals()) + LOG.warn(_("Failed to unlink %(path)s, error: %(e)s"), + {'path': path, 'e': e}) def rmtree_without_raise(path): @@ -57,7 +58,8 @@ def rmtree_without_raise(path): if os.path.isdir(path): shutil.rmtree(path) except OSError as e: - LOG.warn(_("Failed to remove dir %(path)s, error: %(e)s") % locals()) + LOG.warn(_("Failed to remove dir %(path)s, error: %(e)s"), + {'path': path, 'e': e}) def write_to_file(path, contents): @@ -73,7 +75,8 @@ def create_link_without_raise(source, link): return else: LOG.warn(_("Failed to create symlink from %(source)s to %(link)s" - ", error: %(e)s") % locals()) + ", error: %(e)s"), + {'source': source, 'link': link, 'e': e}) def random_alnum(count): diff --git a/nova/virt/disk/api.py b/nova/virt/disk/api.py old mode 100755 new mode 100644 index 5b87829243ea..975b7b52790c --- a/nova/virt/disk/api.py +++ b/nova/virt/disk/api.py @@ -93,7 +93,7 @@ for s in CONF.virt_mkfs: def mkfs(os_type, fs_label, target): mkfs_command = (_MKFS_COMMAND.get(os_type, _DEFAULT_MKFS_COMMAND) or - '') % locals() + '') % {'fs_label': fs_label, 'target': target} if mkfs_command: utils.execute(*mkfs_command.split(), run_as_root=True) diff --git a/nova/virt/disk/mount/api.py b/nova/virt/disk/mount/api.py index 85e1d109f35b..7c442fd3d483 100644 --- a/nova/virt/disk/mount/api.py +++ b/nova/virt/disk/mount/api.py @@ -40,7 +40,9 @@ class Mount(object): def instance_for_format(imgfile, mountdir, partition, imgfmt): LOG.debug(_("Instance for format imgfile=%(imgfile)s " "mountdir=%(mountdir)s partition=%(partition)s " - "imgfmt=%(imgfmt)s") % locals()) + "imgfmt=%(imgfmt)s"), + {'imgfile': imgfile, 'mountdir': mountdir, + 'partition': partition, 'imgfmt': imgfmt}) if imgfmt == "raw": LOG.debug(_("Using LoopMount")) return importutils.import_object( @@ -56,7 +58,9 @@ class Mount(object): def instance_for_device(imgfile, mountdir, partition, device): LOG.debug(_("Instance for device imgfile=%(imgfile)s " "mountdir=%(mountdir)s partition=%(partition)s " - "device=%(device)s") % locals()) + "device=%(device)s"), + {'imgfile': imgfile, 'mountdir': mountdir, + 'partition': partition, 'device': device}) if "loop" in device: LOG.debug(_("Using LoopMount")) return importutils.import_object( diff --git a/nova/virt/disk/vfs/api.py b/nova/virt/disk/vfs/api.py index 445752d9c0ce..b6cff39fb6c6 100644 --- a/nova/virt/disk/vfs/api.py +++ b/nova/virt/disk/vfs/api.py @@ -25,8 +25,9 @@ class VFS(object): @staticmethod def instance_for_image(imgfile, imgfmt, partition): LOG.debug(_("Instance for image imgfile=%(imgfile)s " - "imgfmt=%(imgfmt)s partition=%(partition)s") - % locals()) + "imgfmt=%(imgfmt)s partition=%(partition)s"), + {'imgfile': imgfile, 'imgfmt': imgfmt, + 'partition': partition}) hasGuestfs = False try: LOG.debug(_("Trying to import guestfs")) diff --git a/nova/virt/disk/vfs/guestfs.py b/nova/virt/disk/vfs/guestfs.py index da8bbd6883dd..29b396577594 100644 --- a/nova/virt/disk/vfs/guestfs.py +++ b/nova/virt/disk/vfs/guestfs.py @@ -151,27 +151,27 @@ class VFSGuestFS(vfs.VFS): return path def make_path(self, path): - LOG.debug(_("Make directory path=%(path)s") % locals()) + LOG.debug(_("Make directory path=%s"), path) path = self._canonicalize_path(path) self.handle.mkdir_p(path) def append_file(self, path, content): - LOG.debug(_("Append file path=%(path)s") % locals()) + LOG.debug(_("Append file path=%s"), path) path = self._canonicalize_path(path) self.handle.write_append(path, content) def replace_file(self, path, content): - LOG.debug(_("Replace file path=%(path)s") % locals()) + LOG.debug(_("Replace file path=%s"), path) path = self._canonicalize_path(path) self.handle.write(path, content) def read_file(self, path): - LOG.debug(_("Read file path=%(path)s") % locals()) + LOG.debug(_("Read file path=%s"), path) path = self._canonicalize_path(path) return self.handle.read_file(path) def has_file(self, path): - LOG.debug(_("Has file path=%(path)s") % locals()) + LOG.debug(_("Has file path=%s"), path) path = self._canonicalize_path(path) try: self.handle.stat(path) @@ -180,13 +180,15 @@ class VFSGuestFS(vfs.VFS): return False def set_permissions(self, path, mode): - LOG.debug(_("Set permissions path=%(path)s mode=%(mode)s") % locals()) + LOG.debug(_("Set permissions path=%(path)s mode=%(mode)s"), + {'path': path, 'mode': mode}) path = self._canonicalize_path(path) self.handle.chmod(mode, path) def set_ownership(self, path, user, group): LOG.debug(_("Set ownership path=%(path)s " - "user=%(user)s group=%(group)s") % locals()) + "user=%(user)s group=%(group)s"), + {'path': path, 'user': user, 'group': group}) path = self._canonicalize_path(path) uid = -1 gid = -1 @@ -198,5 +200,6 @@ class VFSGuestFS(vfs.VFS): gid = int(self.handle.aug_get( "/files/etc/group/" + group + "/gid")) - LOG.debug(_("chown uid=%(uid)d gid=%(gid)s") % locals()) + LOG.debug(_("chown uid=%(uid)d gid=%(gid)s"), + {'uid': uid, 'gid': gid}) self.handle.chown(uid, gid, path) diff --git a/nova/virt/disk/vfs/localfs.py b/nova/virt/disk/vfs/localfs.py index 73548134048b..5eaefc3b3d11 100644 --- a/nova/virt/disk/vfs/localfs.py +++ b/nova/virt/disk/vfs/localfs.py @@ -99,12 +99,12 @@ class VFSLocalFS(vfs.VFS): self.mount = None def make_path(self, path): - LOG.debug(_("Make directory path=%(path)s") % locals()) + LOG.debug(_("Make directory path=%s"), path) canonpath = self._canonical_path(path) utils.execute('mkdir', '-p', canonpath, run_as_root=True) def append_file(self, path, content): - LOG.debug(_("Append file path=%(path)s") % locals()) + LOG.debug(_("Append file path=%s"), path) canonpath = self._canonical_path(path) args = ["-a", canonpath] @@ -113,7 +113,7 @@ class VFSLocalFS(vfs.VFS): utils.execute('tee', *args, **kwargs) def replace_file(self, path, content): - LOG.debug(_("Replace file path=%(path)s") % locals()) + LOG.debug(_("Replace file path=%s"), path) canonpath = self._canonical_path(path) args = [canonpath] @@ -122,13 +122,13 @@ class VFSLocalFS(vfs.VFS): utils.execute('tee', *args, **kwargs) def read_file(self, path): - LOG.debug(_("Read file path=%(path)s") % locals()) + LOG.debug(_("Read file path=%s"), path) canonpath = self._canonical_path(path) return utils.read_file_as_root(canonpath) def has_file(self, path): - LOG.debug(_("Has file path=%(path)s") % locals()) + LOG.debug(_("Has file path=%s"), path) canonpath = self._canonical_path(path) exists, _err = utils.trycmd('readlink', '-e', canonpath, @@ -136,13 +136,15 @@ class VFSLocalFS(vfs.VFS): return exists def set_permissions(self, path, mode): - LOG.debug(_("Set permissions path=%(path)s mode=%(mode)o") % locals()) + LOG.debug(_("Set permissions path=%(path)s mode=%(mode)o"), + {'path': path, 'mode': mode}) canonpath = self._canonical_path(path) utils.execute('chmod', "%o" % mode, canonpath, run_as_root=True) def set_ownership(self, path, user, group): LOG.debug(_("Set permissions path=%(path)s " - "user=%(user)s group=%(group)s") % locals()) + "user=%(user)s group=%(group)s"), + {'path': path, 'user': user, 'group': group}) canonpath = self._canonical_path(path) owner = None cmd = "chown" diff --git a/nova/virt/driver.py b/nova/virt/driver.py index a0613a97a386..06a2840535b8 100755 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -963,8 +963,8 @@ class ComputeDriver(object): LOG.debug("Emitting event %s" % str(event)) self._compute_event_callback(event) except Exception as ex: - LOG.error(_("Exception dispatching event %(event)s: %(ex)s") - % locals()) + LOG.error(_("Exception dispatching event %(event)s: %(ex)s"), + {'event': event, 'ex': ex}) def load_compute_driver(virtapi, compute_driver=None): diff --git a/nova/virt/images.py b/nova/virt/images.py index e1b42eafcde9..bbb57cd39990 100755 --- a/nova/virt/images.py +++ b/nova/virt/images.py @@ -206,7 +206,8 @@ def fetch_to_raw(context, image_href, path, user_id, project_id): backing_file = data.backing_file if backing_file is not None: raise exception.ImageUnacceptable(image_id=image_href, - reason=_("fmt=%(fmt)s backed by: %(backing_file)s") % locals()) + reason=(_("fmt=%(fmt)s backed by: %(backing_file)s") % + {'fmt': fmt, 'backing_file': backing_file})) if fmt != "raw" and CONF.force_raw_images: staged = "%s.converted" % path