From a39c7d05b793c95dab51d2508a5eff6ce7a385cb Mon Sep 17 00:00:00 2001 From: Eugene Nikanorov Date: Sun, 23 Jun 2013 20:42:40 +0400 Subject: remove locals() from virt/hyperv package Also fix logging issue with missing local variable for existing placeholder fixes bug 1171936 Change-Id: I6e32364983372945c2b69bb92cd3a96689b7a53c --- nova/virt/hyperv/imagecache.py | 19 ++++++++++++------- nova/virt/hyperv/livemigrationutils.py | 6 ++++-- nova/virt/hyperv/migrationops.py | 33 +++++++++++++++++++++------------ nova/virt/hyperv/networkutils.py | 4 +++- nova/virt/hyperv/pathutils.py | 5 +++-- nova/virt/hyperv/snapshotops.py | 25 +++++++++++++++++-------- nova/virt/hyperv/vmops.py | 21 ++++++++++++++------- nova/virt/hyperv/vmutils.py | 34 ++++++++++++++++++++-------------- nova/virt/hyperv/volumeops.py | 22 +++++++++++++++------- 9 files changed, 109 insertions(+), 60 deletions(-) diff --git a/nova/virt/hyperv/imagecache.py b/nova/virt/hyperv/imagecache.py index 8f29a62dc..6186b81c2 100644 --- a/nova/virt/hyperv/imagecache.py +++ b/nova/virt/hyperv/imagecache.py @@ -66,11 +66,12 @@ class ImageCache(object): root_vhd_size = root_vhd_size_gb * 1024 ** 3 if root_vhd_size < vhd_size: - raise vmutils.HyperVException(_("Cannot resize the image to a " - "size smaller than the VHD max. " - "internal size: %(vhd_size)s. " - "Requested disk size: " - "%(root_vhd_size)s") % locals()) + raise vmutils.HyperVException( + _("Cannot resize the image to a size smaller than the VHD " + "max. internal size: %(vhd_size)s. Requested disk size: " + "%(root_vhd_size)s") % + {'vhd_size': vhd_size, 'root_vhd_size': root_vhd_size} + ) if root_vhd_size > vhd_size: path_parts = os.path.splitext(vhd_path) resized_vhd_path = '%s_%s%s' % (path_parts[0], @@ -82,10 +83,14 @@ class ImageCache(object): if not self._pathutils.exists(resized_vhd_path): try: LOG.debug(_("Copying VHD %(vhd_path)s to " - "%(resized_vhd_path)s") % locals()) + "%(resized_vhd_path)s"), + {'vhd_path': vhd_path, + 'resized_vhd_path': resized_vhd_path}) self._pathutils.copyfile(vhd_path, resized_vhd_path) LOG.debug(_("Resizing VHD %(resized_vhd_path)s to new " - "size %(root_vhd_size)s") % locals()) + "size %(root_vhd_size)s"), + {'resized_vhd_path': resized_vhd_path, + 'root_vhd_size': root_vhd_size}) self._vhdutils.resize_vhd(resized_vhd_path, root_vhd_size) except Exception: diff --git a/nova/virt/hyperv/livemigrationutils.py b/nova/virt/hyperv/livemigrationutils.py index 2563e1182..9fce5343a 100644 --- a/nova/virt/hyperv/livemigrationutils.py +++ b/nova/virt/hyperv/livemigrationutils.py @@ -155,8 +155,10 @@ class LiveMigrationUtils(object): LOG.debug(_("Replacing host resource " "%(old_disk_path)s with " - "%(new_disk_path)s on planned VM %(vm_name)s") % - locals()) + "%(new_disk_path)s on planned VM %(vm_name)s"), + {'old_disk_path': old_disk_path, + 'new_disk_path': new_disk_path, + 'vm_name': vm_name}) sasd.HostResource = [new_disk_path] updated_resource_setting_data.append(sasd.GetText_(1)) diff --git a/nova/virt/hyperv/migrationops.py b/nova/virt/hyperv/migrationops.py index 5ce092bf3..19afdd717 100644 --- a/nova/virt/hyperv/migrationops.py +++ b/nova/virt/hyperv/migrationops.py @@ -71,7 +71,8 @@ class MigrationOps(object): # Skip the config drive as the instance is already configured if os.path.basename(disk_file).lower() != 'configdrive.vhd': LOG.debug(_('Copying disk "%(disk_file)s" to ' - '"%(dest_path)s"') % locals()) + '"%(dest_path)s"'), + {'disk_file': disk_file, 'dest_path': dest_path}) self._pathutils.copy(disk_file, dest_path) self._pathutils.rename(instance_path, revert_path) @@ -100,12 +101,11 @@ class MigrationOps(object): curr_root_gb = instance['root_gb'] if new_root_gb < curr_root_gb: - raise vmutils.VHDResizeException(_("Cannot resize the root disk " - "to a smaller size. Current " - "size: %(curr_root_gb)s GB. " - "Requested size: " - "%(new_root_gb)s GB") % - locals()) + raise vmutils.VHDResizeException( + _("Cannot resize the root disk to a smaller size. Current " + "size: %(curr_root_gb)s GB. Requested size: " + "%(new_root_gb)s GB") % + {'curr_root_gb': curr_root_gb, 'new_root_gb': new_root_gb}) def migrate_disk_and_power_off(self, context, instance, dest, instance_type, network_info, @@ -165,17 +165,23 @@ class MigrationOps(object): os.path.basename(base_vhd_path)) try: LOG.debug(_('Copying base disk %(base_vhd_path)s to ' - '%(base_vhd_copy_path)s'), locals()) + '%(base_vhd_copy_path)s'), + {'base_vhd_path': base_vhd_path, + 'base_vhd_copy_path': base_vhd_copy_path}) self._pathutils.copyfile(base_vhd_path, base_vhd_copy_path) LOG.debug(_("Reconnecting copied base VHD " "%(base_vhd_copy_path)s and diff " - "VHD %(diff_vhd_path)s"), locals()) + "VHD %(diff_vhd_path)s"), + {'base_vhd_copy_path': base_vhd_copy_path, + 'diff_vhd_path': diff_vhd_path}) self._vhdutils.reconnect_parent_vhd(diff_vhd_path, base_vhd_copy_path) LOG.debug(_("Merging base disk %(base_vhd_copy_path)s and " - "diff disk %(diff_vhd_path)s"), locals()) + "diff disk %(diff_vhd_path)s"), + {'base_vhd_copy_path': base_vhd_copy_path, + 'diff_vhd_path': diff_vhd_path}) self._vhdutils.merge_vhd(diff_vhd_path, base_vhd_copy_path) # Replace the differential VHD with the merged one @@ -192,7 +198,8 @@ class MigrationOps(object): # A differential VHD cannot be resized self._merge_base_vhd(vhd_path, base_disk_path) LOG.debug(_("Resizing disk \"%(vhd_path)s\" to new max " - "size %(new_size)s"), locals()) + "size %(new_size)s"), + {'vhd_path': vhd_path, 'new_size': new_size}) self._vhdutils.resize_vhd(vhd_path, new_size) def _check_base_disk(self, context, instance, diff_vhd_path, @@ -204,7 +211,9 @@ class MigrationOps(object): if src_base_disk_path.lower() != base_vhd_path.lower(): LOG.debug(_("Reconnecting copied base VHD " "%(base_vhd_path)s and diff " - "VHD %(diff_vhd_path)s"), locals()) + "VHD %(diff_vhd_path)s"), + {'base_vhd_path': base_vhd_path, + 'diff_vhd_path': diff_vhd_path}) self._vhdutils.reconnect_parent_vhd(diff_vhd_path, base_vhd_path) diff --git a/nova/virt/hyperv/networkutils.py b/nova/virt/hyperv/networkutils.py index 4e1f68685..626240ca3 100644 --- a/nova/virt/hyperv/networkutils.py +++ b/nova/virt/hyperv/networkutils.py @@ -58,5 +58,7 @@ class NetworkUtils(object): if ret_val != 0: raise vmutils.HyperVException(_("Failed to create vswitch port " "%(port_name)s on switch " - "%(vswitch_path)s") % locals()) + "%(vswitch_path)s") % + {'port_name': port_name, + 'vswitch_path': vswitch_path}) return new_port diff --git a/nova/virt/hyperv/pathutils.py b/nova/virt/hyperv/pathutils.py index 6e54bf4c8..21bb82f72 100644 --- a/nova/virt/hyperv/pathutils.py +++ b/nova/virt/hyperv/pathutils.py @@ -69,7 +69,7 @@ class PathUtils(object): # spawning overhead. if subprocess.call(['cmd.exe', '/C', 'copy', '/Y', src, dest]): raise IOError(_('The file copy from %(src)s to %(dest)s failed') - % locals()) + % {'src': src, 'dest': dest}) def rmtree(self, path): shutil.rmtree(path) @@ -83,7 +83,8 @@ class PathUtils(object): else: # Use an administrative share path = local_instance_path.replace(':', '$') - return '\\\\%(remote_server)s\\%(path)s' % locals() + return ('\\\\%(remote_server)s\\%(path)s' % + {'remote_server': remote_server, 'path': path}) else: return local_instance_path diff --git a/nova/virt/hyperv/snapshotops.py b/nova/virt/hyperv/snapshotops.py index 5bed46665..c75b54e9e 100644 --- a/nova/virt/hyperv/snapshotops.py +++ b/nova/virt/hyperv/snapshotops.py @@ -71,7 +71,8 @@ class SnapshotOps(object): dest_vhd_path = os.path.join(export_dir, os.path.basename( src_vhd_path)) LOG.debug(_('Copying VHD %(src_vhd_path)s to %(dest_vhd_path)s'), - locals()) + {'src_vhd_path': src_vhd_path, + 'dest_vhd_path': dest_vhd_path}) self._pathutils.copyfile(src_vhd_path, dest_vhd_path) image_vhd_path = None @@ -81,29 +82,37 @@ class SnapshotOps(object): basename = os.path.basename(src_base_disk_path) dest_base_disk_path = os.path.join(export_dir, basename) LOG.debug(_('Copying base disk %(src_vhd_path)s to ' - '%(dest_base_disk_path)s'), locals()) + '%(dest_base_disk_path)s'), + {'src_vhd_path': src_vhd_path, + 'dest_base_disk_path': dest_base_disk_path}) self._pathutils.copyfile(src_base_disk_path, dest_base_disk_path) LOG.debug(_("Reconnecting copied base VHD " "%(dest_base_disk_path)s and diff " - "VHD %(dest_vhd_path)s"), locals()) + "VHD %(dest_vhd_path)s"), + {'dest_base_disk_path': dest_base_disk_path, + 'dest_vhd_path': dest_vhd_path}) self._vhdutils.reconnect_parent_vhd(dest_vhd_path, dest_base_disk_path) LOG.debug(_("Merging base disk %(dest_base_disk_path)s and " - "diff disk %(dest_vhd_path)s"), locals()) + "diff disk %(dest_vhd_path)s"), + {'dest_base_disk_path': dest_base_disk_path, + 'dest_vhd_path': dest_vhd_path}) self._vhdutils.merge_vhd(dest_vhd_path, dest_base_disk_path) image_vhd_path = dest_base_disk_path - LOG.debug(_("Updating Glance image %(image_id)s with content from " - "merged disk %(image_vhd_path)s"), locals()) + LOG.debug(_("Updating Glance image %(name)s with content from " + "merged disk %(image_vhd_path)s"), + {'image_id': name, 'image_vhd_path': image_vhd_path}) update_task_state(task_state=task_states.IMAGE_UPLOADING, expected_state=task_states.IMAGE_PENDING_UPLOAD) self._save_glance_image(context, name, image_vhd_path) - LOG.debug(_("Snapshot image %(image_id)s updated for VM " - "%(instance_name)s"), locals()) + LOG.debug(_("Snapshot image %(name)s updated for VM " + "%(instance_name)s"), + {'name': name, 'instance_name': instance_name}) finally: try: LOG.debug(_("Removing snapshot %s"), name) diff --git a/nova/virt/hyperv/vmops.py b/nova/virt/hyperv/vmops.py index 2bda94a35..dfae02aad 100644 --- a/nova/virt/hyperv/vmops.py +++ b/nova/virt/hyperv/vmops.py @@ -119,13 +119,16 @@ class VMOps(object): try: if CONF.use_cow_images: LOG.debug(_("Creating differencing VHD. Parent: " - "%(base_vhd_path)s, Target: %(root_vhd_path)s") - % locals()) + "%(base_vhd_path)s, Target: %(root_vhd_path)s"), + {'base_vhd_path': base_vhd_path, + 'root_vhd_path': root_vhd_path}) self._vhdutils.create_differencing_vhd(root_vhd_path, base_vhd_path) else: LOG.debug(_("Copying VHD image %(base_vhd_path)s to target: " - "%(root_vhd_path)s") % locals()) + "%(root_vhd_path)s"), + {'base_vhd_path': base_vhd_path, + 'root_vhd_path': root_vhd_path}) self._pathutils.copyfile(base_vhd_path, root_vhd_path) base_vhd_info = self._vhdutils.get_vhd_info(base_vhd_path) @@ -137,7 +140,9 @@ class VMOps(object): "smaller size")) elif root_vhd_size > base_vhd_size: LOG.debug(_("Resizing VHD %(root_vhd_path)s to new " - "size %(root_vhd_size)s") % locals()) + "size %(root_vhd_size)s"), + {'base_vhd_path': base_vhd_path, + 'root_vhd_path': root_vhd_path}) self._vhdutils.resize_vhd(root_vhd_path, root_vhd_size) except Exception: with excutils.save_and_reraise_exception(): @@ -336,9 +341,11 @@ class VMOps(object): try: self._vmutils.set_vm_state(vm_name, req_state) LOG.debug(_("Successfully changed state of VM %(vm_name)s" - " to: %(req_state)s") % locals()) + " to: %(req_state)s"), + {'vm_name': vm_name, 'req_state': req_state}) except Exception as ex: LOG.exception(ex) - msg = _("Failed to change vm state of %(vm_name)s" - " to %(req_state)s") % locals() + msg = (_("Failed to change vm state of %(vm_name)s" + " to %(req_state)s") % + {'vm_name': vm_name, 'req_state': req_state}) raise vmutils.HyperVException(msg) diff --git a/nova/virt/hyperv/vmutils.py b/nova/virt/hyperv/vmutils.py index 2cc40a1de..dd03eb88b 100644 --- a/nova/virt/hyperv/vmutils.py +++ b/nova/virt/hyperv/vmutils.py @@ -223,8 +223,8 @@ class VMUtils(object): drivedflt = self._conn.query("SELECT * FROM " "Msvm_ResourceAllocationSettingData " "WHERE ResourceSubType LIKE " - "'%(res_sub_type)s' AND InstanceID LIKE " - "'%%Default%%'" % locals())[0] + "'%s' AND InstanceID LIKE " + "'%%Default%%'" % res_sub_type)[0] drive = self._clone_wmi_obj('Msvm_ResourceAllocationSettingData', drivedflt) #Set the IDE ctrller as parent. @@ -243,9 +243,9 @@ class VMUtils(object): drivedefault = self._conn.query("SELECT * FROM " "Msvm_ResourceAllocationSettingData " "WHERE ResourceSubType LIKE " - "'%(res_sub_type)s' AND " + "'%s' AND " "InstanceID LIKE '%%Default%%'" - % locals())[0] + % res_sub_type)[0] #Clone the default and point it to the image file. res = self._clone_wmi_obj('Msvm_ResourceAllocationSettingData', @@ -329,8 +329,9 @@ class VMUtils(object): #Invalid state for current operation (32775) typically means that #the VM is already in the state requested self.check_ret_val(ret_val, job_path, [0, 32775]) - LOG.debug(_("Successfully changed vm state of %(vm_name)s" - " to %(req_state)s") % locals()) + LOG.debug(_("Successfully changed vm state of %(vm_name)s " + "to %(req_state)s"), + {'vm_name': vm_name, 'req_state': req_state}) def get_vm_storage_paths(self, vm_name): vm = self._lookup_vm_check(vm_name) @@ -391,23 +392,28 @@ class VMUtils(object): raise HyperVException(_("WMI job failed with status " "%(job_state)d. Error details: " "%(err_sum_desc)s - %(err_desc)s - " - "Error code: %(err_code)d") - % locals()) + "Error code: %(err_code)d") % + {'job_state': job_state, + 'err_sum_desc': err_sum_desc, + 'err_desc': err_desc, + 'err_code': err_code}) else: (error, ret_val) = job.GetError() if not ret_val and error: raise HyperVException(_("WMI job failed with status " "%(job_state)d. Error details: " - "%(error)s") % locals()) + "%(error)s") % + {'job_state': job_state, + 'error': error}) else: raise HyperVException(_("WMI job failed with status " - "%(job_state)d. No error " - "description available") - % locals()) + "%d. No error " + "description available") % + job_state) desc = job.Description elap = job.ElapsedTime - LOG.debug(_("WMI job succeeded: %(desc)s, Elapsed=%(elap)s") - % locals()) + LOG.debug(_("WMI job succeeded: %(desc)s, Elapsed=%(elap)s"), + {'desc': desc, 'elap': elap}) def _clone_wmi_obj(self, wmi_class, wmi_obj): """Clone a WMI object.""" diff --git a/nova/virt/hyperv/volumeops.py b/nova/virt/hyperv/volumeops.py index 1b6f10d16..b378070c9 100644 --- a/nova/virt/hyperv/volumeops.py +++ b/nova/virt/hyperv/volumeops.py @@ -97,11 +97,15 @@ class VolumeOps(object): if self._volutils.get_device_number_for_target(target_iqn, target_lun): LOG.debug(_("Already logged in on storage target. No need to " "login. Portal: %(target_portal)s, " - "IQN: %(target_iqn)s, LUN: %(target_lun)s") % locals()) + "IQN: %(target_iqn)s, LUN: %(target_lun)s"), + {'target_portal': target_portal, + 'target_iqn': target_iqn, 'target_lun': target_lun}) else: LOG.debug(_("Logging in on storage target. Portal: " "%(target_portal)s, IQN: %(target_iqn)s, " - "LUN: %(target_lun)s") % locals()) + "LUN: %(target_lun)s"), + {'target_portal': target_portal, + 'target_iqn': target_iqn, 'target_lun': target_lun}) self._volutils.login_storage_target(target_lun, target_iqn, target_portal) # Wait for the target to be mounted @@ -112,8 +116,9 @@ class VolumeOps(object): Attach a volume to the SCSI controller or to the IDE controller if ebs_root is True """ - LOG.debug(_("Attach_volume: %(connection_info)s to %(instance_name)s") - % locals()) + LOG.debug(_("Attach_volume: %(connection_info)s to %(instance_name)s"), + {'connection_info': connection_info, + 'instance_name': instance_name}) try: self._login_storage_target(connection_info) @@ -157,13 +162,15 @@ class VolumeOps(object): self.detach_volume(vol['connection_info'], instance_name) def logout_storage_target(self, target_iqn): - LOG.debug(_("Logging off storage target %(target_iqn)s") % locals()) + LOG.debug(_("Logging off storage target %s"), target_iqn) self._volutils.logout_storage_target(target_iqn) def detach_volume(self, connection_info, instance_name): """Dettach a volume to the SCSI controller.""" LOG.debug(_("Detach_volume: %(connection_info)s " - "from %(instance_name)s") % locals()) + "from %(instance_name)s"), + {'connection_info': connection_info, + 'instance_name': instance_name}) data = connection_info['data'] target_lun = data['target_lun'] @@ -198,7 +205,8 @@ class VolumeOps(object): raise exception.NotFound(_('Unable to find a mounted disk for ' 'target_iqn: %s') % target_iqn) LOG.debug(_('Device number: %(device_number)s, ' - 'target lun: %(target_lun)s') % locals()) + 'target lun: %(target_lun)s'), + {'device_number': device_number, 'target_lun': target_lun}) #Finding Mounted disk drive for i in range(0, CONF.hyperv.volume_attach_retry_count): mounted_disk_path = self._vmutils.get_mounted_disk_by_drive_number( -- cgit