Skip to content

Commit 3806fe9

Browse files
committed
storage: free space for XVA import by destroying source VM first
Refactor xva_export_import to create the VM during the test and destroy it before importing the exported image, freeing space for thick-provisioned SRs. Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent 0070121 commit 3806fe9

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

tests/storage/storage.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,13 @@ def coalesce_integrity(vm: VM, vdi: VDI, vdi_op: CoalesceOperation, defer: Defer
252252

253253
XVACompression = Literal['none', 'gzip', 'zstd']
254254

255-
def xva_export_import(vm: VM, compression: XVACompression, temp_large_dir: str, defer: Defer) -> None:
255+
def xva_export_import(source_vm: VM, compression: XVACompression, temp_large_dir: str, defer: Defer) -> None:
256+
# clone the vm, so we can resize the disk without affecting the vm from the fixture
257+
vm: VM | None = source_vm.clone()
258+
defer(lambda: vm.destroy() if vm is not None else None)
259+
assert vm is not None
260+
host = vm.host
261+
sr = vm.vdis[0].sr
256262
# we can't shrink a volume
257263
volume_size = max(vm.vdis[0].get_virtual_size(), config.volume_size)
258264
vm.vdis[0].resize(volume_size)
@@ -285,7 +291,7 @@ def xva_export_import(vm: VM, compression: XVACompression, temp_large_dir: str,
285291
vm.shutdown(verify=True)
286292

287293
xva_path = f'{temp_large_dir}/{vm.uuid}.xva'
288-
defer(lambda: vm.host.ssh(f'rm -f {xva_path}'))
294+
defer(lambda: host.ssh(f'rm -f {xva_path}'))
289295
vm.export(xva_path, compression)
290296
# check that the zero blocks are not part of the result. Most of the data is from the random stream, so
291297
# compression has little effect. We just take into account the system size
@@ -296,9 +302,13 @@ def xva_export_import(vm: VM, compression: XVACompression, temp_large_dir: str,
296302
f"unexpected xva size {size_mb}MiB, was expected to be between {min_size}MiB and {max_size}MiB"
297303
)
298304

299-
imported_vm = vm.host.import_vm(xva_path, vm.vdis[0].sr.uuid)
305+
# destroy the source vm to free some space to re-import the image
306+
vm.destroy()
307+
vm = None
308+
309+
imported_vm = host.import_vm(xva_path, sr.uuid)
300310
defer(lambda: imported_vm.destroy())
301-
assert vm.vdis[0].get_virtual_size() == volume_size
311+
assert imported_vm.vdis[0].get_virtual_size() == volume_size
302312

303313
imported_vm.start()
304314
imported_vm.wait_for_vm_running_and_ssh_up()

0 commit comments

Comments
 (0)