Fix incorrect exception raised during evacuate

This change creates a new exception 'ComputeServiceInUse'
to better represent the error when trying to evacuate
an instance with a running compute service. Also, it adds
a missing test for evacuate API v3.

Closes-Bug: #1230282

Change-Id: I1c4edb01e84cd2a89879bca9c99f5e38f47e16fb
This commit is contained in:
Tiago Mello
2013-09-25 15:55:13 -03:00
committed by Gerrit Code Review
parent 2d5755416c
commit fe513ec370
7 changed files with 22 additions and 5 deletions

View File

@@ -84,7 +84,7 @@ class Controller(wsgi.Controller):
'evacuate')
except exception.InstanceNotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.ComputeServiceUnavailable as e:
except exception.ComputeServiceInUse as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
if password:

View File

@@ -86,7 +86,7 @@ class EvacuateController(wsgi.Controller):
'evacuate')
except exception.InstanceNotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.ComputeServiceUnavailable as e:
except exception.ComputeServiceInUse as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
return {'admin_password': password}

View File

@@ -2899,7 +2899,7 @@ class API(base.Base):
msg = (_('Instance compute service state on %s '
'expected to be down, but it was up.') % inst_host)
LOG.error(msg)
raise exception.ComputeServiceUnavailable(msg)
raise exception.ComputeServiceInUse(host=inst_host)
instance = self.update(context, instance, expected_task_state=None,
task_state=task_states.REBUILDING)

View File

@@ -393,6 +393,10 @@ class ComputeServiceUnavailable(ServiceUnavailable):
msg_fmt = _("Compute service of %(host)s is unavailable at this time.")
class ComputeServiceInUse(NovaException):
msg_fmt = _("Compute service of %(host)s is still in use.")
class UnableToMigrateToSelf(Invalid):
msg_fmt = _("Unable to migrate instance (%(instance_id)s) "
"to current host (%(host)s).")

View File

@@ -126,7 +126,7 @@ class EvacuateTest(test.NoDBTestCase):
})
def fake_evacuate(*args, **kwargs):
raise exception.ComputeServiceUnavailable("Service Unavailable")
raise exception.ComputeServiceInUse("Service still in use")
self.stubs.Set(compute_api.API, 'evacuate', fake_evacuate)

View File

@@ -140,6 +140,19 @@ class EvacuateTest(test.NoDBTestCase):
resp_json = jsonutils.loads(res.body)
self.assertEqual(resp_json['admin_password'], None)
def test_evacuate_with_active_service(self):
req, app = self._gen_request_with_app({'host': 'my_host',
'on_shared_storage': 'false',
'admin_password': 'MyNewPass'})
def fake_evacuate(*args, **kwargs):
raise exception.ComputeServiceInUse("Service still in use")
self.stubs.Set(compute_api.API, 'evacuate', fake_evacuate)
res = req.get_response(app)
self.assertEqual(res.status_int, 400)
def test_not_admin(self):
req, app = self._gen_request_with_app({'host': 'my_host',
'on_shared_storage': 'True'},

View File

@@ -8057,7 +8057,7 @@ class ComputeAPITestCase(BaseTestCase):
self.stubs.Set(self.compute_api.servicegroup_api, 'service_is_up',
fake_service_is_up)
self.assertRaises(exception.ComputeServiceUnavailable,
self.assertRaises(exception.ComputeServiceInUse,
self.compute_api.evacuate, self.context.elevated(), instance,
host='fake_dest_host', on_shared_storage=True,
admin_password=None)