Skip to content

Commit 7c53280

Browse files
committed
storage: avoid removing the xva before going in the debugger
In case of exception, the cleanup code in try…finally was removing the xva image before getting in the debugger, making impossible to look at the xva content. Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent 84b81a4 commit 7c53280

8 files changed

Lines changed: 33 additions & 30 deletions

File tree

tests/storage/ext/test_ext_sr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_ext_sr: VDI, vdi_op: Coalesc
9292

9393
@pytest.mark.small_vm
9494
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
95-
def test_xva_export_import(self, vm_on_ext_sr: VM, compression: XVACompression):
96-
xva_export_import(vm_on_ext_sr, compression)
95+
def test_xva_export_import(self, vm_on_ext_sr: VM, compression: XVACompression, request: pytest.FixtureRequest):
96+
xva_export_import(vm_on_ext_sr, compression, request)
9797

9898
@pytest.mark.small_vm
9999
def test_vdi_export_import(self, storage_test_vm: VM, ext_sr: SR, image_format: ImageFormat):

tests/storage/lvm/test_lvm_sr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_lvm_sr: VDI, vdi_op: Coalesc
145145

146146
@pytest.mark.small_vm
147147
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
148-
def test_xva_export_import(self, vm_on_lvm_sr: VM, compression: XVACompression):
149-
xva_export_import(vm_on_lvm_sr, compression)
148+
def test_xva_export_import(self, vm_on_lvm_sr: VM, compression: XVACompression, request: pytest.FixtureRequest):
149+
xva_export_import(vm_on_lvm_sr, compression, request)
150150

151151
@pytest.mark.small_vm
152152
def test_vdi_export_import(self, storage_test_vm: VM, lvm_sr: SR, image_format: ImageFormat):

