Skip to content

Commit c70e171

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 2710827 commit c70e171

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
@@ -109,13 +109,15 @@ def pytest_addoption(parser: pytest.Parser) -> None:
109109
"--volume-size",
110110
action="store",
111111
default="1GiB",
112-
help="Default volume size for tests"
112+
help="Default volume size for tests."
113+
" Accepts sizes like '1GiB', '2.5TiB', or symbolic values 'VHD_MAX', 'QCOW2_MAX'."
113114
)
114115
parser.addoption(
115116
"--write-volume-cap",
116117
action="store",
117118
default="2GiB",
118-
help="Maximum amount of data written to a volume"
119+
help="Maximum amount of data written to a volume."
120+
" Accepts sizes like '1GiB', '2.5TiB', or symbolic values 'VHD_MAX', 'QCOW2_MAX'."
119121
)
120122

121123
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)