Skip to content

Commit b69878e

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

File tree

6 files changed

+39
-12
lines changed

6 files changed

+39
-12
lines changed

conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def pytest_collection_modifyitems(items, config):
122122
'hostB1',
123123
'sr_disk_4k',
124124
'unused_disks',
125+
'unused_4k_disks',
125126
]
126127

127128
for item in items:
@@ -387,6 +388,15 @@ def unused_disks(disks: dict[Host, list[DiskDevName]]
387388
logging.debug("available disks collected: %s", {host.hostname_or_ip: value for host, value in ret.items()})
388389
yield ret
389390

391+
@pytest.fixture(scope='session')
392+
def unused_4k_disks(unused_disks: dict[Host, list[DiskDevName]]
393+
) -> Generator[dict[Host, list[DiskDevName]]]:
394+
ret = {host: [disk for disk in host_disks if host.disk_is_4k(disk)]
395+
for host, host_disks in unused_disks.items()
396+
}
397+
logging.debug("available 4k disks collected: %s", {host.hostname_or_ip: value for host, value in ret.items()})
398+
yield ret
399+
390400
@pytest.fixture(scope='session')
391401
def sr_disk_4k(pytestconfig, host: Host) -> Generator[DiskDevName]:
392402
"""

jobs.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"--sr-disk": "auto",
9191
},
9292
"paths": ["tests/storage"],
93-
"markers": "(small_vm or no_vm) and not reboot and not quicktest and not sr_disk_4k",
93+
"markers": "(small_vm or no_vm) and not reboot and not quicktest and not unused_4k_disks",
9494
"name_filter": "not migration and not linstor",
9595
},
9696
"storage-migrations": {
@@ -108,7 +108,7 @@
108108
"--sr-disk": "auto",
109109
},
110110
"paths": ["tests/storage"],
111-
"markers": "not sr_disk_4k",
111+
"markers": "not unused_4k_disks",
112112
"name_filter": "migration and not linstor",
113113
},
114114
"storage-reboots": {
@@ -125,7 +125,7 @@
125125
"--sr-disk": "auto",
126126
},
127127
"paths": ["tests/storage"],
128-
"markers": "reboot and not flaky and not sr_disk_4k",
128+
"markers": "reboot and not flaky and not unused_4k_disks",
129129
"name_filter": "not linstor",
130130
},
131131
"storage-quicktest": {
@@ -140,7 +140,7 @@
140140
"--sr-disk": "auto",
141141
},
142142
"paths": ["tests/storage"],
143-
"markers": "quicktest and not sr_disk_4k",
143+
"markers": "quicktest and not unused_4k_disks",
144144
"name_filter": "not linstor and not zfsvol",
145145
},
146146
"linstor-main": {
@@ -217,7 +217,7 @@
217217
"--sr-disk-4k": "auto",
218218
},
219219
"paths": ["tests/storage"],
220-
"markers": "(small_vm or no_vm) and sr_disk_4k and not reboot and not quicktest",
220+
"markers": "(small_vm or no_vm) and unused_4k_disks and not reboot and not quicktest",
221221
"name_filter": "not migration",
222222
},
223223
"largeblock-migrations": {
@@ -234,7 +234,7 @@
234234
"--sr-disk-4k": "auto",
235235
},
236236
"paths": ["tests/storage"],
237-
"markers": "sr_disk_4k",
237+
"markers": "unused_4k_disks",
238238
"name_filter": "migration",
239239
},
240240
"largeblock-reboots": {
@@ -250,7 +250,7 @@
250250
"--sr-disk-4k": "auto",
251251
},
252252
"paths": ["tests/storage"],
253-
"markers": "sr_disk_4k and reboot",
253+
"markers": "unused_4k_disks and reboot",
254254
},
255255
"largeblock-quicktest": {
256256
"description": "runs `quicktest` on the largeblock storage driver",
@@ -263,7 +263,7 @@
263263
"--sr-disk-4k": "auto",
264264
},
265265
"paths": ["tests/storage"],
266-
"markers": "sr_disk_4k and quicktest",
266+
"markers": "unused_4k_disks and quicktest",
267267
},
268268
"sb-main": {
269269
"description": "tests uefistored/varstored and SecureBoot using a small unix VM (or no VM when none needed)",

lib/host.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,20 @@ def disk_is_available(self, disk: DiskDevName) -> bool:
556556
"""
557557
return len(self.ssh(['lsblk', '--noheadings', '--nodeps', '-o', 'MOUNTPOINT', '/dev/' + disk]).strip()) == 0
558558

559+
def disk_is_4k(self, disk: DiskDevName) -> bool:
560+
"""
561+
Check if a disk has 4k blocks.
562+
563+
It may or may not contain identifiable filesystem or partition label.
564+
If there are no mountpoints, it is assumed that the disk is not in use.
565+
566+
Warn: This function may misclassify LVM_member disks (e.g. in XOSTOR, RAID, ZFS) as "available".
567+
Such disks may not have mountpoints but still be in use.
568+
"""
569+
return self.ssh(['lsblk', '--noheadings', '--nodeps',
570+
'-o', 'LOG-SEC',
571+
'/dev/' + disk]).strip() == '4096'
572+
559573
def available_disks(self, blocksize: int = 512) -> list[DiskDevName]:
560574
"""
561575
Return a list of available disks for formatting, creating SRs or such.

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_disks: the test needs a free 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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import pytest
33

44
@pytest.fixture(scope='package')
5-
def largeblock_sr(host, sr_disk_4k):
5+
def largeblock_sr(host, unused_4k_disks):
66
""" A LARGEBLOCK SR on first host. """
7-
sr = host.sr_create('largeblock', "LARGEBLOCK-local-SR-test", {'device': '/dev/' + sr_disk_4k})
7+
sr_disk = unused_4k_disks[host][0]
8+
sr = host.sr_create('largeblock', "LARGEBLOCK-local-SR-test", {'device': '/dev/' + sr_disk})
89
yield sr
910
# teardown
1011
sr.destroy()

tests/storage/largeblock/test_largeblock_sr.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ class TestLARGEBLOCKSRCreateDestroy:
1515
def test_create_sr_with_missing_device(self, host):
1616
try_to_create_sr_with_missing_device('largeblock', 'LARGEBLOCK-local-SR-test', host)
1717

18-
def test_create_and_destroy_sr(self, host, sr_disk_4k):
18+
def test_create_and_destroy_sr(self, host, unused_4k_disks):
1919
# Create and destroy tested in the same test to leave the host as unchanged as possible
20-
sr = host.sr_create('largeblock', "LARGEBLOCK-local-SR-test", {'device': '/dev/' + sr_disk_4k}, verify=True)
20+
sr_disk = unused_4k_disks[host][0]
21+
sr = host.sr_create('largeblock', "LARGEBLOCK-local-SR-test", {'device': '/dev/' + sr_disk}, verify=True)
2122
# import a VM in order to detect vm import issues here rather than in the vm_on_xfs_fixture used in
2223
# the next tests, because errors in fixtures break teardown
2324
vm = host.import_vm(vm_image('mini-linux-x86_64-bios'), sr_uuid=sr.uuid)

0 commit comments

Comments
 (0)