diff --git a/nova/api/openstack/compute/contrib/evacuate.py b/nova/api/openstack/compute/contrib/evacuate.py index b2ef2928c9df..9ec473dbb818 100644 --- a/nova/api/openstack/compute/contrib/evacuate.py +++ b/nova/api/openstack/compute/contrib/evacuate.py @@ -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: diff --git a/nova/api/openstack/compute/plugins/v3/evacuate.py b/nova/api/openstack/compute/plugins/v3/evacuate.py index d26291d1c356..78611de6b899 100644 --- a/nova/api/openstack/compute/plugins/v3/evacuate.py +++ b/nova/api/openstack/compute/plugins/v3/evacuate.py @@ -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} diff --git a/nova/compute/api.py b/nova/compute/api.py index 2b7fca5b15d8..2132a4d95f44 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -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) diff --git a/nova/exception.py b/nova/exception.py index dad99cb80eec..3f83a192ade5 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -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).") diff --git a/nova/tests/api/openstack/compute/contrib/test_evacuate.py b/nova/tests/api/openstack/compute/contrib/test_evacuate.py index 66c11a97e398..27b11d3f07dd 100644 --- a/nova/tests/api/openstack/compute/contrib/test_evacuate.py +++ b/nova/tests/api/openstack/compute/contrib/test_evacuate.py @@ -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) diff --git a/nova/tests/api/openstack/compute/plugins/v3/test_evacuate.py b/nova/tests/api/openstack/compute/plugins/v3/test_evacuate.py index 5b67f231025c..c99dfde55538 100644 --- a/nova/tests/api/openstack/compute/plugins/v3/test_evacuate.py +++ b/nova/tests/api/openstack/compute/plugins/v3/test_evacuate.py @@ -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'}, diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 3e872580d079..07dfb990e63d 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -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)