Skip to content

Commit 27533d0

Browse files
committed
Add VHD_MAX and QCOW2_MAX symbolic size constants
Allow passing VHD_MAX and QCOW2_MAX as values to --volume-size and --write-volume-cap, making it easy to test at the maximum supported VDI size for each image format. MAX_VDI_SIZE in storage.py is now derived from the same constants to keep a single source of truth. Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent ce5225e commit 27533d0

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@ def pytest_addoption(parser: pytest.Parser) -> None:
119119
"--volume-size",
120120
action="store",
121121
default="1GiB",
122-
help="Default volume size for tests"
122+
help="Default volume size for tests."
123+
" Accepts sizes like '1GiB', '2.5TiB', or symbolic values 'VHD_MAX', 'QCOW2_MAX'."
123124
)
124125
parser.addoption(
125126
"--write-volume-cap",
126127
action="store",
127128
default="2GiB",
128-
help="Maximum amount of data written to a volume"
129+
help="Maximum amount of data written to a volume."
130+
" Accepts sizes like '1GiB', '2.5TiB', or symbolic values 'VHD_MAX', 'QCOW2_MAX'."
129131
)
130132

131133
def pytest_configure(config: pytest.Config) -> None:

lib/common.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,21 @@
4040
GiB = KiB**3
4141
TiB = KiB**4
4242

43+
VHD_MAX = 2040 * GiB
44+
QCOW2_MAX = 16 * TiB - 2561 * MiB
45+
46+
_SYMBOLIC_SIZES: dict[str, int] = {
47+
'VHD_MAX': VHD_MAX,
48+
'QCOW2_MAX': QCOW2_MAX,
49+
}
50+
4351
def parse_size(size_str: str) -> int:
4452
"""
45-
Parse a size string like "2.5TiB", "1GiB" or "1024".
53+
Parse a size string like "2.5TiB", "1GiB", "1024", "VHD_MAX", or "QCOW2_MAX".
4654
"""
55+
symbolic = _SYMBOLIC_SIZES.get(size_str.strip().upper())
56+
if symbolic is not None:
57+
return symbolic
4758
try:
4859
return int(size_str)
4960
except ValueError:

tests/storage/storage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
from lib import config
77
from lib.commands import SSHCommandFailed
8-
from lib.common import Defer, GiB, MiB, TiB, strtobool, wait_for
8+
from lib.common import QCOW2_MAX, VHD_MAX, Defer, GiB, MiB, TiB, strtobool, wait_for
99
from lib.host import Host
1010
from lib.sr import SR
1111
from lib.vdi import VDI, ImageFormat
1212
from lib.vm import VM
1313

1414
from typing import Literal
1515

16-
MAX_VDI_SIZE: dict[ImageFormat, int] = {'qcow2': 16 * TiB - 2561 * MiB, 'vhd': 2040 * GiB}
16+
MAX_VDI_SIZE: dict[ImageFormat, int] = {'qcow2': QCOW2_MAX, 'vhd': VHD_MAX}
1717

1818
def try_to_create_sr_with_missing_device(sr_type, label, host) -> None:
1919
try:

0 commit comments

Comments
 (0)