Skip to content

Commit 09c9a94

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 45ae839 commit 09c9a94

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,
@@ -108,6 +109,12 @@ def test_vdi_export_import(
108109
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_ext_sr: VDI, defer: Defer):
109110
full_vdi_write(storage_test_vm, vdi_on_ext_sr, defer)
110111

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

113120
@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,
@@ -150,6 +151,12 @@ def test_coalesce(
150151
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_lvm_sr: VDI, defer: Defer):
151152
full_vdi_write(storage_test_vm, vdi_on_lvm_sr, defer)
152153

154+
@pytest.mark.small_vm
155+
def test_invalid_vdi_size(self, lvm_sr: SR, image_format: ImageFormat):
156+
with pytest.raises(SSHCommandFailed) as excinfo:
157+
lvm_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
158+
assert 'VDI Invalid size' in excinfo.value.stdout
159+
153160
@pytest.mark.small_vm
154161
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
155162
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,
@@ -78,6 +80,12 @@ def test_coalesce(
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(

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,
@@ -125,6 +126,12 @@ def test_coalesce(
125126
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_nfs_sr: VDI, defer: Defer):
126127
full_vdi_write(storage_test_vm, vdi_on_nfs_sr, defer)
127128

129+
@pytest.mark.small_vm
130+
def test_invalid_vdi_size(self, nfs_sr: SR, image_format: ImageFormat):
131+
with pytest.raises(SSHCommandFailed) as excinfo:
132+
nfs_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
133+
assert 'VDI Invalid size' in excinfo.value.stdout
134+
128135
@pytest.mark.small_vm
129136
# Make sure this fixture is called before the parametrized one
130137
@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 = {'qcow': 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,
@@ -116,6 +117,12 @@ def test_coalesce(
116117
def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_zfs_sr: VDI, defer: Defer):
117118
full_vdi_write(storage_test_vm, vdi_on_zfs_sr, defer)
118119

120+
@pytest.mark.small_vm
121+
def test_invalid_vdi_size(self, zfs_sr: SR, image_format: ImageFormat):
122+
with pytest.raises(SSHCommandFailed) as excinfo:
123+
zfs_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1)
124+
assert 'VDI Invalid size' in excinfo.value.stdout
125+
119126
@pytest.mark.small_vm
120127
@pytest.mark.parametrize("compression", ["none", "gzip", "zstd"])
121128
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(
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(

0 commit comments

Comments
 (0)