tests/storage/lvmoiscsi/test_lvmoiscsi_sr.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ def test_coalesce(self, storage_test_vm: 'VM', vdi_on_lvmoiscsi_sr: 'VDI', vdi_o
6969

7070
@pytest.mark.small_vm
7171
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
72-
def test_xva_export_import(self, vm_on_lvmoiscsi_sr: VM, compression: XVACompression):
73-
xva_export_import(vm_on_lvmoiscsi_sr, compression)
72+
def test_xva_export_import(
73+
self, vm_on_lvmoiscsi_sr: VM, compression: XVACompression, request: pytest.FixtureRequest
74+
):
75+
xva_export_import(vm_on_lvmoiscsi_sr, compression, request)
7476

7577
@pytest.mark.small_vm
7678
def test_vdi_export_import(self, storage_test_vm: VM, lvmoiscsi_sr: SR, image_format: ImageFormat):

tests/storage/nfs/test_nfs_sr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def test_coalesce(self, storage_test_vm: VM, dispatch_nfs: VDI, vdi_op: Coalesce
123123
@pytest.mark.usefixtures('vm_ref')
124124
@pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr', 'vm_on_nfs4_sr'], indirect=True)
125125
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
126-
def test_xva_export_import(self, dispatch_nfs: VM, compression: XVACompression):
127-
xva_export_import(dispatch_nfs, compression)
126+
def test_xva_export_import(self, dispatch_nfs: VM, compression: XVACompression, request: pytest.FixtureRequest):
127+
xva_export_import(dispatch_nfs, compression, request)
128128

129129
@pytest.mark.small_vm
130130
@pytest.mark.parametrize('dispatch_nfs', ['nfs_sr', 'nfs4_sr'], indirect=True)

tests/storage/storage.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import pytest
4+
35
import logging
46

57
from lib.commands import SSHCommandFailed
@@ -201,32 +203,31 @@ def coalesce_integrity(vm: VM, vdi: VDI, vdi_op: CoalesceOperation):
201203

202204
XVACompression = Literal['none', 'gzip', 'zstd']
203205

204-
def xva_export_import(vm: VM, compression: XVACompression):
206+
def xva_export_import(vm: VM, compression: XVACompression, request: pytest.FixtureRequest):
205207
# The tests using this function are using specific fixtures to create the VM on the expected SR
206208
# In consequence, we can't use the storage_test_vm, so we have to start the VM explicitly and install randstream
207209
vm.start()
208210
vm.wait_for_vm_running_and_ssh_up()
209211
install_randstream(vm)
212+
210213
# 500MiB, so we have some data to check and some empty spaces in the exported image
211214
vm.ssh("randstream generate -v --size 500MiB /root/data")
212215
vm.ssh("randstream validate -v --expected-checksum 24e905d6 /root/data")
213216
vm.shutdown(verify=True)
217+
214218
xva_path = f'/tmp/{vm.uuid}.xva'
215-
imported_vm = None
216-
try:
217-
vm.export(xva_path, compression)
218-
# check that the zero blocks are not part of the result. Most of the data is from the random stream, so
219-
# compression has little effect. We just check the result is between 500 and 700 MiB
220-
size_mb = int(vm.host.ssh(f'du -sm --apparent-size {xva_path}').split()[0])
221-
assert 500 < size_mb < 700, f"unexpected xva size: {size_mb}"
222-
imported_vm = vm.host.import_vm(xva_path, vm.vdis[0].sr.uuid)
223-
imported_vm.start()
224-
imported_vm.wait_for_vm_running_and_ssh_up()
225-
imported_vm.ssh("randstream validate -v --expected-checksum 24e905d6 /root/data")
226-
finally:
227-
if imported_vm is not None:
228-
imported_vm.destroy()
229-
vm.host.ssh(f'rm -f {xva_path}')
219+
request.addfinalizer(lambda: vm.host.ssh(f'rm -f {xva_path}'))
220+
vm.export(xva_path, compression)
221+
# check that the zero blocks are not part of the result. Most of the data is from the random stream, so
222+
# compression has little effect. We just check the result is between 500 and 700 MiB
223+
size_mb = int(vm.host.ssh(f'du -sm --apparent-size {xva_path}').split()[0])
224+
assert 500 < size_mb < 700, f"unexpected xva size: {size_mb}"
225+
226+
imported_vm = vm.host.import_vm(xva_path, vm.vdis[0].sr.uuid)
227+
request.addfinalizer(lambda: imported_vm.destroy())
228+
imported_vm.start()
229+
imported_vm.wait_for_vm_running_and_ssh_up()
230+
imported_vm.ssh("randstream validate -v --expected-checksum 24e905d6 /root/data")
230231

231232
def vdi_export_import(vm: VM, sr: SR, image_format: ImageFormat):
232233
vdi = sr.create_vdi(image_format=image_format)

tests/storage/xfs/test_xfs_sr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_xfs_sr: VDI, vdi_op: Coalesc
109109

110110
@pytest.mark.small_vm
111111
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
112-
def test_xva_export_import(self, vm_on_xfs_sr: VM, compression: XVACompression):
113-
xva_export_import(vm_on_xfs_sr, compression)
112+
def test_xva_export_import(self, vm_on_xfs_sr: VM, compression: XVACompression, request: pytest.FixtureRequest):
113+
xva_export_import(vm_on_xfs_sr, compression, request)
114114

115115
@pytest.mark.small_vm
116116
def test_vdi_export_import(self, storage_test_vm: VM, xfs_sr: SR, image_format: ImageFormat):

tests/storage/zfs/test_zfs_sr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_zfs_sr: VDI, vdi_op: Coalesc
111111

112112
@pytest.mark.small_vm
113113
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
114-
def test_xva_export_import(self, vm_on_zfs_sr: VM, compression: XVACompression):
115-
xva_export_import(vm_on_zfs_sr, compression)
114+
def test_xva_export_import(self, vm_on_zfs_sr: VM, compression: XVACompression, request: pytest.FixtureRequest):
115+
xva_export_import(vm_on_zfs_sr, compression, request)
116116

117117
@pytest.mark.small_vm
118118
def test_vdi_export_import(self, storage_test_vm: VM, zfs_sr: SR, image_format: ImageFormat):

tests/storage/zfsvol/test_zfsvol_sr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_zfsvol_sr: VDI, vdi_op: Coal
6868

6969
@pytest.mark.small_vm
7070
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
71-
def test_xva_export_import(self, vm_on_zfsvol_sr: VM, compression: XVACompression):
72-
xva_export_import(vm_on_zfsvol_sr, compression)
71+
def test_xva_export_import(self, vm_on_zfsvol_sr: VM, compression: XVACompression, request: pytest.FixtureRequest):
72+
xva_export_import(vm_on_zfsvol_sr, compression, request)
7373

7474
@pytest.mark.small_vm
7575
def test_vdi_export_import(self, storage_test_vm: VM, zfsvol_sr: SR, image_format: ImageFormat):

0 commit comments

Comments
 (0)