raise exception ComputeHostNotFound if host is not found

When performing a live migration,I passed a wrong host parameter,
and then I got a wrong result like this:
"Compute service of host-1 is unavailable at this time".
I thought the compute service stopped, but the fact was I passed
a host id instead of a host name,therefore it could not find the host.

In order to distinguish the error "host not found" from the error
"service not available", I think we should raise a different exception
ComputeHostNotFound instead of ComputeServiceUnavailable.

This patch we will return more accurate error msg for live migration.

Closes-Bug: #1538837
Change-Id: I6ad377147070f85b9b1d5a1d1be459e890e02bcc
This commit is contained in:
Javeme 2015-11-09 20:37:34 +08:00
parent bb50389bb6
commit c824982e6a
4 changed files with 13 additions and 13 deletions

View File

@ -320,6 +320,7 @@ class ComputeTaskManager(base.Base):
try:
task.execute()
except (exception.NoValidHost,
exception.ComputeHostNotFound,
exception.ComputeServiceUnavailable,
exception.InvalidHypervisorType,
exception.InvalidCPUInfo,

View File

@ -77,16 +77,13 @@ class LiveMigrationTask(base.TaskBase):
if self.instance.power_state not in (power_state.RUNNING,
power_state.PAUSED):
raise exception.InstanceInvalidState(
instance_uuid = self.instance.uuid,
attr = 'power_state',
state = self.instance.power_state,
method = 'live migrate')
instance_uuid=self.instance.uuid,
attr='power_state',
state=self.instance.power_state,
method='live migrate')
def _check_host_is_up(self, host):
try:
service = objects.Service.get_by_compute_host(self.context, host)
except exception.NotFound:
raise exception.ComputeServiceUnavailable(host=host)
service = objects.Service.get_by_compute_host(self.context, host)
if not self.servicegroup_api.service_is_up(service):
raise exception.ComputeServiceUnavailable(host=host)

View File

@ -145,7 +145,7 @@ class NovaException(Exception):
# log the issue and the kwargs
LOG.exception(_LE('Exception in string format operation'))
for name, value in six.iteritems(kwargs):
LOG.error("%s: %s" % (name, value)) # noqa
LOG.error("%s: %s" % (name, value)) # noqa
if CONF.fatal_exception_format_errors:
six.reraise(*exc_info)

View File

@ -138,10 +138,11 @@ class LiveMigrationTaskTestCase(test.NoDBTestCase):
self.mox.StubOutWithMock(objects.Service, 'get_by_compute_host')
objects.Service.get_by_compute_host(
self.context, "host").AndRaise(exception.NotFound)
self.context, "host").AndRaise(
exception.ComputeHostNotFound(host='host'))
self.mox.ReplayAll()
self.assertRaises(exception.ComputeServiceUnavailable,
self.assertRaises(exception.ComputeHostNotFound,
self.task._check_host_is_up, "host")
def test_check_requested_destination(self):
@ -187,10 +188,11 @@ class LiveMigrationTaskTestCase(test.NoDBTestCase):
self.mox.StubOutWithMock(objects.Service, 'get_by_compute_host')
objects.Service.get_by_compute_host(
self.context, self.destination).AndRaise(exception.NotFound)
self.context, self.destination).AndRaise(
exception.ComputeHostNotFound(host='host'))
self.mox.ReplayAll()
self.assertRaises(exception.ComputeServiceUnavailable,
self.assertRaises(exception.ComputeHostNotFound,
self.task._check_requested_destination)
def test_check_requested_destination_fails_with_not_enough_memory(self):