Merge "Remove source node allocation after live migration completes"

This commit is contained in:
Jenkins 2017-08-23 15:05:58 +00:00 committed by Gerrit Code Review
commit 320c0f377b
3 changed files with 31 additions and 41 deletions

View File

@ -5633,6 +5633,10 @@ class ComputeManager(manager.Manager):
# method
destroy_vifs = True
# NOTE(danms): Save source node before calling post method on
# destination, which will update it
source_node = instance.node
# Define domain at destination host, without doing it,
# pause/suspend/terminate do not work.
post_at_dest_success = True
@ -5664,6 +5668,10 @@ class ComputeManager(manager.Manager):
# host even before next periodic task.
self.update_available_resource(ctxt)
rt = self._get_resource_tracker()
rt.delete_allocation_for_migrated_instance(
instance, source_node)
self._update_scheduler_instance_info(ctxt, instance)
self._notify_about_instance_usage(ctxt, instance,
"live_migration._post.end",

View File

@ -1225,6 +1225,18 @@ class ResourceTracker(object):
"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)
def _find_orphaned_instances(self):
"""Given the set of instances and migrations already account for
by resource tracker, sanity check the hypervisor to determine

View File

@ -1820,31 +1820,17 @@ class ServerMovingTests(test.TestCase, integrated_helpers.InstanceHelperMixin):
self._run_periodics()
source_usages = self._get_provider_usages(source_rp_uuid)
# NOTE(lajos katona): After bug 1712045 is solved on the source there
# will be no allocations:
# self.assertFlavorMatchesAllocation(
# {'ram': 0, 'disk': 0, 'vcpus': 0}, source_usages)
# NOTE(lajos katona): while bug 1712045 is not solved on the source
# host the allocations are remaining:
# on the original host should not have the old resource usage
self.assertFlavorMatchesAllocation(self.flavor1, source_usages)
# NOTE(danms): There should be no usage for the source
self.assertFlavorMatchesAllocation(
{'ram': 0, 'disk': 0, 'vcpus': 0}, source_usages)
dest_usages = self._get_provider_usages(dest_rp_uuid)
self.assertFlavorMatchesAllocation(self.flavor1, dest_usages)
allocations = self._get_allocations_by_server_uuid(server['id'])
# the server has an allocation on the source and dest nodes
self.assertEqual(2, len(allocations))
# NOTE(lajos katona): When bug 1712045 is solved the server has
# no allocation on the source:
# self.assertNotIn(source_rp_uuid, allocations)
# Instead the source allocation is still there
source_allocation = allocations[source_rp_uuid]['resources']
self.assertFlavorMatchesAllocation(self.flavor1, source_allocation)
# the server has an allocation on only the dest node
self.assertEqual(1, len(allocations))
self.assertNotIn(source_rp_uuid, allocations)
dest_allocation = allocations[dest_rp_uuid]['resources']
self.assertFlavorMatchesAllocation(self.flavor1, dest_allocation)
@ -1874,32 +1860,16 @@ class ServerMovingTests(test.TestCase, integrated_helpers.InstanceHelperMixin):
self._run_periodics()
source_usages = self._get_provider_usages(source_rp_uuid)
# NOTE(lajos katona): After bug 1712045 is solved on the source there
# will be no allocations:
# self.assertFlavorMatchesAllocation(
# {'ram': 0, 'disk': 0, 'vcpus': 0}, source_usages)
# NOTE(lajos katona): while bug 1712045 is not solved on the source
# host the allocations are remaining:
# on the original host should not have the old resource usage
self.assertFlavorMatchesAllocation(self.flavor1, source_usages)
# NOTE(danms): There should be no usage for the source
self.assertFlavorMatchesAllocation(
{'ram': 0, 'disk': 0, 'vcpus': 0}, source_usages)
dest_usages = self._get_provider_usages(dest_rp_uuid)
self.assertFlavorMatchesAllocation(self.flavor1, dest_usages)
allocations = self._get_allocations_by_server_uuid(server['id'])
# NOTE(lajos katona): the server has 2 allocations, instead of one,
# after bug 1712045 will be solved we can expect just one allocation
self.assertEqual(2, len(allocations))
# NOTE(lajos katona): When bug 1712045 is solved the server has
# no allocation on the source:
# self.assertNotIn(source_rp_uuid, allocations)
# Instead the source allocation is still there
source_allocation = allocations[source_rp_uuid]['resources']
self.assertFlavorMatchesAllocation(self.flavor1, source_allocation)
self.assertEqual(1, len(allocations))
self.assertNotIn(source_rp_uuid, allocations)
dest_allocation = allocations[dest_rp_uuid]['resources']
self.assertFlavorMatchesAllocation(self.flavor1, dest_allocation)