Skip to content

Commit f43dc24

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 f072773 commit f43dc24

8 files changed

Lines changed: 39 additions & 38 deletions

File tree

tests/storage/ext/test_ext_sr.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66

77
from lib.commands import SSHCommandFailed
8-
from lib.common import vm_image, wait_for
8+
from lib.common import Defer, vm_image, wait_for
99
from lib.fistpoint import FistPoint
1010
from lib.host import Host
1111
from lib.sr import SR
@@ -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, defer: Defer):
96+
xva_export_import(vm_on_ext_sr, compression, defer)
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66

77
from lib.commands import SSHCommandFailed
8-
from lib.common import vm_image, wait_for
8+
from lib.common import Defer, vm_image, wait_for
99
from lib.fistpoint import FistPoint
1010
from lib.host import Host
1111
from lib.sr import SR
@@ -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, defer: Defer):
149+
xva_export_import(vm_on_lvm_sr, compression, defer)
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from lib.common import vm_image, wait_for
3+
from lib.common import Defer, vm_image, wait_for
44
from lib.sr import SR
55
from lib.vdi import VDI
66
from lib.vm import VM
@@ -69,8 +69,8 @@ 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(self, vm_on_lvmoiscsi_sr: VM, compression: XVACompression, defer: Defer):
73+
xva_export_import(vm_on_lvmoiscsi_sr, compression, defer)
7474

7575
@pytest.mark.small_vm
7676
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from lib.commands import SSHCommandFailed
6-
from lib.common import vm_image, wait_for
6+
from lib.common import Defer, vm_image, wait_for
77
from lib.sr import SR
88
from lib.vdi import VDI
99
from lib.vm import VM
@@ -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, defer: Defer):
127+
xva_export_import(dispatch_nfs, compression, defer)
128128

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

tests/storage/storage.py

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

3+
import pytest
4+
35
import logging
46

57
from lib.commands import SSHCommandFailed
6-
from lib.common import GiB, strtobool, wait_for, wait_for_not
8+
from lib.common import Defer, GiB, strtobool, wait_for, wait_for_not
79
from lib.host import Host
810
from lib.sr import SR
911
from lib.vdi import VDI, ImageFormat
@@ -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, defer: Defer):
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+
defer(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+
defer(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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77

88
from lib.commands import SSHCommandFailed
9-
from lib.common import vm_image, wait_for
9+
from lib.common import Defer, vm_image, wait_for
1010
from lib.host import Host
1111
from lib.sr import SR
1212
from lib.vdi import VDI
@@ -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, defer: Defer):
113+
xva_export_import(vm_on_xfs_sr, compression, defer)
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77

88
from lib.commands import SSHCommandFailed
9-
from lib.common import vm_image, wait_for
9+
from lib.common import Defer, vm_image, wait_for
1010
from lib.sr import SR
1111
from lib.vdi import VDI
1212
from lib.vm import VM
@@ -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, defer: Defer):
115+
xva_export_import(vm_on_zfs_sr, compression, defer)
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import logging
66

7-
from lib.common import vm_image, wait_for
7+
from lib.common import Defer, vm_image, wait_for
88
from lib.sr import SR
99
from lib.vdi import VDI
1010
from lib.vm import VM
@@ -69,8 +69,8 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_zfsvol_sr: VDI, vdi_op: Coal
6969

7070
@pytest.mark.small_vm
7171
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
72-
def test_xva_export_import(self, vm_on_zfsvol_sr: VM, compression: XVACompression):
73-
xva_export_import(vm_on_zfsvol_sr, compression)
72+
def test_xva_export_import(self, vm_on_zfsvol_sr: VM, compression: XVACompression, defer: Defer):
73+
xva_export_import(vm_on_zfsvol_sr, compression, defer)
7474

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

0 commit comments

Comments
 (0)