def test_new_invalid(self): with self.assertRaises(ValueError): block_index = BlockIndex('01234') with self.assertRaises(ValueError): block_index = BlockIndex('012') with self.assertRaises(ValueError): block_index = BlockIndex(i='01', j='345')
def test_new(self): block_index = BlockIndex('1234') self.assertEqual(self.block_index, block_index) block_index = BlockIndex('12', '34') self.assertEqual(self.block_index, block_index) block_index = BlockIndex(i='12', j='34') self.assertEqual(self.block_index, block_index)
def setUp(self): self.block_group_id = BlockGroupID('g000640000000123') self.block_id = BlockID( 'd1g0006300000001230101idc000c62d8736c72800020000000001') self.block_index = BlockIndex('1234') self.drive_id = DriveID('idc000' '1122334455660001')
def test_is_ec_block(self): idc_idx = 0 ec_blk_idxes = ['0000', '0001', '0005'] replica_blk_idxes = ['0002', '0008', '0012'] bg = self.make_test_block_group(ec_blk_idxes + replica_blk_idxes) with self.assertRaises(BlockNotFoundError): gid = 'g000640000000123' bid = BlockID('dp', gid, '0001', DriveID('idc000' 'ab2d8736c7280002'), 0) bg.is_ec_block(bid) act_ec_blk_idxes = [] nr_data, nr_parity = bg['config']['in_idc'] for i in range(0, nr_data + nr_parity): bi = BlockIndex(idc_idx, i) blk = bg.get_block(bi) if blk is None: continue if bg.is_ec_block(blk['block_id']): act_ec_blk_idxes.append(bi) self.assertListEqual(ec_blk_idxes, act_ec_blk_idxes)
def make_test_block_group(self, blk_idxes, config=None): gid = 'g000640000000123' base_blk = BlockDesc({ 'size': 1000, 'range': ['0a', '0b'], 'is_del': 0 }) if config is None: config = _ec_config num_idcs = sum(config['cross_idc']) idcs = ['idc' + (str(i).rjust(3, '0')) for i in range(num_idcs)] bg = BlockGroup(block_group_id=gid, idcs=idcs, config=config) for i, bi in enumerate(blk_idxes): bi = BlockIndex(bi) typ = bg.get_block_type(bi) drive_id = DriveID(idcs[int(bi[0])] + 'c62d8736c7280002') blkid = BlockID(typ, gid, bi, drive_id, i) blk = copy.deepcopy(base_blk) blk['block_id'] = blkid bg.add_block(blk) return bg
def test_new(self): cases = ( ('0000', (0, 0)), ('0001', (0, 1)), ('0101', (1, 1)), ('1234', (12, 34)), (BlockIndex(12, 34), (12, 34)), ) for inp, expected in cases: dd(inp) dd(expected) rst = ectypes.BlockIndex(inp) self.assertEqual(expected, rst.as_tuple()) self.assertEqual(str(inp), str(rst))