Skip to content

Commit

Permalink
Remove locals() from nova/virt/libvirt package
Browse files Browse the repository at this point in the history
fixes bug 1171936

Change-Id: I81198d6bc74991b184b3de2f7977ff3a9a12ac28
  • Loading branch information
eugene64 committed Jun 21, 2013
1 parent 022bd8d commit b68aa0a
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 72 deletions.
137 changes: 78 additions & 59 deletions nova/virt/libvirt/driver.py 100644 → 100755
Expand Up @@ -351,8 +351,9 @@ def __init__(self, virtapi, read_only=False):
for mode_str in CONF.disk_cachemodes:
disk_type, sep, cache_mode = mode_str.partition('=')
if cache_mode not in self.valid_cachemodes:
LOG.warn(_("Invalid cachemode %(cache_mode)s specified "
"for disk type %(disk_type)s.") % locals())
LOG.warn(_('Invalid cachemode %(cache_mode)s specified '
'for disk type %(disk_type)s.'),
{'cache_mode': cache_mode, 'disk_type': disk_type})
continue
self.disk_cachemodes[disk_type] = cache_mode

Expand Down Expand Up @@ -562,8 +563,8 @@ def init_host(self, host):
minor = MIN_LIBVIRT_VERSION[1]
micro = MIN_LIBVIRT_VERSION[2]
LOG.error(_('Nova requires libvirt version '
'%(major)i.%(minor)i.%(micro)i or greater.') %
locals())
'%(major)i.%(minor)i.%(micro)i or greater.'),
{'major': major, 'minor': minor, 'micro': micro})

libvirt.registerErrorHandler(libvirt_error_handler, None)
libvirt.virEventRegisterDefaultImpl()
Expand Down Expand Up @@ -778,9 +779,10 @@ def _destroy(self, instance):

if not is_okay:
with excutils.save_and_reraise_exception():
LOG.error(_("Error from libvirt during destroy. "
"Code=%(errcode)s Error=%(e)s") %
locals(), instance=instance)
LOG.error(_('Error from libvirt during destroy. '
'Code=%(errcode)s Error=%(e)s'),
{'errcode': errcode, 'e': e},
instance=instance)

def _wait_for_destroy(expected_domid):
"""Called at an interval until the VM is gone."""
Expand Down Expand Up @@ -853,9 +855,9 @@ def _undefine_domain(self, instance):
except libvirt.libvirtError as e:
with excutils.save_and_reraise_exception():
errcode = e.get_error_code()
LOG.error(_("Error from libvirt during undefine. "
"Code=%(errcode)s Error=%(e)s") %
locals(), instance=instance)
LOG.error(_('Error from libvirt during undefine. '
'Code=%(errcode)s Error=%(e)s') %
{'errcode': errcode, 'e': e}, instance=instance)

