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/volume/driver.py | 11 ++++++----- nova/volume/manager.py | 5 +++-- nova/volume/netapp.py | 34 ++++++++++++++++++---------------- nova/volume/san.py | 18 ++++++++++-------- nova/volume/xensm.py | 24 +++++++++++++----------- 5 files changed, 50 insertions(+), 42 deletions(-) (limited to 'nova/volume') diff --git a/nova/volume/driver.py b/nova/volume/driver.py index 1ecc32311..add975600 100644 --- a/nova/volume/driver.py +++ b/nova/volume/driver.py @@ -103,7 +103,7 @@ class VolumeDriver(object): run_as_root=True) volume_groups = out.split() if not FLAGS.volume_group in volume_groups: - raise exception.Error(_("volume group %s doesn't exist") + raise exception.NovaException(_("volume group %s doesn't exist") % FLAGS.volume_group) def _create_volume(self, volume_name, sizestr): @@ -381,7 +381,7 @@ class ISCSIDriver(VolumeDriver): location = self._do_iscsi_discovery(volume) if not location: - raise exception.Error(_("Could not find iSCSI export " + raise exception.NovaException(_("Could not find iSCSI export " " for volume %s") % (volume['name'])) @@ -502,7 +502,7 @@ class RBDDriver(VolumeDriver): (stdout, stderr) = self._execute('rados', 'lspools') pools = stdout.split("\n") if not FLAGS.rbd_pool in pools: - raise exception.Error(_("rbd has no pool %s") % + raise exception.NovaException(_("rbd has no pool %s") % FLAGS.rbd_pool) def create_volume(self, volume): @@ -576,9 +576,10 @@ class SheepdogDriver(VolumeDriver): # use it and just check if 'running' is in the output. (out, err) = self._execute('collie', 'cluster', 'info') if not 'running' in out.split(): - raise exception.Error(_("Sheepdog is not working: %s") % out) + msg = _("Sheepdog is not working: %s") % out + raise exception.NovaException(msg) except exception.ProcessExecutionError: - raise exception.Error(_("Sheepdog is not working")) + raise exception.NovaException(_("Sheepdog is not working")) def create_volume(self, volume): """Creates a sheepdog volume""" diff --git a/nova/volume/manager.py b/nova/volume/manager.py index 2e9f21e2a..bd03234d7 100644 --- a/nova/volume/manager.py +++ b/nova/volume/manager.py @@ -152,9 +152,10 @@ class VolumeManager(manager.SchedulerDependentManager): context = context.elevated() volume_ref = self.db.volume_get(context, volume_id) if volume_ref['attach_status'] == "attached": - raise exception.Error(_("Volume is still attached")) + raise exception.NovaException(_("Volume is still attached")) if volume_ref['host'] != self.host: - raise exception.Error(_("Volume is not local to this node")) + msg = _("Volume is not local to this node") + raise exception.NovaException(msg) self._reset_stats() try: diff --git a/nova/volume/netapp.py b/nova/volume/netapp.py index 1ba559d77..5ee0a0371 100644 --- a/nova/volume/netapp.py +++ b/nova/volume/netapp.py @@ -77,7 +77,7 @@ class NetAppISCSIDriver(driver.ISCSIDriver): name = request.Name reason = response.Reason msg = _('API %(name)sfailed: %(reason)s') - raise exception.Error(msg % locals()) + raise exception.NovaException(msg % locals()) def _create_client(self, wsdl_url, login, password, hostname, port): """ @@ -106,7 +106,7 @@ class NetAppISCSIDriver(driver.ISCSIDriver): 'netapp_storage_service'] for flag in required_flags: if not getattr(FLAGS, flag, None): - raise exception.Error(_('%s is not set') % flag) + raise exception.NovaException(_('%s is not set') % flag) def do_setup(self, context): """ @@ -156,7 +156,7 @@ class NetAppISCSIDriver(driver.ISCSIDriver): events = self._get_job_progress(job_id) for event in events: if event.EventStatus == 'error': - raise exception.Error(_('Job failed: %s') % + raise exception.NovaException(_('Job failed: %s') % (event.ErrorMessage)) if event.EventType == 'job-end': return events @@ -237,7 +237,8 @@ class NetAppISCSIDriver(driver.ISCSIDriver): AssumeConfirmation=True) except (suds.WebFault, Exception): server.DatasetEditRollback(EditLockId=lock_id) - raise exception.Error(_('Failed to provision dataset member')) + msg = _('Failed to provision dataset member') + raise exception.NovaException(msg) lun_id = None @@ -249,7 +250,8 @@ class NetAppISCSIDriver(driver.ISCSIDriver): lun_id = event.ProgressLunInfo.LunPathId if not lun_id: - raise exception.Error(_('No LUN was created by the provision job')) + msg = _('No LUN was created by the provision job') + raise exception.NovaException(msg) def _remove_destroy(self, name, project): """ @@ -258,8 +260,8 @@ class NetAppISCSIDriver(driver.ISCSIDriver): """ lun_id = self._get_lun_id(name, project) if not lun_id: - raise exception.Error(_("Failed to find LUN ID for volume %s") % - (name)) + msg = _("Failed to find LUN ID for volume %s") % (name) + raise exception.NovaException(msg) member = self.client.factory.create('DatasetMemberParameter') member.ObjectNameOrId = lun_id @@ -278,7 +280,7 @@ class NetAppISCSIDriver(driver.ISCSIDriver): except (suds.WebFault, Exception): server.DatasetEditRollback(EditLockId=lock_id) msg = _('Failed to remove and delete dataset member') - raise exception.Error(msg) + raise exception.NovaException(msg) def create_volume(self, volume): """Driver entry point for creating a new volume""" @@ -431,7 +433,7 @@ class NetAppISCSIDriver(driver.ISCSIDriver): lun_id = self._get_lun_id(name, project) if not lun_id: msg = _("Failed to find LUN ID for volume %s") - raise exception.Error(msg % name) + raise exception.NovaException(msg % name) return {'provider_location': lun_id} def ensure_export(self, context, volume): @@ -601,29 +603,29 @@ class NetAppISCSIDriver(driver.ISCSIDriver): lun_id = volume['provider_location'] if not lun_id: msg = _("No LUN ID for volume %s") - raise exception.Error(msg % volume['name']) + raise exception.NovaException(msg % volume['name']) lun = self._get_lun_details(lun_id) if not lun: msg = _('Failed to get LUN details for LUN ID %s') - raise exception.Error(msg % lun_id) + raise exception.NovaException(msg % lun_id) lun_num = self._ensure_initiator_mapped(lun.HostId, lun.LunPath, initiator_name) host = self._get_host_details(lun.HostId) if not host: msg = _('Failed to get host details for host ID %s') - raise exception.Error(msg % lun.HostId) + raise exception.NovaException(msg % lun.HostId) portal = self._get_target_portal_for_host(host.HostId, host.HostAddress) if not portal: msg = _('Failed to get target portal for filer: %s') - raise exception.Error(msg % host.HostName) + raise exception.NovaException(msg % host.HostName) iqn = self._get_iqn_for_host(host.HostId) if not iqn: msg = _('Failed to get target IQN for filer: %s') - raise exception.Error(msg % host.HostName) + raise exception.NovaException(msg % host.HostName) properties = {} properties['target_discovered'] = False @@ -655,11 +657,11 @@ class NetAppISCSIDriver(driver.ISCSIDriver): lun_id = volume['provider_location'] if not lun_id: msg = _('No LUN ID for volume %s') - raise exception.Error(msg % (volume['name'])) + raise exception.NovaException(msg % (volume['name'])) lun = self._get_lun_details(lun_id) if not lun: msg = _('Failed to get LUN details for LUN ID %s') - raise exception.Error(msg % (lun_id)) + raise exception.NovaException(msg % (lun_id)) self._ensure_initiator_unmapped(lun.HostId, lun.LunPath, initiator_name) diff --git a/nova/volume/san.py b/nova/volume/san.py index 9d83864d0..e43a64a59 100644 --- a/nova/volume/san.py +++ b/nova/volume/san.py @@ -111,7 +111,8 @@ class SanISCSIDriver(nova.volume.driver.ISCSIDriver): username=FLAGS.san_login, pkey=privatekey) else: - raise exception.Error(_("Specify san_password or san_private_key")) + msg = _("Specify san_password or san_private_key") + raise exception.NovaException(msg) return ssh def _execute(self, *cmd, **kwargs): @@ -149,12 +150,12 @@ class SanISCSIDriver(nova.volume.driver.ISCSIDriver): """Returns an error if prerequisites aren't met.""" if not self.run_local: if not (FLAGS.san_password or FLAGS.san_private_key): - raise exception.Error(_('Specify san_password or ' + raise exception.NovaException(_('Specify san_password or ' 'san_private_key')) # The san_ip must always be set, because we use it for the target if not (FLAGS.san_ip): - raise exception.Error(_("san_ip must be set")) + raise exception.NovaException(_("san_ip must be set")) def _collect_lines(data): @@ -225,7 +226,8 @@ class SolarisISCSIDriver(SanISCSIDriver): if "View Entry:" in out: return True - raise exception.Error("Cannot parse list-view output: %s" % (out)) + msg = _("Cannot parse list-view output: %s") % (out) + raise exception.NovaException() def _get_target_groups(self): """Gets list of target groups from host.""" @@ -459,7 +461,7 @@ class HpSanISCSIDriver(SanISCSIDriver): msg = (_("Malformed response to CLIQ command " "%(verb)s %(cliq_args)s. Result=%(out)s") % locals()) - raise exception.Error(msg) + raise exception.NovaException(msg) result_code = response_node.attrib.get("result") @@ -467,7 +469,7 @@ class HpSanISCSIDriver(SanISCSIDriver): msg = (_("Error running CLIQ command %(verb)s %(cliq_args)s. " " Result=%(out)s") % locals()) - raise exception.Error(msg) + raise exception.NovaException(msg) return result_xml @@ -497,7 +499,7 @@ class HpSanISCSIDriver(SanISCSIDriver): msg = (_("Unexpected number of virtual ips for cluster " " %(cluster_name)s. Result=%(_xml)s") % locals()) - raise exception.Error(msg) + raise exception.NovaException(msg) def _cliq_get_volume_info(self, volume_name): """Gets the volume info, including IQN""" @@ -600,7 +602,7 @@ class HpSanISCSIDriver(SanISCSIDriver): def local_path(self, volume): # TODO(justinsb): Is this needed here? - raise exception.Error(_("local_path not supported")) + raise exception.NovaException(_("local_path not supported")) def initialize_connection(self, volume, connector): """Assigns the volume to a server. diff --git a/nova/volume/xensm.py b/nova/volume/xensm.py index f998dae28..b052ff903 100644 --- a/nova/volume/xensm.py +++ b/nova/volume/xensm.py @@ -59,7 +59,7 @@ class XenSMDriver(nova.volume.driver.VolumeDriver): except Exception as ex: LOG.debug(_("Failed to create sr %s...continuing") % str(backend_ref['id'])) - raise exception.Error(_('Create failed')) + raise exception.NovaException(_('Create failed')) LOG.debug(_('SR UUID of new SR is: %s') % sr_uuid) try: @@ -68,7 +68,7 @@ class XenSMDriver(nova.volume.driver.VolumeDriver): dict(sr_uuid=sr_uuid)) except Exception as ex: LOG.exception(ex) - raise exception.Error(_("Failed to update db")) + raise exception.NovaException(_("Failed to update db")) else: # sr introduce, if not already done @@ -88,7 +88,7 @@ class XenSMDriver(nova.volume.driver.VolumeDriver): self._create_storage_repo(context, backend) except Exception as ex: LOG.exception(ex) - raise exception.Error(_('Failed to reach backend %d') + raise exception.NovaException(_('Failed to reach backend %d') % backend['id']) def __init__(self, *args, **kwargs): @@ -97,7 +97,8 @@ class XenSMDriver(nova.volume.driver.VolumeDriver): # This driver leverages Xen storage manager, and hence requires # hypervisor to be Xen if FLAGS.connection_type != 'xenapi': - raise exception.Error(_('XenSMDriver requires xenapi connection')) + msg = _('XenSMDriver requires xenapi connection') + raise exception.NovaException(msg) url = FLAGS.xenapi_connection_url username = FLAGS.xenapi_connection_username @@ -107,7 +108,7 @@ class XenSMDriver(nova.volume.driver.VolumeDriver): self._volumeops = volumeops.VolumeOps(session) except Exception as ex: LOG.exception(ex) - raise exception.Error(_("Failed to initiate session")) + raise exception.NovaException(_("Failed to initiate session")) super(XenSMDriver, self).__init__(execute=utils.execute, sync_exec=utils.execute, @@ -151,10 +152,11 @@ class XenSMDriver(nova.volume.driver.VolumeDriver): self.db.sm_volume_create(self.ctxt, sm_vol_rec) except Exception as ex: LOG.exception(ex) - raise exception.Error(_("Failed to update volume in db")) + msg = _("Failed to update volume in db") + raise exception.NovaException(msg) else: - raise exception.Error(_('Unable to create volume')) + raise exception.NovaException(_('Unable to create volume')) def delete_volume(self, volume): @@ -168,13 +170,13 @@ class XenSMDriver(nova.volume.driver.VolumeDriver): self._volumeops.delete_volume_for_sm(vol_rec['vdi_uuid']) except Exception as ex: LOG.exception(ex) - raise exception.Error(_("Failed to delete vdi")) + raise exception.NovaException(_("Failed to delete vdi")) try: self.db.sm_volume_delete(self.ctxt, volume['id']) except Exception as ex: LOG.exception(ex) - raise exception.Error(_("Failed to delete volume in db")) + raise exception.NovaException(_("Failed to delete volume in db")) def local_path(self, volume): return str(volume['id']) @@ -207,7 +209,7 @@ class XenSMDriver(nova.volume.driver.VolumeDriver): volume['id'])) except Exception as ex: LOG.exception(ex) - raise exception.Error(_("Failed to find volume in db")) + raise exception.NovaException(_("Failed to find volume in db")) # Keep the volume id key consistent with what ISCSI driver calls it xensm_properties['volume_id'] = xensm_properties['id'] @@ -218,7 +220,7 @@ class XenSMDriver(nova.volume.driver.VolumeDriver): xensm_properties['backend_id']) except Exception as ex: LOG.exception(ex) - raise exception.Error(_("Failed to find backend in db")) + raise exception.NovaException(_("Failed to find backend in db")) params = self._convert_config_params(backend_conf['config_params']) -- cgit