def get_instance_objects_sorted(ctx, filters, limit, marker, expected_attrs, sort_keys, sort_dirs): """Same as above, but return an InstanceList.""" query_cell_subset = CONF.api.instance_list_per_project_cells # NOTE(danms): Replicated in part from instance_get_all_by_sort_filters(), # where if we're not admin we're restricted to our context's project if query_cell_subset and not ctx.is_admin: # We are not admin, and configured to only query the subset of cells # we could possibly have instances in. cell_mappings = objects.CellMappingList.get_by_project_id( ctx, ctx.project_id) else: # Either we are admin, or configured to always hit all cells, # so don't limit the list to a subset. context.load_cells() cell_mappings = context.CELLS batch_size = get_instance_list_cells_batch_size(limit, cell_mappings) columns_to_join = instance_obj._expected_cols(expected_attrs) instance_generator = get_instances_sorted(ctx, filters, limit, marker, columns_to_join, sort_keys, sort_dirs, cell_mappings=cell_mappings, batch_size=batch_size) if 'fault' in expected_attrs: # We join fault above, so we need to make sure we don't ask # make_instance_list to do it again for us expected_attrs = copy.copy(expected_attrs) expected_attrs.remove('fault') return instance_obj._make_instance_list(ctx, objects.InstanceList(), instance_generator, expected_attrs)
def test_service_get_all_cells_with_minimal_constructs(self, mock_sg, mock_get_hm, mock_cm_list): service = objects.Service(binary='nova-compute', host='host-%s' % uuids.cell0) cells = [ objects.CellMapping(uuid=uuids.cell1, id=1), objects.CellMapping(uuid=uuids.cell2, id=2), ] mock_cm_list.return_value = cells context.load_cells() # create two hms in cell1, which is the down cell in this test. hm1 = objects.HostMapping(self.ctxt, host='host1-unavailable', cell_mapping=cells[0]) hm1.create() hm2 = objects.HostMapping(self.ctxt, host='host2-unavailable', cell_mapping=cells[0]) hm2.create() mock_sg.return_value = { cells[0].uuid: [service], cells[1].uuid: context.did_not_respond_sentinel, } mock_get_hm.return_value = [hm1, hm2] services = self.host_api.service_get_all(self.ctxt, all_cells=True, cell_down_support=True) # returns the results from cell0 and minimal construct from cell1. self.assertEqual(sorted(['host-%s' % uuids.cell0, 'host1-unavailable', 'host2-unavailable']), sorted([svc.host for svc in services])) mock_sg.assert_called_once_with(self.ctxt, objects.ServiceList.get_all, None, set_zones=False) mock_get_hm.assert_called_once_with(self.ctxt, cells[1].id)
def test_service_get_all_cells_with_minimal_constructs(self, mock_sg, mock_get_hm, mock_cm_list): service = objects.Service(binary='nova-compute', host='host-%s' % uuids.cell0) cells = [ objects.CellMapping(uuid=uuids.cell1, id=1), objects.CellMapping(uuid=uuids.cell2, id=2), ] mock_cm_list.return_value = cells context.load_cells() # create two hms in cell1, which is the down cell in this test. hm1 = objects.HostMapping(self.ctxt, host='host1-unavailable', cell_mapping=cells[0]) hm1.create() hm2 = objects.HostMapping(self.ctxt, host='host2-unavailable', cell_mapping=cells[0]) hm2.create() mock_sg.return_value = { cells[0].uuid: [service], cells[1].uuid: context.did_not_respond_sentinel, } mock_get_hm.return_value = [hm1, hm2] services = self.host_api.service_get_all(self.ctxt, all_cells=True, cell_down_support=True) # returns the results from cell0 and minimal construct from cell1. self.assertEqual(sorted(['host-%s' % uuids.cell0, 'host1-unavailable', 'host2-unavailable']), sorted([svc.host for svc in services])) mock_sg.assert_called_once_with(self.ctxt, objects.ServiceList.get_all, None, set_zones=False) mock_get_hm.assert_called_once_with(self.ctxt, cells[1].id)
def get_instance_objects_sorted(ctx, filters, limit, marker, expected_attrs, sort_keys, sort_dirs, cell_down_support=False): """Return a list of instances and information about down cells. This returns a tuple of (objects.InstanceList, list(of down cell uuids) for the requested operation. The instances returned are those that were collected from the cells that responded. The uuids of any cells that did not respond (or raised an error) are included in the list as the second element of the tuple. That list is empty if all cells responded. """ query_cell_subset = CONF.api.instance_list_per_project_cells # NOTE(danms): Replicated in part from instance_get_all_by_sort_filters(), # where if we're not admin we're restricted to our context's project if query_cell_subset and not ctx.is_admin: # We are not admin, and configured to only query the subset of cells # we could possibly have instances in. cell_mappings = objects.CellMappingList.get_by_project_id( ctx, ctx.project_id) else: # Either we are admin, or configured to always hit all cells, # so don't limit the list to a subset. context.load_cells() cell_mappings = context.CELLS batch_size = get_instance_list_cells_batch_size(limit, cell_mappings) columns_to_join = instance_obj._expected_cols(expected_attrs) instance_lister, instance_generator = get_instances_sorted( ctx, filters, limit, marker, columns_to_join, sort_keys, sort_dirs, cell_mappings=cell_mappings, batch_size=batch_size, cell_down_support=cell_down_support) if 'fault' in expected_attrs: # We join fault above, so we need to make sure we don't ask # make_instance_list to do it again for us expected_attrs = copy.copy(expected_attrs) expected_attrs.remove('fault') instance_list = instance_obj._make_instance_list(ctx, objects.InstanceList(), instance_generator, expected_attrs) down_cell_uuids = (instance_lister.cells_failed + instance_lister.cells_timed_out) return instance_list, down_cell_uuids
def get_instance_objects_sorted(ctx, filters, limit, marker, expected_attrs, sort_keys, sort_dirs): """Return a list of instances and information about down cells. This returns a tuple of (objects.InstanceList, list(of down cell uuids) for the requested operation. The instances returned are those that were collected from the cells that responded. The uuids of any cells that did not respond (or raised an error) are included in the list as the second element of the tuple. That list is empty if all cells responded. """ query_cell_subset = CONF.api.instance_list_per_project_cells # NOTE(danms): Replicated in part from instance_get_all_by_sort_filters(), # where if we're not admin we're restricted to our context's project if query_cell_subset and not ctx.is_admin: # We are not admin, and configured to only query the subset of cells # we could possibly have instances in. cell_mappings = objects.CellMappingList.get_by_project_id( ctx, ctx.project_id) else: # Either we are admin, or configured to always hit all cells, # so don't limit the list to a subset. context.load_cells() cell_mappings = context.CELLS batch_size = get_instance_list_cells_batch_size(limit, cell_mappings) columns_to_join = instance_obj._expected_cols(expected_attrs) instance_lister, instance_generator = get_instances_sorted(ctx, filters, limit, marker, columns_to_join, sort_keys, sort_dirs, cell_mappings=cell_mappings, batch_size=batch_size) if 'fault' in expected_attrs: # We join fault above, so we need to make sure we don't ask # make_instance_list to do it again for us expected_attrs = copy.copy(expected_attrs) expected_attrs.remove('fault') instance_list = instance_obj._make_instance_list(ctx, objects.InstanceList(), instance_generator, expected_attrs) down_cell_uuids = (instance_lister.cells_failed + instance_lister.cells_timed_out) return instance_list, down_cell_uuids
def get_instance_objects_sorted(ctx, filters, limit, marker, expected_attrs, sort_keys, sort_dirs): """Same as above, but return an InstanceList.""" query_cell_subset = CONF.api.instance_list_per_project_cells # NOTE(danms): Replicated in part from instance_get_all_by_sort_filters(), # where if we're not admin we're restricted to our context's project if query_cell_subset and not ctx.is_admin: # We are not admin, and configured to only query the subset of cells # we could possibly have instances in. cell_mappings = objects.CellMappingList.get_by_project_id( ctx, ctx.project_id) else: # Either we are admin, or configured to always hit all cells, # so don't limit the list to a subset. context.load_cells() cell_mappings = context.CELLS batch_size = get_instance_list_cells_batch_size(limit, cell_mappings) columns_to_join = instance_obj._expected_cols(expected_attrs) instance_generator = get_instances_sorted(ctx, filters, limit, marker, columns_to_join, sort_keys, sort_dirs, cell_mappings=cell_mappings, batch_size=batch_size) if 'fault' in expected_attrs: # We join fault above, so we need to make sure we don't ask # make_instance_list to do it again for us expected_attrs = copy.copy(expected_attrs) expected_attrs.remove('fault') return instance_obj._make_instance_list(ctx, objects.InstanceList(), instance_generator, expected_attrs)