From cd35610e0fb02dd9b05f097cdc0a03c572e3ddec Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Fri, 29 Mar 2024 15:56:20 +0100 Subject: [PATCH] zfs-vol: add a test for VDI resize Signed-off-by: Yann Dirson --- lib/vdi.py | 4 ++++ tests/storage/zfsvol/test_zfsvol_sr.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/vdi.py b/lib/vdi.py index b2781cfd1..562eb7bdb 100644 --- a/lib/vdi.py +++ b/lib/vdi.py @@ -7,6 +7,10 @@ def __init__(self, sr, uuid, snapshot_of=None): # TODO: use a different approach when migration is possible self.sr = sr + def resize(self, size): + return self.sr.pool.master.xe('vdi-resize', {'uuid': self.uuid, + 'disk-size': str(size)}) + def snapshot(self): logging.info(f"Create snapshot of {self}") return VDI(self.sr, diff --git a/tests/storage/zfsvol/test_zfsvol_sr.py b/tests/storage/zfsvol/test_zfsvol_sr.py index 083e38b03..93ea58883 100755 --- a/tests/storage/zfsvol/test_zfsvol_sr.py +++ b/tests/storage/zfsvol/test_zfsvol_sr.py @@ -30,6 +30,20 @@ def test_create_and_destroy_sr(self, host, sr_disk_wiped): @pytest.mark.usefixtures("zfsvol_sr") class TestZfsvolSrBasics: + def test_vdi_resize(self, vdi_on_zfsvol_sr): + logging.info("Resize up") + vdi_on_zfsvol_sr.resize(1024 * 1024) + logging.info("Attempt to resize down") + try: + vdi_on_zfsvol_sr.resize(64 * 1024) + except Exception as e: + if "shrinking not allowed" in str(e): + # properly refused + pass + else: + logging.error("unexpected error on downsize attempt: %s", e) + raise + @pytest.mark.xfail # needs support for cloning non-snapshots def test_vdi_clone(self, vdi_on_zfsvol_sr): clone = vdi_on_zfsvol_sr.clone()