Skip to content

Commit 83daf10

Browse files
committed
storage: test that we can't create a vdi over its max allowed size
Depending on the image format. Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent caadb1e commit 83daf10

9 files changed

Lines changed: 55 additions & 0 deletions

File tree

tests/storage/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .storage import (
2+
MAX_VDI_SIZE,
23
CoalesceOperation,
34
ImageFormat,
45
XVACompression,

tests/storage/ext/test_ext_sr.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from lib.vdi import VDI
1313
from lib.vm import VM
1414
from tests.storage import (
15+
MAX_VDI_SIZE,
1516
CoalesceOperation,
1617
ImageFormat,
1718
XVACompression,
@@ -106,6 +107,12 @@ def test_vdi_export_import(self, storage_test_vm: VM, ext_sr: SR, image_format:
106107
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_ext_sr: VDI, defer: Defer):
107108
full_vdi_write(storage_test_vm, vdi_on_ext_sr, defer)
108109

110+
@pytest.mark.small_vm
111+
def test_invalid_vdi_size(self, ext_sr: SR, image_format: ImageFormat):
112+
with pytest.raises(SSHCommandFailed) as excinfo:
113+
ext_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
114+
assert 'VDI Invalid size' in excinfo.value.stdout
115+
109116
# *** tests with reboots (longer tests).
110117

111118
@pytest.mark.small_vm

tests/storage/lvm/test_lvm_sr.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from lib.vdi import VDI
1313
from lib.vm import VM
1414
from tests.storage import (
15+
MAX_VDI_SIZE,
1516
CoalesceOperation,
1617
ImageFormat,
1718
XVACompression,
@@ -152,6 +153,12 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_lvm_sr: VDI, vdi_op: Coalesc
152153
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_lvm_sr: VDI, defer: Defer):
153154
full_vdi_write(storage_test_vm, vdi_on_lvm_sr, defer)
154155

156+
@pytest.mark.small_vm
157+
def test_invalid_vdi_size(self, lvm_sr: SR, image_format: ImageFormat):
158+
with pytest.raises(SSHCommandFailed) as excinfo:
159+
lvm_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
160+
assert 'VDI Invalid size' in excinfo.value.stdout
161+
155162
@pytest.mark.small_vm
156163
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
157164
def test_xva_export_import(self, vm_on_lvm_sr: VM, compression: XVACompression, temp_large_dir: str, defer: Defer) \

tests/storage/lvmoiscsi/test_lvmoiscsi_sr.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import pytest
22

3+
from lib.commands import SSHCommandFailed
34
from lib.common import Defer, vm_image, wait_for
45
from lib.host import Host
56
from lib.sr import SR
67
from lib.vdi import VDI, ImageFormat
78
from lib.vm import VM
89
from tests.storage import (
10+
MAX_VDI_SIZE,
911
CoalesceOperation,
1012
ImageFormat,
1113
XVACompression,
@@ -78,6 +80,12 @@ def test_coalesce(self, storage_test_vm: 'VM', vdi_on_lvmoiscsi_sr: 'VDI', vdi_o
7880
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_lvmoiscsi_sr: VDI, defer: Defer):
7981
full_vdi_write(storage_test_vm, vdi_on_lvmoiscsi_sr, defer)
8082

83+
@pytest.mark.small_vm
84+
def test_invalid_vdi_size(self, lvmoiscsi_sr: SR, image_format: ImageFormat):
85+
with pytest.raises(SSHCommandFailed) as excinfo:
86+
lvmoiscsi_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
87+
assert 'VDI Invalid size' in excinfo.value.stdout
88+
8189
@pytest.mark.small_vm
8290
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
8391
def test_xva_export_import(self, vm_on_lvmoiscsi_sr: VM, compression: XVACompression, temp_large_dir: str,

tests/storage/nfs/test_nfs_sr.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from lib.vdi import VDI
1010
from lib.vm import VM
1111
from tests.storage import (
12+
MAX_VDI_SIZE,
1213
CoalesceOperation,
1314
ImageFormat,
1415
XVACompression,
@@ -124,6 +125,12 @@ def test_coalesce(self, storage_test_vm: VM, dispatch_nfs: VDI, vdi_op: Coalesce
124125
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_nfs_sr: VDI, defer: Defer):
125126
full_vdi_write(storage_test_vm, vdi_on_nfs_sr, defer)
126127

128+
@pytest.mark.small_vm
129+
def test_invalid_vdi_size(self, nfs_sr: SR, image_format: ImageFormat):
130+
with pytest.raises(SSHCommandFailed) as excinfo:
131+
nfs_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
132+
assert 'VDI Invalid size' in excinfo.value.stdout
133+
127134
@pytest.mark.small_vm
128135
# Make sure this fixture is called before the parametrized one
129136
@pytest.mark.usefixtures('vm_ref')

tests/storage/storage.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
from typing import Literal, Tuple
1616

17+
MAX_VDI_SIZE: dict[ImageFormat, int] = {'qcow2': 16 * TiB - 2561 * MiB, 'vhd': 2040 * GiB}
18+
1719
def try_to_create_sr_with_missing_device(sr_type, label, host) -> None:
1820
try:
1921
host.sr_create(sr_type, label, {}, verify=True)

tests/storage/xfs/test_xfs_sr.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from lib.vdi import VDI
1313
from lib.vm import VM
1414
from tests.storage import (
15+
MAX_VDI_SIZE,
1516
CoalesceOperation,
1617
ImageFormat,
1718
XVACompression,
@@ -112,6 +113,12 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_xfs_sr: VDI, vdi_op: Coalesc
112113
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_xfs_sr: VDI, defer: Defer):
113114
full_vdi_write(storage_test_vm, vdi_on_xfs_sr, defer)
114115

116+
@pytest.mark.small_vm
117+
def test_invalid_vdi_size(self, xfs_sr: SR, image_format: ImageFormat):
118+
with pytest.raises(SSHCommandFailed) as excinfo:
119+
xfs_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
120+
assert 'VDI Invalid size' in excinfo.value.stdout
121+
115122
@pytest.mark.small_vm
116123
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
117124
def test_xva_export_import(self, vm_on_xfs_sr: VM, compression: XVACompression, temp_large_dir: str, defer: Defer) \

tests/storage/zfs/test_zfs_sr.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from lib.vdi import VDI
1313
from lib.vm import VM
1414
from tests.storage import (
15+
MAX_VDI_SIZE,
1516
CoalesceOperation,
1617
ImageFormat,
1718
XVACompression,
@@ -109,6 +110,12 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_zfs_sr: VDI, vdi_op: Coalesc
109110
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_zfs_sr: VDI, defer: Defer):
110111
full_vdi_write(storage_test_vm, vdi_on_zfs_sr, defer)
111112

113+
@pytest.mark.small_vm
114+
def test_invalid_vdi_size(self, zfs_sr: SR, image_format: ImageFormat):
115+
with pytest.raises(SSHCommandFailed) as excinfo:
116+
zfs_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
117+
assert 'VDI Invalid size' in excinfo.value.stdout
118+
112119
@pytest.mark.small_vm
113120
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
114121
def test_xva_export_import(self, vm_on_zfs_sr: VM, compression: XVACompression, temp_large_dir: str, defer: Defer) \

tests/storage/zfsvol/test_zfsvol_sr.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import logging
66

77
from lib import config
8+
from lib.commands import SSHCommandFailed
89
from lib.common import Defer, KiB, MiB, vm_image, wait_for
910
from lib.host import Host
1011
from lib.sr import SR
1112
from lib.vdi import VDI
1213
from lib.vm import VM
1314
from tests.storage import (
15+
MAX_VDI_SIZE,
1416
CoalesceOperation,
1517
ImageFormat,
1618
XVACompression,
@@ -83,6 +85,13 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_zfsvol_sr: VDI, vdi_op: Coal
8385
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_zfsvol_sr: VDI, defer: Defer):
8486
full_vdi_write(storage_test_vm, vdi_on_zfsvol_sr, defer)
8587

88+
@pytest.mark.small_vm
89+
@pytest.mark.xfail(reason="not implemented yet")
90+
def test_invalid_vdi_size(self, zfsvol_sr: SR, image_format: ImageFormat):
91+
with pytest.raises(SSHCommandFailed) as excinfo:
92+
zfsvol_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
93+
assert 'VDI Invalid size' in excinfo.value.stdout
94+
8695
@pytest.mark.small_vm
8796
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
8897
def test_xva_export_import(self, vm_on_zfsvol_sr: VM, compression: XVACompression, temp_large_dir: str,

0 commit comments

Comments
 (0)