Merge "Optimize _cleanup_incomplete_migrations periodic task"
This commit is contained in:
commit
858b0b7687
|
@ -6575,29 +6575,28 @@ class ComputeManager(manager.Manager):
|
|||
in migrations])
|
||||
|
||||
inst_filters = {'deleted': True, 'soft_deleted': False,
|
||||
'uuid': inst_uuid_from_migrations}
|
||||
'uuid': inst_uuid_from_migrations, 'host': CONF.host}
|
||||
attrs = ['info_cache', 'security_groups', 'system_metadata']
|
||||
with utils.temporary_mutation(context, read_deleted='yes'):
|
||||
instances = objects.InstanceList.get_by_filters(
|
||||
context, inst_filters, expected_attrs=attrs, use_slave=True)
|
||||
|
||||
for instance in instances:
|
||||
if instance.host != CONF.host:
|
||||
for migration in migrations:
|
||||
if instance.uuid == migration.instance_uuid:
|
||||
# Delete instance files if not cleanup properly either
|
||||
# from the source or destination compute nodes when
|
||||
# the instance is deleted during resizing.
|
||||
self.driver.delete_instance_files(instance)
|
||||
try:
|
||||
migration.status = 'failed'
|
||||
with migration.obj_as_admin():
|
||||
migration.save()
|
||||
except exception.MigrationNotFound:
|
||||
LOG.warning(_LW("Migration %s is not found."),
|
||||
migration.id, context=context,
|
||||
instance=instance)
|
||||
break
|
||||
for migration in migrations:
|
||||
if instance.uuid == migration.instance_uuid:
|
||||
# Delete instance files if not cleanup properly either
|
||||
# from the source or destination compute nodes when
|
||||
# the instance is deleted during resizing.
|
||||
self.driver.delete_instance_files(instance)
|
||||
try:
|
||||
migration.status = 'failed'
|
||||
with migration.obj_as_admin():
|
||||
migration.save()
|
||||
except exception.MigrationNotFound:
|
||||
LOG.warning(_LW("Migration %s is not found."),
|
||||
migration.id, context=context,
|
||||
instance=instance)
|
||||
break
|
||||
|
||||
@messaging.expected_exceptions(exception.InstanceQuiesceNotSupported,
|
||||
exception.QemuGuestAgentNotEnabled,
|
||||
|
|
|
@ -1569,10 +1569,13 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
# files deletion for those instances whose instance.host is not
|
||||
# same as compute host where periodic task is running.
|
||||
for inst in fake_instances:
|
||||
if inst.host != CONF.host:
|
||||
for mig in fake_migrations:
|
||||
if inst.uuid == mig.instance_uuid:
|
||||
self.assertEqual('failed', mig.status)
|
||||
for mig in fake_migrations:
|
||||
if inst.uuid == mig.instance_uuid:
|
||||
self.assertEqual('failed', mig.status)
|
||||
|
||||
# Make sure we filtered the instances by host in the DB query.
|
||||
self.assertEqual(CONF.host,
|
||||
mock_inst_get_by_filters.call_args[0][1]['host'])
|
||||
|
||||
def test_cleanup_incomplete_migrations_dest_node(self):
|
||||
"""Test to ensure instance files are deleted from destination node.
|
||||
|
|
Loading…
Reference in New Issue