def test_user_gets_subset_of_cells(self, mock_cm, mock_gi, mock_br): self.flags(instance_list_per_project_cells=True, group='api') mock_gi.return_value = [] mock_br.return_value = [] user_context = nova_context.RequestContext('fake', 'fake') instance_list.get_instance_objects_sorted( user_context, {}, None, None, [], None, None) mock_gi.assert_called_once_with(user_context, {}, None, None, [], None, None, cell_mappings=mock_cm.return_value)
def test_user_gets_subset_of_cells(self, mock_cm, mock_gi, mock_br): self.flags(instance_list_per_project_cells=True, group='api') mock_gi.return_value = [] mock_br.return_value = [] user_context = nova_context.RequestContext('fake', 'fake') instance_list.get_instance_objects_sorted( user_context, {}, None, None, [], None, None) mock_gi.assert_called_once_with(user_context, {}, None, None, [], None, None, cell_mappings=mock_cm.return_value)
def test_admin_gets_all_cells(self, mock_cm, mock_gi, mock_br): mock_gi.return_value = [] mock_br.return_value = [] admin_context = nova_context.RequestContext('fake', 'fake', is_admin=True) instance_list.get_instance_objects_sorted( admin_context, {}, None, None, [], None, None) mock_gi.assert_called_once_with(admin_context, {}, None, None, [], None, None, cell_mappings=None) mock_cm.assert_not_called()
def test_admin_gets_all_cells(self, mock_cm, mock_gi, mock_br): mock_gi.return_value = [] mock_br.return_value = [] admin_context = nova_context.RequestContext('fake', 'fake', is_admin=True) instance_list.get_instance_objects_sorted( admin_context, {}, None, None, [], None, None) mock_gi.assert_called_once_with(admin_context, {}, None, None, [], None, None, cell_mappings=None) mock_cm.assert_not_called()
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 = [] user_context = nova_context.RequestContext('fake', 'fake') instance_list.get_instance_objects_sorted( user_context, {}, None, None, [], None, None) mock_gi.assert_called_once_with(user_context, {}, None, None, [], None, None, cell_mappings=FAKE_CELLS, batch_size=100) mock_lc.assert_called_once_with()
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 = instance_list.InstanceLister(None, None), [] mock_br.return_value = [] user_context = nova_context.RequestContext('fake', 'fake') instance_list.get_instance_objects_sorted( user_context, {}, None, None, [], None, None) mock_gi.assert_called_once_with(user_context, {}, None, None, [], None, None, cell_mappings=FAKE_CELLS, batch_size=100) mock_lc.assert_called_once_with()
def test_admin_gets_all_cells(self, mock_cm, mock_gi, mock_br, mock_lc): mock_gi.return_value = instance_list.InstanceLister(None, None), [] mock_br.return_value = [] admin_context = nova_context.RequestContext('fake', 'fake', is_admin=True) instance_list.get_instance_objects_sorted( admin_context, {}, None, None, [], None, None) mock_gi.assert_called_once_with(admin_context, {}, None, None, [], None, None, cell_mappings=FAKE_CELLS, batch_size=100) mock_cm.assert_not_called() mock_lc.assert_called_once_with()
def test_get_instance_objects_sorted_paged(self): """Query a full first page and ensure an empty second one. This uses created_at which is enforced to be the same across each instance by setUp(). This will help make sure we still have a stable ordering, even when we only claim to care about created_at. """ instp1 = instance_list.get_instance_objects_sorted( self.context, {}, None, None, [], ['created_at'], ['asc']) self.assertEqual(len(self.instances), len(instp1)) instp2 = instance_list.get_instance_objects_sorted( self.context, {}, None, instp1[-1]['uuid'], [], ['created_at'], ['asc']) self.assertEqual(0, len(instp2))
def test_get_instance_objects_sorted_paged(self): """Query a full first page and ensure an empty second one. This uses created_at which is enforced to be the same across each instance by setUp(). This will help make sure we still have a stable ordering, even when we only claim to care about created_at. """ instp1, down_cell_uuids = instance_list.get_instance_objects_sorted( self.context, {}, None, None, [], ['created_at'], ['asc']) self.assertEqual(len(self.instances), len(instp1)) instp2, down_cell_uuids = instance_list.get_instance_objects_sorted( self.context, {}, None, instp1[-1]['uuid'], [], ['created_at'], ['asc']) self.assertEqual(0, len(instp2))
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 = instance_list.InstanceLister(None, None), [] mock_br.return_value = [] admin_context = nova_context.RequestContext('fake', 'fake', is_admin=True) instance_list.get_instance_objects_sorted( admin_context, {}, None, None, [], None, None) mock_gi.assert_called_once_with(admin_context, {}, None, None, [], None, None, cell_mappings=FAKE_CELLS, batch_size=100, cell_down_support=False) mock_cm.assert_not_called() mock_lc.assert_called_once_with()
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 = instance_list.InstanceLister(None, None), [] mock_br.return_value = [] admin_context = nova_context.RequestContext('fake', 'fake', is_admin=True) instance_list.get_instance_objects_sorted( admin_context, {}, None, None, [], None, None) mock_gi.assert_called_once_with(admin_context, {}, None, None, [], None, None, cell_mappings=FAKE_CELLS, batch_size=100, cell_down_support=False) mock_cm.assert_not_called() mock_lc.assert_called_once_with()
def test_get_instance_objects_sorted(self): filters = {} limit = None marker = None expected_attrs = [] sort_keys = ['uuid'] sort_dirs = ['asc'] insts = instance_list.get_instance_objects_sorted( self.context, filters, limit, marker, expected_attrs, sort_keys, sort_dirs) found_uuids = [x.uuid for x in insts] had_uuids = sorted([x['uuid'] for x in self.instances]) self.assertEqual(had_uuids, found_uuids) # Make sure none of the instances have fault set self.assertEqual(0, len([inst for inst in insts if 'fault' in inst]))
def test_get_instance_objects_sorted_with_fault(self): filters = {} limit = None marker = None expected_attrs = ['fault'] sort_keys = ['uuid'] sort_dirs = ['asc'] insts = instance_list.get_instance_objects_sorted( self.context, filters, limit, marker, expected_attrs, sort_keys, sort_dirs) found_uuids = [x.uuid for x in insts] had_uuids = sorted([x['uuid'] for x in self.instances]) self.assertEqual(had_uuids, found_uuids) # They should all have fault set, but only some have # actual faults self.assertEqual(2, len([inst for inst in insts if inst.fault]))
def test_get_instance_objects_sorted(self): filters = {} limit = None marker = None expected_attrs = [] sort_keys = ['uuid'] sort_dirs = ['asc'] insts, down_cell_uuids = instance_list.get_instance_objects_sorted( self.context, filters, limit, marker, expected_attrs, sort_keys, sort_dirs) found_uuids = [x.uuid for x in insts] had_uuids = sorted([x['uuid'] for x in self.instances]) self.assertEqual(had_uuids, found_uuids) # Make sure none of the instances have fault set self.assertEqual(0, len([inst for inst in insts if 'fault' in inst]))
def test_get_instance_objects_sorted_with_fault(self): filters = {} limit = None marker = None expected_attrs = ['fault'] sort_keys = ['uuid'] sort_dirs = ['asc'] insts, down_cell_uuids = instance_list.get_instance_objects_sorted( self.context, filters, limit, marker, expected_attrs, sort_keys, sort_dirs) found_uuids = [x.uuid for x in insts] had_uuids = sorted([x['uuid'] for x in self.instances]) self.assertEqual(had_uuids, found_uuids) # They should all have fault set, but only some have # actual faults self.assertEqual(2, len([inst for inst in insts if inst.fault]))