From 00e46a313c45a7e5676476d453230fe0cdc89342 Mon Sep 17 00:00:00 2001 From: Andrew Laski Date: Wed, 10 Aug 2016 15:04:31 -0400 Subject: [PATCH] Fix migration list + MigrationList operation Fixes up the get_migrations cells method and corresponding tests. The tests were not in line with reality since the MigrationList object was introduced. This patch removes the [] + MigrationList operation that was occurring since the operation is poorly defined and only works by accident. Future objects work may break this so it should be removed now. Change-Id: I5dabd8c745cc287322a1ef0f0dd2d4733484188d --- nova/cells/manager.py | 6 ++++-- nova/tests/unit/cells/test_cells_manager.py | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/nova/cells/manager.py b/nova/cells/manager.py index d335e549b513..38fab22668bd 100644 --- a/nova/cells/manager.py +++ b/nova/cells/manager.py @@ -452,8 +452,10 @@ class CellsManager(manager.Manager): False, filters) migrations = [] for response in responses: - migrations += response.value_or_raise() - return migrations + # response.value_or_raise returns MigrationList objects. + # MigrationList.objects returns the list of Migration objects. + migrations.extend(response.value_or_raise().objects) + return objects.MigrationList(objects=migrations) def instance_update_from_api(self, ctxt, instance, expected_vm_state, expected_task_state, admin_state_reset): diff --git a/nova/tests/unit/cells/test_cells_manager.py b/nova/tests/unit/cells/test_cells_manager.py index 2dec56413b6b..287faf4cdc0e 100644 --- a/nova/tests/unit/cells/test_cells_manager.py +++ b/nova/tests/unit/cells/test_cells_manager.py @@ -652,8 +652,10 @@ class CellsManagerClassTestCase(test.NoDBTestCase): def test_get_migrations(self): filters = {'status': 'confirmed'} - cell1_migrations = [{'id': 123}] - cell2_migrations = [{'id': 456}] + cell1_migrations = objects.MigrationList( + objects=[objects.Migration(id=123)]) + cell2_migrations = objects.MigrationList( + objects=[objects.Migration(id=456)]) fake_responses = [self._get_fake_response(cell1_migrations), self._get_fake_response(cell2_migrations)] self.mox.StubOutWithMock(self.msg_runner, @@ -664,12 +666,13 @@ class CellsManagerClassTestCase(test.NoDBTestCase): response = self.cells_manager.get_migrations(self.ctxt, filters) - self.assertEqual([cell1_migrations[0], cell2_migrations[0]], response) + self.assertEqual(cell1_migrations.objects + cell2_migrations.objects, + response.objects) def test_get_migrations_for_a_given_cell(self): filters = {'status': 'confirmed', 'cell_name': 'ChildCell1'} target_cell = '%s%s%s' % (CONF.cells.name, '!', filters['cell_name']) - migrations = [{'id': 123}] + migrations = objects.MigrationList(objects=[objects.Migration(id=123)]) fake_responses = [self._get_fake_response(migrations)] self.mox.StubOutWithMock(self.msg_runner, 'get_migrations') @@ -678,7 +681,7 @@ class CellsManagerClassTestCase(test.NoDBTestCase): self.mox.ReplayAll() response = self.cells_manager.get_migrations(self.ctxt, filters) - self.assertEqual(migrations, response) + self.assertEqual(migrations.objects, response.objects) def test_instance_update_from_api(self): self.mox.StubOutWithMock(self.msg_runner,