Fix instance not destroyed after successful evacuation
After complete evacuate action, the status of migration will change to 'done' from 'accepted', so the _destroy_evacuated_instances action in old nova-compute should consider the status 'done' to filter migration list when they're back up. Closes-bug: #1518200 Co-Authored-By: Sylvain Bauza <sbauza@redhat.com> Change-Id: Ie4825dcaa778d229922c963a96590ad5a2604257
This commit is contained in:
parent
fc9f0de086
commit
a79ac83bae
|
@ -826,7 +826,7 @@ class ComputeManager(manager.Manager):
|
|||
"""
|
||||
filters = {
|
||||
'source_compute': self.host,
|
||||
'status': 'accepted',
|
||||
'status': ['accepted', 'done'],
|
||||
'migration_type': 'evacuation',
|
||||
}
|
||||
evacuations = objects.MigrationList.get_by_filters(context, filters)
|
||||
|
|
|
@ -4554,7 +4554,9 @@ def migration_get_in_progress_by_host_and_node(context, host, node):
|
|||
def migration_get_all_by_filters(context, filters):
|
||||
query = model_query(context, models.Migration)
|
||||
if "status" in filters:
|
||||
query = query.filter(models.Migration.status == filters["status"])
|
||||
status = filters["status"]
|
||||
status = [status] if isinstance(status, str) else status
|
||||
query = query.filter(models.Migration.status.in_(status))
|
||||
if "host" in filters:
|
||||
host = filters["host"]
|
||||
query = query.filter(or_(models.Migration.source_compute == host,
|
||||
|
|
|
@ -6704,7 +6704,7 @@ class ComputeTestCase(BaseTestCase):
|
|||
self.compute._destroy_evacuated_instances(fake_context)
|
||||
mock_get.assert_called_once_with(fake_context,
|
||||
{'source_compute': self.compute.host,
|
||||
'status': 'accepted',
|
||||
'status': ['accepted', 'done'],
|
||||
'migration_type': 'evacuation'})
|
||||
|
||||
@mock.patch('nova.objects.MigrationList.get_by_filters')
|
||||
|
|
|
@ -2470,6 +2470,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
|
||||
# Only instance 2 has a migration record
|
||||
migration = objects.Migration(instance_uuid=instance_2.uuid)
|
||||
# Consider the migration successful
|
||||
migration.status = 'done'
|
||||
|
||||
with test.nested(
|
||||
mock.patch.object(self.compute, '_get_instances_on_driver',
|
||||
|
|
|
@ -1445,6 +1445,14 @@ class MigrationTestCase(test.TestCase):
|
|||
hosts = [migration['source_compute'], migration['dest_compute']]
|
||||
self.assertIn(filters["host"], hosts)
|
||||
|
||||
def test_get_migrations_by_filters_with_multiple_statuses(self):
|
||||
filters = {"status": ["reverted", "confirmed"],
|
||||
"migration_type": None, "hidden": False}
|
||||
migrations = db.migration_get_all_by_filters(self.ctxt, filters)
|
||||
self.assertEqual(2, len(migrations))
|
||||
for migration in migrations:
|
||||
self.assertIn(migration['status'], filters['status'])
|
||||
|
||||
def test_get_migrations_by_filters_with_type(self):
|
||||
self._create(status="special", source_compute="host9",
|
||||
migration_type="evacuation")
|
||||
|
|
Loading…
Reference in New Issue