From 2f552e957fddcd9e042a09a2d32d32fa564c18e7 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 3 May 2012 14:29:50 -0400 Subject: Replaces exceptions.Error with NovaException Fixes bug 817107 Change-Id: I6253e6bbcc44676c587b315fa32afba6459e676a --- nova/virt/baremetal/nodes.py | 2 +- nova/virt/baremetal/tilera.py | 2 +- nova/virt/disk/api.py | 20 +++++++++++--------- nova/virt/libvirt/connection.py | 9 +++++---- nova/virt/libvirt/volume.py | 4 ++-- nova/virt/vmwareapi/fake.py | 9 ++++----- nova/virt/vmwareapi/io_util.py | 14 +++++++------- nova/virt/vmwareapi/network_utils.py | 4 ++-- nova/virt/vmwareapi/vmops.py | 2 +- nova/virt/vmwareapi/vmware_images.py | 2 +- nova/virt/vmwareapi_conn.py | 4 ++-- nova/virt/xenapi/fake.py | 4 ++-- nova/virt/xenapi/vm_utils.py | 12 ++++++------ nova/virt/xenapi/volumeops.py | 10 +++++----- 14 files changed, 50 insertions(+), 48 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/baremetal/nodes.py b/nova/virt/baremetal/nodes.py index f78eaf74d..c3c806557 100644 --- a/nova/virt/baremetal/nodes.py +++ b/nova/virt/baremetal/nodes.py @@ -39,4 +39,4 @@ def get_baremetal_nodes(): elif d == 'fake': return fake.get_baremetal_nodes() else: - raise exception.Error(_("Unknown baremetal driver %(d)s")) + raise exception.NovaException(_("Unknown baremetal driver %(d)s")) diff --git a/nova/virt/baremetal/tilera.py b/nova/virt/baremetal/tilera.py index c92d9b219..9231e8f7b 100644 --- a/nova/virt/baremetal/tilera.py +++ b/nova/virt/baremetal/tilera.py @@ -325,7 +325,7 @@ class BareMetalNodes(object): return power_state.RUNNING except Exception as ex: self.deactivate_node(node_id) - raise exception.Error(_("Node is unknown error state.")) + raise exception.NovaException(_("Node is unknown error state.")) def get_console_output(self, console_log, node_id): """ diff --git a/nova/virt/disk/api.py b/nova/virt/disk/api.py index 6cb19f235..09ede2d50 100644 --- a/nova/virt/disk/api.py +++ b/nova/virt/disk/api.py @@ -162,7 +162,8 @@ class _DiskImage(object): self.handlers.remove('loop') if not self.handlers: - raise exception.Error(_('no capable image handler configured')) + msg = _('no capable image handler configured') + raise exception.NovaException(msg) @property def errors(self): @@ -175,7 +176,8 @@ class _DiskImage(object): for cls in (loop.Mount, nbd.Mount, guestfs.Mount): if cls.mode == mode: return cls - raise exception.Error(_("unknown disk image handler: %s") % mode) + msg = _("unknown disk image handler: %s") % mode + raise exception.NovaException(msg) def mount(self): """Mount a disk image, using the object attributes. @@ -186,7 +188,7 @@ class _DiskImage(object): contains any diagnostics. """ if self._mounter: - raise exception.Error(_('image already mounted')) + raise exception.NovaException(_('image already mounted')) if not self.mount_dir: self.mount_dir = tempfile.mkdtemp() @@ -242,7 +244,7 @@ def inject_data(image, finally: img.umount() else: - raise exception.Error(img.errors) + raise exception.NovaException(img.errors) def inject_files(image, files, partition=None, use_cow=False): @@ -255,7 +257,7 @@ def inject_files(image, files, partition=None, use_cow=False): finally: img.umount() else: - raise exception.Error(img.errors) + raise exception.NovaException(img.errors) def setup_container(image, container_dir=None, use_cow=False): @@ -271,7 +273,7 @@ def setup_container(image, container_dir=None, use_cow=False): if img.mount(): return img else: - raise exception.Error(img.errors) + raise exception.NovaException(img.errors) except Exception, exn: LOG.exception(_('Failed to mount filesystem: %s'), exn) @@ -403,7 +405,7 @@ def _set_passwd(username, admin_passwd, passwd_file, shadow_file): :param passwd_file: path to the passwd file :param shadow_file: path to the shadow password file :returns: nothing - :raises: exception.Error(), IOError() + :raises: exception.NovaException(), IOError() """ salt_set = ('abcdefghijklmnopqrstuvwxyz' @@ -439,7 +441,7 @@ def _set_passwd(username, admin_passwd, passwd_file, shadow_file): break if not found: msg = _('User %(username)s not found in password file.') - raise exception.Error(msg % username) + raise exception.NovaException(msg % username) # update password in the shadow file.It's an error if the # the user doesn't exist. @@ -455,7 +457,7 @@ def _set_passwd(username, admin_passwd, passwd_file, shadow_file): s_file.close() if not found: msg = _('User %(username)s not found in shadow file.') - raise exception.Error(msg % username) + raise exception.NovaException(msg % username) s_file = open(shadow_file, 'wb') for entry in new_shadow: s_file.write(entry) diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index 4f7a15a86..610df88e1 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -990,7 +990,8 @@ class LibvirtConnection(driver.ComputeDriver): continue break else: - raise exception.Error(_("Guest does not have a console available")) + msg = _("Guest does not have a console available") + raise exception.NovaException(msg) self._chown_console_log_for_instance(instance['name']) data = self._flush_libvirt_console(pty) @@ -1708,7 +1709,7 @@ class LibvirtConnection(driver.ComputeDriver): msg = _("Error from libvirt while looking up %(instance_name)s: " "[Error Code %(error_code)s] %(ex)s") % locals() - raise exception.Error(msg) + raise exception.NovaException(msg) def get_info(self, instance): """Retrieve information from libvirt for a specific instance name. @@ -1947,7 +1948,7 @@ class LibvirtConnection(driver.ComputeDriver): # But ... we can at least give the user a nice message method = getattr(self._conn, 'getVersion', None) if method is None: - raise exception.Error(_("libvirt version is too old" + raise exception.NovaException(_("libvirt version is too old" " (does not support getVersion)")) # NOTE(justinsb): If we wanted to get the version, we could: # method = getattr(libvirt, 'getVersion', None) @@ -2162,7 +2163,7 @@ class LibvirtConnection(driver.ComputeDriver): timeout_count.pop() if len(timeout_count) == 0: msg = _('Timeout migrating for %s. nwfilter not found.') - raise exception.Error(msg % instance_ref.name) + raise exception.NovaException(msg % instance_ref.name) time.sleep(1) def live_migration(self, ctxt, instance_ref, dest, diff --git a/nova/virt/libvirt/volume.py b/nova/virt/libvirt/volume.py index 23cf3390e..839a00db2 100644 --- a/nova/virt/libvirt/volume.py +++ b/nova/virt/libvirt/volume.py @@ -160,8 +160,8 @@ class LibvirtISCSIVolumeDriver(LibvirtVolumeDriver): tries = 0 while not os.path.exists(host_device): if tries >= FLAGS.num_iscsi_scan_tries: - raise exception.Error(_("iSCSI device not found at %s") % - (host_device)) + raise exception.NovaException(_("iSCSI device not found at %s") + % (host_device)) LOG.warn(_("ISCSI volume not yet found at: %(mount_device)s. " "Will rescan & retry. Try number: %(tries)s") % diff --git a/nova/virt/vmwareapi/fake.py b/nova/virt/vmwareapi/fake.py index 4681ef334..10f834ba1 100644 --- a/nova/virt/vmwareapi/fake.py +++ b/nova/virt/vmwareapi/fake.py @@ -128,10 +128,9 @@ class ManagedObject(object): for elem in self.propSet: if elem.name == attr: return elem.val - raise exception.Error(_("Property %(attr)s not set for the managed " - "object %(objName)s") % - {'attr': attr, - 'objName': self.objName}) + msg = _("Property %(attr)s not set for the managed object %(name)s") + raise exception.NovaException(msg % {'attr': attr, + 'name': self.objName}) class DataObject(object): @@ -498,7 +497,7 @@ class FakeVim(object): s = self._session self._session = None if s not in _db_content['session']: - raise exception.Error( + raise exception.NovaException( _("Logging out a session that is invalid or already logged " "out: %s") % s) del _db_content['session'][s] diff --git a/nova/virt/vmwareapi/io_util.py b/nova/virt/vmwareapi/io_util.py index 4a627833f..02ffe90b0 100644 --- a/nova/virt/vmwareapi/io_util.py +++ b/nova/virt/vmwareapi/io_util.py @@ -96,21 +96,21 @@ class GlanceWriteThread(object): # If the state is killed, then raise an exception. elif image_status == "killed": self.stop() - exc_msg = (_("Glance image %s is in killed state") % - self.image_id) - LOG.error(exc_msg) - self.done.send_exception(exception.Error(exc_msg)) + msg = (_("Glance image %s is in killed state") % + self.image_id) + LOG.error(msg) + self.done.send_exception(exception.NovaException(msg)) elif image_status in ["saving", "queued"]: greenthread.sleep(GLANCE_POLL_INTERVAL) else: self.stop() - exc_msg = _("Glance image " + msg = _("Glance image " "%(image_id)s is in unknown state " "- %(state)s") % { "image_id": self.image_id, "state": image_status} - LOG.error(exc_msg) - self.done.send_exception(exception.Error(exc_msg)) + LOG.error(msg) + self.done.send_exception(exception.NovaException(msg)) except Exception, exc: self.stop() self.done.send_exception(exc) diff --git a/nova/virt/vmwareapi/network_utils.py b/nova/virt/vmwareapi/network_utils.py index 8fbe02dc3..1f051fa7e 100644 --- a/nova/virt/vmwareapi/network_utils.py +++ b/nova/virt/vmwareapi/network_utils.py @@ -128,7 +128,7 @@ def get_vlanid_and_vswitch_for_portgroup(session, pg_name): excep = _("ESX SOAP server returned an empty port group " "for the host system in its response") LOG.exception(excep) - raise exception.Error(excep) + raise exception.NovaException(excep) port_grps_on_host = port_grps_on_host_ret.HostPortGroup for p_gp in port_grps_on_host: if p_gp.spec.name == pg_name: @@ -165,6 +165,6 @@ def create_port_group(session, pg_name, vswitch_name, vlan_id=0): # concerned with the port group being created, which is done # by the other call, we can ignore the exception. if error_util.FAULT_ALREADY_EXISTS not in exc.fault_list: - raise exception.Error(exc) + raise exception.NovaException(exc) LOG.debug(_("Created Port Group with name %s on " "the ESX host") % pg_name) diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index e90771ef6..9230272af 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -125,7 +125,7 @@ class VMWareVMOps(object): if data_store_name is None: msg = _("Couldn't get a local Datastore reference") LOG.error(msg, instance=instance) - raise exception.Error(msg) + raise exception.NovaException(msg) data_store_name = _get_datastore_ref() diff --git a/nova/virt/vmwareapi/vmware_images.py b/nova/virt/vmwareapi/vmware_images.py index a73130cde..c72782037 100644 --- a/nova/virt/vmwareapi/vmware_images.py +++ b/nova/virt/vmwareapi/vmware_images.py @@ -75,7 +75,7 @@ def start_transfer(read_file_handle, data_size, write_file_handle=None, # Log and raise the exception. LOG.exception(exc) - raise exception.Error(exc) + raise exception.NovaException(exc) finally: # No matter what, try closing the read and write handles, if it so # applies. diff --git a/nova/virt/vmwareapi_conn.py b/nova/virt/vmwareapi_conn.py index a5f771eee..aeb94d8c7 100644 --- a/nova/virt/vmwareapi_conn.py +++ b/nova/virt/vmwareapi_conn.py @@ -276,7 +276,7 @@ class VMWareAPISession(object): except Exception, excep: LOG.critical(_("In vmwareapi:_create_session, " "got this exception: %s") % excep) - raise exception.Error(excep) + raise exception.NovaException(excep) def __del__(self): """Logs-out the session.""" @@ -404,7 +404,7 @@ class VMWareAPISession(object): action["error"] = error_info LOG.warn(_("Task [%(task_name)s] %(task_ref)s " "status: error %(error_info)s") % locals()) - done.send_exception(exception.Error(error_info)) + done.send_exception(exception.NovaException(error_info)) db.instance_action_create(context.get_admin_context(), action) except Exception, excep: LOG.warn(_("In vmwareapi:_poll_task, Got this error %s") % excep) diff --git a/nova/virt/xenapi/fake.py b/nova/virt/xenapi/fake.py index bc616abd6..1d07f209c 100644 --- a/nova/virt/xenapi/fake.py +++ b/nova/virt/xenapi/fake.py @@ -321,7 +321,7 @@ def get_record(table, ref): def check_for_session_leaks(): if len(_db_content['session']) > 0: - raise exception.Error('Sessions have leaked: %s' % + raise exception.NovaException('Sessions have leaked: %s' % _db_content['session']) @@ -583,7 +583,7 @@ class SessionBase(object): s = self._session self._session = None if s not in _db_content['session']: - raise exception.Error( + raise exception.NovaException( "Logging out a session that is invalid or already logged " "out: %s" % s) del _db_content['session'][s] diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 83dc7180a..deeebbcb9 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -374,8 +374,8 @@ class VMHelper(xenapi.HelperBase): if vbd_rec['userdevice'] == '0': vdi_rec = session.call_xenapi("VDI.get_record", vbd_rec['VDI']) return vbd_rec['VDI'], vdi_rec - raise exception.Error(_("No primary VDI found for %(vm_ref)s") % - locals()) + raise exception.NovaException(_("No primary VDI found for %(vm_ref)s") + % locals()) @classmethod def create_snapshot(cls, session, instance, vm_ref, label): @@ -851,7 +851,7 @@ class VMHelper(xenapi.HelperBase): elif (image_type in (ImageType.KERNEL, ImageType.RAMDISK) and vdi_size > FLAGS.max_kernel_ramdisk_size): max_size = FLAGS.max_kernel_ramdisk_size - raise exception.Error( + raise exception.NovaException( _("Kernel/Ramdisk image is too large: %(vdi_size)d bytes, " "max %(max_size)d bytes") % locals()) @@ -972,8 +972,8 @@ class VMHelper(xenapi.HelperBase): # 4. ISO is_pv = False else: - raise exception.Error(_("Unknown image format %(disk_image_type)s") - % locals()) + msg = _("Unknown image format %(disk_image_type)s") % locals() + raise exception.NovaException(msg) return is_pv @@ -1424,7 +1424,7 @@ def _wait_for_vhd_coalesce(session, instance, sr_ref, vdi_ref, msg = (_("VHD coalesce attempts exceeded (%(max_attempts)d)" ", giving up...") % locals()) - raise exception.Error(msg) + raise exception.NovaException(msg) def remap_vbd_dev(dev): diff --git a/nova/virt/xenapi/volumeops.py b/nova/virt/xenapi/volumeops.py index f4a7ee24a..1bf62bfa7 100644 --- a/nova/virt/xenapi/volumeops.py +++ b/nova/virt/xenapi/volumeops.py @@ -58,7 +58,7 @@ class VolumeOps(object): def delete_volume_for_sm(self, vdi_uuid): vdi_ref = self._session.call_xenapi("VDI.get_by_uuid", vdi_uuid) if vdi_ref is None: - raise exception.Error(_('Could not find VDI ref')) + raise exception.NovaException(_('Could not find VDI ref')) vm_utils.VMHelper.destroy_vdi(self._session, vdi_ref) @@ -67,10 +67,10 @@ class VolumeOps(object): sr_ref = volume_utils.VolumeHelper.create_sr(self._session, label, params) if sr_ref is None: - raise exception.Error(_('Could not create SR')) + raise exception.NovaException(_('Could not create SR')) sr_rec = self._session.call_xenapi("SR.get_record", sr_ref) if sr_rec is None: - raise exception.Error(_('Could not retrieve SR record')) + raise exception.NovaException(_('Could not retrieve SR record')) return sr_rec['uuid'] # Checks if sr has already been introduced to this host @@ -84,7 +84,7 @@ class VolumeOps(object): sr_ref = volume_utils.VolumeHelper.introduce_sr(self._session, sr_uuid, label, params) if sr_ref is None: - raise exception.Error(_('Could not introduce SR')) + raise exception.NovaException(_('Could not introduce SR')) return sr_ref def is_sr_on_host(self, sr_uuid): @@ -106,7 +106,7 @@ class VolumeOps(object): volume_utils.VolumeHelper.forget_sr(self._session, sr_uuid) except volume_utils.StorageError, exc: LOG.exception(exc) - raise exception.Error(_('Could not forget SR')) + raise exception.NovaException(_('Could not forget SR')) def attach_volume(self, connection_info, instance_name, mountpoint): """Attach volume storage to VM instance""" -- cgit