summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorBrian Waldon <brian.waldon@rackspace.com>2011-04-14 17:34:09 -0400
committerBrian Waldon <brian.waldon@rackspace.com>2011-04-14 17:34:09 -0400
commit4b0785632ba626d34a8a9fae5e0a5c742660e2dc (patch)
treeee1997a88cbf903d98141a385c64700fc2057616 /nova
parent9761e7690ab8f13a76c761ba6055372a0d29eaff (diff)
initial roundup of all 'exception.Invalid' cases
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/servers.py4
-rw-r--r--nova/exception.py90
-rw-r--r--nova/network/vmwareapi_net.py16
-rw-r--r--nova/scheduler/driver.py27
-rw-r--r--nova/virt/libvirt_conn.py19
-rw-r--r--nova/virt/vmwareapi/vmops.py13
6 files changed, 116 insertions, 53 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 43e0c7963..2332b1af7 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -561,9 +561,7 @@ class Controller(common.OpenstackController):
"""
image_id = image_meta['id']
if image_meta['status'] != 'active':
- raise exception.Invalid(
- _("Cannot build from image %(image_id)s, status not active") %
- locals())
+ raise exception.InstanceNotRunning(image_id=image_id)
if image_meta.get('container_format') != 'ami':
return None, None
diff --git a/nova/exception.py b/nova/exception.py
index 4e2bbdbaf..cbfbb2920 100644
--- a/nova/exception.py
+++ b/nova/exception.py
@@ -80,10 +80,6 @@ class NotEmpty(Error):
pass
-class Invalid(Error):
- pass
-
-
class InvalidInputException(Error):
pass
@@ -127,3 +123,89 @@ def wrap_exception(f):
raise
_wrap.func_name = f.func_name
return _wrap
+
+
+class NovaException(Exception):
+ message = ""
+
+ def __init__(self, **kwargs):
+ self._error_string = _(self.message) % kwargs
+
+ def __str__(self):
+ return self._error_string
+
+
+#TODO: EOL this exception!
+class Invalid(NovaException):
+ pass
+
+
+class InstanceNotRunning(Invalid):
+ message = "Instance is not 'running'."
+
+
+class InstanceNotSuspended(Invalid):
+ message = "Instance is not 'suspended'."
+
+
+class InstanceSuspendFailure(Invalid):
+ message = "Failed to suspend instance: %(reason)s."
+
+
+class InstanceResumeFailure(Invalid):
+ message = "Failed to resume server: %(reson)s."
+
+
+class InstanceRebootFailure(Invalid):
+ message = "Failed to reboot instance: %(reason)s."
+
+
+class ServiceUnavailable(Invalid):
+ message = "Service is unavailable at this time."
+
+
+class VolumeServiceUnavailable(ServiceUnavailable):
+ message = "Volume service is unavailable at this time."
+
+
+class ComputeServiceUnavailable(ServiceUnavailable):
+ message = "Compute service on %(host)s is unavailable at this time."
+
+
+class UnableToMigrateToSelf(Invalid):
+ message = "Unable to migrate instance (%(instance_id)s) " \
+ "to current host (%(host)s."
+
+
+class SourceHostUnavailable(Invalid):
+ message = "Original compute host is unavailable at this time."
+
+
+class InvalidHypervisorType(Invalid):
+ message = "The supplied hypervisor type of %(type)s is invalid."
+
+
+class DestinationHypervisorTooOld(Invalid):
+ message = "The instance requires a newer hypervisor version than " \
+ "has been provided."
+
+
+class InvalidDevicePath(Invalid):
+ message = "The supplied device path (%(path)s) is invalid."
+
+
+class InvalidCPUInfo(Invalid):
+ message = "Unacceptable CPU info: %(reason)s."
+
+
+class InvalidVLANTag(Invalid):
+ message = "VLAN tag is not appropriate for the port group " \
+ "%(bridge)s. Expected VLAN tag is %(tag)s, " \
+ "but the one associated with the port group is %(pgroup)s."
+
+
+class InvalidVLANPortGroup(Invalid):
+ message = "vSwitch which contains the port group %(bridge)s is " \
+ "not associated with the desired physical adapter. " \
+ "Expected vSwitch is %(expected)s, but the one associated " \
+ "is %(actual)s."
diff --git a/nova/network/vmwareapi_net.py b/nova/network/vmwareapi_net.py
index 93e6584f0..6e1ed480b 100644
--- a/nova/network/vmwareapi_net.py
+++ b/nova/network/vmwareapi_net.py
@@ -75,17 +75,13 @@ def ensure_vlan_bridge(vlan_num, bridge, net_attrs=None):
pg_vlanid, pg_vswitch = \
network_utils.get_vlanid_and_vswitch_for_portgroup(session, bridge)
- # Check if the vsiwtch associated is proper
+ # Check if the vswitch associated is proper
if pg_vswitch != vswitch_associated:
- raise exception.Invalid(_("vSwitch which contains the port group "
- "%(bridge)s is not associated with the desired "
- "physical adapter. Expected vSwitch is "
- "%(vswitch_associated)s, but the one associated"
- " is %(pg_vswitch)s") % locals())
+ raise exception.InvalidVLANPortGroup(bridge=bridge,
+ expected=vswitch_associated,
+ actual=pg_vswitch)
# Check if the vlan id is proper for the port group
if pg_vlanid != vlan_num:
- raise exception.Invalid(_("VLAN tag is not appropriate for the "
- "port group %(bridge)s. Expected VLAN tag is "
- "%(vlan_num)s, but the one associated with the "
- "port group is %(pg_vlanid)s") % locals())
+ raise exception.InvalidVLANTag(bridge=bridge, tag=vlan_num,
+ pgroup=pg_vlanid)
diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py
index ce05d9f6a..02e65357c 100644
--- a/nova/scheduler/driver.py
+++ b/nova/scheduler/driver.py
@@ -129,15 +129,14 @@ class Scheduler(object):
if (power_state.RUNNING != instance_ref['state'] or \
'running' != instance_ref['state_description']):
ec2_id = instance_ref['hostname']
- raise exception.Invalid(_('Instance(%s) is not running') % ec2_id)
+ raise exception.InstanceNotRunning(instance_id=ec2_id)
# Checing volume node is running when any volumes are mounted
# to the instance.
if len(instance_ref['volumes']) != 0:
services = db.service_get_all_by_topic(context, 'volume')
if len(services) < 1 or not self.service_is_up(services[0]):
- raise exception.Invalid(_("volume node is not alive"
- "(time synchronize problem?)"))
+ raise exception.VolumeServiceUnavailable()
# Checking src host exists and compute node
src = instance_ref['host']
@@ -145,8 +144,7 @@ class Scheduler(object):
# Checking src host is alive.
if not self.service_is_up(services[0]):
- raise exception.Invalid(_("%s is not alive(time "
- "synchronize problem?)") % src)
+ raise exception.ComputeServiceUnavailable(host=src)
def _live_migration_dest_check(self, context, instance_ref, dest):
"""Live migration check routine (for destination host).
@@ -163,17 +161,14 @@ class Scheduler(object):
# Checking dest host is alive.
if not self.service_is_up(dservice_ref):
- raise exception.Invalid(_("%s is not alive(time "
- "synchronize problem?)") % dest)
+ raise exception.ComputeServiceUnavailable(host=dest)
# Checking whether The host where instance is running
# and dest is not same.
src = instance_ref['host']
if dest == src:
ec2_id = instance_ref['hostname']
- raise exception.Invalid(_("%(dest)s is where %(ec2_id)s is "
- "running now. choose other host.")
- % locals())
+ raise exception.UnableToMigrateToSelf(instance_id=ec2_id, host=dest)
# Checking dst host still has enough capacities.
self.assert_compute_node_has_enough_resources(context,
@@ -204,26 +199,20 @@ class Scheduler(object):
oservice_refs = db.service_get_all_compute_by_host(context,
instance_ref['launched_on'])
except exception.NotFound:
- raise exception.Invalid(_("host %s where instance was launched "
- "does not exist.")
- % instance_ref['launched_on'])
+ raise exception.SourceHostUnavailable()
oservice_ref = oservice_refs[0]['compute_node'][0]
# Checking hypervisor is same.
orig_hypervisor = oservice_ref['hypervisor_type']
dest_hypervisor = dservice_ref['hypervisor_type']
if orig_hypervisor != dest_hypervisor:
- raise exception.Invalid(_("Different hypervisor type"
- "(%(orig_hypervisor)s->"
- "%(dest_hypervisor)s)')" % locals()))
+ raise exception.InvalidHypervisorType()
# Checkng hypervisor version.
orig_hypervisor = oservice_ref['hypervisor_version']
dest_hypervisor = dservice_ref['hypervisor_version']
if orig_hypervisor > dest_hypervisor:
- raise exception.Invalid(_("Older hypervisor version"
- "(%(orig_hypervisor)s->"
- "%(dest_hypervisor)s)") % locals())
+ raise exception.DestinationHypervisorTooOld()
# Checking cpuinfo.
try:
diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py
index 94410003e..78190cb6d 100644
--- a/nova/virt/libvirt_conn.py
+++ b/nova/virt/libvirt_conn.py
@@ -421,7 +421,7 @@ class LibvirtConnection(driver.ComputeDriver):
name,
mount_device)
else:
- raise exception.Invalid(_("Invalid device path %s") % device_path)
+ raise exception.InvalidDevicePath(path=device_path)
virt_dom.attachDevice(xml)
@@ -1302,9 +1302,9 @@ class LibvirtConnection(driver.ComputeDriver):
xml = libxml2.parseDoc(xml)
nodes = xml.xpathEval('//host/cpu')
if len(nodes) != 1:
- raise exception.Invalid(_("Invalid xml. '<cpu>' must be 1,"
- "but %d\n") % len(nodes)
- + xml.serialize())
+ reason = _("'<cpu>' must be 1, but %d\n") % len(nodes)
+ reason += xml.serialize()
+ raise exception.InvalidCPUInfo(reason=reason)
cpu_info = dict()
@@ -1333,9 +1333,8 @@ class LibvirtConnection(driver.ComputeDriver):
tkeys = topology.keys()
if set(tkeys) != set(keys):
ks = ', '.join(keys)
- raise exception.Invalid(_("Invalid xml: topology"
- "(%(topology)s) must have "
- "%(ks)s") % locals())
+ reason = _("topology (%(topology)s) must have %(ks)s")
+ raise exception.InvalidCPUInfo(reason=reason % locals())
feature_nodes = xml.xpathEval('//host/cpu/feature')
features = list()
@@ -1390,9 +1389,7 @@ class LibvirtConnection(driver.ComputeDriver):
try:
service_ref = db.service_get_all_compute_by_host(ctxt, host)[0]
except exception.NotFound:
- raise exception.Invalid(_("Cannot update compute manager "
- "specific info, because no service "
- "record was found."))
+ raise exception.ComputeServiceUnavailable()
# Updating host information
dic = {'vcpus': self.get_vcpu_total(),
@@ -1445,7 +1442,7 @@ class LibvirtConnection(driver.ComputeDriver):
raise
if ret <= 0:
- raise exception.Invalid(m % locals())
+ raise exception.InvalidCPUInfo(reason=m % locals())
return
diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py
index cf6c88bbd..f2f68ec22 100644
--- a/nova/virt/vmwareapi/vmops.py
+++ b/nova/virt/vmwareapi/vmops.py
@@ -501,8 +501,8 @@ class VMWareVMOps(object):
# Raise an exception if the VM is not powered On.
if pwr_state not in ["poweredOn"]:
- raise exception.Invalid(_("instance - %s not poweredOn. So can't "
- "be rebooted.") % instance.name)
+ reason = _("instance is not powered on")
+ raise exception.InstanceRebootFailure(reason=reason)
# If latest vmware tools are installed in the VM, and that the tools
# are running, then only do a guest reboot. Otherwise do a hard reset.
@@ -620,8 +620,9 @@ class VMWareVMOps(object):
LOG.debug(_("Suspended the VM %s ") % instance.name)
# Raise Exception if VM is poweredOff
elif pwr_state == "poweredOff":
- raise exception.Invalid(_("instance - %s is poweredOff and hence "
- " can't be suspended.") % instance.name)
+ reason = _("instance is poweredOff and can not be suspended.")
+ raise exception.InstanceSuspendFailure(reason=reason)
+
LOG.debug(_("VM %s was already in suspended state. So returning "
"without doing anything") % instance.name)
@@ -643,8 +644,8 @@ class VMWareVMOps(object):
self._wait_with_callback(instance.id, suspend_task, callback)
LOG.debug(_("Resumed the VM %s ") % instance.name)
else:
- raise exception.Invalid(_("instance - %s not in Suspended state "
- "and hence can't be Resumed.") % instance.name)
+ reason = _("instance is not in a suspended state")
+ raise exception.InstanceResumeFailure(reason=reason)
def get_info(self, instance_name):
"""Return data about the VM instance."""