Skip to content

Commit e484193

Browse files
committed
repair pipeline
Signed-off-by: Ronan Abhamon <[email protected]>
1 parent d75879f commit e484193

File tree

7 files changed

+36
-28
lines changed

7 files changed

+36
-28
lines changed

drivers/LinstorSR.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
import xmlrpc.client
5757
import xs_errors
5858

59-
from cowutil import getCowUtil, getVdiTypeFromImageFormat
59+
from cowutil import getVdiTypeFromImageFormat
6060
from srmetadata import \
6161
NAME_LABEL_TAG, NAME_DESCRIPTION_TAG, IS_A_SNAPSHOT_TAG, SNAPSHOT_OF_TAG, \
6262
TYPE_TAG, VDI_TYPE_TAG, READ_ONLY_TAG, SNAPSHOT_TIME_TAG, \
@@ -156,7 +156,7 @@ def attach_thin(session, journaler, linstor, sr_uuid, vdi_uuid):
156156

157157
device_path = linstor.get_device_path(vdi_uuid)
158158

159-
linstorcowutil = LinstorCowUtil(session, linstor, getCowUtil(vdi_type))
159+
linstorcowutil = LinstorCowUtil(session, linstor, vdi_type)
160160

161161
# If the virtual COW size is lower than the LINSTOR volume size,
162162
# there is nothing to do.
@@ -201,7 +201,7 @@ def check_vbd_count():
201201
util.retry(check_vbd_count, maxretry=10, period=1)
202202

