def test_wrapper_sentinels(self): inst1 = {'key0': 'foo', 'key1': 'd', 'key2': 456} ctx = context.RequestContext() ctx.cell_uuid = uuids.cell sort_ctx = multi_cell_list.RecordSortContext(['key0', 'key1'], ['asc', 'asc']) iw1 = multi_cell_list.RecordWrapper(ctx, sort_ctx, inst1) # Wrappers with sentinels iw2 = multi_cell_list.RecordWrapper(ctx, sort_ctx, context.did_not_respond_sentinel) iw3 = multi_cell_list.RecordWrapper(ctx, sort_ctx, context.raised_exception_sentinel) # NOTE(danms): The sentinel wrappers always win self.assertTrue(iw2 < iw1) self.assertTrue(iw3 < iw1) self.assertFalse(iw1 < iw2) self.assertFalse(iw1 < iw3) # NOTE(danms): Comparing two wrappers with sentinels will always return # True for less-than because we're just naive about always favoring the # left hand side. This is fine for our purposes but put it here to make # it explicit. self.assertTrue(iw2 < iw3) self.assertTrue(iw3 < iw2)
def test_wrapper(self): inst1 = {'key0': 'foo', 'key1': 'd', 'key2': 456} inst2 = {'key0': 'foo', 'key1': 's', 'key2': 123} ctx = context.RequestContext() ctx.cell_uuid = uuids.cell # Should sort by key1 sort_ctx = multi_cell_list.RecordSortContext(['key0', 'key1'], ['asc', 'asc']) iw1 = multi_cell_list.RecordWrapper(ctx, sort_ctx, inst1) iw2 = multi_cell_list.RecordWrapper(ctx, sort_ctx, inst2) # Check this both ways to make sure we're comparing against -1 # and not just nonzero return from cmp() self.assertTrue(iw1 < iw2) self.assertFalse(iw2 < iw1) # Should sort reverse by key1 sort_ctx = multi_cell_list.RecordSortContext(['key0', 'key1'], ['asc', 'desc']) iw1 = multi_cell_list.RecordWrapper(ctx, sort_ctx, inst1) iw2 = multi_cell_list.RecordWrapper(ctx, sort_ctx, inst2) # Check this both ways to make sure we're comparing against -1 # and not just nonzero return from cmp() self.assertTrue(iw1 > iw2) self.assertFalse(iw2 > iw1) # Make sure we can tell which cell a request came from self.assertEqual(uuids.cell, iw1.cell_uuid)
def test_wrapper(self): inst1 = {'key0': 'foo', 'key1': 'd', 'key2': 456} inst2 = {'key0': 'foo', 'key1': 's', 'key2': 123} # Should sort by key1 ctx = multi_cell_list.RecordSortContext(['key0', 'key1'], ['asc', 'asc']) iw1 = multi_cell_list.RecordWrapper(ctx, inst1) iw2 = multi_cell_list.RecordWrapper(ctx, inst2) # Check this both ways to make sure we're comparing against -1 # and not just nonzero return from cmp() self.assertTrue(iw1 < iw2) self.assertFalse(iw2 < iw1) # Should sort reverse by key1 ctx = multi_cell_list.RecordSortContext(['key0', 'key1'], ['asc', 'desc']) iw1 = multi_cell_list.RecordWrapper(ctx, inst1) iw2 = multi_cell_list.RecordWrapper(ctx, inst2) # Check this both ways to make sure we're comparing against -1 # and not just nonzero return from cmp() self.assertTrue(iw1 > iw2) self.assertFalse(iw2 > iw1)
def test_get_instances_with_down_cells(self, mock_sg): inst_cell0 = self.insts[uuids.cell0] # storing the uuids of the instances from the up cell uuid_initial = [inst['uuid'] for inst in inst_cell0] instances = (multi_cell_list.RecordWrapper(self.context, inst) for inst in inst_cell0) # creating one up cell and two down cells ret_val = {} ret_val[uuids.cell0] = instances ret_val[uuids.cell1] = nova_context.raised_exception_sentinel ret_val[uuids.cell2] = nova_context.did_not_respond_sentinel mock_sg.return_value = ret_val res = instance_list.get_instances_sorted(self.context, {}, None, None, [], None, None) uuid_final = [inst['uuid'] for inst in res] # return the results from the up cell, ignoring the down cell. self.assertEqual(uuid_initial, uuid_final)
def wrap(thing): return multi_cell_list.RecordWrapper(ctx, self.context, thing)