Skip to content

Commit 8f8d5ac

Browse files
committed
New fixtures to access disks without assuming uniform naming in first pool
Signed-off-by: Yann Dirson <[email protected]>
1 parent 85599d5 commit 8f8d5ac

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

conftest.py

Lines changed: 26 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,24 @@ 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]]
344+
) -> Generator[dict[Host, list[DiskDevName]]]:
345+
ret = {host: [disk for disk in disks if host.disk_is_available(disk)]
346+
for host, disks in disks.items()
347+
}
348+
logging.debug("available disks collected: %s", {host.hostname_or_ip: value for host, value in ret.items()})
349+
yield ret
350+
332351
@pytest.fixture(scope='session')
333352
def sr_disk(pytestconfig, host):
334353
"""
@@ -412,6 +431,13 @@ def sr_disk_for_all_hosts(pytestconfig, request, host):
412431
logging.info(f">> Disk or block device {disk} is present and free on all pool members")
413432
yield candidates[0]
414433

434+
@pytest.fixture(scope='session')
435+
def pool_with_unused_disk(host: Host, unused_disks: dict[Host, list[DiskDevName]]) -> Pool:
436+
for h in host.pool.hosts:
437+
assert h in unused_disks
438+
assert unused_disks[h], f"host {h} does not have any unused disk"
439+
return host.pool
440+
415441
@pytest.fixture(scope='session')
416442
def sr_disks_for_all_hosts(pytestconfig, request, host):
417443
"""

0 commit comments

Comments
 (0)