Skip to content

Commit a6f83ea

Browse files
committed
New fixture unused_4k_disks for largeblocks tests
Signed-off-by: Yann Dirson <[email protected]>
1 parent 6ac9204 commit a6f83ea

File tree

5 files changed

+42
-12
lines changed

5 files changed

+42
-12
lines changed

conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def pytest_collection_modifyitems(items, config):
131131
'hostB1',
132132
'sr_disk_4k',
133133
'unused_512B_disks',
134+
'unused_4k_disks',
134135
]
135136

136137
for item in items:
@@ -403,6 +404,17 @@ def unused_512B_disks(disks: dict[Host, list[Host.BlockDeviceInfo]]
403404
logging.debug("available disks collected: %s", {host.hostname_or_ip: value for host, value in ret.items()})
404405
return ret
405406

407+
@pytest.fixture(scope='session')
408+
def unused_4k_disks(disks: dict[Host, list[Host.BlockDeviceInfo]]
409+
) -> dict[Host, list[Host.BlockDeviceInfo]]:
410+
"""Dict identifying names of all 4K-blocks disks for on all hosts of first pool."""
411+
ret = {host: [disk for disk in host_disks
412+
if disk["log-sec"] == "4096" and host.disk_is_available(disk["name"])]
413+
for host, host_disks in disks.items()
414+
}
415+
logging.debug("available 4k disks collected: %s", {host.hostname_or_ip: value for host, value in ret.items()})
416+
return ret
417+
406418
@pytest.fixture(scope='session')
407419
def sr_disk_4k(pytestconfig, host: Host) -> Generator[DiskDevName]:
408420
"""

jobs.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"--sr-disk": "auto",
9292
},
9393
"paths": ["tests/storage"],
94-
"markers": "(small_vm or no_vm) and not reboot and not quicktest and not sr_disk_4k",
94+
"markers": "(small_vm or no_vm) and not reboot and not quicktest and not unused_4k_disks",
9595
"name_filter": "not migration and not linstor",
9696
},
9797
"storage-migrations": {
@@ -109,7 +109,7 @@
109109
"--sr-disk": "auto",
110110
},
111111
"paths": ["tests/storage"],
112-
"markers": "not sr_disk_4k",
112+
"markers": "not unused_4k_disks",
113113
"name_filter": "migration and not linstor",
114114
},
115115
"storage-reboots": {
@@ -126,7 +126,7 @@
126126
"--sr-disk": "auto",
127127
},
128128
"paths": ["tests/storage"],
129-
"markers": "reboot and not flaky and not sr_disk_4k",
129+
"markers": "reboot and not flaky and not unused_4k_disks",
130130
"name_filter": "not linstor",
131131
},
132132
"storage-quicktest": {
@@ -141,7 +141,7 @@
141141
"--sr-disk": "auto",
142142
},
143143
"paths": ["tests/storage"],
144-
"markers": "quicktest and not sr_disk_4k",
144+
"markers": "quicktest and not unused_4k_disks",
145145
"name_filter": "not linstor and not zfsvol",
146146
},
147147
"linstor-main": {
@@ -218,7 +218,7 @@
218218
"--sr-disk-4k": "auto",
219219
},
220220
"paths": ["tests/storage"],
221-
"markers": "(small_vm or no_vm) and sr_disk_4k and not reboot and not quicktest",
221+
"markers": "(small_vm or no_vm) and unused_4k_disks and not reboot and not quicktest",
222222
"name_filter": "not migration",
223223
},
224224
"largeblock-migrations": {
@@ -235,7 +235,7 @@
235235
"--sr-disk-4k": "auto",
236236
},
237237
"paths": ["tests/storage"],
238-
"markers": "sr_disk_4k",
238+
"markers": "unused_4k_disks",
239239
"name_filter": "migration",
240240
},
241241
"largeblock-reboots": {
@@ -251,7 +251,7 @@
251251
"--sr-disk-4k": "auto",
252252
},
253253
"paths": ["tests/storage"],
254-
"markers": "sr_disk_4k and reboot",
254+
"markers": "unused_4k_disks and reboot",
255255
},
256256
"largeblock-quicktest": {
257257
"description": "runs `quicktest` on the largeblock storage driver",
@@ -264,7 +264,7 @@
264264
"--sr-disk-4k": "auto",
265265
},
266266
"paths": ["tests/storage"],
267-
"markers": "sr_disk_4k and quicktest",
267+
"markers": "unused_4k_disks and quicktest",
268268
},
269269
"sb-main": {
270270
"description": "tests uefistored/varstored and SecureBoot using a small unix VM (or no VM when none needed)",

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ markers =
1111
hostB1: a second pool.
1212
sr_disk_4k: the test needs a free 4KiB block device that it can erase.
1313
unused_512B_disks: the test needs one or more free 512B-blocks disk or writable block device that it can erase.
14+
unused_4k_disks: the test needs a free 4KiB block device that it can erase.
1415

1516
# * VM-related markers, automatically set based on fixtures
1617
no_vm: tests that do not require a VM to run.

tests/storage/largeblock/conftest.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35
import logging
46

7+
from typing import TYPE_CHECKING, Generator
8+
9+
if TYPE_CHECKING:
10+
from lib.host import Host
11+
from lib.sr import SR
12+
513
@pytest.fixture(scope='package')
6-
def largeblock_sr(host, sr_disk_4k):
14+
def largeblock_sr(host: Host, unused_4k_disks: dict[Host, list[Host.BlockDeviceInfo]]) -> Generator[SR]:
715
""" A LARGEBLOCK SR on first host. """
8-
sr = host.sr_create('largeblock', "LARGEBLOCK-local-SR-test", {'device': '/dev/' + sr_disk_4k})
16+
sr_disk = unused_4k_disks[host][0]["name"]
17+
sr = host.sr_create('largeblock', "LARGEBLOCK-local-SR-test", {'device': '/dev/' + sr_disk})
918
yield sr
1019
# teardown
1120
sr.destroy()

tests/storage/largeblock/test_largeblock_sr.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35
from lib.common import vm_image, wait_for
46
from tests.storage import try_to_create_sr_with_missing_device, vdi_is_open
57

8+
from typing import TYPE_CHECKING
9+
10+
if TYPE_CHECKING:
11+
from lib.host import Host
12+
613
# Requirements:
714
# - one XCP-ng host with an additional unused 4KiB disk for the SR
815

@@ -16,9 +23,10 @@ class TestLARGEBLOCKSRCreateDestroy:
1623
def test_create_sr_with_missing_device(self, host):
1724
try_to_create_sr_with_missing_device('largeblock', 'LARGEBLOCK-local-SR-test', host)
1825

19-
def test_create_and_destroy_sr(self, host, sr_disk_4k):
26+
def test_create_and_destroy_sr(self, host: Host, unused_4k_disks: dict[Host, list[Host.BlockDeviceInfo]]) -> None:
2027
# Create and destroy tested in the same test to leave the host as unchanged as possible
21-
sr = host.sr_create('largeblock', "LARGEBLOCK-local-SR-test", {'device': '/dev/' + sr_disk_4k}, verify=True)
28+
sr_disk = unused_4k_disks[host][0]["name"]
29+
sr = host.sr_create('largeblock', "LARGEBLOCK-local-SR-test", {'device': '/dev/' + sr_disk}, verify=True)
2230
# import a VM in order to detect vm import issues here rather than in the vm_on_xfs_fixture used in
2331
# the next tests, because errors in fixtures break teardown
2432
vm = host.import_vm(vm_image('mini-linux-x86_64-bios'), sr_uuid=sr.uuid)

0 commit comments

Comments
 (0)