Skip to content

Commit dacabae

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

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
@@ -238,6 +240,14 @@ def url_download(url: str, filename: str) -> None:
238240
fd.write(chunk)
239241
os.rename(tempfilename, filename)
240242

243+
def randid(length=6):
244+
"""
245+
Generates a random string of a specified length.
246+
The string consists of lowercase letters, uppercase letters, and digits.
247+
"""
248+
characters = string.ascii_lowercase + string.digits
249+
return ''.join(random.choices(characters, k=length))
250+
241251
@overload
242252
def _param_get(host: 'lib.host.Host', xe_prefix: str, uuid: str, param_name: str, key: Optional[str] = ...,
243253
accept_unknown_key: Literal[False] = ...) -> str:

lib/sr.py

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

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

0 commit comments

Comments
 (0)