Skip to content

Commit 9c4d791

Browse files
committed
WIP New fixtures to access disks without assuming uniform naming in pool
FIXME: applies to all pools without a way to restrict matching
1 parent 8516b28 commit 9c4d791

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

conftest.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import lib.config as global_config
1414

1515
from lib import pxe
16+
from lib.common import DiskDevName
1617
from lib.common import callable_marker, shortened_nodeid, prefix_object_name
1718
from lib.common import wait_for, vm_image, is_uuid
1819
from lib.common import setup_formatted_and_mounted_disk, teardown_formatted_and_mounted_disk
@@ -329,6 +330,23 @@ def local_sr_on_hostB1(hostB1):
329330
logging.info(">> local SR on hostB1 present : %s" % sr.uuid)
330331
yield sr
331332

333+
@pytest.fixture(scope='session')
334+
def disks(hosts: list[Host]) -> Generator[dict[Host, list[DiskDevName]], None, None]:
335+
ret = {host: host.disks()
336+
for pool_master in hosts
337+
for host in pool_master.pool.hosts
338+
}
339+
logging.debug("disks collected: %s", {host.hostname_or_ip: value for host, value in ret.items()})
340+
yield ret
341+
342+
@pytest.fixture(scope='session')
343+
def unused_disks(disks: dict[Host, list[DiskDevName]]) -> Generator[dict[Host, list[DiskDevName]], None, None]:
344+
ret = {host: [disk for disk in disks if host.disk_is_available(disk)]
345+
for host, disks in disks.items()
346+
}
347+
logging.debug("available disks collected: %s", {host.hostname_or_ip: value for host, value in ret.items()})
348+
yield ret
349+
332350
@pytest.fixture(scope='session')
333351
def sr_disk(pytestconfig, host):
334352
disks = pytestconfig.getoption("sr_disk")
@@ -399,6 +417,13 @@ def sr_disk_for_all_hosts(pytestconfig, request, host):
399417
logging.info(f">> Disk or block device {disk} is present and free on all pool members")
400418
yield candidates[0]
401419

420+
@pytest.fixture(scope='session')
421+
def pool_with_unused_disk(host: Host, unused_disks: dict[Host, list[DiskDevName]]) -> Pool:
422+
for h in host.pool.hosts:
423+
assert h in unused_disks
424+
assert unused_disks[h], f"host {h} does not have any unused disk"
425+
return host.pool
426+
402427
@pytest.fixture(scope='session')
403428
def sr_disks_for_all_hosts(pytestconfig, request, host):
404429
"""

0 commit comments

Comments
 (0)