class TestBlockVolumeSize(VdsmTestCase): @permutations([ # (preallocate, format, capacity, initial size), # allocation size in bytes # Preallocate, raw, capacity 1 MiB, No initial size. [(sc.PREALLOCATED_VOL, sc.RAW_FORMAT, MiB, None), MiB], # Preallocate, raw, capacity 1 MiB + 1 byte, No initial size. [(sc.PREALLOCATED_VOL, sc.RAW_FORMAT, MiB + 1, None), MiB + 1], # Preallocate, raw, capacity 1 GiB, No initial size. [(sc.PREALLOCATED_VOL, sc.RAW_FORMAT, GiB, None), GiB], # Preallocate, cow, capacity 2 GiB, initial size GiB. # Expected GiB allocated [(sc.PREALLOCATED_VOL, sc.COW_FORMAT, 2 * GiB, GiB), GiB], # Preallocate, cow, capacity 2 GiB, No initial size. # Expected GiB allocated [(sc.PREALLOCATED_VOL, sc.COW_FORMAT, GiB, None), GiB], # Sparse, cow, capacity config.volume_utilization_chunk_mb - 1, # No initial size. # Expected 1024 MiB allocated (config.volume_utilization_chunk_mb) [(sc.SPARSE_VOL, sc.COW_FORMAT, (CONFIG.getint("irs", "volume_utilization_chunk_mb") - 1) * MiB, None), GiB], # Sparse, cow, capacity 4 GiB, initial size 952320 B. [(sc.SPARSE_VOL, sc.COW_FORMAT, 4 * GiB, 952320), int(952320 * blockVolume.QCOW_OVERHEAD_FACTOR)], # Sparse, cow, capacity 4 GiB, initial size 1870. [(sc.SPARSE_VOL, sc.COW_FORMAT, 4 * GiB, 957440), int(957440 * blockVolume.QCOW_OVERHEAD_FACTOR)], # Sparse, cow, capacity 1 GiB, initial size 2359296. [(sc.SPARSE_VOL, sc.COW_FORMAT, GiB, BlockVolume.max_size(GiB, sc.COW_FORMAT)), int( BlockVolume.max_size(GiB, sc.COW_FORMAT) * blockVolume.QCOW_OVERHEAD_FACTOR)], ]) @MonkeyPatch(blockVolume, 'config', CONFIG) def test_block_volume_size(self, args, result): size = BlockVolume.calculate_volume_alloc_size(*args) self.assertEqual(size, result) @permutations([ [sc.PREALLOCATED_VOL, sc.RAW_FORMAT], [sc.PREALLOCATED_VOL, sc.COW_FORMAT], [sc.SPARSE_VOL, sc.COW_FORMAT], ]) def test_fail_invalid_block_volume_size(self, preallocate, vol_format): with self.assertRaises(se.InvalidParameterException): max_size = BlockVolume.max_size(GiB, vol_format) BlockVolume.calculate_volume_alloc_size(preallocate, vol_format, GiB, max_size + 1)
def test_fail_invalid_block_volume_size(self, preallocate): with self.assertRaises(se.InvalidParameterException): max_size = BlockVolume.max_size(GIB, sc.COW_FORMAT) max_size_blk = max_size // sc.BLOCK_SIZE BlockVolume.calculate_volume_alloc_size(preallocate, GIB_IN_SECTORS, max_size_blk + 1)
def test_fail_invalid_block_volume_size(self, preallocate): with self.assertRaises(se.InvalidParameterException): max_size = BlockVolume.max_size(GIB, sc.COW_FORMAT) max_size_blk = max_size // sc.BLOCK_SIZE BlockVolume.calculate_volume_alloc_size(preallocate, GIB_IN_BLOCKS, max_size_blk + 1)
class TestBlockVolumeSize(VdsmTestCase): @permutations([ # (preallocate, capacity, initial size), allocation size in bytes # Preallocate, capacity 1 MiB, No initial size. [(sc.PREALLOCATED_VOL, MEGAB, None), MEGAB], # Preallocate, capacity 1 MiB + 1 byte, No initial size. [(sc.PREALLOCATED_VOL, MEGAB + 1, None), MEGAB + 1], # Preallocate, capacity 1 GiB, No initial size. [(sc.PREALLOCATED_VOL, GIB, None), GIB], # Sparse, capacity config.volume_utilization_chunk_mb - 1, # No initial size. # Expected 1024 Mb allocated (config.volume_utilization_chunk_mb) [(sc.SPARSE_VOL, (config.getint("irs", "volume_utilization_chunk_mb") - 1) * MEGAB, None), GIB], # Sparse, capacity 4 GiB, initial size 952320 B. [(sc.SPARSE_VOL, 4 * GIB, 952320), int(952320 * blockVolume.QCOW_OVERHEAD_FACTOR)], # Sparse, capacity 4 GiB, initial size 1870. [(sc.SPARSE_VOL, 4 * GIB, 957440), int(957440 * blockVolume.QCOW_OVERHEAD_FACTOR)], # Sparse, capacity 1 GiB, initial size 2359296. [(sc.SPARSE_VOL, GIB, BlockVolume.max_size(GIB, sc.COW_FORMAT)), int( BlockVolume.max_size(GIB, sc.COW_FORMAT) * blockVolume.QCOW_OVERHEAD_FACTOR)], ]) def test_block_volume_size(self, args, result): size = BlockVolume.calculate_volume_alloc_size(*args) self.assertEqual(size, result) @permutations( # preallocate [ [sc.PREALLOCATED_VOL], [sc.SPARSE_VOL], ]) def test_fail_invalid_block_volume_size(self, preallocate): with self.assertRaises(se.InvalidParameterException): max_size = BlockVolume.max_size(GIB, sc.COW_FORMAT) BlockVolume.calculate_volume_alloc_size(preallocate, GIB, max_size + 1)
class TestBlockVolumeSize(VdsmTestCase): @permutations([ # (preallocate, capacity in blocks, initial size in blocks), # allocation size in MB # Preallocate, capacity 2048 blocks, No initial size. # Expected 1 Mb allocated [(sc.PREALLOCATED_VOL, 2048, None), 1], # Preallocate, capacity 2049 blocks, No initial size. # Expected 2 Mb allocated [(sc.PREALLOCATED_VOL, 2049, None), 2], # Preallocate, capacity 2097152 blocks, No initial size. # Expected 1024 Mb allocated [(sc.PREALLOCATED_VOL, 2097152, None), 1024], # Sparse, capacity 9999 blocks, No initial size. # Expected 1024 Mb allocated [(sc.SPARSE_VOL, 9999, None), config.getint("irs", "volume_utilization_chunk_mb")], # Sparse, capacity 8388608 blocks, initial size 1860. # Expected 1 Mb allocated [(sc.SPARSE_VOL, 8388608, 1860), 1], # Sparse, capacity 8388608 blocks, initial size 1870. # Expected 2 Mb allocated [(sc.SPARSE_VOL, 8388608, 1870), 2], # Sparse, capacity 2097152 blocks, initial size 2359296. # Expected 1268 Mb allocated [(sc.SPARSE_VOL, GIB_IN_BLOCKS, BlockVolume.max_size(GIB, sc.COW_FORMAT) // sc.BLOCK_SIZE), 1268], ]) def test_block_volume_size(self, args, result): size = BlockVolume.calculate_volume_alloc_size(*args) self.assertEqual(size, result) @permutations( # preallocate [[sc.PREALLOCATED_VOL], [sc.SPARSE_VOL], ]) def test_fail_invalid_block_volume_size(self, preallocate): with self.assertRaises(se.InvalidParameterException): max_size = BlockVolume.max_size(GIB, sc.COW_FORMAT) max_size_blk = max_size // sc.BLOCK_SIZE BlockVolume.calculate_volume_alloc_size(preallocate, GIB_IN_BLOCKS, max_size_blk + 1)
def test_max_size_cow(self): # verify that max size equals to virtual size with estimated cow # overhead, aligned to vg extent size. self.assertEqual(BlockVolume.max_size(10 * GIB, sc.COW_FORMAT), 11811160064)
def test_max_size_raw(self): # verify that max size equals to virtual size. self.assertEqual(BlockVolume.max_size(1 * GIB, sc.RAW_FORMAT), 1 * GIB)
def test_fail_invalid_block_volume_size(self, preallocate): with self.assertRaises(se.InvalidParameterException): max_size = BlockVolume.max_size(GIB, sc.COW_FORMAT) BlockVolume.calculate_volume_alloc_size(preallocate, GIB, max_size + 1)
def test_max_size_cow(self): # verify that max size equals to virtual size with estimated cow # overhead, aligned to vg extent size. self.assertEqual(BlockVolume.max_size(10 * GIB, sc.COW_FORMAT), 11811160064)
def test_max_size_raw(self): # verify that max size equals to virtual size. self.assertEqual(BlockVolume.max_size(1 * GIB, sc.RAW_FORMAT), 1 * GIB)
def test_fail_invalid_block_volume_size(self, preallocate, vol_format): with self.assertRaises(se.InvalidParameterException): max_size = BlockVolume.max_size(GiB, vol_format) BlockVolume.calculate_volume_alloc_size(preallocate, vol_format, GiB, max_size + 1)