Skip to content

Commit 57ee6c2

Browse files
lib/vdi: Add VDI resize support and integrate into VM & linstor operations
- Added `resize` method to `VDI` class to allow resizing of VDIs via `xe vdi-resize`. - Introduced `vdi_resize` method in VM class to support 2x VDI resizing. - Implemented `test_resize_vdi` in Linstor and basic VM tests, verifying VDI resize functionality and ensuring VM boot post-resize. - Refactored VM operations to include `wait_for_vm_running`. Signed-off-by: Rushikesh Jadhav <[email protected]>
1 parent 346096e commit 57ee6c2

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

Diff for: lib/vdi.py

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def clone(self):
3131
def readonly(self):
3232
return self.param_get("read-only") == "true"
3333

34+
def resize(self, vdi_size):
35+
logging.info("Resize VDI %s", self.uuid)
36+
self.sr.pool.master.xe('vdi-resize', {'uuid': self.uuid, 'disk-size': vdi_size})
37+
3438
def __str__(self):
3539
return f"VDI {self.uuid} on SR {self.sr.uuid}"
3640

Diff for: lib/vm.py

+22
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from lib.common import PackageManagerEnum, parse_xe_dict, safe_split, strtobool, wait_for, wait_for_not
1111
from lib.snapshot import Snapshot
1212
from lib.vif import VIF
13+
from lib.vdi import VDI
1314

1415
class VM(BaseVM):
1516
def __init__(self, uuid, host):
@@ -130,6 +131,9 @@ def wait_for_vm_running_and_ssh_up(self):
130131
self.wait_for_os_booted()
131132
wait_for(self.is_ssh_up, "Wait for SSH up")
132133

134+
def wait_for_vm_running(self):
135+
wait_for(self.is_running)
136+
133137
def ssh_touch_file(self, filepath):
134138
logging.info("Create file on VM (%s)" % filepath)
135139
self.ssh(['touch', filepath])
@@ -361,6 +365,24 @@ def test_snapshot_on_running_vm(self):
361365
finally:
362366
snapshot.destroy(verify=True)
363367

368+
def vdi_resize(self, vdi_uuid, new_size=None):
369+
# Reference
370+
MAX_VHD_SIZE = 2088960 * 1024 * 1024 # 2088960 MB
371+
MIN_VHD_SIZE = 1 * 1024 * 1024 # 1MB
372+
373+
# Following assert may be removed in future if we support online vdi resize
374+
assert not self.is_running(), f"Expected halted, got running"
375+
376+
vdi_obj = VDI(vdi_uuid, sr=self.get_sr())
377+
if new_size is None:
378+
# Resize by double, ideally it should be within min and max limits reference
379+
vdi_size = int(vdi_obj.param_get("virtual-size"))
380+
new_size = str(vdi_size * 2)
381+
382+
vdi_obj.resize(new_size)
383+
resized_vdi_size = vdi_obj.param_get("virtual-size")
384+
assert int(resized_vdi_size) == int(new_size), f"Expected {new_size}, got {resized_vdi_size}"
385+
364386
def get_messages(self, name):
365387
args = {
366388
'obj-uuid': self.uuid,

Diff for: tests/misc/test_basic_without_ssh.py

+16
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ def test_checkpoint(self, imported_vm):
7575
finally:
7676
snapshot.destroy(verify=True)
7777

78+
def test_resize_vdi(self, imported_vm):
79+
from lib.vdi import VDI
80+
81+
vm = imported_vm
82+
if vm.is_running():
83+
vm.shutdown(verify=True, force_if_fails=True)
84+
85+
logging.info("* VDI Resize started *")
86+
for vdi_uuid in vm.vdi_uuids():
87+
vm.vdi_resize(vdi_uuid)
88+
logging.info("* VDI Resize completed *")
89+
90+
vm.start()
91+
vm.wait_for_vm_running() # early decision to check if VDI was ok and VM is able to start
92+
vm.shutdown(verify=True, force_if_fails=True)
93+
7894
# Live migration tests
7995
# We want to test storage migration (memory+disks) and live migration without storage migration (memory only).
8096
# The order will depend on the initial location of the VM: a local SR or a shared SR.

Diff for: tests/storage/linstor/test_linstor_sr.py

+11
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ def test_snapshot(self, vm_on_linstor_sr):
7878
finally:
7979
vm.shutdown(verify=True)
8080

81+
@pytest.mark.small_vm
82+
@pytest.mark.big_vm
83+
def test_resize_vdi(self, vm_on_linstor_sr):
84+
vm = vm_on_linstor_sr
85+
if vm.is_running():
86+
vm.shutdown(verify=True, force_if_fails=True)
87+
logging.info("* VDI Resize started *")
88+
for vdi_uuid in vm.vdi_uuids():
89+
vm.vdi_resize(vdi_uuid)
90+
logging.info("* VDI Resize completed *")
91+
8192
# *** tests with reboots (longer tests).
8293

8394
@pytest.mark.reboot

0 commit comments

Comments
 (0)