Skip to content

Commit 0ea97f5

Browse files
refactor: rename VHD_BLOCK_SIZE to DEFAULT_VHD_BLOCK_SIZE
Signed-off-by: Mathieu Labourier <mathieu.labourier@vates.tech>
1 parent fc386a4 commit 0ea97f5

5 files changed

Lines changed: 15 additions & 15 deletions

File tree

libs/sm/drivers/FileSR.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def create(self, sr_uuid, vdi_uuid, size):
563563
try:
564564
size = vhdutil.validate_and_round_vhd_size(
565565
int(size),
566-
vhdutil.VHD_BLOCK_SIZE
566+
vhdutil.DEFAULT_VHD_BLOCK_SIZE
567567
)
568568
mb = 1024 * 1024
569569
size_mb = size // mb

libs/sm/drivers/LVHDSR.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ def create(self, sr_uuid, vdi_uuid, size):
13511351

13521352
size = vhdutil.validate_and_round_vhd_size(
13531353
int(size),
1354-
vhdutil.VHD_BLOCK_SIZE
1354+
vhdutil.DEFAULT_VHD_BLOCK_SIZE
13551355
)
13561356

13571357
util.SMlog("LVHDVDI.create: type = %s, %s (size=%s)" % \
@@ -1367,7 +1367,7 @@ def create(self, sr_uuid, vdi_uuid, size):
13671367
elif self.sr.provision == "thick":
13681368
lvSize = lvhdutil.calcSizeVHDLV(
13691369
int(size),
1370-
vhdutil.VHD_BLOCK_SIZE
1370+
vhdutil.DEFAULT_VHD_BLOCK_SIZE
13711371
)
13721372

13731373
self.sr._ensureSpaceAvailable(lvSize)

libs/sm/vhdutil.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
MAX_CHAIN_SIZE = 30 # max VHD parent chain size
3131
VHD_UTIL = "/usr/bin/vhd-util"
3232
OPT_LOG_ERR = "--debug"
33-
VHD_BLOCK_SIZE = 2 * 1024 * 1024
33+
DEFAULT_VHD_BLOCK_SIZE = 2 * 1024 * 1024
3434
VHD_FOOTER_SIZE = 512
3535

3636
# lock to lock the entire SR for short ops
@@ -99,7 +99,7 @@ def getBlockSize(path):
9999
ret = ioretry(cmd)
100100
except util.CommandException as e:
101101
util.SMlog("WARN: unable to fetch block size: {}".format(e))
102-
return VHD_BLOCK_SIZE
102+
return DEFAULT_VHD_BLOCK_SIZE
103103
if isinstance(ret, bytes):
104104
import locale
105105
ret = ret.decode(
@@ -111,7 +111,7 @@ def getBlockSize(path):
111111
field = field.strip()
112112
if not field.startswith("Block size"): continue
113113
return int(field.split(':')[1].strip().split(' ')[0])
114-
return VHD_BLOCK_SIZE
114+
return DEFAULT_VHD_BLOCK_SIZE
115115

116116

117117
def convertAllocatedSizeToBytes(size, block_size):

tests/test_FileSR.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def test_create_vdi_vhd(self, mock_vhdutil):
327327
vdi = FakeFileVDI(sr, vdi_uuid)
328328
vdi.vdi_type = vhdutil.VDI_TYPE_VHD
329329
mock_vhdutil.validate_and_round_vhd_size.side_effect = vhdutil.validate_and_round_vhd_size
330-
mock_vhdutil.VHD_BLOCK_SIZE = 2 * 1024 * 1024
330+
mock_vhdutil.DEFAULT_VHD_BLOCK_SIZE = vhdutil.DEFAULT_VHD_BLOCK_SIZE
331331

332332
# Act
333333
vdi.create(sr_uuid, vdi_uuid, 20 * 1024 * 1024)

tests/test_vhdutil.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,35 @@ class TestVhdUtil(unittest.TestCase):
2222
def test_validate_and_round_min_size(self):
2323
size = vhdutil.validate_and_round_vhd_size(
2424
2 * 1024 * 1024,
25-
vhdutil.VHD_BLOCK_SIZE
25+
vhdutil.DEFAULT_VHD_BLOCK_SIZE
2626
)
2727

2828
self.assertTrue(size == 2 * 1024 * 1024)
2929

3030
def test_validate_and_round_max_size(self):
3131
size = vhdutil.validate_and_round_vhd_size(
3232
vhdutil.MAX_VHD_SIZE,
33-
vhdutil.VHD_BLOCK_SIZE
33+
vhdutil.DEFAULT_VHD_BLOCK_SIZE
3434
)
3535

3636
self.assertTrue(size == vhdutil.MAX_VHD_SIZE)
3737

3838
def test_validate_and_round_odd_size_up_to_next_boundary(self):
3939
size = vhdutil.validate_and_round_vhd_size(
4040
vhdutil.MAX_VHD_SIZE - 1,
41-
vhdutil.VHD_BLOCK_SIZE)
41+
vhdutil.DEFAULT_VHD_BLOCK_SIZE)
4242

4343
self.assertTrue(size == vhdutil.MAX_VHD_SIZE)
4444

4545
def test_validate_and_round_negative(self):
4646
with self.assertRaises(xs_errors.SROSError):
47-
vhdutil.validate_and_round_vhd_size(-1, vhdutil.VHD_BLOCK_SIZE)
47+
vhdutil.validate_and_round_vhd_size(-1, vhdutil.DEFAULT_VHD_BLOCK_SIZE)
4848

4949
def test_validate_and_round_too_large(self):
5050
with self.assertRaises(xs_errors.SROSError):
5151
vhdutil.validate_and_round_vhd_size(
5252
vhdutil.MAX_VHD_SIZE + 1,
53-
vhdutil.VHD_BLOCK_SIZE
53+
vhdutil.DEFAULT_VHD_BLOCK_SIZE
5454
)
5555

5656
@testlib.with_context
@@ -78,7 +78,7 @@ def test_calc_overhead_bitmap_round_blocks(self, context):
7878

7979
result = vhdutil.calcOverheadBitmap(
8080
virtual_size,
81-
vhdutil.VHD_BLOCK_SIZE
81+
vhdutil.DEFAULT_VHD_BLOCK_SIZE
8282
)
8383

8484
self.assertEqual(49152, result)
@@ -88,7 +88,7 @@ def test_calc_overhead_bitmap_extra_block(self, context):
8888

8989
result = vhdutil.calcOverheadBitmap(
9090
virtual_size,
91-
vhdutil.VHD_BLOCK_SIZE
91+
vhdutil.DEFAULT_VHD_BLOCK_SIZE
9292
)
9393

9494
self.assertEqual(53248, result)
@@ -416,7 +416,7 @@ def test_function(args, inp):
416416
result = 0
417417
with unittest.mock.patch(
418418
"sm.vhdutil.getBlockSize",
419-
return_value=vhdutil.VHD_BLOCK_SIZE
419+
return_value=vhdutil.DEFAULT_VHD_BLOCK_SIZE
420420
):
421421
result = vhdutil.getAllocatedSize(TEST_VHD_NAME)
422422

0 commit comments

Comments
 (0)