Skip to content

Commit 4c866c7

Browse files
fix: adjust block size parsing
fix: remove default value if error in fetch fix: raise an error instead of return default value if block size is not found Signed-off-by: Mathieu Labourier <[email protected]> Co-authored-by: Ronan Abhamon <[email protected]> Signed-off-by: Mathieu Labourier <[email protected]>
1 parent 0ea97f5 commit 4c866c7

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

libs/sm/vhdutil.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,18 @@ def ioretry(cmd, text=True):
9595

9696
def getBlockSize(path):
9797
cmd = [VHD_UTIL, "read", "-pn", path]
98-
try:
99-
ret = ioretry(cmd)
100-
except util.CommandException as e:
101-
util.SMlog("WARN: unable to fetch block size: {}".format(e))
102-
return DEFAULT_VHD_BLOCK_SIZE
98+
ret = ioretry(cmd)
10399
if isinstance(ret, bytes):
104100
import locale
105101
ret = ret.decode(
106102
encoding = locale.getpreferredencoding(False),
107103
errors="replace"
108104
)
109-
fields = ret.strip().split('\n')
110-
for field in fields:
111-
field = field.strip()
105+
for field in ret.split('\n'):
106+
field = field.lstrip()
112107
if not field.startswith("Block size"): continue
113-
return int(field.split(':')[1].strip().split(' ')[0])
114-
return DEFAULT_VHD_BLOCK_SIZE
108+
return int(field.split(':')[1].lstrip().split()[0])
109+
raise util.SMException("Unable to find block size in VHD with path: {}".format(path))
115110

116111

117112
def convertAllocatedSizeToBytes(size, block_size):

0 commit comments

Comments
 (0)