From 59f55a14b5f5396e653d9eb1e5ded31db72f620b Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 21 Jun 2016 15:47:50 +0100 Subject: [PATCH] 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 --- nova/compute/manager.py | 10 +++++++--- nova/tests/unit/compute/test_shelve.py | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 4400312ba870..57470aac525d 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -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') diff --git a/nova/tests/unit/compute/test_shelve.py b/nova/tests/unit/compute/test_shelve.py index 635604f4d9b2..1bf91bd073ed 100644 --- a/nova/tests/unit/compute/test_shelve.py +++ b/nova/tests/unit/compute/test_shelve.py @@ -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!')