Skip to content

Commit 9cd804f

Browse files
committed
Fix unit tests with QCOW2 changes
Also add a fix to have phy vdi_type giving a raw cowutil We also needed to patch pathlib.Path before any os.* Signed-off-by: Damien Thenot <damien.thenot@vates.tech>
1 parent 2a51cfa commit 9cd804f

8 files changed

Lines changed: 24 additions & 8 deletions

File tree

drivers/blktap2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,7 @@ def _get_vdi_chain(self, cowutil, extractUuid) -> List[str]:
16861686
def _check_journal_coalesce_chain(self, sr_uuid: str, vdi_uuid: str) -> bool:
16871687
vdi_type = self.target.get_vdi_type()
16881688
cowutil = getCowUtil(vdi_type)
1689+
16891690
if not cowutil.isCoalesceableOnRemote(): #We only need to stop the coalesce in case of QCOW2
16901691
return True
16911692

drivers/cleanup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,7 @@ def _setChainRo(self, was_ro: List[str]) -> None:
14981498
@override
14991499
def _doCoalesce(self) -> None:
15001500
"""LVMVDI parents must first be activated, inflated, and made writable"""
1501+
was_ro = []
15011502
try:
15021503
self._activateChain()
15031504
self.sr.lvmCache.setReadonly(self.parent.fileName, False)

drivers/cowutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def _ioretry(cmd: Sequence[str], text: bool = True) -> Union[str, bytes]:
315315
# ------------------------------------------------------------------------------
316316

317317
def getImageFormatFromVdiType(vdi_type: str) -> ImageFormat:
318-
if vdi_type == VdiType.RAW:
318+
if vdi_type == VdiType.RAW or vdi_type == VdiType.PHY:
319319
return ImageFormat.RAW
320320
if vdi_type == VdiType.VHD:
321321
return ImageFormat.VHD

drivers/vditype.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# TODO: Use StrEnum in python 3.11.
2020
class VdiType(object):
2121
RAW = "aio"
22+
PHY = "phy"
2223
VHD = "vhd"
2324
QCOW2 = "qcow2"
2425
ISO = "iso"

tests/test_FileSR.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def setUp(self) -> None:
4949
endlog_patcher = mock.patch('FileSR.util.end_log_entry',
5050
autospec=True)
5151
self.mock_endlog = endlog_patcher.start()
52+
pathlib_path_patcher = mock.patch("pathlib.Path", autospec=True)
53+
self.mock_pathlib_path = pathlib_path_patcher.start()
5254
os_link_patcher = mock.patch('FileSR.os.link', autospec=True)
5355
self.mock_os_link = os_link_patcher.start()
5456
os_stat_patcher = mock.patch('FileSR.os.stat')
@@ -385,7 +387,10 @@ def test_vdi_load_vhd(self, mock_chdir, mock_pathexists):
385387
srcmd.cmd = "vdi_create"
386388
srcmd.dconf = {}
387389
srcmd.params = {
388-
'command': 'vdi_create'
390+
'command': 'vdi_create',
391+
'vdi_sm_config': {
392+
'image-format': 'vhd'
393+
},
389394
}
390395
sr = FakeSharedFileSR(srcmd, sr_uuid)
391396
vdi = FileSR.FileVDI(sr, vdi_uuid)

