summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-08-09 17:04:39 +0000
committerGerrit Code Review <review@openstack.org>2012-08-09 17:04:39 +0000
commiteb1538763450d7d0f95d4c29ff54f4bf7defaa09 (patch)
treeb0b6c2708711ba4897e7679dcd7558bd2a95b8b3
parentfd00534df464095c780dd2e5a292b4d3696ad375 (diff)
parentc45eb1fe80e6e224b0617fb3d789949c0d0b8dd1 (diff)
downloadnova-eb1538763450d7d0f95d4c29ff54f4bf7defaa09.tar.gz
nova-eb1538763450d7d0f95d4c29ff54f4bf7defaa09.tar.xz
nova-eb1538763450d7d0f95d4c29ff54f4bf7defaa09.zip
Merge "Fix stale instances being sent over rpc."
-rw-r--r--nova/compute/api.py60
-rw-r--r--nova/tests/api/openstack/compute/test_server_actions.py5
2 files changed, 25 insertions, 40 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 7164930f0..be00552d8 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -868,10 +868,9 @@ class API(base.Base):
# that are in soft delete. If there is no host assigned, there is
# no daemon to reclaim, so delete it immediately.
if instance['host']:
- self.update(context,
- instance,
- task_state=task_states.POWERING_OFF,
- deleted_at=timeutils.utcnow())
+ instance = self.update(context, instance,
+ task_state=task_states.POWERING_OFF,
+ deleted_at=timeutils.utcnow())
self.compute_rpcapi.power_off_instance(context, instance)
else:
@@ -903,10 +902,8 @@ class API(base.Base):
# Refresh to get new host information
instance = self.get(context, instance['uuid'])
- self.update(context,
- instance,
- task_state=task_states.DELETING,
- progress=0)
+ instance = self.update(context, instance,
+ task_state=task_states.DELETING, progress=0)
if instance['vm_state'] == vm_states.RESIZED:
# If in the middle of a resize, use confirm_resize to
@@ -949,10 +946,8 @@ class API(base.Base):
def restore(self, context, instance):
"""Restore a previously deleted (but not reclaimed) instance."""
if instance['host']:
- self.update(context,
- instance,
- task_state=task_states.POWERING_ON,
- deleted_at=None)
+ instance = self.update(context, instance,
+ task_state=task_states.POWERING_ON, deleted_at=None)
self.compute_rpcapi.power_on_instance(context, instance)
else:
self.update(context,
@@ -977,10 +972,8 @@ class API(base.Base):
"""Stop an instance."""
LOG.debug(_("Going to try to stop instance"), instance=instance)
- self.update(context,
- instance,
- task_state=task_states.STOPPING,
- progress=0)
+ instance = self.update(context, instance,
+ task_state=task_states.STOPPING, progress=0)
self.compute_rpcapi.stop_instance(context, instance, cast=do_cast)
@@ -991,9 +984,8 @@ class API(base.Base):
"""Start an instance."""
LOG.debug(_("Going to try to start instance"), instance=instance)
- self.update(context,
- instance,
- task_state=task_states.STARTING)
+ instance = self.update(context, instance,
+ task_state=task_states.STARTING)
# TODO(yamahata): injected_files isn't supported right now.
# It is used only for osapi. not for ec2 api.
@@ -1252,10 +1244,8 @@ class API(base.Base):
"""Reboot the given instance."""
state = {'SOFT': task_states.REBOOTING,
'HARD': task_states.REBOOTING_HARD}[reboot_type]
- self.update(context,
- instance,
- vm_state=vm_states.ACTIVE,
- task_state=state)
+ instance = self.update(context, instance, vm_state=vm_states.ACTIVE,
+ task_state=state)
self.compute_rpcapi.reboot_instance(context, instance=instance,
reboot_type=reboot_type)
@@ -1313,14 +1303,11 @@ class API(base.Base):
self.db.instance_system_metadata_update(context,
instance['uuid'], sys_metadata, True)
- self.update(context,
- instance,
- task_state=task_states.REBUILDING,
- # Unfortunately we need to set image_ref early,
- # so API users can see it.
- image_ref=image_href,
- progress=0,
- **kwargs)
+ instance = self.update(context, instance,
+ task_state=task_states.REBUILDING,
+ # Unfortunately we need to set image_ref early,
+ # so API users can see it.
+ image_ref=image_href, progress=0, **kwargs)
# On a rebuild, since we're potentially changing images, we need to
# wipe out the old image properties that we're storing as instance
@@ -1343,9 +1330,8 @@ class API(base.Base):
raise exception.MigrationNotFoundByStatus(
instance_id=instance['uuid'], status='finished')
- self.update(context,
- instance,
- task_state=task_states.RESIZE_REVERTING)
+ instance = self.update(context, instance,
+ task_state=task_states.RESIZE_REVERTING)
self.compute_rpcapi.revert_resize(context,
instance=instance, migration_id=migration_ref['id'],
@@ -1366,10 +1352,8 @@ class API(base.Base):
raise exception.MigrationNotFoundByStatus(
instance_id=instance['uuid'], status='finished')
- self.update(context,
- instance,
- vm_state=vm_states.ACTIVE,
- task_state=None)
+ instance = self.update(context, instance, vm_state=vm_states.ACTIVE,
+ task_state=None)
self.compute_rpcapi.confirm_resize(context,
instance=instance, migration_id=migration_ref['id'],
diff --git a/nova/tests/api/openstack/compute/test_server_actions.py b/nova/tests/api/openstack/compute/test_server_actions.py
index 851fb57f2..f062dd5a9 100644
--- a/nova/tests/api/openstack/compute/test_server_actions.py
+++ b/nova/tests/api/openstack/compute/test_server_actions.py
@@ -41,7 +41,7 @@ def return_server_not_found(context, uuid):
def instance_update(context, instance_uuid, kwargs):
- inst = fakes.stub_instance(INSTANCE_IDS[instance_uuid])
+ inst = fakes.stub_instance(INSTANCE_IDS[instance_uuid], host='fake_host')
return (inst, inst)
@@ -463,7 +463,8 @@ class ServerActionsControllerTest(test.TestCase):
update(context, mox.IgnoreArg(),
image_ref=self._image_href,
task_state=task_states.REBUILDING,
- progress=0, **attributes).AndReturn(None)
+ progress=0, **attributes).AndReturn(
+ fakes.stub_instance(1, host='fake_host'))
self.mox.ReplayAll()
self.controller._action_rebuild(req, FAKE_UUID, body)