Merge "Remove old-style cell v1 instance listing"

This commit is contained in:
Zuul 2019-04-18 19:39:53 +00:00 committed by Gerrit Code Review
commit b7a018f126
2 changed files with 15 additions and 282 deletions

View File

@ -2744,14 +2744,9 @@ class API(base.Base):
if expected_attrs:
fields.extend(expected_attrs)
if CONF.cells.enable:
insts = self._do_old_style_instance_list_for_poor_cellsv1_users(
context, filters, limit, marker, fields, sort_keys,
sort_dirs)
else:
insts, down_cell_uuids = instance_list.get_instance_objects_sorted(
context, filters, limit, marker, fields, sort_keys, sort_dirs,
cell_down_support=cell_down_support)
insts, down_cell_uuids = instance_list.get_instance_objects_sorted(
context, filters, limit, marker, fields, sort_keys, sort_dirs,
cell_down_support=cell_down_support)
def _get_unique_filter_method():
seen_uuids = set()
@ -2793,51 +2788,6 @@ class API(base.Base):
return instances
def _do_old_style_instance_list_for_poor_cellsv1_users(self,
context, filters,
limit, marker,
fields,
sort_keys,
sort_dirs):
try:
cell0_mapping = objects.CellMapping.get_by_uuid(context,
objects.CellMapping.CELL0_UUID)
except exception.CellMappingNotFound:
cell0_instances = objects.InstanceList(objects=[])
else:
with nova_context.target_cell(context, cell0_mapping) as cctxt:
try:
cell0_instances = self._get_instances_by_filters(
cctxt, filters, limit=limit, marker=marker,
fields=fields, sort_keys=sort_keys,
sort_dirs=sort_dirs)
# If we found the marker in cell0 we need to set it to None
# so we don't expect to find it in the cells below.
marker = None
except exception.MarkerNotFound:
# We can ignore this since we need to look in the cell DB
cell0_instances = objects.InstanceList(objects=[])
# Only subtract from limit if it is not None
limit = (limit - len(cell0_instances)) if limit else limit
# There is only planned support for a single cell here. Multiple cell
# instance lists should be proxied to project Searchlight, or a similar
# alternative.
if limit is None or limit > 0:
# 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,
fields=fields, sort_keys=sort_keys,
sort_dirs=sort_dirs)
else:
LOG.debug('Limit excludes any results from real cells')
cell_instances = objects.InstanceList(objects=[])
return cell0_instances + cell_instances
@staticmethod
def _ip_filter(inst_models, filters, limit):
ipv4_f = re.compile(str(filters.get('ip')))

View File

