Skip to content

Commit 2bd0b7d

Browse files
committed
create_vdi: make vdi name optional
Signed-off-by: Gaëtan Lehmann <[email protected]>
1 parent bb23281 commit 2bd0b7d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/common.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import itertools
88
import logging
99
import os
10+
import random
11+
import string
1012
import sys
1113
import time
1214
import traceback
@@ -233,6 +235,14 @@ def url_download(url: str, filename: str) -> None:
233235
fd.write(chunk)
234236
os.rename(tempfilename, filename)
235237

238+
def randid(length=6):
239+
"""
240+
Generates a random string of a specified length.
241+
The string consists of lowercase letters, uppercase letters, and digits.
242+
"""
243+
characters = string.ascii_lowercase + string.digits
244+
return ''.join(random.choices(characters, k=length))
245+
236246
@overload
237247
def _param_get(host: 'lib.host.Host', xe_prefix: str, uuid: str, param_name: str, key: Optional[str] = ...,
238248
accept_unknown_key: Literal[False] = ...) -> str:

lib/sr.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import lib.commands as commands
55
from lib.common import (
66
prefix_object_name,
7+
randid,
78
safe_split,
89
strtobool,
910
wait_for,
@@ -166,7 +167,10 @@ def get_type(self) -> str:
166167
self._type = self.pool.master.xe("sr-param-get", {"uuid": self.uuid, "param-name": "type"})
167168
return self._type
168169

169-
def create_vdi(self, name_label: str, virtual_size: int | str = '1GiB', image_format: Optional[str] = None) -> VDI:
170+
def create_vdi(
171+
self, name_label: str | None = None, virtual_size: int | str = '1GiB', image_format: Optional[str] = None
172+
) -> VDI:
173+
name_label = name_label or f'test-vdi-{randid()}'
170174
logging.info("Create VDI %r on SR %s", name_label, self.uuid)
171175
args = {
172176
'name-label': prefix_object_name(name_label),

0 commit comments

Comments
 (0)