203203
device_path = linstor.get_device_path(vdi_uuid)
204-
linstorcowutil = LinstorCowUtil(session, linstor, getCowUtil(vdi_type))
204+
linstorcowutil = LinstorCowUtil(session, linstor, vdi_type)
205205
new_volume_size = LinstorVolumeManager.round_up_volume_size(
206206
# TODO: Replace pylint comment with this feature when possible:
207207
# https://github.com/PyCQA/pylint/pull/2926
@@ -1162,7 +1162,7 @@ def _load_vdis_ex(self):
11621162
if not VdiType.isCowImage(vdi_type):
11631163
managed = not volume_metadata.get(HIDDEN_TAG)
11641164
else:
1165-
image_info = LinstorCowUtil(self.session, self._linstor, getCowUtil(vdi_type)).get_info(vdi_uuid)
1165+
image_info = LinstorCowUtil(self.session, self._linstor, vdi_type).get_info(vdi_uuid)
11661166
managed = not image_info.hidden
11671167
if image_info.parentUuid:
11681168
sm_config['vhd-parent'] = image_info.parentUuid
@@ -1303,7 +1303,7 @@ def _get_vdi_path_and_parent(self, vdi_uuid, volume_name):
13031303
return (device_path, None)
13041304

13051305
# Otherwise it's a COW and a parent can exist.
1306-
linstorcowutil = LinstorCowUtil(self.session, self._linstor, getCowUtil(vdi_type))
1306+
linstorcowutil = LinstorCowUtil(self.session, self._linstor, vdi_type)
13071307
if linstorcowutil.check(vdi_uuid) != cowutil.CheckResult.Success:
13081308
return (None, None)
13091309

@@ -1419,7 +1419,7 @@ def _undo_clone(self, volume_names, vdi_uuid, base_uuid, snap_uuid):
14191419
util.SMlog('*** INTERRUPTED CLONE OP: rollback fail')
14201420
return
14211421

1422-
linstorcowutil = LinstorCowUtil(self.session, self._linstor, getCowUtil(base_type))
1422+
linstorcowutil = LinstorCowUtil(self.session, self._linstor, base_type)
14231423

14241424
# Un-hide the parent.
14251425
self._linstor.update_volume_metadata(base_uuid, {READ_ONLY_TAG: False})
@@ -1468,7 +1468,8 @@ def _undo_clone(self, volume_names, vdi_uuid, base_uuid, snap_uuid):
14681468
# Inflate to the right size.
14691469
if VdiType.isCowImage(base_type):
14701470
vdi = self.vdi(vdi_uuid)
1471-
volume_size = linstorcowutil.compute_volume_size(vdi.size, vdi.vdi_type)
1471+
linstorcowutil = LinstorCowUtil(self.session, self._linstor, vdi.vdi_type)
1472+
volume_size = linstorcowutil.compute_volume_size(vdi.size)
14721473
linstorcowutil.inflate(
14731474
self._journaler, vdi_uuid, vdi.path,
14741475
volume_size, vdi.capacity
@@ -1667,7 +1668,7 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
16671668

16681669
# 2. Compute size and check space available.
16691670
size = self.linstorcowutil.cowutil.validateAndRoundImageSize(int(size))
1670-
volume_size = self.linstorcowutil.compute_volume_size(size, self.vdi_type)
1671+
volume_size = self.linstorcowutil.compute_volume_size(size)
16711672
util.SMlog(
16721673
'LinstorVDI.create: type={}, cow-size={}, volume-size={}'
16731674
.format(self.vdi_type, size, volume_size)
@@ -1831,7 +1832,7 @@ def attach(self, sr_uuid, vdi_uuid) -> str:
18311832
if (
18321833
not VdiType.isCowImage(self.vdi_type) or
18331834
not writable or
1834-
self.capacity >= self.linstorcowutil.compute_volume_size(self.size, self.vdi_type)
1835+
self.capacity >= self.linstorcowutil.compute_volume_size(self.size)
18351836
):
18361837
need_inflate = False
18371838

@@ -1876,7 +1877,7 @@ def detach(self, sr_uuid, vdi_uuid) -> None:
18761877

18771878
# The VDI is already deflated if the COW image size + metadata is
18781879
# equal to the LINSTOR volume size.
1879-
volume_size = self.linstorcowutil.compute_volume_size(self.size, self.vdi_type)
1880+
volume_size = self.linstorcowutil.compute_volume_size(self.size)
18801881
already_deflated = self.capacity <= volume_size
18811882

18821883
if already_deflated:
@@ -1939,7 +1940,7 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
19391940

19401941
# Compute the virtual COW and DRBD volume size.
19411942
size = self.linstorcowutil.cowutil.validateAndRoundImageSize(int(size))
1942-
volume_size = self.linstorcowutil.compute_volume_size(size, self.vdi_type)
1943+
volume_size = self.linstorcowutil.compute_volume_size(size)
19431944
util.SMlog(
19441945
'LinstorVDI.resize: type={}, cow-size={}, volume-size={}'
19451946
.format(self.vdi_type, size, volume_size)
@@ -1964,7 +1965,7 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
19641965
# VDI is currently deflated, so keep it deflated.
19651966
new_volume_size = old_volume_size
19661967
else:
1967-
new_volume_size = self.linstorcowutil.compute_volume_size(size, self.vdi_type)
1968+
new_volume_size = self.linstorcowutil.compute_volume_size(size)
19681969
assert new_volume_size >= old_volume_size
19691970

19701971
space_needed = new_volume_size - old_volume_size

drivers/cleanup.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Script to coalesce and garbage collect COW-based SR's in the background
1919
#
2020

21-
from sm_typing import Optional, override
21+
from sm_typing import Any, Optional, override
2222

2323
import os
2424
import os.path
@@ -1528,7 +1528,7 @@ def load(self, info=None) -> None:
15281528

15291529
self.fileName = self.sr._linstor.get_volume_name(self.uuid)
15301530
self.path = self.sr._linstor.build_device_path(self.fileName)
1531-
self.linstorcowutil = LinstorCowUtil(self.xapi.session, self.sr._linstor, self.cowutil)
1531+
self.linstorcowutil = LinstorCowUtil(self.sr.xapi.session, self.sr._linstor, self.cowutil)
15321532

15331533
if not info:
15341534
try:
@@ -1597,7 +1597,7 @@ def deflate(self):
15971597

15981598
def inflateFully(self):
15991599
if VdiType.isCowImage(self.vdi_type):
1600-
self.inflate(linstorcowutil.compute_volume_size(self.sizeVirt, self.vdi_type))
1600+
self.inflate(self.linstorcowutil.compute_volume_size(self.sizeVirt))
16011601

16021602
@override
16031603
def rename(self, uuid) -> None:
@@ -1786,7 +1786,7 @@ def _setSizeVirt(self, size) -> None:
17861786
jfile, self.cowutil.getResizeJournalSize(), persistent=False, volume_name=jfile
17871787
)
17881788
try:
1789-
self.inflate(linstorcowutil.compute_volume_size(size, self.vdi_type))
1789+
self.inflate(self.linstorcowutil.compute_volume_size(size))
17901790
self.linstorcowutil.set_size_virt(size, jfile)
17911791
finally:
17921792
try:
@@ -1810,9 +1810,7 @@ def _inflateParentForCoalesce(self):
18101810
def _calcExtraSpaceForCoalescing(self) -> int:
18111811
if not VdiType.isCowImage(self.parent.vdi_type):
18121812
return 0
1813-
size_coalesced = linstorcowutil.compute_volume_size(
1814-
self._getCoalescedSizeData(), self.vdi_type
1815-
)
1813+
size_coalesced = self.linstorcowutil.compute_volume_size(self._getCoalescedSizeData())
18161814
Util.log("Coalesced size = %s" % Util.num2str(size_coalesced))
18171815
return size_coalesced - self.parent.getDrbdSize()
18181816

@@ -3447,7 +3445,9 @@ def _finishCoalesceLeaf(self, parent) -> None:
34473445

34483446
@override
34493447
def _calcExtraSpaceNeeded(self, child, parent) -> int:
3450-
return linstorcowutil.compute_volume_size(parent.sizeVirt, parent.vdi_type) - parent.getDrbdSize()
3448+
return LinstorCowUtil(
3449+
self.xapi.session, self._linstor, parent.vdi_type
3450+
).compute_volume_size(parent.sizeVirt) - parent.getDrbdSize()
34513451

34523452
def _hasValidDevicePath(self, uuid):
34533453
try:

drivers/cowutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def check(
243243
path: str,
244244
ignoreMissingFooter: Optional[bool] = False,
245245
fast: Optional[bool] = False
246-
) -> CheckResult:
246+
) -> CowUtil.CheckResult:
247247
pass
248248

249249
@abstractmethod

drivers/linstorcowutil.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,17 @@ def _force_deflate(self, cowutil_inst, path, newSize, oldSize, zeroize):
404404
# Helpers.
405405
# --------------------------------------------------------------------------
406406

407-
def compute_volume_size(cls, virtual_size: int) -> int:
408-
if VdiType.isCowImage(vdi_type):
407+
def compute_volume_size(self, virtual_size: int) -> int:
408+
if VdiType.isCowImage(self._vdi_type):
409409
# All LINSTOR VDIs have the metadata area preallocated for
410410
# the maximum possible virtual size (for fast online VDI.resize).
411-
meta_overhead = self._cowutil.calcOverheadEmpty(self.MAX_SIZE) # TODO: getDefaultPreallocaqatio... + max
411+
meta_overhead = self._cowutil.calcOverheadEmpty(
412+
max(virtual_size, self._cowutil.getDefaultPreallocationSizeVirt())
413+
)
412414
bitmap_overhead = self._cowutil.calcOverheadBitmap(virtual_size)
413415
virtual_size += meta_overhead + bitmap_overhead
414416
else:
415-
raise Exception('Invalid image type: {}'.format(vdi_type))
417+
raise Exception('Invalid image type: {}'.format(self._vdi_type))
416418

417419
return LinstorVolumeManager.round_up_volume_size(virtual_size)
418420

drivers/lvmcowutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import lock
2929
import util
30-
import XenAPI
30+
import XenAPI # pylint: disable=import-error
3131

3232
from constants import NS_PREFIX_LVM, VG_LOCATION, VG_PREFIX
3333
from cowutil import CowImageInfo, CowUtil, getCowUtil

mocks/XenAPI/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import six.moves.xmlrpc_client as xmlrpclib
2+
13
class Failure(Exception):
24
def __init__(self, details):
35
self.details = details
@@ -6,5 +8,6 @@ def xapi_local():
68
# Mock stub
79
pass
810

9-
class Session(object):
10-
pass
11+
class Session(xmlrpclib.ServerProxy):
12+
def __getattr__(self, name):
13+
pass

tests/test_vhdutil.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from sm_typing import override
12

23
import unittest
34
import zlib
@@ -15,6 +16,7 @@
1516

1617

1718
class TestVhdUtil(unittest.TestCase):
19+
@override
1820
def setUp(self):
1921
self.vhdutil = vhdutil.VhdUtil()
2022

0 commit comments

Comments
 (0)