Skip to content

Commit 6360b2e

Browse files
feat: Add pool_with_qcow2 to check if qcow2 is already present before tests. Install qcow2 before tests and remove qcow2 after tests
Add pool_with_qcow2 fixture in ext, lvm, xfs, zfs & largeblock SR. Signed-off-by: Rushikesh Jadhav <[email protected]>
1 parent ebb9752 commit 6360b2e

File tree

11 files changed

+92
-10
lines changed

11 files changed

+92
-10
lines changed

tests/storage/conftest.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,66 @@
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+
119
def pytest_collection_modifyitems(config, items):
220
# modify ordering so that ext is always tested first,
321
# before more complex storage drivers
422
for item in reversed(list(items)):
523
if "_ext_" in item.path.name:
624
items.remove(item)
725
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))

tests/storage/ext/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import logging
66

7+
from lib.pool import Pool
8+
79
from typing import TYPE_CHECKING, Generator
810

911
if TYPE_CHECKING:
@@ -13,7 +15,8 @@
1315
@pytest.fixture(scope='package')
1416
def ext_sr(host: Host,
1517
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
16-
image_format: str
18+
image_format: str,
19+
pool_with_qcow2: Pool
1720
) -> Generator[SR]:
1821
""" An EXT SR on first host. """
1922
sr_disk = unused_512B_disks[host][0]["name"]

tests/storage/ext/test_ext_sr.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from lib.commands import SSHCommandFailed
88
from lib.common import vm_image, wait_for
99
from lib.fistpoint import FistPoint
10+
from lib.pool import Pool
1011
from lib.vdi import VDI
1112
from tests.storage import try_to_create_sr_with_missing_device, vdi_is_open
1213

@@ -30,7 +31,8 @@ def test_create_sr_with_missing_device(self, host):
3031

3132
def test_create_and_destroy_sr(self, host: Host,
3233
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
33-
image_format: str
34+
image_format: str,
35+
pool_with_qcow2: Pool
3436
) -> None:
3537
# Create and destroy tested in the same test to leave the host as unchanged as possible
3638
sr_disk = unused_512B_disks[host][0]["name"]

tests/storage/largeblock/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88

99
if TYPE_CHECKING:
1010
from lib.host import Host
11+
from lib.pool import Pool
1112
from lib.sr import SR
1213

1314
@pytest.fixture(scope='package')
1415
def largeblock_sr(host: Host,
1516
unused_4k_disks: dict[Host,
1617
list[Host.BlockDeviceInfo]],
17-
image_format: str) -> Generator[SR]:
18+
image_format: str,
19+
pool_with_qcow2: Pool
20+
) -> Generator[SR]:
1821
""" A LARGEBLOCK SR on first host. """
1922
sr_disk = unused_4k_disks[host][0]["name"]
2023
sr = host.sr_create('largeblock', "LARGEBLOCK-local-SR-test",

tests/storage/largeblock/test_largeblock_sr.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
from lib.common import vm_image, wait_for
6+
from lib.pool import Pool
67
from tests.storage import try_to_create_sr_with_missing_device, vdi_is_open
78

89
from typing import TYPE_CHECKING
@@ -25,7 +26,9 @@ def test_create_sr_with_missing_device(self, host):
2526

2627
def test_create_and_destroy_sr(self, host: Host,
2728
unused_4k_disks: dict[Host, list[Host.BlockDeviceInfo]],
28-
image_format: str) -> None:
29+
image_format: str,
30+
pool_with_qcow2: Pool
31+
) -> None:
2932
# Create and destroy tested in the same test to leave the host as unchanged as possible
3033
sr_disk = unused_4k_disks[host][0]["name"]
3134
sr = host.sr_create('largeblock', "LARGEBLOCK-local-SR-test",

tests/storage/lvm/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
if TYPE_CHECKING:
1010
from lib.host import Host
11+
from lib.pool import Pool
1112
from lib.sr import SR
1213

1314
@pytest.fixture(scope='package')
1415
def lvm_sr(host: Host,
1516
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
16-
image_format: str
17+
image_format: str,
18+
pool_with_qcow2: Pool
1719
) -> Generator[SR]:
1820
""" An LVM SR on first host. """
1921
sr_disk = unused_512B_disks[host][0]["name"]

tests/storage/lvm/test_lvm_sr.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from lib.commands import SSHCommandFailed
88
from lib.common import vm_image, wait_for
99
from lib.fistpoint import FistPoint
10+
from lib.pool import Pool
1011
from lib.vdi import VDI
1112
from tests.storage import try_to_create_sr_with_missing_device, vdi_is_open
1213

@@ -30,7 +31,8 @@ def test_create_sr_with_missing_device(self, host):
3031

3132
def test_create_and_destroy_sr(self, host: Host,
3233
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
33-
image_format: str
34+
image_format: str,
35+
pool_with_qcow2: Pool
3436
) -> None:
3537
sr_disk = unused_512B_disks[host][0]["name"]
3638
# Create and destroy tested in the same test to leave the host as unchanged as possible

tests/storage/xfs/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
if TYPE_CHECKING:
1010
from lib.host import Host
11+
from lib.pool import Pool
1112
from lib.sr import SR
1213

1314
# NOTE: @pytest.mark.usefixtures does not parametrize this fixture.
@@ -28,7 +29,8 @@ def host_with_xfsprogs(host: Host, image_format: str):
2829
def xfs_sr(unused_512B_disks: dict[Host,
2930
list[Host.BlockDeviceInfo]],
3031
host_with_xfsprogs: Host,
31-
image_format: str
32+
image_format: str,
33+
pool_with_qcow2: Pool
3234
) -> Generator[SR]:
3335
""" A XFS SR on first host. """
3436
sr_disk = unused_512B_disks[host_with_xfsprogs][0]["name"]

tests/storage/xfs/test_xfs_sr.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def test_create_xfs_sr_without_xfsprogs(self,
4848

4949
def test_create_and_destroy_sr(self,
5050
unused_512B_disks: dict[Host, list[Host.BlockDeviceInfo]],
51-
host_with_xfsprogs: Host
51+
host_with_xfsprogs: Host,
52+
pool_with_qcow2
5253
) -> None:
5354
# Create and destroy tested in the same test to leave the host as unchanged as possible
5455
host = host_with_xfsprogs

tests/storage/zfs/conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44

55
# Explicitly import package-scoped fixtures (see explanation in pkgfixtures.py)
6+
from lib.pool import Pool
67
from pkgfixtures import host_with_saved_yum_state, sr_disk_wiped
78

89
from typing import TYPE_CHECKING, Generator
@@ -46,7 +47,10 @@ def zpool_vol0(sr_disk_wiped, host_with_zfs):
4647
host_with_zfs.ssh(['zpool', 'destroy', POOL_NAME])
4748

4849
@pytest.fixture(scope='package')
49-
def zfs_sr(host: Host, image_format: str, zpool_vol0: None) -> Generator[SR]:
50+
def zfs_sr(host: Host, image_format: str,
51+
zpool_vol0: None,
52+
pool_with_qcow2: Pool
53+
) -> Generator[SR]:
5054
""" A ZFS SR on first host. """
5155
sr = host.sr_create('zfs', "ZFS-local-SR-test", {
5256
'location': POOL_PATH,

0 commit comments

Comments
 (0)