From e00584f157991df4e8533965f16d4b5210c01524 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Wed, 23 Aug 2017 22:32:29 +0100 Subject: [PATCH] De-duplicate two delete_allocation_for_* methods delete_allocation_for_migrated_instance and delete_allocation_for_evacuated_instance are only different in their log messages, so extract their guts to a shared private method. This same method could also be used at the end of drop_move_claim, but the extent of change to the logging there made me pause. Perhaps another time. Change-Id: Ifad17e08aa3ddbd95f25b6133564ea1a1a1bb87c (cherry picked from commit 5a0aa097374d739800d394841ad9ad4243217f11) --- nova/compute/resource_tracker.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/nova/compute/resource_tracker.py b/nova/compute/resource_tracker.py index 41a8047f02a4..40cf7fd7609e 100644 --- a/nova/compute/resource_tracker.py +++ b/nova/compute/resource_tracker.py @@ -1211,6 +1211,13 @@ class ResourceTracker(object): instance_uuid, instance.host, instance.node, alloc) def delete_allocation_for_evacuated_instance(self, instance, node): + self._delete_allocation_for_moved_instance(instance, node, 'evacuated') + + def delete_allocation_for_migrated_instance(self, instance, node): + self._delete_allocation_for_moved_instance(instance, node, 'migrated') + + def _delete_allocation_for_moved_instance( + self, instance, node, move_type): # Clean up the instance allocation from this node in placement my_resources = scheduler_utils.resources_from_flavor( instance, instance.flavor) @@ -1221,21 +1228,9 @@ class ResourceTracker(object): instance.uuid, cn_uuid, instance.user_id, instance.project_id, my_resources) if not res: - LOG.error("Failed to clean allocation of an evacuated " + LOG.error("Failed to clean allocation of %s " "instance on the source node %s", - cn_uuid, instance=instance) - - def delete_allocation_for_migrated_instance(self, instance, node): - my_resources = scheduler_utils.resources_from_flavor(instance, - instance.flavor) - cn = self.compute_nodes[node] - res = self.reportclient.remove_provider_from_instance_allocation( - instance.uuid, cn.uuid, instance.user_id, instance.project_id, - my_resources) - if not res: - LOG.error('Failed to clean allocation of a migrated instance ' - 'on the source node %s', cn.uuid, - instance=instance) + move_type, cn_uuid, instance=instance) def delete_allocation_for_failed_resize(self, instance, node, flavor): """Delete instance allocations for the node during a failed resize