Skip to content

Commit 8b902b7

Browse files
Added sr_disks_for_all_hosts fixture to support multiple disks, ensuring availability across all hosts and handling "auto" selection dynamically.
Signed-off-by: Rushikesh Jadhav <[email protected]>
1 parent bd8ba6b commit 8b902b7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

conftest.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,40 @@ def sr_disk_for_all_hosts(pytestconfig, request, host):
329329
logging.info(f">> Disk or block device {disk} is present and free on all pool members")
330330
yield candidates[0]
331331

332+
@pytest.fixture(scope='session')
333+
def sr_disks_for_all_hosts(pytestconfig, request, host):
334+
disks = pytestconfig.getoption("sr_disk")
335+
assert len(disks) > 0, "This test requires at least one --sr-disk parameter"
336+
# Fetch available disks on the master host
337+
master_disks = host.available_disks()
338+
assert len(master_disks) > 0, "a free disk device is required on the master host"
339+
340+
if "auto" in disks:
341+
candidates = list(master_disks)
342+
else:
343+
# Validate that all specified disks exist on the master host
344+
for disk in disks:
345+
assert disk in master_disks, \
346+
f"Disk or block device {disk} is either not present or already used on the master host"
347+
candidates = list(disks)
348+
349+
# Check if all disks are available on all hosts in the pool
350+
for h in host.pool.hosts[1:]:
351+
other_disks = h.available_disks()
352+
candidates = [d for d in candidates if d in other_disks]
353+
354+
if "auto" in disks:
355+
# Automatically select disks if "auto" is passed
356+
assert len(candidates) > 0, \
357+
f"Free disk devices are required on all pool members. Pool master has: {' '.join(master_disks)}."
358+
logging.info(">> Using free disk device(s) on all pool hosts: %s.", candidates)
359+
else:
360+
# Ensure specified disks are free on all hosts
361+
assert len(candidates) == len(disks), \
362+
f"Some specified disks ({', '.join(disks)}) are not free or available on all hosts."
363+
logging.info(">> Disk(s) %s are present and free on all pool members", candidates)
364+
yield candidates
365+
332366
@pytest.fixture(scope='module')
333367
def vm_ref(request):
334368
ref = request.param

0 commit comments

Comments
 (0)