|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +import logging |
| 6 | + |
| 7 | +# explicit import for package-scope fixtures |
| 8 | +from pkgfixtures import pool_with_saved_yum_state |
| 9 | + |
| 10 | +from typing import TYPE_CHECKING |
| 11 | + |
| 12 | +if TYPE_CHECKING: |
| 13 | + from lib.host import Host |
| 14 | + |
| 15 | +QCOW2_REPO = "qcow2" |
| 16 | +QCOW2_REPO_FILE = f"/etc/yum.repos.d/xcp-ng-{QCOW2_REPO}.repo" |
| 17 | + |
| 18 | + |
1 | 19 | def pytest_collection_modifyitems(config, items): |
2 | 20 | # modify ordering so that ext is always tested first, |
3 | 21 | # before more complex storage drivers |
4 | 22 | for item in reversed(list(items)): |
5 | 23 | if "_ext_" in item.path.name: |
6 | 24 | items.remove(item) |
7 | 25 | items.insert(0, item) |
| 26 | + |
| 27 | + |
| 28 | +@pytest.fixture(scope='package') |
| 29 | +def pool_with_qcow2(hostA1: Host, image_format): |
| 30 | + import concurrent.futures |
| 31 | + pool = hostA1.pool |
| 32 | + |
| 33 | + # If we're testing VHD image format, skip installing qcow2 and just return the pool. |
| 34 | + # Use yield+return because this is a generator fixture. |
| 35 | + if image_format == "vhd": |
| 36 | + yield pool |
| 37 | + return |
| 38 | + |
| 39 | + def check_qcow2_installed(host): |
| 40 | + if host.file_exists(QCOW2_REPO_FILE): |
| 41 | + raise Exception( |
| 42 | + f'{QCOW2_REPO_FILE} is already installed on host {host}. This should not be the case.' |
| 43 | + ) |
| 44 | + |
| 45 | + with concurrent.futures.ThreadPoolExecutor() as executor: |
| 46 | + list(executor.map(check_qcow2_installed, pool.hosts)) |
| 47 | + |
| 48 | + def install_qcow2(host): |
| 49 | + logging.info(f"Installing qcow2 packages on host {host}...") |
| 50 | + host.add_xcpng_repo(QCOW2_REPO, base_repo="vates") |
| 51 | + host.yum_install(["sm", "sm-fairlock", "blktap"]) |
| 52 | + host.restart_toolstack(verify=True) |
| 53 | + |
| 54 | + with concurrent.futures.ThreadPoolExecutor() as executor: |
| 55 | + list(executor.map(install_qcow2, pool.hosts)) |
| 56 | + |
| 57 | + yield pool |
| 58 | + |
| 59 | + def remove_qcow2(host): |
| 60 | + logging.info(f"Cleaning up qcow2 packages from host {host}...") |
| 61 | + host.remove_xcpng_repo(QCOW2_REPO) |
| 62 | + host.yum_downgrade(["sm", "sm-fairlock", "blktap"]) |
| 63 | + host.restart_toolstack(verify=True) |
| 64 | + |
| 65 | + with concurrent.futures.ThreadPoolExecutor() as executor: |
| 66 | + list(executor.map(remove_qcow2, pool.hosts)) |
0 commit comments