def _cleanup(self, instance, network_info, block_device_info,
destroy_disks):
Expand All @@ -879,9 +881,10 @@ def _cleanup(self, instance, network_info, block_device_info,
else:
retry = False
errcode = e.get_error_code()
LOG.error(_("Error from libvirt during unfilter. "
"Code=%(errcode)s Error=%(e)s") %
locals(), instance=instance)
LOG.error(_('Error from libvirt during unfilter. '
'Code=%(errcode)s Error=%(e)s') %
{'errcode': errcode, 'e': e},
instance=instance)
reason = "Error unfiltering instance."
raise exception.InstanceTerminationFailure(reason=reason)
except Exception:
Expand All @@ -907,7 +910,7 @@ def _cleanup(self, instance, network_info, block_device_info,

if destroy_disks:
target = libvirt_utils.get_instance_path(instance)
LOG.info(_('Deleting instance files %(target)s') % locals(),
LOG.info(_('Deleting instance files %s'), target,
instance=instance)
if os.path.exists(target):
# If we fail to get rid of the directory
Expand All @@ -916,8 +919,8 @@ def _cleanup(self, instance, network_info, block_device_info,
try:
shutil.rmtree(target)
except OSError as e:
LOG.error(_("Failed to cleanup directory %(target)s: %(e)s"
) % locals())
LOG.error(_('Failed to cleanup directory %(target)s: '
'%(e)s'), {'target': target, 'e': e})

#NOTE(bfilippov): destroy all LVM disks for this instance
self._cleanup_lvm(instance)
Expand Down Expand Up @@ -1605,7 +1608,8 @@ def _flush_libvirt_console(self, pty):
return out

def _append_to_file(self, data, fpath):
LOG.info(_('data: %(data)r, fpath: %(fpath)r') % locals())
LOG.info(_('data: %(data)r, fpath: %(fpath)r'),
{'data': data, 'fpath': fpath})
fp = open(fpath, 'a+')
fp.write(data)
return fpath
Expand Down Expand Up @@ -1959,10 +1963,16 @@ def raw(fname):
injection_path = image('disk').path
img_id = instance['image_ref']

for inj in ('key', 'net', 'metadata', 'admin_pass', 'files'):
if locals()[inj]:
for inj, val in [('key', key),
('net', net),
('metadata', metadata),
('admin_pass', admin_pass),
('files', files)]:
if val:
LOG.info(_('Injecting %(inj)s into image '
'%(img_id)s'), locals(), instance=instance)
'%(img_id)s'),
{'inj': inj, 'img_id': img_id},
instance=instance)
try:
disk.inject_data(injection_path,
key, net, metadata, admin_pass, files,
Expand All @@ -1972,7 +1982,8 @@ def raw(fname):
except Exception as e:
with excutils.save_and_reraise_exception():
LOG.error(_('Error injecting data into image '
'%(img_id)s (%(e)s)') % locals(),
'%(img_id)s (%(e)s)'),
{'img_id': img_id, 'e': e},
instance=instance)

if CONF.libvirt_type == 'uml':
Expand Down Expand Up @@ -2384,12 +2395,14 @@ def get_guest_config(self, instance, network_info, image_meta,
def to_xml(self, instance, network_info, disk_info,
image_meta=None, rescue=None,
block_device_info=None, write_to_disk=False):
LOG.debug(_("Start to_xml instance=%(instance)s "
"network_info=%(network_info)s "
"disk_info=%(disk_info)s "
"image_meta=%(image_meta)s rescue=%(rescue)s"
"block_device_info=%(block_device_info)s") %
locals())
LOG.debug(_('Start to_xml instance=%(instance)s '
'network_info=%(network_info)s '
'disk_info=%(disk_info)s '
'image_meta=%(image_meta)s rescue=%(rescue)s'
'block_device_info=%(block_device_info)s'),
{'instance': instance, 'network_info': network_info,
'disk_info': disk_info, 'image_meta': image_meta,
'rescue': rescue, 'block_device_info': block_device_info})
conf = self.get_guest_config(instance, network_info, image_meta,
disk_info, rescue, block_device_info)
xml = conf.to_xml()
Expand All @@ -2399,7 +2412,8 @@ def to_xml(self, instance, network_info, disk_info,
xml_path = os.path.join(instance_dir, 'libvirt.xml')
libvirt_utils.write_to_file(xml_path, xml)

LOG.debug(_('End to_xml instance=%(instance)s xml=%(xml)s') % locals())
LOG.debug(_('End to_xml instance=%(instance)s xml=%(xml)s'),
{'instance': instance, 'xml': xml})
return xml

def _lookup_by_id(self, instance_id):
Expand Down Expand Up @@ -2437,8 +2451,11 @@ def _lookup_by_name(self, instance_name):
if error_code == libvirt.VIR_ERR_NO_DOMAIN:
raise exception.InstanceNotFound(instance_id=instance_name)

msg = _("Error from libvirt while looking up %(instance_name)s: "
"[Error Code %(error_code)s] %(ex)s") % locals()
msg = (_('Error from libvirt while looking up %(instance_name)s: '
'[Error Code %(error_code)s] %(ex)s') %
{'instance_name': instance_name,
'error_code': error_code,
'ex': ex})
raise exception.NovaException(msg)

def get_info(self, instance):
Expand Down Expand Up @@ -2911,13 +2928,14 @@ def block_stats(self, instance_name, disk):
return domain.blockStats(disk)
except libvirt.libvirtError as e:
errcode = e.get_error_code()
LOG.info(_("Getting block stats failed, device might have "
"been detached. Instance=%(instance_name)s "
"Disk=%(disk)s Code=%(errcode)s Error=%(e)s")
% locals())
LOG.info(_('Getting block stats failed, device might have '
'been detached. Instance=%(instance_name)s '
'Disk=%(disk)s Code=%(errcode)s Error=%(e)s'),
{'instance_name': instance_name, 'disk': disk,
'errcode': errcode, 'e': e})
except exception.InstanceNotFound:
LOG.info(_("Could not find domain in libvirt for instance %s. "
"Cannot get block stats for device") % instance_name)
LOG.info(_('Could not find domain in libvirt for instance %s. '
'Cannot get block stats for device'), instance_name)

def interface_stats(self, instance_name, interface):
"""
Expand Down Expand Up @@ -3127,12 +3145,14 @@ def _assert_dest_node_has_enough_disk(self, context, instance,

# Check that available disk > necessary disk
if (available - necessary) < 0:
instance_uuid = instance['uuid']
reason = _("Unable to migrate %(instance_uuid)s: "
"Disk of instance is too large(available"
" on destination host:%(available)s "
"< need:%(necessary)s)")
raise exception.MigrationPreCheckError(reason=reason % locals())
reason = (_('Unable to migrate %(instance_uuid)s: '
'Disk of instance is too large(available'
' on destination host:%(available)s '
'< need:%(necessary)s)') %
{'instance_uuid': instance['uuid'],
'available': available,
'necessary': necessary})
raise exception.MigrationPreCheckError(reason=reason)

def _compare_cpu(self, cpu_info):
"""Checks the host cpu is compatible to a cpu given by xml.
Expand Down Expand Up @@ -3172,11 +3192,11 @@ def _compare_cpu(self, cpu_info):
except libvirt.libvirtError as e:
with excutils.save_and_reraise_exception():
ret = e.message
LOG.error(m % locals())
LOG.error(m, {'ret': ret, 'u': u})

if ret <= 0:
LOG.error(m % locals())
raise exception.InvalidCPUInfo(reason=m % locals())
LOG.error(m, {'ret': ret, 'u': u})
raise exception.InvalidCPUInfo(reason=m % {'ret': ret, 'u': u})

def _create_shared_storage_test_file(self):
"""Makes tmpfile under CONF.instances_path."""
Expand Down Expand Up @@ -3304,7 +3324,7 @@ def _live_migration(self, context, instance, dest, post_method,

except Exception as e:
with excutils.save_and_reraise_exception():
LOG.error(_("Live Migration failure: %(e)s") % locals(),
LOG.error(_("Live Migration failure: %s"), e,
instance=instance)
recover_method(context, instance, dest, block_migration)

Expand Down Expand Up @@ -3518,9 +3538,12 @@ def get_instance_disk_info(self, instance_name, xml=None):
xml = virt_dom.XMLDesc(0)
except libvirt.libvirtError as ex:
error_code = ex.get_error_code()
msg = _("Error from libvirt while getting description of "
"%(instance_name)s: [Error Code %(error_code)s] "
"%(ex)s") % locals()
msg = (_('Error from libvirt while getting description of '
'%(instance_name)s: [Error Code %(error_code)s] '
'%(ex)s') %
{'instance_name': instance_name,
'error_code': error_code,
'ex': ex})
LOG.warn(msg)
raise exception.InstanceNotFound(instance_id=instance_name)

Expand All @@ -3535,14 +3558,12 @@ def get_instance_disk_info(self, instance_name, xml=None):
path = path_node.get('file')

if disk_type != 'file':
LOG.debug(_('skipping %(path)s since it looks like volume') %
locals())
LOG.debug(_('skipping %s since it looks like volume'), path)
continue

if not path:
LOG.debug(_('skipping disk for %(instance_name)s as it'
' does not have a path') %
locals())
LOG.debug(_('skipping disk for %s as it does not have a path'),
instance_name)
continue

# get the real disk size or
Expand Down Expand Up @@ -3581,8 +3602,8 @@ def get_disk_over_committed_size_total(self):
info['over_committed_disk_size'])
except OSError as e:
if e.errno == errno.ENOENT:
LOG.error(_("Getting disk size of %(i_name)s: %(e)s") %
locals())
LOG.error(_('Getting disk size of %(i_name)s: %(e)s'),
{'i_name': i_name, 'e': e})
else:
raise
except exception.InstanceNotFound:
Expand Down Expand Up @@ -3913,9 +3934,7 @@ def undo_aggregate_operation(self, context, op, aggregate,
def instance_on_disk(self, instance):
# ensure directories exist and are writable
instance_path = libvirt_utils.get_instance_path(instance)
LOG.debug(_('Checking instance files accessability'
'%(instance_path)s')
% locals())
LOG.debug(_('Checking instance files accessability %s'), instance_path)
return os.access(instance_path, os.W_OK)

def inject_network_info(self, instance, nw_info):
Expand Down
9 changes: 5 additions & 4 deletions nova/virt/libvirt/firewall.py
Expand Up @@ -245,9 +245,8 @@ def unfilter_instance(self, instance, network_info):
# This happens when the instance filter is still in
# use (ie. when the instance has not terminated properly)
raise
LOG.debug(_('The nwfilter(%(instance_filter_name)s) '
'is not found.') % locals(),
instance=instance)
LOG.debug(_('The nwfilter(%s) is not found.'),
instance_filter_name, instance=instance)

def _define_filters(self, filter_name, filter_children):
self._define_filter(self._filter_container(filter_name,
Expand All @@ -269,7 +268,9 @@ def instance_filter_exists(self, instance, network_info):
except libvirt.libvirtError:
name = instance['name']
LOG.debug(_('The nwfilter(%(instance_filter_name)s) for'
'%(name)s is not found.') % locals(),
'%(name)s is not found.'),
{'instance_filter_name': instance_filter_name,
'name': name},
instance=instance)
return False
return True
Expand Down
21 changes: 12 additions & 9 deletions nova/virt/libvirt/vif.py
Expand Up @@ -262,9 +262,10 @@ def get_config_802qbh(self, instance, network, mapping, image_meta):
def get_config(self, instance, network, mapping, image_meta):
vif_type = mapping.get('vif_type')

LOG.debug(_("vif_type=%(vif_type)s instance=%(instance)s "
"network=%(network)s mapping=%(mapping)s")
% locals())
LOG.debug(_('vif_type=%(vif_type)s instance=%(instance)s '
'network=%(network)s mapping=%(mapping)s'),
{'vif_type': vif_type, 'instance': instance,
'network': network, 'mapping': mapping})

if vif_type is None:
raise exception.NovaException(
Expand Down Expand Up @@ -383,9 +384,10 @@ def plug(self, instance, vif):
network, mapping = vif
vif_type = mapping.get('vif_type')

LOG.debug(_("vif_type=%(vif_type)s instance=%(instance)s "
"network=%(network)s mapping=%(mapping)s")
% locals())
LOG.debug(_('vif_type=%(vif_type)s instance=%(instance)s '
'network=%(network)s mapping=%(mapping)s'),
{'vif_type': vif_type, 'instance': instance,
'network': network, 'mapping': mapping})

if vif_type is None:
raise exception.NovaException(
Expand Down Expand Up @@ -470,9 +472,10 @@ def unplug(self, instance, vif):
network, mapping = vif
vif_type = mapping.get('vif_type')

LOG.debug(_("vif_type=%(vif_type)s instance=%(instance)s "
"network=%(network)s mapping=%(mapping)s")
% locals())
LOG.debug(_('vif_type=%(vif_type)s instance=%(instance)s '
'network=%(network)s mapping=%(mapping)s'),
{'vif_type': vif_type, 'instance': instance,
'network': network, 'mapping': mapping})

if vif_type is None:
raise exception.NovaException(
Expand Down

0 comments on commit b68aa0a

Please sign in to comment.