diff options
author | Jenkins <jenkins@review.openstack.org> | 2017-10-12 12:07:23 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2017-10-12 12:07:23 +0000 |
commit | 783c42905782dfba9f74cb919b82defa71249523 (patch) | |
tree | d1f7c5c85f16ac56dc42917f593850d8595cedb5 /nova/tests/unit/test_context.py | |
parent | 0445422217da71098dffb67f8403f7d7b0648837 (diff) | |
parent | 3cc3cc453dc16e22365bea597c1be5bb0be57aeb (diff) | |
download | nova-783c42905782dfba9f74cb919b82defa71249523.tar.gz |
Merge "Fix target_cell usage for scatter_gather_cells"
Diffstat (limited to 'nova/tests/unit/test_context.py')
-rw-r--r-- | nova/tests/unit/test_context.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/nova/tests/unit/test_context.py b/nova/tests/unit/test_context.py index e0191e1be9..724e6202b6 100644 --- a/nova/tests/unit/test_context.py +++ b/nova/tests/unit/test_context.py @@ -309,21 +309,35 @@ class ContextTestCase(test.NoDBTestCase): @mock.patch('nova.context.target_cell') @mock.patch('nova.objects.InstanceList.get_by_filters') def test_scatter_gather_cells(self, mock_get_inst, mock_target_cell): - self.useFixture(nova_fixtures.SpawnIsSynchronousFixture()) ctxt = context.get_context() mapping = objects.CellMapping(database_connection='fake://db', transport_url='fake://mq', uuid=uuids.cell) mappings = objects.CellMappingList(objects=[mapping]) + # Use a mock manager to assert call order across mocks. + manager = mock.Mock() + manager.attach_mock(mock_get_inst, 'get_inst') + manager.attach_mock(mock_target_cell, 'target_cell') + filters = {'deleted': False} context.scatter_gather_cells( ctxt, mappings, 60, objects.InstanceList.get_by_filters, filters, sort_dir='foo') - mock_get_inst.assert_called_once_with( + # NOTE(melwitt): This only works without the SpawnIsSynchronous fixture + # because when the spawn is treated as synchronous and the thread + # function is called immediately, it will occur inside the target_cell + # context manager scope when it wouldn't with a real spawn. + + # Assert that InstanceList.get_by_filters was called before the + # target_cell context manager exited. + get_inst_call = mock.call.get_inst( mock_target_cell.return_value.__enter__.return_value, filters, sort_dir='foo') + expected_calls = [get_inst_call, + mock.call.target_cell().__exit__(None, None, None)] + manager.assert_has_calls(expected_calls) @mock.patch('nova.context.LOG.warning') @mock.patch('eventlet.timeout.Timeout') |