From 1dba0cdc332e54162dc1d880e80deca968dbff4e Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Thu, 10 Nov 2011 23:36:17 -0500 Subject: Convert remaining calls to use instance objects Related to blueprint internal-uuids. This touches get_diagnostics, get_actions, and restore. Change-Id: Ic4b3d9476fb53cb97b4ea75ad2e846374b2b4a41 --- nova/api/openstack/contrib/deferred_delete.py | 3 ++- nova/api/openstack/servers.py | 6 +++-- nova/compute/api.py | 14 ++++++------ nova/tests/test_compute.py | 33 ++++++++++++++++++++++++++- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/nova/api/openstack/contrib/deferred_delete.py b/nova/api/openstack/contrib/deferred_delete.py index 013acbbea..8415ca4b3 100644 --- a/nova/api/openstack/contrib/deferred_delete.py +++ b/nova/api/openstack/contrib/deferred_delete.py @@ -42,7 +42,8 @@ class Deferred_delete(extensions.ExtensionDescriptor): """Restore a previously deleted instance.""" context = req.environ["nova.context"] - self.compute_api.restore(context, instance_id) + instance = self.compute_api.get(context, instance_id) + self.compute_api.restore(context, instance) return webob.Response(status_int=202) def _force_delete(self, input_dict, req, instance_id): diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 1e9089560..677635354 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -646,12 +646,14 @@ class Controller(object): def diagnostics(self, req, id): """Permit Admins to retrieve server diagnostics.""" ctxt = req.environ["nova.context"] - return self.compute_api.get_diagnostics(ctxt, id) + instance = self._get_server(ctxt, id) + return self.compute_api.get_diagnostics(ctxt, instance) def actions(self, req, id): """Permit Admins to retrieve server actions.""" ctxt = req.environ["nova.context"] - items = self.compute_api.get_actions(ctxt, id) + instance = self._get_server(ctxt, id) + items = self.compute_api.get_actions(ctxt, instance) actions = [] # TODO(jk0): Do not do pre-serialization here once the default # serializer is updated diff --git a/nova/compute/api.py b/nova/compute/api.py index 2a0685fc2..ffd2efd29 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -827,9 +827,9 @@ class API(base.Base): self._delete(context, instance) @scheduler_api.reroute_compute("restore") - def restore(self, context, instance_id): + def restore(self, context, instance): """Restore a previously deleted (but not reclaimed) instance.""" - instance = self._get_instance(context, instance_id, 'restore') + instance_id = instance['id'] if not _is_queued_delete(instance): return @@ -846,7 +846,7 @@ class API(base.Base): instance_id, task_state=task_states.POWERING_ON) self._cast_compute_message('power_on_instance', context, - instance_id, host) + instance_id, host) @scheduler_api.reroute_compute("force_delete") def force_delete(self, context, instance): @@ -1370,15 +1370,15 @@ class API(base.Base): context, host=host, params={"action": action}) @scheduler_api.reroute_compute("diagnostics") - def get_diagnostics(self, context, instance_id): + def get_diagnostics(self, context, instance): """Retrieve diagnostics for the given instance.""" return self._call_compute_message("get_diagnostics", context, - instance_id) + instance['id']) - def get_actions(self, context, instance_id): + def get_actions(self, context, instance): """Retrieve actions for the given instance.""" - return self.db.instance_get_actions(context, instance_id) + return self.db.instance_get_actions(context, instance['id']) @scheduler_api.reroute_compute("suspend") def suspend(self, context, instance): diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 69b998d68..4d0832e2a 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -1112,7 +1112,7 @@ class ComputeAPITestCase(BaseTestCase): db.instance_destroy(self.context, instance_id) def test_force_delete(self): - """Ensure instance can be soft rebooted""" + """Ensure instance can be deleted after a soft delete""" instance_id = self._create_instance() self.compute.run_instance(self.context, instance_id) @@ -1189,6 +1189,24 @@ class ComputeAPITestCase(BaseTestCase): db.instance_destroy(self.context, instance_id) + def test_restore(self): + """Ensure instance can be restored from a soft delete""" + instance_id = self._create_instance() + self.compute.run_instance(self.context, instance_id) + + instance = db.instance_get(self.context, instance_id) + self.compute_api.soft_delete(self.context, instance) + + instance = db.instance_get(self.context, instance_id) + self.assertEqual(instance['task_state'], task_states.POWERING_OFF) + + self.compute_api.restore(self.context, instance) + + instance = db.instance_get(self.context, instance_id) + self.assertEqual(instance['task_state'], task_states.POWERING_ON) + + db.instance_destroy(self.context, instance_id) + def test_rebuild(self): instance_id = self._create_instance() self.compute.run_instance(self.context, instance_id) @@ -1980,6 +1998,7 @@ class ComputeAPITestCase(BaseTestCase): instance = self.compute_api.get(self.context, instance_id) self.compute_api.add_fixed_ip(self.context, instance, '1') self.compute_api.remove_fixed_ip(self.context, instance, '192.168.1.1') + self.compute_api.delete(self.context, instance) def test_attach_volume_invalid(self): self.assertRaises(exception.ApiError, @@ -2106,6 +2125,18 @@ class ComputeAPITestCase(BaseTestCase): self.compute_api.remove_security_group(self.context, instance, security_group_name) + + def test_get_diagnostics(self): + instance_id = self._create_instance() + instance = self.compute_api.get(self.context, instance_id) + self.compute_api.get_diagnostics(self.context, instance) + self.compute_api.delete(self.context, instance) + + def test_get_actions(self): + context = self.context.elevated() + instance_id = self._create_instance() + instance = self.compute_api.get(self.context, instance_id) + self.compute_api.get_actions(context, instance) self.compute_api.delete(self.context, instance) def test_inject_file(self): -- cgit