Allow querying for migrations by source_compute only
The existing filtering only allows source-or-dest querying, and for evacuate we want to look for things only *from* our host. Related to blueprint robustify-evacuate Change-Id: I05dbc71e969bcb8f64e6aa3b979cc0ffc75c1205
This commit is contained in:
@@ -4444,6 +4444,9 @@ def migration_get_all_by_filters(context, filters):
|
||||
host = filters["host"]
|
||||
query = query.filter(or_(models.Migration.source_compute == host,
|
||||
models.Migration.dest_compute == host))
|
||||
elif "source_compute" in filters:
|
||||
host = filters['source_compute']
|
||||
query = query.filter(models.Migration.source_compute == host)
|
||||
if "migration_type" in filters:
|
||||
migtype = filters["migration_type"]
|
||||
query = query.filter(models.Migration.migration_type == migtype)
|
||||
|
||||
@@ -1291,6 +1291,15 @@ class MigrationTestCase(test.TestCase):
|
||||
hosts = [migration['source_compute'], migration['dest_compute']]
|
||||
self.assertIn(filters["host"], hosts)
|
||||
|
||||
def test_get_migrations_by_filters_source_compute(self):
|
||||
filters = {'source_compute': 'host2'}
|
||||
migrations = db.migration_get_all_by_filters(self.ctxt, filters)
|
||||
self.assertEqual(2, len(migrations))
|
||||
sources = [x['source_compute'] for x in migrations]
|
||||
self.assertEqual(['host2', 'host2'], sources)
|
||||
dests = [x['dest_compute'] for x in migrations]
|
||||
self.assertEqual(['host1', 'host3'], dests)
|
||||
|
||||
def test_migration_get_unconfirmed_by_dest_compute(self):
|
||||
# Ensure no migrations are returned.
|
||||
results = db.migration_get_unconfirmed_by_dest_compute(self.ctxt, 10,
|
||||
|
||||
Reference in New Issue
Block a user