Don't immediately null host/node when shelving

When offloading a shelved instance, resources should be freed. However,
the ability to free resources is dependant on being able to find the
resource tracker for an instance's node. At present, the instance node
and host are nulled before attempting to update the resource tracker,
meaning the resources are never actually freed. Fix this by nullifying
these values *after* resources updates.

Change-Id: I8f91367aacca0c7c673b28b3c844c70c0d12f0a5
Related-bug: #1545675
This commit is contained in:
Stephen Finucane 2016-06-21 15:47:50 +01:00
parent f1320a7c2d
commit 59f55a14b5
2 changed files with 12 additions and 5 deletions

View File

@ -4159,15 +4159,19 @@ class ComputeManager(manager.Manager):
block_device_info)
instance.power_state = current_power_state
instance.host = None
instance.node = None
instance.vm_state = vm_states.SHELVED_OFFLOADED
instance.task_state = None
instance.save(expected_task_state=[task_states.SHELVING,
task_states.SHELVING_OFFLOADING])
# NOTE(ndipanov): This frees the resources with the resource_tracker
# NOTE(ndipanov): Free resources from the resource tracker
self._update_resource_tracker(context, instance)
# NOTE(sfinucan): RPC calls should no longer be attempted against this
# instance, so ensure any calls result in errors
self._nil_out_instance_obj_host_and_node(instance)
instance.save(expected_task_state=None)
self._delete_scheduler_instance_info(context, instance.uuid)
self._notify_about_instance_usage(context, instance,
'shelve_offload.end')

View File

@ -98,8 +98,6 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
tracking['last_state'] = instance.vm_state
elif (tracking['last_state'] == vm_states.SHELVED and
CONF.shelved_offload_time == 0):
self.assertIsNone(instance.host)
self.assertIsNone(instance.node)
self.assertIsNone(instance.task_state)
self.assertEqual(vm_states.SHELVED_OFFLOADED,
instance.vm_state)
@ -107,6 +105,11 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
task_states.SHELVING_OFFLOADING],
expected_task_state)
tracking['last_state'] = instance.vm_state
elif (tracking['last_state'] == vm_states.SHELVED_OFFLOADED and
CONF.shelved_offload_time == 0):
self.assertIsNone(instance.host)
self.assertIsNone(instance.node)
self.assertIsNone(expected_task_state)
else:
self.fail('Unexpected save!')