tests/test_blktap2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ def test_linknbd(self, nbd_link2, nbd_link):
197197
@mock.patch('blktap2.VDI.BackendLink', autospec=True)
198198
@mock.patch('blktap2.VDI.NBDLink', autospec=True)
199199
@mock.patch('blktap2.Tapdisk')
200-
def test_activate(self, mock_tapdisk, mock_nbd_link, mock_backend,
200+
@mock.patch('blktap2.VDI._check_journal_coalesce_chain', autospec=True)
201+
def test_activate(self, mock_checkjournalcoalesce, mock_tapdisk, mock_nbd_link, mock_backend,
201202
mock_phy, mock_attach,
202203
mock_this_host, mock_sleep):
203204
"""

tests/test_cleanup.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,8 +1487,9 @@ def add_vdis_for_coalesce(self, sr):
14871487
@mock.patch('vhdutil.VhdUtil')
14881488
@mock.patch('cleanup.journaler.Journaler', autospec=True)
14891489
@mock.patch('cleanup.Util.runAbortable')
1490+
@mock.patch('cleanup.SR._create_running_file', autospec=True)
14901491
def test_coalesce_success(
1491-
self, mock_abortable, mock_journaler, mock_vhdutil, mock_util,
1492+
self, mock_create_running_file, mock_abortable, mock_journaler, mock_vhdutil, mock_util,
14921493
mock_unlink):
14931494
"""
14941495
Non-leaf coalesce
@@ -1497,6 +1498,7 @@ def test_coalesce_success(
14971498

14981499
mock_abortable.side_effect = self.runAbortable
14991500
mock_vhdutil.return_value.check.return_value = cowutil.CowUtil.CheckResult.Success
1501+
mock_vhdutil.return_value.isCoalesceableOnRemote.return_value = False
15001502

15011503
sr_uuid = uuid4()
15021504
sr = create_cleanup_sr(self.xapi_mock, uuid=str(sr_uuid))
@@ -1537,8 +1539,9 @@ def test_coalesce_success(
15371539
@mock.patch('vhdutil.VhdUtil')
15381540
@mock.patch('cleanup.journaler.Journaler', autospec=True)
15391541
@mock.patch('cleanup.Util.runAbortable')
1542+
@mock.patch('cleanup.SR._create_running_file', autospec=True)
15401543
def test_coalesce_error(
1541-
self, mock_abortable, mock_journaler, mock_vhdutil, mock_util,
1544+
self, mock_running_file, mock_abortable, mock_journaler, mock_vhdutil, mock_util,
15421545
mock_unlink):
15431546
"""
15441547
Handle errors in coalesce
@@ -1548,6 +1551,7 @@ def test_coalesce_error(
15481551

15491552
self.xapi_mock.getConfigVDI.return_value = {}
15501553

1554+
15511555
def run_abortable(func, ret, ns, abortTest, pollInterval, timeOut):
15521556
raise util.SMException("Timed out")
15531557

@@ -1565,6 +1569,7 @@ def run_abortable(func, ret, ns, abortTest, pollInterval, timeOut):
15651569
mock_journaler.get.return_value = None
15661570

15671571
mock_vhdutil.return_value.getParent.return_value = vdis['parent'].path
1572+
mock_vhdutil.return_value.isCoalesceableOnRemote.return_value = False
15681573

15691574
sr.coalesce(vdis['vdi'], False)
15701575

@@ -1576,8 +1581,9 @@ def run_abortable(func, ret, ns, abortTest, pollInterval, timeOut):
15761581
@mock.patch('vhdutil.VhdUtil')
15771582
@mock.patch('cleanup.journaler.Journaler', autospec=True)
15781583
@mock.patch('cleanup.Util.runAbortable')
1584+
@mock.patch('cleanup.SR._create_running_file', autospec=True)
15791585
def test_coalesce_error_raw_parent(
1580-
self, mock_abortable, mock_journaler, mock_vhdutil, mock_util,
1586+
self, mock_create_running_file, mock_abortable, mock_journaler, mock_vhdutil, mock_util,
15811587
mock_unlink):
15821588
"""
15831589
Handle errors in coalesce with raw parent
@@ -1605,6 +1611,7 @@ def run_abortable(func, ret, ns, abortTest, pollInterval, timeOut):
16051611
mock_journaler.get.return_value = None
16061612

16071613
mock_vhdutil.return_value.getParent.return_value = vdis['parent'].path
1614+
mock_vhdutil.return_value.isCoalesceableOnRemote.return_value = False
16081615

16091616
sr.coalesce(vdis['vdi'], False)
16101617

tests/test_on_slave.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_is_open_nfssr_success(self):
7070

7171
def test_is_open_lvm_success(self):
7272
"""
73-
LVM srs are uplifted to lvhd
73+
LVM srs are uplifted to lvm
7474
"""
7575
vdi_uuid = uuid.uuid4()
7676
mock_session = mock.MagicMock()
@@ -85,7 +85,7 @@ def test_is_open_lvm_success(self):
8585
'vdiUuid': vdi_uuid,
8686
'srRef': 'opaqueref:sr_mine'
8787
})
88-
self.mock_sr.driver.assert_called_once_with('lvhd')
88+
self.mock_sr.driver.assert_called_once_with('lvm')
8989
self.assertEqual('True', is_open)
9090

9191
def test_is_open_false(self):

0 commit comments

Comments
 (0)