diff --git a/nova/compute/api.py b/nova/compute/api.py index fd887ceb5798..cf0adfaf1a77 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -2451,10 +2451,21 @@ class API(base.Base): # instance lists should be proxied to project Searchlight, or a similar # alternative. if limit is None or limit > 0: - cell_instances = self._get_instances_by_filters_all_cells( - context, filters, - limit=limit, marker=marker, expected_attrs=expected_attrs, - sort_keys=sort_keys, sort_dirs=sort_dirs) + if not CONF.cells.enable: + cell_instances = self._get_instances_by_filters_all_cells( + context, filters, + limit=limit, marker=marker, + expected_attrs=expected_attrs, sort_keys=sort_keys, + sort_dirs=sort_dirs) + else: + # NOTE(melwitt): If we're on cells v1, we need to read + # instances from the top-level database because reading from + # cells results in changed behavior, because of the syncing. + # We can remove this path once we stop supporting cells v1. + cell_instances = self._get_instances_by_filters( + context, filters, limit=limit, marker=marker, + expected_attrs=expected_attrs, sort_keys=sort_keys, + sort_dirs=sort_dirs) else: LOG.debug('Limit excludes any results from real cells') cell_instances = objects.InstanceList(objects=[]) diff --git a/nova/tests/unit/compute/test_compute_api.py b/nova/tests/unit/compute/test_compute_api.py index 6997d0e55ba6..c962ad2ea645 100644 --- a/nova/tests/unit/compute/test_compute_api.py +++ b/nova/tests/unit/compute/test_compute_api.py @@ -4533,8 +4533,9 @@ class _ComputeAPIUnitTestMixIn(object): limit=10, marker='fake-marker', sort_keys=['baz'], sort_dirs=['desc']) - for cm in mock_cm_get_all.return_value: - mock_target_cell.assert_any_call(self.context, cm) + if self.cell_type is None: + for cm in mock_cm_get_all.return_value: + mock_target_cell.assert_any_call(self.context, cm) inst_get_calls = [mock.call(self.context, {'foo': 'bar'}, limit=10, marker='fake-marker', expected_attrs=None, sort_keys=['baz'], @@ -4588,8 +4589,9 @@ class _ComputeAPIUnitTestMixIn(object): limit=10, marker='fake-marker', sort_keys=['baz'], sort_dirs=['desc']) - for cm in mock_cm_get_all.return_value: - mock_target_cell.assert_any_call(self.context, cm) + if self.cell_type is None: + for cm in mock_cm_get_all.return_value: + mock_target_cell.assert_any_call(self.context, cm) inst_get_calls = [mock.call(self.context, {'foo': 'bar'}, limit=8, marker='fake-marker', expected_attrs=None, sort_keys=['baz'], @@ -4644,8 +4646,9 @@ class _ComputeAPIUnitTestMixIn(object): limit=10, marker=marker, sort_keys=['baz'], sort_dirs=['desc']) - for cm in mock_cm_get_all.return_value: - mock_target_cell.assert_any_call(self.context, cm) + if self.cell_type is None: + for cm in mock_cm_get_all.return_value: + mock_target_cell.assert_any_call(self.context, cm) inst_get_calls = [mock.call(self.context, {'foo': 'bar'}, limit=10, marker=marker, expected_attrs=None, sort_keys=['baz'],