Remove locals() from virt directory

fixes bug 1171936

Change-Id: Id91f2fd516f57970d3af59c1bae6e8da46c5482c
This commit is contained in:
Eugene Nikanorov 2013-07-04 18:06:53 +04:00
parent 77a66a248b
commit 03df827e78
9 changed files with 42 additions and 28 deletions

View File

@ -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)

View File

@ -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):

2
nova/virt/disk/api.py Executable file → Normal file
View File

@ -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)

View File

@ -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(

View File

@ -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"))

View File

@ -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)

View File

@ -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"

View File

@ -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):

View File

@ -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