List instances from all cells explicitly

This is a minor refactor with no functional change that will make
the next patch easier. If we're not limiting cell scope during an
instance list, we just let context.scatter_gather_all_cells() load
and use the global list of cells. Since we will want to count
those cells and adjust the batch size, we might as well just always
pass in the list of cells, which will either be a subset or all
of them.

Change-Id: Id167ab6d01698878d783999d54bcf77f37eec020
This commit is contained in:
Dan Smith 2018-08-20 09:16:23 -07:00
parent 0a88916911
commit 7bc6de3f24
2 changed files with 21 additions and 7 deletions

View File

@ -112,7 +112,9 @@ def get_instance_objects_sorted(ctx, filters, limit, marker, expected_attrs,
else:
# Either we are admin, or configured to always hit all cells,
# so don't limit the list to a subset.
cell_mappings = None
context.load_cells()
cell_mappings = context.CELLS
columns_to_join = instance_obj._expected_cols(expected_attrs)
instance_generator = get_instances_sorted(ctx, filters, limit, marker,
columns_to_join, sort_keys,

View File

@ -20,6 +20,8 @@ from nova import test
from nova.tests import fixtures
from nova.tests import uuidsentinel as uuids
FAKE_CELLS = [objects.CellMapping(), objects.CellMapping()]
class TestInstanceList(test.NoDBTestCase):
def setUp(self):
@ -94,10 +96,12 @@ class TestInstanceList(test.NoDBTestCase):
None, None,
cell_mappings=mock_cm.return_value)
@mock.patch('nova.context.CELLS', new=FAKE_CELLS)
@mock.patch('nova.context.load_cells')
@mock.patch('nova.objects.BuildRequestList.get_by_filters')
@mock.patch('nova.compute.instance_list.get_instances_sorted')
@mock.patch('nova.objects.CellMappingList.get_by_project_id')
def test_admin_gets_all_cells(self, mock_cm, mock_gi, mock_br):
def test_admin_gets_all_cells(self, mock_cm, mock_gi, mock_br, mock_lc):
mock_gi.return_value = []
mock_br.return_value = []
admin_context = nova_context.RequestContext('fake', 'fake',
@ -106,13 +110,16 @@ class TestInstanceList(test.NoDBTestCase):
admin_context, {}, None, None, [], None, None)
mock_gi.assert_called_once_with(admin_context, {}, None, None, [],
None, None,
cell_mappings=None)
cell_mappings=FAKE_CELLS)
mock_cm.assert_not_called()
mock_lc.assert_called_once_with()
@mock.patch('nova.context.CELLS', new=FAKE_CELLS)
@mock.patch('nova.context.load_cells')
@mock.patch('nova.objects.BuildRequestList.get_by_filters')
@mock.patch('nova.compute.instance_list.get_instances_sorted')
@mock.patch('nova.objects.CellMappingList.get_by_project_id')
def test_user_gets_all_cells(self, mock_cm, mock_gi, mock_br):
def test_user_gets_all_cells(self, mock_cm, mock_gi, mock_br, mock_lc):
self.flags(instance_list_per_project_cells=False, group='api')
mock_gi.return_value = []
mock_br.return_value = []
@ -121,12 +128,16 @@ class TestInstanceList(test.NoDBTestCase):
user_context, {}, None, None, [], None, None)
mock_gi.assert_called_once_with(user_context, {}, None, None, [],
None, None,
cell_mappings=None)
cell_mappings=FAKE_CELLS)
mock_lc.assert_called_once_with()
@mock.patch('nova.context.CELLS', new=FAKE_CELLS)
@mock.patch('nova.context.load_cells')
@mock.patch('nova.objects.BuildRequestList.get_by_filters')
@mock.patch('nova.compute.instance_list.get_instances_sorted')
@mock.patch('nova.objects.CellMappingList.get_by_project_id')
def test_admin_gets_all_cells_anyway(self, mock_cm, mock_gi, mock_br):
def test_admin_gets_all_cells_anyway(self, mock_cm, mock_gi, mock_br,
mock_lc):
self.flags(instance_list_per_project_cells=True, group='api')
mock_gi.return_value = []
mock_br.return_value = []
@ -136,8 +147,9 @@ class TestInstanceList(test.NoDBTestCase):
admin_context, {}, None, None, [], None, None)
mock_gi.assert_called_once_with(admin_context, {}, None, None, [],
None, None,
cell_mappings=None)
cell_mappings=FAKE_CELLS)
mock_cm.assert_not_called()
mock_lc.assert_called_once_with()
@mock.patch('nova.context.scatter_gather_cells')
def test_get_instances_with_down_cells(self, mock_sg):