@ -6854,240 +6854,23 @@ class ComputeAPIUnitTestCase(_ComputeAPIUnitTestMixIn, test.NoDBTestCase):
class Cellsv1DeprecatedTestMixIn(object):
@mock.patch.object(objects.BuildRequestList, 'get_by_filters')
@mock.patch.object(objects.CellMapping, 'get_by_uuid',
side_effect=exception.CellMappingNotFound(uuid='fake'))
def test_get_all_includes_build_requests(self, mock_cell_mapping_get,
mock_buildreq_get):
def test_get_all_build_requests_decrement_limit(self):
self.skipTest("Removing cells v1")
build_req_instances = self._list_of_instances(2)
build_reqs = [objects.BuildRequest(self.context, instance=instance)
for instance in build_req_instances]
mock_buildreq_get.return_value = objects.BuildRequestList(self.context,
objects=build_reqs)
def test_get_all_cell0_marker_not_found(self):
self.skipTest("Removing cells v1")
cell_instances = self._list_of_instances(2)
def test_get_all_includes_build_request_cell0(self):
self.skipTest("Removing cells v1")
with mock.patch.object(self.compute_api,
'_get_instances_by_filters') as mock_inst_get:
mock_inst_get.return_value = objects.InstanceList(
self.context, objects=cell_instances)
def test_get_all_includes_build_requests(self):
self.skipTest("Removing cells v1")
instances = self.compute_api.get_all(
self.context, search_opts={'foo': 'bar'},
limit=None, marker='fake-marker', sort_keys=['baz'],
sort_dirs=['desc'])
def test_get_all_includes_build_requests_filter_dupes(self):
self.skipTest("Removing cells v1")
mock_buildreq_get.assert_called_once_with(
self.context, {'foo': 'bar'}, limit=None, marker='fake-marker',
sort_keys=['baz'], sort_dirs=['desc'])
fields = ['metadata', 'info_cache', 'security_groups']
mock_inst_get.assert_called_once_with(
self.context, {'foo': 'bar'}, limit=None, marker=None,
fields=fields, sort_keys=['baz'], sort_dirs=['desc'])
for i, instance in enumerate(build_req_instances + cell_instances):
self.assertEqual(instance, instances[i])
@mock.patch.object(objects.BuildRequestList, 'get_by_filters')
@mock.patch.object(objects.CellMapping, 'get_by_uuid',
side_effect=exception.CellMappingNotFound(uuid='fake'))
def test_get_all_includes_build_requests_filter_dupes(self,
mock_cell_mapping_get, mock_buildreq_get):
build_req_instances = self._list_of_instances(2)
build_reqs = [objects.BuildRequest(self.context, instance=instance)
for instance in build_req_instances]
mock_buildreq_get.return_value = objects.BuildRequestList(self.context,
objects=build_reqs)
cell_instances = self._list_of_instances(2)
with mock.patch.object(self.compute_api,
'_get_instances_by_filters') as mock_inst_get:
# Insert one of the build_req_instances here so it shows up twice
mock_inst_get.return_value = objects.InstanceList(
self.context, objects=build_req_instances[:1] + cell_instances)
instances = self.compute_api.get_all(
self.context, search_opts={'foo': 'bar'},
limit=None, marker='fake-marker', sort_keys=['baz'],
sort_dirs=['desc'])
mock_buildreq_get.assert_called_once_with(
self.context, {'foo': 'bar'}, limit=None, marker='fake-marker',
sort_keys=['baz'], sort_dirs=['desc'])
fields = ['metadata', 'info_cache', 'security_groups']
mock_inst_get.assert_called_once_with(
self.context, {'foo': 'bar'}, limit=None, marker=None,
fields=fields, sort_keys=['baz'], sort_dirs=['desc'])
for i, instance in enumerate(build_req_instances + cell_instances):
self.assertEqual(instance, instances[i])
@mock.patch.object(objects.BuildRequestList, 'get_by_filters')
@mock.patch.object(objects.CellMapping, 'get_by_uuid',
side_effect=exception.CellMappingNotFound(uuid='fake'))
def test_get_all_build_requests_decrement_limit(self,
mock_cell_mapping_get,
mock_buildreq_get):
build_req_instances = self._list_of_instances(2)
build_reqs = [objects.BuildRequest(self.context, instance=instance)
for instance in build_req_instances]
mock_buildreq_get.return_value = objects.BuildRequestList(self.context,
objects=build_reqs)
cell_instances = self._list_of_instances(2)
with mock.patch.object(self.compute_api,
'_get_instances_by_filters') as mock_inst_get:
mock_inst_get.return_value = objects.InstanceList(
self.context, objects=cell_instances)
instances = self.compute_api.get_all(
self.context, search_opts={'foo': 'bar'},
limit=10, marker='fake-marker', sort_keys=['baz'],
sort_dirs=['desc'])
mock_buildreq_get.assert_called_once_with(
self.context, {'foo': 'bar'}, limit=10, marker='fake-marker',
sort_keys=['baz'], sort_dirs=['desc'])
fields = ['metadata', 'info_cache', 'security_groups']
mock_inst_get.assert_called_once_with(
self.context, {'foo': 'bar'}, limit=8, marker=None,
fields=fields, sort_keys=['baz'], sort_dirs=['desc'])
for i, instance in enumerate(build_req_instances + cell_instances):
self.assertEqual(instance, instances[i])
@mock.patch.object(context, 'target_cell')
@mock.patch.object(objects.BuildRequestList, 'get_by_filters')
@mock.patch.object(objects.CellMapping, 'get_by_uuid')
@mock.patch.object(objects.CellMappingList, 'get_all')
def test_get_all_includes_build_request_cell0(self, mock_cm_get_all,
mock_cell_mapping_get,
mock_buildreq_get, mock_target_cell):
build_req_instances = self._list_of_instances(2)
build_reqs = [objects.BuildRequest(self.context, instance=instance)
for instance in build_req_instances]
mock_buildreq_get.return_value = objects.BuildRequestList(self.context,
objects=build_reqs)
cell0_instances = self._list_of_instances(2)
cell_instances = self._list_of_instances(2)
cell_mapping = objects.CellMapping(uuid=objects.CellMapping.CELL0_UUID,
name='0')
mock_cell_mapping_get.return_value = cell_mapping
mock_cm_get_all.return_value = [
cell_mapping,
objects.CellMapping(uuid=uuids.cell1, name='1'),
]
cctxt = mock_target_cell.return_value.__enter__.return_value
with mock.patch.object(self.compute_api,
'_get_instances_by_filters') as mock_inst_get:
mock_inst_get.side_effect = [objects.InstanceList(
self.context,
objects=cell0_instances),
objects.InstanceList(
self.context,
objects=cell_instances)]
instances = self.compute_api.get_all(
self.context, search_opts={'foo': 'bar'},
limit=10, marker='fake-marker', sort_keys=['baz'],
sort_dirs=['desc'])
if self.cell_type is None:
for cm in mock_cm_get_all.return_value:
mock_target_cell.assert_any_call(self.context, cm)
fields = ['metadata', 'info_cache', 'security_groups']
inst_get_calls = [mock.call(cctxt, {'foo': 'bar'},
limit=8, marker=None,
fields=fields, sort_keys=['baz'],
sort_dirs=['desc']),
mock.call(mock.ANY, {'foo': 'bar'},
limit=6, marker=None,
fields=fields, sort_keys=['baz'],
sort_dirs=['desc'])
]
self.assertEqual(2, mock_inst_get.call_count)
mock_inst_get.assert_has_calls(inst_get_calls)
for i, instance in enumerate(build_req_instances +
cell0_instances +
cell_instances):
self.assertEqual(instance, instances[i])
@mock.patch.object(objects.BuildRequestList, 'get_by_filters')
@mock.patch.object(compute_api.API, '_get_instances_by_filters')
@mock.patch.object(objects.CellMapping, 'get_by_uuid')
def test_tenant_to_project_conversion(self, mock_cell_map_get, mock_get,
mock_buildreq_get):
mock_cell_map_get.side_effect = exception.CellMappingNotFound(
uuid='fake')
mock_get.return_value = objects.InstanceList(objects=[])
api = compute_api.API()
api.get_all(self.context, search_opts={'tenant_id': 'foo'})
filters = mock_get.call_args_list[0][0][1]
self.assertEqual({'project_id': 'foo'}, filters)
@mock.patch.object(context, 'target_cell')
@mock.patch.object(objects.BuildRequestList, 'get_by_filters',
side_effect=exception.MarkerNotFound(
marker=uuids.marker))
@mock.patch.object(objects.CellMapping, 'get_by_uuid')
@mock.patch.object(objects.CellMappingList, 'get_all')
def test_get_all_cell0_marker_not_found(self, mock_cm_get_all,
mock_cell_mapping_get,
mock_buildreq_get,
mock_target_cell):
"""Tests that we handle a MarkerNotFound raised from the cell0 database
and continue looking for instances from the normal cell database.
"""
cell_instances = self._list_of_instances(2)
cell_mapping = objects.CellMapping(uuid=objects.CellMapping.CELL0_UUID,
name='0')
mock_cell_mapping_get.return_value = cell_mapping
mock_cm_get_all.return_value = [
cell_mapping,
objects.CellMapping(uuid=uuids.cell1, name='1'),
]
marker = uuids.marker
cctxt = mock_target_cell.return_value.__enter__.return_value
with mock.patch.object(self.compute_api,
'_get_instances_by_filters') as mock_inst_get:
# simulate calling _get_instances_by_filters twice, once for cell0
# which raises a MarkerNotFound and once from the cell DB which
# returns two instances
mock_inst_get.side_effect = [
exception.MarkerNotFound(marker=marker),
objects.InstanceList(self.context, objects=cell_instances)]
instances = self.compute_api.get_all(
self.context, search_opts={'foo': 'bar'},
limit=10, marker=marker, sort_keys=['baz'],
sort_dirs=['desc'])
if self.cell_type is None:
for cm in mock_cm_get_all.return_value:
mock_target_cell.assert_any_call(self.context, cm)
fields = ['metadata', 'info_cache', 'security_groups']
inst_get_calls = [mock.call(cctxt, {'foo': 'bar'},
limit=10, marker=marker,
fields=fields, sort_keys=['baz'],
sort_dirs=['desc']),
mock.call(mock.ANY, {'foo': 'bar'},
limit=10, marker=marker,
fields=fields, sort_keys=['baz'],
sort_dirs=['desc'])
]
self.assertEqual(2, mock_inst_get.call_count)
mock_inst_get.assert_has_calls(inst_get_calls)
for i, instance in enumerate(cell_instances):
self.assertEqual(instance, instances[i])
def test_tenant_to_project_conversion(self):
self.skipTest("Removing cells v1")
def test_get_all_with_cell_down_support(self):
self.skipTest("Cell down handling is not supported for cells_v1.")