libvirt: Stop misusing NovaException
This is not intended to be used directly. Rather, it should be subclassed and these subclasses used. InternalError is the generic exception of choice, thus, this is used in place of NovaException. Change-Id: I0091959c7c23df32e83579984378c7ca98620c5d
This commit is contained in:
parent
0f26569649
commit
ad1c7ac2b1
@ -1762,6 +1762,10 @@ class PciConfigInvalidWhitelist(Invalid):
|
||||
|
||||
# Cannot be templated, msg needs to be constructed when raised.
|
||||
class InternalError(NovaException):
|
||||
"""Generic hypervisor errors.
|
||||
|
||||
Consider subclassing this to provide more specific exceptions.
|
||||
"""
|
||||
msg_fmt = "%(err)s"
|
||||
|
||||
|
||||
|
@ -142,7 +142,7 @@ def get_dev_prefix_for_disk_bus(disk_bus):
|
||||
elif disk_bus == "sata":
|
||||
return "sd"
|
||||
else:
|
||||
raise exception.NovaException(
|
||||
raise exception.InternalError(
|
||||
_("Unable to determine disk prefix for %s") %
|
||||
disk_bus)
|
||||
|
||||
@ -191,9 +191,8 @@ def find_disk_dev_for_disk_bus(mapping, bus,
|
||||
if disk_dev not in assigned_devices:
|
||||
return disk_dev
|
||||
|
||||
raise exception.NovaException(
|
||||
_("No free disk device names for prefix '%s'") %
|
||||
dev_prefix)
|
||||
msg = _("No free disk device names for prefix '%s'") % dev_prefix
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
|
||||
def is_disk_bus_valid_for_virt(virt_type, disk_bus):
|
||||
@ -312,9 +311,8 @@ def get_disk_bus_for_disk_dev(virt_type, disk_dev):
|
||||
elif disk_dev.startswith('ubd'):
|
||||
return "uml"
|
||||
else:
|
||||
raise exception.NovaException(
|
||||
_("Unable to determine disk bus for '%s'") %
|
||||
disk_dev[:1])
|
||||
msg = _("Unable to determine disk bus for '%s'") % disk_dev[:1]
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
|
||||
def get_next_disk_info(mapping, disk_bus,
|
||||
|
@ -509,23 +509,23 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
guestfs.force_tcg()
|
||||
|
||||
if not self._host.has_min_version(MIN_LIBVIRT_VERSION):
|
||||
raise exception.NovaException(
|
||||
raise exception.InternalError(
|
||||
_('Nova requires libvirt version %s or greater.') %
|
||||
self._version_to_string(MIN_LIBVIRT_VERSION))
|
||||
|
||||
if (CONF.libvirt.virt_type in ("qemu", "kvm") and
|
||||
not self._host.has_min_version(hv_ver=MIN_QEMU_VERSION)):
|
||||
raise exception.NovaException(
|
||||
raise exception.InternalError(
|
||||
_('Nova requires QEMU version %s or greater.') %
|
||||
self._version_to_string(MIN_QEMU_VERSION))
|
||||
|
||||
if CONF.libvirt.virt_type == 'parallels':
|
||||
if not self._host.has_min_version(hv_ver=MIN_VIRTUOZZO_VERSION):
|
||||
raise exception.NovaException(
|
||||
raise exception.InternalError(
|
||||
_('Nova requires Virtuozzo version %s or greater.') %
|
||||
self._version_to_string(MIN_VIRTUOZZO_VERSION))
|
||||
if not self._host.has_min_version(MIN_LIBVIRT_VIRTUOZZO_VERSION):
|
||||
raise exception.NovaException(
|
||||
raise exception.InternalError(
|
||||
_('Running Nova with parallels virt_type requires '
|
||||
'libvirt version %s') %
|
||||
self._version_to_string(MIN_LIBVIRT_VIRTUOZZO_VERSION))
|
||||
@ -554,7 +554,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
not self._host.has_min_version(
|
||||
MIN_LIBVIRT_OTHER_ARCH.get(kvm_arch),
|
||||
MIN_QEMU_OTHER_ARCH.get(kvm_arch))):
|
||||
raise exception.NovaException(
|
||||
raise exception.InternalError(
|
||||
_('Running Nova with qemu/kvm virt_type on %(arch)s '
|
||||
'requires libvirt version %(libvirt_ver)s and '
|
||||
'qemu version %(qemu_ver)s, or greater') %
|
||||
@ -717,7 +717,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
try:
|
||||
self._host.get_guest(instance)
|
||||
return True
|
||||
except exception.NovaException:
|
||||
except exception.InternalError:
|
||||
return False
|
||||
|
||||
def list_instances(self):
|
||||
@ -1678,7 +1678,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
msg = (_('Error from libvirt while set password for username '
|
||||
'"%(user)s": [Error Code %(error_code)s] %(ex)s')
|
||||
% {'user': user, 'error_code': error_code, 'ex': ex})
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
def _can_quiesce(self, instance, image_meta):
|
||||
if (CONF.libvirt.virt_type not in ('kvm', 'qemu') or
|
||||
@ -1703,7 +1703,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
'[Error Code %(error_code)s] %(ex)s')
|
||||
% {'instance_name': instance.name,
|
||||
'error_code': error_code, 'ex': ex})
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
def quiesce(self, context, instance, image_meta):
|
||||
"""Freeze the guest filesystems to prepare for snapshot.
|
||||
@ -1857,7 +1857,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
|
||||
if not disks_to_snap and not network_disks_to_snap:
|
||||
msg = _('Found no disk to snapshot.')
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
snapshot = vconfig.LibvirtConfigGuestSnapshot()
|
||||
|
||||
@ -1946,13 +1946,13 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
raise exception.InstanceNotRunning(instance_id=instance.uuid)
|
||||
|
||||
if create_info['type'] != 'qcow2':
|
||||
raise exception.NovaException(_('Unknown type: %s') %
|
||||
create_info['type'])
|
||||
msg = _('Unknown type: %s') % create_info['type']
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
snapshot_id = create_info.get('snapshot_id', None)
|
||||
if snapshot_id is None:
|
||||
raise exception.NovaException(_('snapshot_id required '
|
||||
'in create_info'))
|
||||
msg = _('snapshot_id required in create_info')
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
try:
|
||||
self._volume_snapshot_create(context, instance, guest,
|
||||
@ -2005,7 +2005,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
"has not been fully tested") % {'protocol':
|
||||
active_protocol}
|
||||
LOG.error(msg)
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
if rebase_base is None:
|
||||
# If backing_file is specified as "" (the empty string), then
|
||||
@ -2050,7 +2050,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
|
||||
if delete_info['type'] != 'qcow2':
|
||||
msg = _('Unknown delete_info type %s') % delete_info['type']
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
try:
|
||||
guest = self._host.get_guest(instance)
|
||||
@ -2085,17 +2085,17 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
break
|
||||
|
||||
if my_dev is None or (active_disk is None and active_protocol is None):
|
||||
msg = _('Disk with id: %s '
|
||||
'not found attached to instance.') % volume_id
|
||||
LOG.debug('Domain XML: %s', xml, instance=instance)
|
||||
raise exception.NovaException(msg)
|
||||
msg = (_('Disk with id: %s not found attached to instance.')
|
||||
% volume_id)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
LOG.debug("found device at %s", my_dev, instance=instance)
|
||||
|
||||
def _get_snap_dev(filename, backing_store):
|
||||
if filename is None:
|
||||
msg = _('filename cannot be None')
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
# libgfapi delete
|
||||
LOG.debug("XML: %s", xml)
|
||||
@ -2124,7 +2124,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
|
||||
if matched_name is None:
|
||||
msg = _('no match found for %s') % (filename_to_merge)
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
LOG.debug('index of match (%s) is %s', b.source_name, index)
|
||||
|
||||
@ -2558,7 +2558,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
|
||||
if state in ignored_states:
|
||||
return
|
||||
except exception.NovaException:
|
||||
except (exception.InternalError, exception.InstanceNotFound):
|
||||
pass
|
||||
|
||||
# Instance is not up and could be in an unknown state.
|
||||
@ -3625,7 +3625,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
"""
|
||||
if not os.path.exists("/etc/machine-id"):
|
||||
msg = _("Unable to get host UUID: /etc/machine-id does not exist")
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
with open("/etc/machine-id") as f:
|
||||
# We want to have '-' in the right place
|
||||
@ -3633,7 +3633,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
lines = f.read().split()
|
||||
if not lines:
|
||||
msg = _("Unable to get host UUID: /etc/machine-id is empty")
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
return str(uuid.UUID(lines[0]))
|
||||
|
||||
@ -5917,7 +5917,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
timeout_count.pop()
|
||||
if len(timeout_count) == 0:
|
||||
msg = _('The firewall filter for %s does not exist')
|
||||
raise exception.NovaException(msg % instance.name)
|
||||
raise exception.InternalError(msg % instance.name)
|
||||
greenthread.sleep(1)
|
||||
|
||||
def filter_defer_apply_on(self):
|
||||
|
@ -479,7 +479,7 @@ class Guest(object):
|
||||
{'instance_name': self.name,
|
||||
'error_code': error_code,
|
||||
'ex': ex})
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
return hardware.InstanceInfo(
|
||||
state=LIBVIRT_POWER_STATE[dom_info[0]],
|
||||
|
@ -199,7 +199,7 @@ class Host(object):
|
||||
def _connect_auth_cb(creds, opaque):
|
||||
if len(creds) == 0:
|
||||
return 0
|
||||
raise exception.NovaException(
|
||||
raise exception.InternalError(
|
||||
_("Can not handle authentication request for %d credentials")
|
||||
% len(creds))
|
||||
|
||||
@ -527,7 +527,7 @@ class Host(object):
|
||||
|
||||
:returns: a nova.virt.libvirt.Guest object
|
||||
:raises exception.InstanceNotFound: The domain was not found
|
||||
:raises exception.NovaException: A libvirt error occured
|
||||
:raises exception.InternalError: A libvirt error occured
|
||||
"""
|
||||
return libvirt_guest.Guest(self.get_domain(instance))
|
||||
|
||||
@ -542,7 +542,7 @@ class Host(object):
|
||||
|
||||
:returns: a libvirt.Domain object
|
||||
:raises exception.InstanceNotFound: The domain was not found
|
||||
:raises exception.NovaException: A libvirt error occured
|
||||
:raises exception.InternalError: A libvirt error occured
|
||||
"""
|
||||
try:
|
||||
conn = self.get_connection()
|
||||
@ -552,14 +552,12 @@ class Host(object):
|
||||
if error_code == libvirt.VIR_ERR_NO_DOMAIN:
|
||||
raise exception.InstanceNotFound(instance_id=instance.uuid)
|
||||
|
||||
# TODO(stephenfin): Stop using NovaException here - it's too
|
||||
# generic. InternalError would be a better fit.
|
||||
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)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
def list_guests(self, only_running=True, only_guests=True):
|
||||
"""Get a list of Guest objects for nova instances
|
||||
@ -703,7 +701,7 @@ class Host(object):
|
||||
usage_type_const = libvirt.VIR_SECRET_USAGE_TYPE_VOLUME
|
||||
else:
|
||||
msg = _("Invalid usage_type: %s")
|
||||
raise exception.NovaException(msg % usage_type)
|
||||
raise exception.InternalError(msg % usage_type)
|
||||
|
||||
try:
|
||||
conn = self.get_connection()
|
||||
@ -732,7 +730,7 @@ class Host(object):
|
||||
secret_conf.usage_type = 'volume'
|
||||
else:
|
||||
msg = _("Invalid usage_type: %s")
|
||||
raise exception.NovaException(msg % usage_type)
|
||||
raise exception.InternalError(msg % usage_type)
|
||||
|
||||
xml = secret_conf.to_xml()
|
||||
try:
|
||||
|
@ -65,9 +65,9 @@ class Image(object):
|
||||
"""
|
||||
if (CONF.ephemeral_storage_encryption.enabled and
|
||||
not self._supports_encryption()):
|
||||
raise exception.NovaException(_('Incompatible settings: '
|
||||
'ephemeral storage encryption is supported '
|
||||
'only for LVM images.'))
|
||||
msg = _('Incompatible settings: ephemeral storage encryption is '
|
||||
'supported only for LVM images.')
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
self.path = path
|
||||
|
||||
@ -718,7 +718,7 @@ class Lvm(Image):
|
||||
LOG.error(_LE("Failed to retrieve ephemeral encryption"
|
||||
" key"))
|
||||
else:
|
||||
raise exception.NovaException(
|
||||
raise exception.InternalError(
|
||||
_("Instance disk to be encrypted but no context provided"))
|
||||
# Generate images with specified size right on volume
|
||||
if generated and size:
|
||||
|
@ -467,7 +467,7 @@ class LibvirtGenericVIFDriver(object):
|
||||
profilefunc = "_set_config_" + vif.port_profile.obj_name()
|
||||
func = getattr(self, profilefunc, None)
|
||||
if not func:
|
||||
raise exception.NovaException(
|
||||
raise exception.InternalError(
|
||||
_("Unsupported VIF port profile type %(obj)s func %(func)s") %
|
||||
{'obj': vif.port_profile.obj_name(), 'func': profilefunc})
|
||||
|
||||
@ -495,7 +495,7 @@ class LibvirtGenericVIFDriver(object):
|
||||
viffunc = "_set_config_" + vif.obj_name()
|
||||
func = getattr(self, viffunc, None)
|
||||
if not func:
|
||||
raise exception.NovaException(
|
||||
raise exception.InternalError(
|
||||
_("Unsupported VIF type %(obj)s func %(func)s") %
|
||||
{'obj': vif.obj_name(), 'func': viffunc})
|
||||
func(instance, vif, conf, host)
|
||||
@ -514,7 +514,7 @@ class LibvirtGenericVIFDriver(object):
|
||||
'vif': vif, 'virt_type': virt_type})
|
||||
|
||||
if vif_type is None:
|
||||
raise exception.NovaException(
|
||||
raise exception.InternalError(
|
||||
_("vif_type parameter must be present "
|
||||
"for this vif_driver implementation"))
|
||||
|
||||
@ -528,7 +528,7 @@ class LibvirtGenericVIFDriver(object):
|
||||
vif_slug = self._normalize_vif_type(vif_type)
|
||||
func = getattr(self, 'get_config_%s' % vif_slug, None)
|
||||
if not func:
|
||||
raise exception.NovaException(
|
||||
raise exception.InternalError(
|
||||
_("Unexpected vif_type=%s") % vif_type)
|
||||
return func(instance, vif, image_meta,
|
||||
inst_type, virt_type, host)
|
||||
@ -780,7 +780,7 @@ class LibvirtGenericVIFDriver(object):
|
||||
except osv_exception.ExceptionBase as ex:
|
||||
msg = (_("Failure running os_vif plugin plug method: %(ex)s")
|
||||
% {'ex': ex})
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
def plug(self, instance, vif):
|
||||
vif_type = vif['type']
|
||||
@ -989,7 +989,7 @@ class LibvirtGenericVIFDriver(object):
|
||||
except osv_exception.ExceptionBase as ex:
|
||||
msg = (_("Failure running os_vif plugin unplug method: %(ex)s")
|
||||
% {'ex': ex})
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
def unplug(self, instance, vif):
|
||||
vif_type = vif['type']
|
||||
@ -1000,9 +1000,9 @@ class LibvirtGenericVIFDriver(object):
|
||||
'vif': vif})
|
||||
|
||||
if vif_type is None:
|
||||
raise exception.NovaException(
|
||||
_("vif_type parameter must be present "
|
||||
"for this vif_driver implementation"))
|
||||
msg = _("vif_type parameter must be present for this vif_driver "
|
||||
"implementation")
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
# Try os-vif codepath first
|
||||
vif_obj = os_vif_util.nova_to_osvif_vif(vif)
|
||||
@ -1014,6 +1014,6 @@ class LibvirtGenericVIFDriver(object):
|
||||
vif_slug = self._normalize_vif_type(vif_type)
|
||||
func = getattr(self, 'unplug_%s' % vif_slug, None)
|
||||
if not func:
|
||||
raise exception.NovaException(
|
||||
_("Unexpected vif_type=%s") % vif_type)
|
||||
msg = _("Unexpected vif_type=%s") % vif_type
|
||||
raise exception.InternalError(msg)
|
||||
func(instance, vif)
|
||||
|
@ -105,11 +105,11 @@ class LibvirtNetVolumeDriver(libvirt_volume.LibvirtBaseVolumeDriver):
|
||||
netdisk_properties)
|
||||
target_portal = netdisk_properties['target_portal']
|
||||
except KeyError:
|
||||
raise exception.NovaException(_("Invalid volume source data"))
|
||||
raise exception.InternalError(_("Invalid volume source data"))
|
||||
|
||||
ip, port = utils.parse_server_string(target_portal)
|
||||
if ip == '' or port == '':
|
||||
raise exception.NovaException(_("Invalid target_lun"))
|
||||
raise exception.InternalError(_("Invalid target_lun"))
|
||||
conf.source_hosts = [ip]
|
||||
conf.source_ports = [port]
|
||||
self._set_auth_config_iscsi(conf, netdisk_properties)
|
||||
|
@ -78,12 +78,12 @@ def validate_volume(mnt_base):
|
||||
msg = (_("The mount %(mount_path)s is not a valid"
|
||||
" Quobyte volume. Error: %(exc)s")
|
||||
% {'mount_path': mnt_base, 'exc': exc})
|
||||
raise nova_exception.NovaException(msg)
|
||||
raise nova_exception.InternalError(msg)
|
||||
|
||||
if not os.access(mnt_base, os.W_OK | os.X_OK):
|
||||
msg = (_LE("Volume is not writable. Please broaden the file"
|
||||
" permissions. Mount: %s") % mnt_base)
|
||||
raise nova_exception.NovaException(msg)
|
||||
raise nova_exception.InternalError(msg)
|
||||
|
||||
|
||||
class LibvirtQuobyteVolumeDriver(fs.LibvirtBaseFileSystemVolumeDriver):
|
||||
|
@ -91,7 +91,7 @@ class LibvirtScalityVolumeDriver(fs.LibvirtBaseFileSystemVolumeDriver):
|
||||
if not config:
|
||||
msg = _("Value required for 'scality_sofs_config'")
|
||||
LOG.warning(msg)
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
# config can be a file path or a URL, check it
|
||||
if urlparse.urlparse(config).scheme == '':
|
||||
@ -102,13 +102,13 @@ class LibvirtScalityVolumeDriver(fs.LibvirtBaseFileSystemVolumeDriver):
|
||||
except urllib.error.URLError as e:
|
||||
msg = _("Cannot access 'scality_sofs_config': %s") % e
|
||||
LOG.warning(msg)
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
# mount.sofs must be installed
|
||||
if not os.access('/sbin/mount.sofs', os.X_OK):
|
||||
msg = _("Cannot execute /sbin/mount.sofs")
|
||||
LOG.warning(msg)
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
def _sofs_is_mounted(self):
|
||||
"""Detects whether Scality SOFS is already mounted."""
|
||||
@ -133,4 +133,4 @@ class LibvirtScalityVolumeDriver(fs.LibvirtBaseFileSystemVolumeDriver):
|
||||
if not self._sofs_is_mounted():
|
||||
msg = _("Cannot mount Scality SOFS, check syslog for errors")
|
||||
LOG.warning(msg)
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
@ -52,7 +52,7 @@ class LibvirtVZStorageVolumeDriver(fs.LibvirtBaseFileSystemVolumeDriver):
|
||||
msg = (_("You can't use %s options in vzstorage_mount_opts "
|
||||
"configuration parameter.") %
|
||||
', '.join(invalid_cfg_opts))
|
||||
raise exception.NovaException(msg)
|
||||
raise exception.InternalError(msg)
|
||||
|
||||
# Call the factory here so we can support
|
||||
# more than x86 architectures.
|
||||
|
Loading…
x
Reference in New Issue
Block a user