Read instances from API cell for cells v1

Recent work on cells v2 has us reading instances from compute cells
via target_cell, but that breaks the existing behavior of cells v1
because of the syncing between API cell and compute cells. When
state changes are effected in the API cell, there is a slight delay
before they are reflected in the compute cell. So, reading from the
compute cell instead of the API cell results in behavior changes.

This adds a conditional in compute/api get_all to read instances
from the API cell if cells v1 is enabled. We are already doing this
for compute/api get, and get_all was missed.

Closes-Bug: #1660747

Change-Id: I7df5c4616ef386216c7bd7efea2be68173c61be0
This commit is contained in:
melanie witt 2017-01-31 20:20:17 +00:00
parent 91b4a56bc5
commit 826df45a40
2 changed files with 24 additions and 10 deletions

View File

@ -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=[])

View File

@ -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'],