Skip to content

Commit 9ff5803

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 aad99de commit 9ff5803

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,
@@ -105,6 +106,12 @@ def test_vdi_export_import(self, storage_test_vm: VM, ext_sr: SR, image_format:
105106
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_ext_sr: VDI, defer: Defer):
106107
full_vdi_write(storage_test_vm, vdi_on_ext_sr, defer)
107108

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

110117
@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,
@@ -148,6 +149,12 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_lvm_sr: VDI, vdi_op: Coalesc
148149
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_lvm_sr: VDI, defer: Defer):
149150
full_vdi_write(storage_test_vm, vdi_on_lvm_sr, defer)
150151

152+
@pytest.mark.small_vm
153+
def test_invalid_vdi_size(self, lvm_sr: SR, image_format: ImageFormat):
154+
with pytest.raises(SSHCommandFailed) as excinfo:
155+
lvm_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
156+
assert 'VDI Invalid size' in excinfo.value.stdout
157+
151158
@pytest.mark.small_vm
152159
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
153160
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,10 +1,12 @@
11
import pytest
22

3+
from lib.commands import SSHCommandFailed
34
from lib.common import Defer, vm_image, wait_for
45
from lib.sr import SR
56
from lib.vdi import VDI
67
from lib.vm import VM
78
from tests.storage import (
9+
MAX_VDI_SIZE,
810
CoalesceOperation,
911
ImageFormat,
1012
XVACompression,
@@ -72,6 +74,12 @@ def test_coalesce(self, storage_test_vm: 'VM', vdi_on_lvmoiscsi_sr: 'VDI', vdi_o
7274
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_lvmoiscsi_sr: VDI, defer: Defer):
7375
full_vdi_write(storage_test_vm, vdi_on_lvmoiscsi_sr, defer)
7476

77+
@pytest.mark.small_vm
78+
def test_invalid_vdi_size(self, lvmoiscsi_sr: SR, image_format: ImageFormat):
79+
with pytest.raises(SSHCommandFailed) as excinfo:
80+
lvmoiscsi_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
81+
assert 'VDI Invalid size' in excinfo.value.stdout
82+
7583
@pytest.mark.small_vm
7684
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
7785
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
@@ -8,6 +8,7 @@
88
from lib.vdi import VDI
99
from lib.vm import VM
1010
from tests.storage import (
11+
MAX_VDI_SIZE,
1112
CoalesceOperation,
1213
ImageFormat,
1314
XVACompression,
@@ -123,6 +124,12 @@ def test_coalesce(self, storage_test_vm: VM, dispatch_nfs: VDI, vdi_op: Coalesce
123124
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_nfs_sr: VDI, defer: Defer):
124125
full_vdi_write(storage_test_vm, vdi_on_nfs_sr, defer)
125126

127+
@pytest.mark.small_vm
128+
def test_invalid_vdi_size(self, nfs_sr: SR, image_format: ImageFormat):
129+
with pytest.raises(SSHCommandFailed) as excinfo:
130+
nfs_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
131+
assert 'VDI Invalid size' in excinfo.value.stdout
132+
126133
@pytest.mark.small_vm
127134
# Make sure this fixture is called before the parametrized one
128135
@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, 'vhd': 2040 * GiB}
18+
1719
def try_to_create_sr_with_missing_device(sr_type, label, host):
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,
@@ -114,6 +115,12 @@ def test_coalesce(
114115
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_xfs_sr: VDI, defer: Defer):
115116
full_vdi_write(storage_test_vm, vdi_on_xfs_sr, defer)
116117

118+
@pytest.mark.small_vm
119+
def test_invalid_vdi_size(self, xfs_sr: SR, image_format: ImageFormat):
120+
with pytest.raises(SSHCommandFailed) as excinfo:
121+
xfs_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
122+
assert 'VDI Invalid size' in excinfo.value.stdout
123+
117124
@pytest.mark.small_vm
118125
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
119126
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
@@ -11,6 +11,7 @@
1111
from lib.vdi import VDI
1212
from lib.vm import VM
1313
from tests.storage import (
14+
MAX_VDI_SIZE,
1415
CoalesceOperation,
1516
ImageFormat,
1617
XVACompression,
@@ -114,6 +115,12 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_zfs_sr: VDI, vdi_op: Coalesc
114115
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_zfs_sr: VDI, defer: Defer):
115116
full_vdi_write(storage_test_vm, vdi_on_zfs_sr, defer)
116117

118+
@pytest.mark.small_vm
119+
def test_invalid_vdi_size(self, zfs_sr: SR, image_format: ImageFormat):
120+
with pytest.raises(SSHCommandFailed) as excinfo:
121+
zfs_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
122+
assert 'VDI Invalid size' in excinfo.value.stdout
123+
117124
@pytest.mark.small_vm
118125
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
119126
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,
@@ -81,6 +83,13 @@ def test_coalesce(self, storage_test_vm: VM, vdi_on_zfsvol_sr: VDI, vdi_op: Coal
8183
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_zfsvol_sr: VDI, defer: Defer):
8284
full_vdi_write(storage_test_vm, vdi_on_zfsvol_sr, defer)
8385

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

0 commit comments

Comments
 (0)