Test Fixtures¶
This section documents the test fixtures provided by sts-libs. These fixtures help set up test environments for various storage technologies.
Common Fixtures¶
sts.fixtures.common_fixtures
¶
Common test fixtures.
This module provides fixtures that can be used across different test suites: - Virtual block devices (loop, scsi_debug) - System resources - Common utilities
Fixture Dependencies: 1. loop_devices - Independent fixture - Creates temporary loop devices - Handles cleanup automatically
- scsi_debug_devices
- Independent fixture
- Creates SCSI debug devices
- Handles cleanup automatically
Common Usage:
-
Basic device testing:
def test_single_device(loop_devices): device = loop_devices[0] # Test with single device -
Multi-device testing:
@pytest.mark.parametrize('loop_devices', [2], indirect=True) def test_multiple_devices(loop_devices): dev1, dev2 = loop_devices # Test with multiple devices -
SCSI debug testing:
@pytest.mark.parametrize('scsi_debug_devices', [2], indirect=True) def test_scsi_devices(scsi_debug_devices): dev1, dev2 = scsi_debug_devices # Test with SCSI debug devices
Error Handling: - Device creation failures skip the test - Cleanup runs even if test fails - Resource limits are checked
debugfs_module_reader(managed_module)
¶
Fixture to prepare and provide access to a module's debugfs directory.
Relies on the 'managed_module' fixture to ensure the module is loaded. Ensures debugfs is mounted and the module's debugfs directory exists.
Source code in sts_libs/src/sts/fixtures/common_fixtures.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
ensure_minimum_devices()
¶
Fixture that ensures minimum number of devices without block size filtering.
Source code in sts_libs/src/sts/fixtures/common_fixtures.py
384 385 386 387 | |
ensure_minimum_devices_with_same_block_sizes()
¶
Fixture that ensures minimum number of devices with same block sizes.
Source code in sts_libs/src/sts/fixtures/common_fixtures.py
378 379 380 381 | |
loop_devices(request)
¶
Create loop devices for testing.
Creates virtual block devices using the loop driver: - Each device is 1GB in size - Devices are sparse (only allocate used space) - Devices are automatically cleaned up - Supports multiple devicesce(loop_devices): assert len(loop_devices) == 1 assert loop_d per test
Configuration: - count: Number of devices to create (default: 1) - size_mb: Size of each device in MB (default: 1024) Set via parametrize: @pytest.mark.parametrize('loop_devices', [2], indirect=True) Or with custom size: @pytest.mark.parametrize('loop_devices', [{'count': 1, 'size_mb': 4096}], indirect=True)
Error Handling: - Skips test if device creation fails - Cleans up any created devices on failure - Validates device paths before yielding
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FixtureRequest
|
Pytest fixture request with 'count' parameter |
required |
Yields:
| Type | Description |
|---|---|
list[str]
|
List of loop device paths (e.g. ['/dev/loop0', '/dev/loop1']) |
Example
Single device¶
def test_device(loop_devices):
assert len(loop_devices) == 1
assert loop_devices[0].startswith('/dev/loop')
Multiple devices¶
@pytest.mark.parametrize('loop_devices', [2], indirect=True)
def test_devices(loop_devices):
assert len(loop_devices) == 2
assert all(d.startswith('/dev/loop') for d in loop_devices)
Source code in sts_libs/src/sts/fixtures/common_fixtures.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
prepare_1minutetip_disk()
¶
This fixture is used to prepare a spare disk for testing on specific 1minutetip flavor (ci.m1.small.ephemeral).
It will wipe /dev/vdb and return a single-item list of BlockDevice objects.
Source code in sts_libs/src/sts/fixtures/common_fixtures.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
ramdisk_loop_devices(request)
¶
Create loopback devices backed by ramdisk using targetcli.
Uses targetcli to create ramdisk backstores and export them via the loopback fabric. This provides very fast I/O as data is stored in RAM, ideal for sanity testing on VMs with limited resources.
Key benefits: - Much faster than file-backed loop devices - No disk I/O bottleneck - Uses kernel ramdisk (not tmpfs files) - Suitable for VMs with ~4GB RAM
Configuration via parametrize: - count: Number of devices to create (default: 1) - size_mb: Size of each device in MB (default: 512)
Examples:
# Single 512MB ramdisk device
def test_fast(ramdisk_loop_devices):
device = ramdisk_loop_devices[0]
# Multiple smaller devices
@pytest.mark.parametrize(
'ramdisk_loop_devices',
[{'count': 2, 'size_mb': 256}],
indirect=True,
)
def test_multi_fast(ramdisk_loop_devices):
dev1, dev2 = ramdisk_loop_devices
Warning
Total device size should not exceed available RAM. With 4GB RAM, recommend max 1-2GB total for devices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FixtureRequest
|
Pytest fixture request with optional 'count' and 'size_mb' parameters |
required |
Yields:
| Type | Description |
|---|---|
list[str]
|
List of block device paths backed by ramdisk |
Source code in sts_libs/src/sts/fixtures/common_fixtures.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
scsi_debug_devices(request)
¶
Create SCSI debug devices for testing.
Creates virtual SCSI devices using the scsi_debug module: - Each device is 1GB in size - Devices share a single scsi_debug instance - Devices are automatically cleaned up - Supports multiple devices per test
Configuration: - count: Number of devices to create (default: 1) Set via parametrize: @pytest.mark.parametrize('scsi_debug_devices', [2])
Error Handling: - Skips test if module loading fails - Skips test if device creation fails - Cleans up module and devices on failure - Validates device count before yielding
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FixtureRequest
|
Pytest fixture request with 'count' parameter |
required |
Yields:
| Type | Description |
|---|---|
list[str]
|
List of SCSI device paths (e.g. ['/dev/sda', '/dev/sdb']) |
Example
# Single device
def test_device(scsi_debug_devices):
assert len(scsi_debug_devices) == 1
assert scsi_debug_devices[0].startswith('/dev/sd')
# Multiple devices
@pytest.mark.parametrize('scsi_debug_devices', [2], indirect=True)
def test_devices(scsi_debug_devices):
assert len(scsi_debug_devices) == 4
assert all(d.startswith('/dev/sd') for d in scsi_debug_devices)
Source code in sts_libs/src/sts/fixtures/common_fixtures.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
time_controller()
¶
Fixture providing a TimeController for system time manipulation.
Disables NTP before yielding and restores it after the test. Use this fixture when testing time-dependent functionality.
Warning: Requires root privileges. Temporarily changes system time.
Yields:
| Type | Description |
|---|---|
TimeController
|
TimeController instance with NTP disabled |
Example
def test_time_sensitive_feature(time_controller):
# NTP is already disabled
with time_controller.time_offset(hours=-5):
# System time is 5 hours in the past
create_timestamped_resource()
# Time is still offset here
# After test, NTP is re-enabled and time is restored
Source code in sts_libs/src/sts/fixtures/common_fixtures.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | |
timed_operation()
¶
Fixture providing timed operation context manager.
Example
def test_example(timed_operation):
with timed_operation('My operation'):
do_something()
Source code in sts_libs/src/sts/fixtures/common_fixtures.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
iSCSI Fixtures¶
sts.fixtures.iscsi_fixtures
¶
iSCSI test fixtures.
This module provides fixtures for testing iSCSI: - Package installation - Service management - Device configuration - Parameter verification - Session management
Fixture Dependencies: 1. _iscsi_test (base fixture) - Installs iSCSI utilities - Manages sessions 2. iscsi_localhost_test (depends on _iscsi_test) - Sets up target environment 3. iscsi_target (depends on iscsi_localhost_test) - Creates target and initiator - Manages connections
IscsiTestConfig
dataclass
¶
Configuration for iSCSI test environment.
Attributes:
| Name | Type | Description |
|---|---|---|
base_iqn |
str
|
Base IQN for test |
target_iqn |
str
|
Target IQN |
initiator_iqn |
str
|
Initiator IQN |
size |
str
|
Size of LUNs |
n_luns |
int
|
Number of LUNs |
Source code in sts_libs/src/sts/fixtures/iscsi_fixtures.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
generate_test_iqns(test_name)
¶
Generate IQNs for test environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_name
|
str
|
Name of the test |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str, str]
|
Tuple of (base_iqn, target_iqn, initiator_iqn) |
Source code in sts_libs/src/sts/fixtures/iscsi_fixtures.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
get_test_device()
¶
Get test device paths.
Returns:
| Type | Description |
|---|---|
Callable[[str], list[Path]]
|
Function to get device paths with optional vendor parameter |
Example
def test_device(get_test_device):
devices = get_test_device('LIO-ORG') # or get_test_device('COMPELNT')
for device in devices:
assert device.exists()
Source code in sts_libs/src/sts/fixtures/iscsi_fixtures.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
iscsi_localhost_test(request, _iscsi_test)
¶
Set up iSCSI target environment.
This fixture: - Installs target utilities - Creates target configuration - Cleans up environment
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FixtureRequest
|
Fixture request |
required |
_iscsi_test
|
None
|
Parent fixture providing base setup |
required |
Yields:
| Type | Description |
|---|---|
str
|
Target IQN |
Example
def test_target(iscsi_localhost_test):
target_iqn = iscsi_localhost_test
assert Iscsi(target_iqn).exists()
Source code in sts_libs/src/sts/fixtures/iscsi_fixtures.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
iscsi_target(request, iscsi_localhost_test)
¶
Create iSCSI target and connect initiator.
This fixture: - Creates target with specified size and number of LUNs - Sets up initiator - Logs in to target - Yields connected node - Cleans up on exit
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FixtureRequest
|
Fixture request with parameters: - size: Size of each LUN (default: '1G') - n_luns: Number of LUNs (default: 1) |
required |
iscsi_localhost_test
|
None
|
Parent fixture providing target IQN |
required |
Example
@pytest.mark.parametrize('iscsi_target', [{'size': '2G', 'n_luns': 2}], indirect=True)
def test_something(iscsi_target):
assert iscsi_target.exists()
Source code in sts_libs/src/sts/fixtures/iscsi_fixtures.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
manage_iscsi_session(node)
¶
Context manager for iSCSI session management.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
IscsiNode
|
IscsiNode instance to manage |
required |
Yields:
| Type | Description |
|---|---|
None
|
None |
Source code in sts_libs/src/sts/fixtures/iscsi_fixtures.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
LVM Fixtures¶
sts.fixtures.lvm_fixtures
¶
LVM test fixtures.
This module provides fixtures for testing LVM (Logical Volume Management): - Package installation and cleanup - Service management - Device configuration - VDO (Virtual Data Optimizer) support
Fixture Dependencies: 1. _lvm_test (base fixture) - Installs LVM packages - Manages volume cleanup - Logs system information
- _vdo_test (depends on _lvm_test)
- Installs VDO packages
- Manages kernel module
- Provides data reduction features
Common Usage: 1. Basic LVM testing: @pytest.mark.usefixtures('_lvm_test') def test_lvm(): # LVM utilities are installed # Volumes are cleaned up after test
- VDO-enabled testing: @pytest.mark.usefixtures('_vdo_test') def test_vdo(): # VDO module is loaded # Data reduction is available
Error Handling: - Package installation failures fail the test - Module loading failures fail the test - Volume cleanup runs even if test fails - Service issues are logged
binary_metadata_file()
¶
Create a pre-allocated binary file for thin metadata operations.
This fixture creates a 5MB binary file in /var/tmp that can be used as output for thin_restore or other DMPD tools that require pre-allocated files.
Yields:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
Path to the allocated binary metadata file in /var/tmp |
Example
def test_thin_restore(binary_metadata_file, metadata_backup):
xml_file = metadata_backup['metadata_backup_path']
binary_file = binary_metadata_file
# thin_restore can now write to the pre-allocated binary file
restore_result = dmpd.thin_restore(input=str(xml_file), output=str(binary_file))
assert restore_result.succeeded
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 | |
cache_metadata_backup(cache_metadata_swap)
¶
Create cache metadata backup files for testing.
Creates cache metadata dump and prepares repair files for testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_metadata_swap
|
dict[str, Any]
|
Cache metadata swap setup from cache_metadata_swap fixture |
required |
Yields:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Extended information with backup file paths |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 | |
cache_metadata_swap(cache_split, swap_volume)
¶
Perform cache metadata swap operation.
Swaps cache metadata to the swap volume for DMPD testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_split
|
dict[str, Any]
|
Cache split setup from cache_split fixture |
required |
swap_volume
|
dict[str, Any]
|
Swap volume setup from swap_volume fixture |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Combined information with cache metadata device details |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 | |
cache_pool(cache_volumes)
¶
Create cache pool by merging cache data and metadata volumes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_volumes
|
dict[str, Any]
|
Cache volumes setup from cache_volumes fixture |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Extended cache information with pool details |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 | |
cache_split(cache_volume)
¶
Split cache volume to separate cache pool and origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_volume
|
dict[str, Any]
|
Cache volume setup from cache_volume fixture |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Extended cache information with split cache details |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 | |
cache_volume(cache_pool)
¶
Create cached volume by adding origin to cache pool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_pool
|
dict[str, Any]
|
Cache pool setup from cache_pool fixture |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Extended cache information with cached volume details |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 | |
cache_volumes(setup_loopdev_vg)
¶
Create cache volumes for testing.
Creates cache metadata, origin, and data logical volumes that can be used for creating cache pools and cached volumes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
setup_loopdev_vg
|
str
|
Volume group name from setup_loopdev_vg fixture |
required |
Yields:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Information about the created cache volumes |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 | |
install_dmpd(_lvm_test)
¶
Install required packages for device-mapper-persistent-data tools.
This fixture installs the device-mapper-persistent-data package which provides cache metadata tools like cache_check, cache_dump, cache_repair, etc.
Example
@pytest.mark.usefixtures('install_dmpd_packages')
def test_cache_tools():
# DMPD tools are now available
pass
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 | |
load_vdo_module(_lvm_test)
¶
Load the appropriate VDO kernel module based on kernel version.
This fixture installs the VDO package and loads the correct VDO kernel module depending on the system's kernel version: - For kernel 6.9+: uses dm-vdo module (built into kernel) - For kernel 6.8 and earlier: uses kvdo module (from kmod-kvdo package)
The fixture handles kernel version detection and falls back to dm-vdo if version parsing fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_lvm_test
|
None
|
LVM test fixture dependency (ensures LVM setup is complete) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Name of the loaded VDO module ('dm-vdo' or 'kvdo') |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If VDO package installation or module loading fails |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
lv_fixture(_lvm_test, setup_vg, request)
¶
Create a logical volume for testing with automatic cleanup.
This fixture creates either a COW (regular) or thin logical volume depending on the parameters provided. It handles proper cleanup including thin pool removal for thin volumes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_lvm_test
|
None
|
LVM test fixture dependency |
required |
setup_vg
|
str
|
Volume group name from setup_vg fixture |
required |
request
|
FixtureRequest
|
Pytest fixture request for accessing parameters |
required |
Yields:
| Name | Type | Description |
|---|---|---|
str |
str
|
Device path to the created logical volume |
Default Configuration
- lv_type: 'cow' (regular logical volume)
- extents: '25%vg'
Parameters (via pytest.mark.parametrize with indirect=True): - lv_type (str): 'cow' for regular LV or 'thin' for thin LV (default: 'cow') - lv_name (str): Name for the logical volume (default: based on lv_type) - extents (str): Size specification in extents (default: '25%vg') - pool_name (str): Thin pool name (only for thin type, default: 'stspool1_25vg') - virtualsize (str): Virtual size for thin LV (only for thin type, default: '512M')
Examples:
Basic COW usage with default parameters:
def test_cow_operations(lv_fixture):
dev_path = lv_fixture
# dev_path is '/dev/vgname/stscow25vglv1'
With thin LV:
@pytest.mark.parametrize('lv_fixture', [{'lv_type': 'thin'}], indirect=True)
def test_thin_operations(lv_fixture):
dev_path = lv_fixture
# dev_path is '/dev/vgname/ststhin25vglv1'
With custom configuration:
@pytest.mark.parametrize(
'lv_fixture',
[
{'lv_type': 'cow', 'extents': '50%vg', 'lv_name': 'custom_lv'},
{'lv_type': 'thin', 'virtualsize': '1G', 'pool_name': 'mypool'},
],
indirect=True,
ids=['large-cow', 'large-thin'],
)
def test_various_lvs(lv_fixture):
dev_path = lv_fixture
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
lvm2_version()
¶
Get LVM2 package version as VersionInfo.
This fixture retrieves the LVM2 version from the installed package and returns it as a VersionInfo object for proper version comparison.
Returns:
| Name | Type | Description |
|---|---|---|
VersionInfo |
VersionInfo
|
Parsed LVM2 version or VersionInfo(0, 0, 0) if not found |
Example
def test_with_version(lvm2_version):
if lvm2_version >= VersionInfo.from_string('2.02.171-6'):
# Handle new behavior
else:
# Handle old behavior
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
lvm_config()
¶
Provide an LvmConfig instance for LVM configuration management.
This fixture provides access to LVM configuration settings through the LvmConfig class. Use this for tests that need to read or modify lvm.conf settings.
Yields:
| Name | Type | Description |
|---|---|---|
LvmConfig |
LvmConfig
|
An LvmConfig instance for configuration management |
Example
def test_config_value(lvm_config):
threshold = lvm_config.get_thin_pool_autoextend_threshold()
assert threshold == '100'
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 | |
lvm_config_restore(lvm_config)
¶
Provide LvmConfig with automatic restoration of thin pool settings after test.
This fixture saves the current thin pool configuration values before the test and restores them after the test completes. Use this when your test modifies LVM configuration settings that should be restored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lvm_config
|
LvmConfig
|
LvmConfig fixture dependency |
required |
Yields:
| Name | Type | Description |
|---|---|---|
LvmConfig |
LvmConfig
|
The same LvmConfig instance with restoration on cleanup |
Example
def test_modify_config(lvm_config_restore):
config = lvm_config_restore
config.set_thin_pool_metadata_require_separate_pvs('1')
# ... test ...
# Configuration is automatically restored after test
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 | |
metadata_backup(metadata_swap)
¶
Create metadata backup files for testing.
Creates metadata backup using thin_dump and prepares repair file for testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata_swap
|
dict[str, Any]
|
Metadata swap setup from metadata_swap fixture |
required |
Yields:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Extended information with backup file paths |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 | |
metadata_snapshot(thin_volumes_with_lifecycle)
¶
Create metadata snapshot for thin pool.
Creates a metadata snapshot while the thin pool is active and handles the suspend/message/resume sequence for snapshot creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thin_volumes_with_lifecycle
|
dict[str, Any]
|
Thin volumes setup from thin_volumes_with_lifecycle fixture |
required |
Yields:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Pool information with snapshot status |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 | |
metadata_swap(metadata_snapshot, swap_volume)
¶
Perform metadata swap operation between thin pool and swap volume.
Deactivates the thin pool and swap volume, then uses lvconvert to swap the metadata from the thin pool to the swap volume.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata_snapshot
|
dict[str, Any]
|
Metadata snapshot setup from metadata_snapshot fixture |
required |
swap_volume
|
dict[str, Any]
|
Swap volume setup from swap_volume fixture |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Combined information with metadata device details |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 | |
mount_lv_fixture(_lvm_test, setup_vg, request)
¶
Mount a logical volume on a test directory with automatic cleanup.
This fixture creates a logical volume (COW or thin), formats it with a filesystem, mounts it, and handles cleanup. It combines the functionality of lv_fixture and mount operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_lvm_test
|
None
|
LVM test fixture dependency |
required |
setup_vg
|
str
|
Volume group name from setup_vg fixture |
required |
request
|
FixtureRequest
|
Pytest fixture request for accessing parameters |
required |
Yields:
| Name | Type | Description |
|---|---|---|
Directory |
Directory
|
Directory representation of mount point |
Default Configuration
- lv_type: 'cow' (regular logical volume)
- fs_type: 'xfs'
- mount_point: '/mnt/lvmntdir'
Parameters (via pytest.mark.parametrize with indirect=True): - lv_type (str): 'cow' for regular LV or 'thin' for thin LV (default: 'cow') - lv_name (str): Name for the logical volume (default: based on lv_type) - extents (str): Size specification in extents (default: '25%vg') - pool_name (str): Thin pool name (only for thin type) - virtualsize (str): Virtual size for thin LV (default: '512M') - fs_type (str): Filesystem type (default: 'xfs') - mount_point (str): Mount point path (default: '/mnt/lvmntdir')
Examples:
Basic COW usage:
def test_filesystem_operations(mount_lv_fixture):
mnt_dir = mount_lv_fixture
# Write files to mnt_dir.path
With thin LV and ext4:
@pytest.mark.parametrize('mount_lv_fixture', [{'lv_type': 'thin', 'fs_type': 'ext4'}], indirect=True)
def test_thin_ext4(mount_lv_fixture):
mnt_dir = mount_lv_fixture
Multiple configurations:
@pytest.mark.parametrize(
'mount_lv_fixture',
[
{'lv_type': 'cow', 'fs_type': 'xfs'},
{'lv_type': 'thin', 'fs_type': 'xfs'},
{'lv_type': 'cow', 'fs_type': 'ext4'},
{'lv_type': 'thin', 'fs_type': 'ext4'},
],
indirect=True,
ids=['cow-xfs', 'thin-xfs', 'cow-ext4', 'thin-ext4'],
)
def test_all_combinations(mount_lv_fixture):
mnt_dir = mount_lv_fixture
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 | |
mount_lv_ramdisk_fixture(_lvm_test, setup_ramdisk_vg, request)
¶
Mount a logical volume backed by ramdisk for fast testing.
This fixture creates a logical volume on a ramdisk-backed VG, formats it, and mounts it. Ideal for sanity testing where I/O speed is important and tests run on VMs with limited resources.
Key benefits: - Much faster than file-backed loop devices - Suitable for VMs with ~4GB RAM - Default smaller sizes to conserve memory
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_lvm_test
|
None
|
LVM test fixture dependency |
required |
setup_ramdisk_vg
|
str
|
VG name from setup_ramdisk_vg fixture |
required |
request
|
FixtureRequest
|
Pytest fixture request for accessing parameters |
required |
Yields:
| Name | Type | Description |
|---|---|---|
Directory |
Directory
|
Directory representation of mount point |
Default Configuration
- lv_type: 'thin' (thin provisioning works well with ramdisk)
- fs_type: 'xfs'
- virtualsize: '400M' (must be >300MB for XFS)
- extents: '50%vg'
Parameters (via pytest.mark.parametrize with indirect=True): - lv_type (str): 'cow' or 'thin' (default: 'thin') - lv_name (str): LV name (default: based on lv_type) - extents (str): Size specification (default: '50%vg') - pool_name (str): Thin pool name (for thin type) - virtualsize (str): Virtual size for thin LV (default: '256M') - fs_type (str): Filesystem type (default: 'xfs') - mount_point (str): Mount point path
Examples:
# Default thin LV on ramdisk
def test_fast_io(mount_lv_ramdisk_fixture):
mnt_dir = mount_lv_ramdisk_fixture
# Very fast I/O operations
# With custom ramdisk size
@pytest.mark.parametrize(
'ramdisk_loop_devices',
[{'count': 1, 'size_mb': 1024}],
indirect=True,
)
def test_larger_ramdisk(mount_lv_ramdisk_fixture):
mnt_dir = mount_lv_ramdisk_fixture
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 | |
mounted_thin_and_regular_lvs(thin_and_regular_lvs)
¶
Mount thin and regular LVs for performance testing.
Creates ext4 filesystems on both volumes and mounts them. Useful for I/O performance comparison tests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thin_and_regular_lvs
|
dict[str, Any]
|
Volume information from thin_and_regular_lvs fixture |
required |
Yields:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Extended information including: - All fields from thin_and_regular_lvs - thin_lv_mnt: Path to thin volume mount point - regular_lv_mnt: Path to regular volume mount point - filesystem: Filesystem type used (ext4) |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 | |
multiple_mntpoints_fixture(_lvm_test, setup_vg, request)
¶
Create multiple logical volumes with mounted filesystems for testing.
This fixture creates multiple logical volumes (COW or thin) within a volume group, formats them with filesystems, and mounts them to separate mount points. It provides a unified interface replacing the separate cow/thin and xfs/ext4 fixtures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_lvm_test
|
None
|
LVM test fixture dependency |
required |
setup_vg
|
str
|
Volume group name from setup_vg fixture |
required |
request
|
FixtureRequest
|
Pytest fixture request for accessing parameters |
required |
Yields:
| Type | Description |
|---|---|
list[Directory]
|
list[Directory]: List of Directory objects representing the mount points |
Default Configuration
- lv_type: 'cow'
- fs_type: 'xfs'
- num_of_mntpoints: 6
Parameters (via pytest.mark.parametrize with indirect=True): - lv_type (str): 'cow' for regular LVs or 'thin' for thin LVs (default: 'cow') - fs_type (str): Filesystem type - 'xfs' or 'ext4' (default: 'xfs') - num_of_mntpoints (int): Number of mount points to create (default: 6) - lv_name (str): Base name for logical volumes - mount_point (str): Base mount point path - pool_name (str): Base name for thin pools (thin only) - virtualsize (str): Virtual size for thin LVs (default: '512M') - percentage_of_vg_to_use (int): Total VG percentage to use (default: 50)
Examples:
Basic COW with xfs (default):
def test_cow_xfs(multiple_mntpoints_fixture):
mntpoints = multiple_mntpoints_fixture
assert len(mntpoints) == 6
Thin with ext4:
@pytest.mark.parametrize('multiple_mntpoints_fixture', [{'lv_type': 'thin', 'fs_type': 'ext4'}], indirect=True)
def test_thin_ext4(multiple_mntpoints_fixture):
mntpoints = multiple_mntpoints_fixture
All combinations for comprehensive testing:
@pytest.mark.parametrize(
'multiple_mntpoints_fixture',
[
{'lv_type': 'cow', 'fs_type': 'xfs'},
{'lv_type': 'thin', 'fs_type': 'xfs'},
{'lv_type': 'cow', 'fs_type': 'ext4'},
{'lv_type': 'thin', 'fs_type': 'ext4'},
],
indirect=True,
ids=['cow-xfs', 'thin-xfs', 'cow-ext4', 'thin-ext4'],
)
def test_all_fs_types(multiple_mntpoints_fixture):
mntpoints = multiple_mntpoints_fixture
Custom number of mount points:
@pytest.mark.parametrize(
'multiple_mntpoints_fixture', [{'num_of_mntpoints': 10, 'percentage_of_vg_to_use': 80}], indirect=True
)
def test_many_volumes(multiple_mntpoints_fixture):
assert len(multiple_mntpoints_fixture) == 10
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 | |
multiple_mntpoints_ramdisk_fixture(_lvm_test, setup_ramdisk_vg, request)
¶
Create multiple logical volumes on ramdisk-backed VG for fast testing.
This fixture creates multiple LVs on a ramdisk-backed VG for significantly faster I/O. Ideal for sanity testing on VMs with limited resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_lvm_test
|
None
|
LVM test fixture dependency |
required |
setup_ramdisk_vg
|
str
|
VG name from setup_ramdisk_vg fixture |
required |
request
|
FixtureRequest
|
Pytest fixture request for accessing parameters |
required |
Yields:
| Type | Description |
|---|---|
list[Directory]
|
list[Directory]: List of Directory objects representing the mount points |
Default Configuration (smaller for ramdisk): - lv_type: 'thin' - fs_type: 'xfs' - num_of_mntpoints: 2 (smaller for memory constraints) - virtualsize: '400M' (must be >300MB for XFS)
Examples:
@pytest.mark.parametrize(
'ramdisk_loop_devices',
[{'count': 1, 'size_mb': 1024}],
indirect=True,
)
@pytest.mark.parametrize(
'multiple_mntpoints_ramdisk_fixture',
[{'lv_type': 'thin', 'num_of_mntpoints': 2}],
indirect=True,
)
def test_fast_multi_mount(multiple_mntpoints_ramdisk_fixture):
mntpoints = multiple_mntpoints_ramdisk_fixture
assert len(mntpoints) == 2
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 | |
multiple_thin_pools(setup_loopdev_vg)
¶
Create multiple thin pools with thin volumes for concurrent testing.
Creates configurable number of thin pools, each with a thin volume, for testing concurrent operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
setup_loopdev_vg
|
str
|
Volume group name from setup_loopdev_vg fixture |
required |
Yields:
| Name | Type | Description |
|---|---|---|
list |
list[ThinPool]
|
List of ThinPool objects |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 | |
regular_lv_fixture(setup_loopdev_vg, request)
¶
Create a regular (non-thin) logical volume for testing.
This fixture creates a regular LV that can be used for conversion to thin, testing, or other operations that require a standard logical volume.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
setup_loopdev_vg
|
str
|
Volume group name from setup_loopdev_vg fixture |
required |
request
|
FixtureRequest
|
Pytest fixture request for accessing parameters |
required |
Yields:
| Name | Type | Description |
|---|---|---|
LogicalVolume |
LogicalVolume
|
The created regular logical volume |
Default Configuration
- lv_name: 'lv'
- size: '50M' (or extents if specified)
Parameters (via pytest.mark.parametrize with indirect=True): - lv_name (str): Name for the LV (default: 'lv') - size (str): Size of the LV (default: '50M') - extents (str): Size in extents (alternative to size) - inactive (bool): Create as inactive LV with '-an' flag (default: False) - zero (str): Zero option for LV creation (default: None) - skip_cleanup (bool): Skip automatic cleanup (default: False) - use when LV will be converted to thin pool and cleanup handled separately
Examples:
Basic usage:
def test_regular_lv(regular_lv_fixture):
lv = regular_lv_fixture
assert lv.report.lv_attr[0] == '-' # Regular volume
With custom size:
@pytest.mark.parametrize('regular_lv_fixture', [{'size': '100M', 'lv_name': 'data'}], indirect=True)
def test_large_lv(regular_lv_fixture):
lv = regular_lv_fixture
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 | |
restored_thin_pool(metadata_backup)
¶
Restore thin pool to a usable state after metadata operations.
WARNING: Use this fixture ONLY for tests that specifically need an active thin pool (like thin_trim). Most DMPD tools are designed to work with "broken" metadata and should use setup_thin_metadata_for_dmpd instead, which preserves the intentionally inconsistent metadata state.
This fixture uses thin_restore to repair the metadata and make the pool activatable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata_backup
|
dict[str, Any]
|
Metadata backup setup from metadata_backup fixture |
required |
Yields:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Pool information with restored pool that can be activated |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 | |
setup_cache_metadata_for_dmpd(install_dmpd, cache_metadata_backup)
¶
Set up cache metadata configuration for DMPD tool testing.
This fixture creates the necessary cache metadata setup that DMPD cache tools can operate on. Unlike thin metadata which intentionally creates "broken" state, cache metadata swap creates a working metadata device that cache tools can analyze.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
install_dmpd
|
None
|
DMPD package installation fixture |
required |
cache_metadata_backup
|
dict[str, Any]
|
Cache metadata backup setup from cache_metadata_backup fixture |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Extended cache information for DMPD testing |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 | |
setup_loopdev_vg(_lvm_test, loop_devices)
¶
Set up a volume group using loop devices.
This fixture creates a volume group using the provided loop devices. The volume group name can be customized using the STS_VG_NAME environment variable, otherwise defaults to 'stsvg0'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loop_devices
|
list[str]
|
List of loop device paths to use as physical volumes. |
required |
Yields:
| Name | Type | Description |
|---|---|---|
str |
str
|
The name of the created volume group. |
Examples:
Basic usage with custom loop device configuration:
@pytest.mark.parametrize('loop_devices', [{'count': 1, 'size_mb': 4096}], indirect=True)
@pytest.mark.usefixtures('setup_loopdev_vg')
def test_large_vg_operations(setup_loopdev_vg):
vg_name = setup_loopdev_vg
# Create logical volumes in the 4GB VG
lv = LogicalVolume(name='testlv', vg=vg_name, size='1G')
assert lv.create()
Using with multiple loop devices:
@pytest.mark.parametrize('loop_devices', [{'count': 2, 'size_mb': 2048}], indirect=True)
@pytest.mark.usefixtures('setup_loopdev_vg')
def test_multi_pv_vg(setup_loopdev_vg):
vg_name = setup_loopdev_vg
vg = VolumeGroup(name=vg_name)
assert vg.exists()
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
setup_ramdisk_vg(_lvm_test, ramdisk_loop_devices)
¶
Set up a volume group using ramdisk-backed loop devices.
This fixture creates a volume group using loop devices backed by tmpfs for significantly faster I/O. Ideal for sanity testing where speed matters more than testing actual disk I/O patterns.
Key benefits: - Much faster than file-backed loop devices - Suitable for VMs with limited RAM (~4GB) - Perfect for functional/sanity tests
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ramdisk_loop_devices
|
list[str]
|
List of ramdisk loop device paths |
required |
Yields:
| Name | Type | Description |
|---|---|---|
str |
str
|
The name of the created volume group |
Examples:
# Single 512MB device (default)
@pytest.mark.usefixtures('setup_ramdisk_vg')
def test_fast_lvm(setup_ramdisk_vg):
vg_name = setup_ramdisk_vg
lv = LogicalVolume(name='testlv', vg=vg_name, size='100M')
assert lv.create()
# Custom size
@pytest.mark.parametrize(
'ramdisk_loop_devices',
[{'count': 1, 'size_mb': 1024}],
indirect=True,
)
def test_larger_ramdisk_vg(setup_ramdisk_vg):
vg_name = setup_ramdisk_vg
# Use 1GB VG
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
setup_thin_metadata_for_dmpd(install_dmpd, metadata_backup)
¶
Set up thin metadata configuration for DMPD tool testing with snapshot support.
This fixture creates the intended "broken" metadata state that DMPD tools are designed to detect, analyze, and repair. The metadata swap operation intentionally leaves the thin pool in an inconsistent state (transaction_id mismatch) to test that DMPD tools can properly handle corrupted/problematic metadata scenarios.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
install_dmpd
|
None
|
DMPD package installation fixture |
required |
metadata_backup
|
dict[str, Any]
|
Metadata backup setup from metadata_backup fixture |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Extended volume information with intentionally inconsistent metadata for testing |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 | |
setup_thin_pool_with_vols(thin_volumes_with_lifecycle, swap_volume)
¶
Set up thin pool with thin volumes for DMPD testing.
This is a backward-compatible fixture that combines the modular fixtures to recreate the original functionality. Uses the new modular approach internally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thin_volumes_with_lifecycle
|
dict[str, str]
|
Thin volumes setup from thin_volumes_with_lifecycle fixture |
required |
swap_volume
|
dict[str, str]
|
Swap volume setup from swap_volume fixture |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, str]
|
Information about created volumes (compatible with original format) |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 | |
setup_vg(_lvm_test, ensure_minimum_devices_with_same_block_sizes)
¶
Set up an LVM Volume Group (VG) with Physical Volumes (PVs) for testing.
This fixture creates a Volume Group using the provided block devices. It handles the creation of Physical Volumes from the block devices and ensures proper cleanup after tests, even if they fail.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ensure_minimum_devices_with_same_block_sizes
|
list[BlockDevice]
|
List of BlockDevice objects with matching block sizes to be used for creating Physical Volumes. |
required |
Yields:
| Name | Type | Description |
|---|---|---|
str |
str
|
Name of the created Volume Group. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If PV creation fails for any device. |
Example
def test_volume_group(setup_vg): vg_name = setup_vg # Use vg_name in your test...
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
swap_volume(setup_loopdev_vg)
¶
Create a swap volume for metadata operations.
Creates a 75MB swap logical volume that can be used for metadata swapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
setup_loopdev_vg
|
str
|
Volume group name from setup_loopdev_vg fixture |
required |
Yields:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Information about the created swap volume |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 | |
temp_mount_fixture(request)
¶
Create a temporary mount point with automatic cleanup.
This fixture creates a mount point directory and handles cleanup of the directory and any temp files after the test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FixtureRequest
|
Pytest fixture request for accessing parameters |
required |
Yields:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Mount information including: - mount_point: Path to the mount point - mount_dir: Directory object - temp_files: List to track temp files for cleanup |
Default Configuration
- mount_point: '/mnt/test'
Parameters (via pytest.mark.parametrize with indirect=True): - mount_point (str): Path for the mount point (default: '/mnt/test')
Examples:
def test_with_mount(temp_mount_fixture, regular_lv_fixture):
mount_info = temp_mount_fixture
lv = regular_lv_fixture
mkfs(lv.device_path, 'ext4')
mount(lv.device_path, mount_info['mount_point'])
# ... test operations ...
umount(mount_info['mount_point'])
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 | |
thin_and_regular_lvs(setup_loopdev_vg)
¶
Create a thin pool with thin volume and a regular LV for performance testing.
Creates: - Thin pool (1G) - Thin volume (900M virtual size) - Regular logical volume (900M)
This fixture is useful for comparing thin vs regular LV performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
setup_loopdev_vg
|
str
|
Volume group name from setup_loopdev_vg fixture |
required |
Yields:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Information about created volumes including: - vg_name: Volume group name - pool: ThinPool object - regular_lv: LogicalVolume object - thin_device: Device path for thin volume - regular_device: Device path for regular volume |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 | |
thin_pool_with_volume(setup_loopdev_vg)
¶
Create a thin pool with a single thin volume for testing.
Creates a basic thin pool and one thin volume for simple activation and attribute testing scenarios.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
setup_loopdev_vg
|
str
|
Volume group name from setup_loopdev_vg fixture |
required |
Yields:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Information about the thin pool and thin volume |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 | |
thin_volumes_with_lifecycle(setup_loopdev_vg)
¶
Create thin volumes and perform filesystem lifecycle operations.
Creates a 3GB thin pool and 10 thin volumes of 300MB each, then performs filesystem operations (create, mount, unmount, deactivate) to generate metadata activity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
setup_loopdev_vg
|
str
|
Volume group name from setup_loopdev_vg fixture |
required |
Yields:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Extended pool information with thin volume details |
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 | |
thinpool_fixture(setup_loopdev_vg, request)
¶
Create a thin pool for testing with automatic cleanup.
This fixture creates a thin pool and automatically removes all thin volumes and the pool itself during cleanup. It supports parameterization for flexible pool configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
setup_loopdev_vg
|
str
|
Volume group name from setup_loopdev_vg fixture |
required |
request
|
FixtureRequest
|
Pytest fixture request for accessing parameters |
required |
Yields:
| Name | Type | Description |
|---|---|---|
ThinPool |
ThinPool
|
The created thin pool object that can be used to create thin volumes |
Default Configuration
- pool_name: 'pool'
- size: '500M'
Parameters (via pytest.mark.parametrize with indirect=True): - pool_name (str): Name for the thin pool (default: 'pool') - size (str): Size of the thin pool (default: '500M') - extents (str): Size in extents (alternative to size) - discards (str): Discard mode - 'passdown', 'nopassdown', or 'ignore' (default: None) - stripes (str): Number of stripes for the pool (default: None) - stripesize (str): Stripe size in KB (default: None) - chunksize (str): Chunk size for the pool (default: None) - poolmetadatasize (str): Metadata size for the pool (default: None) - poolmetadataspare (str): Create pool metadata spare - 'y' or 'n' (default: None) - create_thin_volume (bool): Whether to create a thin volume (default: False) - thin_volume_name (str): Name for the thin volume (default: 'lv1') - thin_volume_size (str): Virtual size for thin volume (default: '50M')
Examples:
Basic usage with default parameters:
def test_thin_operations(thinpool_fixture):
pool = thinpool_fixture
lv = pool.create_thin_volume('test_lv', virtualsize='100M')
# ... test operations ...
# Cleanup is automatic - all thin volumes and pool are removed
With custom pool size:
@pytest.mark.parametrize('thinpool_fixture', [{'size': '1G'}], indirect=True)
def test_large_pool(thinpool_fixture):
pool = thinpool_fixture
lv = pool.create_thin_volume('large_lv', virtualsize='500M')
With multiple parameter combinations:
@pytest.mark.parametrize(
'thinpool_fixture',
[
{'size': '200M', 'pool_name': 'small_pool'},
{'size': '1G', 'pool_name': 'large_pool'},
],
indirect=True,
ids=['small', 'large'],
)
def test_various_sizes(thinpool_fixture):
pool = thinpool_fixture
# Test with different pool configurations
Combined with loop_devices parameterization:
@pytest.mark.parametrize('loop_devices', [{'count': 1, 'size_mb': 4096}], indirect=True)
@pytest.mark.parametrize('thinpool_fixture', [{'size': '3G'}], indirect=True)
def test_discard_performance(thinpool_fixture):
pool = thinpool_fixture
discard_lv = pool.create_thin_volume('discard', virtualsize='1T')
# ... performance test ...
Source code in sts_libs/src/sts/fixtures/lvm_fixtures.py
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 | |
RDMA Fixtures¶
sts.fixtures.rdma_fixtures
¶
RDMA test fixtures.
This module provides fixtures for testing RDMA (Remote Direct Memory Access): - Device discovery and validation - Device configuration and management - Port and interface handling - SR-IOV configuration
Fixture Dependencies: 1. _exists_rdma (base fixture) - Validates RDMA device presence - Skips tests if no devices found
- rdma_device (independent fixture)
- Creates device factory function
- Validates device existence
- Provides device management
Common Usage: 1. Basic device validation: @pytest.mark.usefixtures('_exists_rdma') def test_rdma(): # Test runs only if RDMA device exists
-
Specific device testing: def test_device(rdma_device): device = rdma_device('mlx5_0') # Test specific RDMA device
-
Port configuration: def test_ports(rdma_device): device = rdma_device('mlx5_0') ports = device.get_ports() # Test port configuration
-
SR-IOV setup: def test_sriov(rdma_device): device = rdma_device('mlx5_0') sriov = device.get_sriov() # Test SR-IOV configuration
Error Handling: - Missing devices skip tests - Invalid device IDs raise assertion errors - Device access issues are logged - Configuration failures are reported
rdma_device()
¶
Create RDMA device factory.
This fixture provides a factory function for RDMA devices: - Creates device instances on demand - Validates device existence - Provides device management interface - Supports multiple device types
Device Management: - Port configuration - Interface binding - SR-IOV setup - Power management
Returns:
| Type | Description |
|---|---|
Callable[[str], RdmaDevice]
|
Factory function that takes HCA ID and returns RdmaDevice |
Example
def test_rdma(rdma_device):
# Create device instance
device = rdma_device('mlx5_0')
...
# Access device information
assert device.exists
...
# Configure ports
ports = device.get_ports()
for port in ports:
print(f'Port {port.name}: {port.state}')
...
# Set up SR-IOV if supported
if device.is_sriov_capable:
sriov = device.get_sriov()
sriov.set_numvfs('4')
Source code in sts_libs/src/sts/fixtures/rdma_fixtures.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
Stratis Fixtures¶
sts.fixtures.stratis_fixtures
¶
Stratis test fixtures.
This module provides fixtures for testing Stratis storage: - Pool creation and management - Filesystem operations - Encryption configuration - Error injection and recovery
Fixture Dependencies: 1. _stratis_test (base fixture) - Installs Stratis packages - Manages pool cleanup - Logs system information
- setup_stratis_key (independent fixture)
- Creates encryption key
- Manages key registration
-
Handles key cleanup
-
stratis_test_pool (depends on loop_devices)
- Creates test pool
- Manages devices
-
Handles cleanup
-
stratis_encrypted_pool (depends on loop_devices, setup_stratis_key)
- Creates encrypted pool
- Manages key and devices
-
Handles secure cleanup
-
stratis_failing_pool (depends on scsi_debug_devices)
- Creates pool with failing device
- Injects failures
- Tests error handling
Common Usage: 1. Basic pool testing: @pytest.mark.usefixtures('_stratis_test') def test_stratis(): # Create and test pools # Pools are cleaned up after test
-
Encrypted pool testing: def test_encryption(stratis_encrypted_pool): assert stratis_encrypted_pool.is_encrypted # Test encrypted operations
-
Error handling testing: def test_failures(stratis_failing_pool): assert not stratis_failing_pool.stop() # Test failure handling
Error Handling: - Package installation failures fail test - Pool creation failures skip test - Device failures are handled gracefully - Resources are cleaned up on failure
setup_stratis_key()
¶
Set up Stratis encryption key.
Creates and manages encryption key: - Creates temporary key file - Registers key with Stratis - Handles key cleanup - Supports custom key configuration
Configuration (via environment): - STRATIS_KEY_DESC: Key description (default: 'sts-stratis-test-key') - STRATIS_KEY_PATH: Key file path (default: '/tmp/sts-stratis-test-key') - STRATIS_KEY: Key content (default: 'Stra123tisKey45')
Key Management: 1. Creates key file with specified content 2. Registers key with Stratis daemon 3. Yields key description for use 4. Unregisters key and removes file
Example
def test_encryption(setup_stratis_key):
# Create encrypted pool
pool = StratisPool()
pool.create(key_desc=setup_stratis_key)
assert pool.is_encrypted
Source code in sts_libs/src/sts/fixtures/stratis_fixtures.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
stratis_clevis_test()
¶
Set up Tang server for Stratis Clevis encryption testing.
This fixture configures the Tang server environment: - Ensures Tang server packages are installed - Starts Tang service - Gets server information for encryption - Handles cleanup
Package Installation: - tang: Tang server package - curl: For HTTP requests - jose: For JWK operations - jq: For JSON processing
Service Management: 1. Installs required packages 2. Starts Tang service 3. Gets server thumbprint 4. Cleans up after tests
Returns:
| Type | Description |
|---|---|
None
|
Dictionary containing: |
None
|
|
None
|
|
Example
def test_tang(stratis_clevis_test):
# Create encrypted pool with Tang
config = PoolCreateConfig(
clevis='tang', tang_url=stratis_clevis_test['url'], thumbprint=stratis_clevis_test['thumbprint']
)
Source code in sts_libs/src/sts/fixtures/stratis_fixtures.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
stratis_encrypted_pool(loop_devices, setup_stratis_key)
¶
Create encrypted test pool with loop devices.
Creates and manages encrypted pool: - Uses loop devices as storage - Creates encrypted pool - Manages encryption key - Handles secure cleanup
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loop_devices
|
list[str]
|
Loop device fixture (requires 2 devices) |
required |
setup_stratis_key
|
str
|
Stratis key fixture |
required |
Pool Configuration: - Name: 'sts-stratis-test-pool' - Devices: Provided loop devices - Encrypted with provided key - Default settings
Example
@pytest.mark.parametrize('loop_devices', [2], indirect=True)
def test_pool(stratis_encrypted_pool):
# Test encrypted operations
assert stratis_encrypted_pool.is_encrypted
fs = stratis_encrypted_pool.create_filesystem('test')
assert fs.exists
Source code in sts_libs/src/sts/fixtures/stratis_fixtures.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
stratis_extend_lvm(_lvm_test, loop_devices)
¶
Create a logical volume 70%vg size which we will use to test stratis extend-data.
First two devices from loop_devices are used for creating stratis pool. This fixture will use third and fourth loop device as PV.
Source code in sts_libs/src/sts/fixtures/stratis_fixtures.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
stratis_failing_pool(scsi_debug_devices)
¶
Create test pool with failing devices.
Creates pool for failure testing: - Uses SCSI debug devices - Injects device failures - Tests error handling - Manages cleanup
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scsi_debug_devices
|
list[str]
|
SCSI debug device fixture |
required |
Failure Injection: - Every operation fails - Noisy error reporting - Tests error handling - Recovery procedures
Example
@pytest.mark.parametrize('scsi_debug_devices', [2], indirect=True)
def test_pool(stratis_failing_pool):
# Test failure handling
assert not stratis_failing_pool.stop()
assert 'error' in stratis_failing_pool.status
Source code in sts_libs/src/sts/fixtures/stratis_fixtures.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | |
stratis_filesystem(stratis_no_enc_pool)
¶
Create a test filesystem on a non-encrypted pool.
Creates a plain filesystem with default settings. Automatically destroys the filesystem after the test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stratis_no_enc_pool
|
StratisPool
|
Non-encrypted pool fixture |
required |
Yields:
| Type | Description |
|---|---|
StratisFilesystem
|
Created StratisFilesystem instance |
Example
@pytest.mark.parametrize('loop_devices', [2], indirect=True)
def test_fs(stratis_filesystem):
assert stratis_filesystem.rename('new-name')
Source code in sts_libs/src/sts/fixtures/stratis_fixtures.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | |
stratis_filesystem_with_snapshot(stratis_filesystem)
¶
Create a test filesystem with a snapshot.
Depends on the stratis_filesystem fixture for the origin filesystem. Automatically cancels any scheduled revert and destroys the snapshot after the test. The origin filesystem is cleaned up by the stratis_filesystem fixture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stratis_filesystem
|
StratisFilesystem
|
Filesystem fixture (origin) |
required |
Yields:
| Type | Description |
|---|---|
tuple[StratisFilesystem, StratisFilesystem]
|
Tuple of (origin filesystem, snapshot filesystem) |
Example
@pytest.mark.parametrize('loop_devices', [2], indirect=True)
def test_snap(stratis_filesystem_with_snapshot):
origin, snap = stratis_filesystem_with_snapshot
assert snap.schedule_revert()
Source code in sts_libs/src/sts/fixtures/stratis_fixtures.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
stratis_key_desc_pool(loop_devices, setup_stratis_key)
¶
Create a pool with keyring encryption.
Source code in sts_libs/src/sts/fixtures/stratis_fixtures.py
349 350 351 352 353 354 355 356 357 358 | |
stratis_no_enc_pool(loop_devices)
¶
Create a pool without encryption.
Source code in sts_libs/src/sts/fixtures/stratis_fixtures.py
417 418 419 420 421 422 423 424 425 | |
stratis_tang_pool(loop_devices, stratis_clevis_test)
¶
Create a pool with Tang encryption.
Source code in sts_libs/src/sts/fixtures/stratis_fixtures.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
stratis_test_key(tmp_path)
¶
Create and register a test encryption key with automatic cleanup.
Creates a key file, registers the key with stratis, and ensures the key is unset after the test even if the test fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tmp_path
|
Path
|
Pytest temporary directory |
required |
Yields:
| Type | Description |
|---|---|
tuple[Key, str]
|
Tuple of (Key instance, key description string) |
Example
def test_key_ops(stratis_test_key):
key, keydesc = stratis_test_key
assert key.exists(keydesc)
Source code in sts_libs/src/sts/fixtures/stratis_fixtures.py
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | |
stratis_test_pool(loop_devices)
¶
Create test pool with loop devices.
Creates and manages test pool: - Uses loop devices as storage - Creates standard pool - Handles cleanup - Supports testing operations
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loop_devices
|
list[str]
|
Loop device fixture (requires 2 devices) |
required |
Pool Configuration: - Name: 'sts-stratis-test-pool' - Devices: Provided loop devices - Standard (non-encrypted) pool - Default settings
Example
@pytest.mark.parametrize('loop_devices', [2], indirect=True)
def test_pool(stratis_test_pool):
# Test pool operations
fs = stratis_test_pool.create_filesystem('test')
assert fs.exists
Source code in sts_libs/src/sts/fixtures/stratis_fixtures.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
Target Fixtures¶
sts.fixtures.target_fixtures
¶
Target test fixtures.
This module provides fixtures for testing storage targets: - Target creation and configuration - Backstore management (block, fileio, ramdisk) - ACL and authentication setup - LUN management
Fixture Dependencies: 1. _target_test (base fixture) - Installs target utilities - Manages target cleanup - Logs system information
- backstore_*_setup (depends on _target_test)
- block: Creates block backstore with loop device
- fileio: Creates fileio backstore
-
ramdisk: Creates ramdisk backstore
-
iscsi_target_setup (depends on _target_test)
- Creates iSCSI target
- Configures ACLs and LUNs
-
Manages cleanup
-
configure_auth (depends on _target_test)
- Sets up CHAP authentication
- Configures mutual CHAP
-
Manages credentials
-
loopback_devices
- Creates loopback devices for testing
- Supports custom block size and device count
- Manages device cleanup automatically
- Yields list of BlockDevice instances
Common Usage: 1. Basic target testing: @pytest.mark.usefixtures('_target_test') def test_target(): # Create and test targets # Targets are cleaned up after test
-
Backstore testing: @pytest.mark.parametrize('backstore_block_setup', [{'name': 'test', 'size': 1024*1024}], indirect=True) def test_backstore(backstore_block_setup): # Test backstore operations
-
iSCSI target testing: @pytest.mark.parametrize('iscsi_target_setup', [{'t_iqn': 'iqn.test', 'n_luns': 2}], indirect=True) def test_iscsi(iscsi_target_setup): # Test iSCSI target operations
-
Authentication testing: @pytest.mark.parametrize('configure_auth', [{'t_iqn': 'iqn.test', 'chap_username': 'user', 'chap_password': 'pass'}], indirect=True) def test_auth(configure_auth): # Test authentication
-
Loopback device testing: # Using test parametrization @pytest.mark.parametrize('block_size', [512, 1024]) def test_loopback(loopback_devices): # Uses block_size from parametrize, device_count=2 (default)
# Using fixture parametrization @pytest.mark.parametrize('loopback_devices', [{'device_count': 4, 'block_size': 1024}], indirect=True) def test_loopback_custom(loopback_devices): # Uses custom device_count and block_size # Devices are automatically cleaned up
Error Handling: - Package installation failures fail test - Target creation failures are handled - Resource cleanup runs on failure - Authentication errors are logged
backstore_block_setup(_target_test, request)
¶
Create block backstore with loop device.
Creates block backstore using loop device: - Creates temporary loop device - Sets up block backstore - Manages cleanup - Supports custom size
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FixtureRequest
|
Fixture request with parameters: - name: Backstore name - size: Loop device size in MB |
required |
Example
@pytest.mark.parametrize('backstore_block_setup', [{'name': 'test', 'size': 1024}], indirect=True)
def test_backstore(backstore_block_setup):
assert backstore_block_setup.exists
Source code in sts_libs/src/sts/fixtures/target_fixtures.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
backstore_fileio_setup(_target_test, request)
¶
Create fileio backstore.
Creates fileio backstore: - Creates backing file - Sets up fileio backstore - Manages cleanup - Supports custom size
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FixtureRequest
|
Fixture request with parameters: - name: Backstore name - size: File size in bytes - file_or_dev: File path |
required |
Example
@pytest.mark.parametrize('backstore_fileio_setup', [{'name': 'test', 'size': 1024 * 1024}], indirect=True)
def test_backstore(backstore_fileio_setup):
assert backstore_fileio_setup.exists
Source code in sts_libs/src/sts/fixtures/target_fixtures.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
backstore_ramdisk_setup(_target_test, request)
¶
Create ramdisk backstore.
Creates ramdisk backstore: - Allocates memory - Sets up ramdisk backstore - Manages cleanup - Supports custom size
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FixtureRequest
|
Fixture request with parameters: - name: Backstore name - size: Size in bytes |
required |
Example
@pytest.mark.parametrize('backstore_ramdisk_setup', [{'name': 'test', 'size': 1024 * 1024}], indirect=True)
def test_backstore(backstore_ramdisk_setup):
assert backstore_ramdisk_setup.exists
Source code in sts_libs/src/sts/fixtures/target_fixtures.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
configure_auth(request)
¶
Configure CHAP authentication.
Sets up CHAP authentication: - Creates target with auth - Configures CHAP credentials - Supports mutual CHAP - Manages cleanup
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FixtureRequest
|
Fixture request with parameters: - t_iqn: Target IQN - i_iqn: Initiator IQN - chap_username: CHAP username - chap_password: CHAP password - chap_target_username: Mutual CHAP username (optional) - chap_target_password: Mutual CHAP password (optional) - tpg_or_acl: Configure TPG or ACL auth |
required |
Example
@pytest.mark.parametrize(
'configure_auth', [{'t_iqn': 'iqn.test', 'chap_username': 'user', 'chap_password': 'pass'}], indirect=True
)
def test_auth(configure_auth):
assert configure_auth.exists
Source code in sts_libs/src/sts/fixtures/target_fixtures.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
iscsi_target_setup(_target_test, request)
¶
Create iSCSI target with ACLs and LUNs.
Creates complete iSCSI target: - Creates target with IQN - Sets up ACLs - Creates LUNs - Manages cleanup
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FixtureRequest
|
Fixture request with parameters: - t_iqn: Target IQN (optional) - i_iqn: Initiator IQN (optional) - n_luns: Number of LUNs (optional) - back_size: Backstore size in bytes (optional) |
required |
Example
@pytest.mark.parametrize('iscsi_target_setup', [{'t_iqn': 'iqn.test', 'n_luns': 2}], indirect=True)
def test_target(iscsi_target_setup):
assert iscsi_target_setup.exists
Source code in sts_libs/src/sts/fixtures/target_fixtures.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |
loopback_devices(request)
¶
Create loopback devices for testing.
This fixture creates loopback devices with the specified block size from the parametrized test, yields them for testing, and ensures proper cleanup afterward.
Parameters (from test parametrization or fixture params): block_size: Block size for devices (default: 512) device_count: Number of devices to create (default: 2)
Yields:
| Type | Description |
|---|---|
list[BlockDevice]
|
List of BlockDevice instances representing the created loopback devices |
Example
# Using test parametrization
@pytest.mark.parametrize('block_size', [512, 1024])
def test_loopback(loopback_devices):
# Uses block_size from parametrize, device_count=2 (default)
# Using fixture parametrization
@pytest.mark.parametrize('loopback_devices', [{'device_count': 4, 'block_size': 1024}], indirect=True)
def test_loopback(loopback_devices):
# Uses custom device_count and block_size
Source code in sts_libs/src/sts/fixtures/target_fixtures.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
ramdisk_loopback_devices(_target_test, request)
¶
Create loopback devices backed by ramdisk for fast testing.
Uses targetcli to create ramdisk backstores and export them via the loopback fabric. This provides very fast I/O as data is stored in RAM, ideal for sanity testing on VMs with limited resources.
Key benefits: - Much faster than file-backed devices - No disk I/O bottleneck - Suitable for VMs with ~4GB RAM
Configuration via parametrize: - count: Number of devices to create (default: 1) - size_mb: Size of each device in MB (default: 512)
Examples:
# Single 512MB ramdisk device
def test_fast(ramdisk_loopback_devices):
device = ramdisk_loopback_devices[0]
# Multiple smaller devices
@pytest.mark.parametrize(
'ramdisk_loopback_devices',
[{'count': 2, 'size_mb': 256}],
indirect=True,
)
def test_multi_fast(ramdisk_loopback_devices):
dev1, dev2 = ramdisk_loopback_devices
Warning
Total device size should not exceed available RAM. With 4GB RAM, recommend max 1-2GB total for devices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FixtureRequest
|
Pytest fixture request with optional 'count' and 'size_mb' parameters |
required |
Yields:
| Type | Description |
|---|---|
list[str]
|
List of block device paths backed by ramdisk |
Source code in sts_libs/src/sts/fixtures/target_fixtures.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | |
target_setup(*, t_iqn=None, i_iqn=None, n_luns=0, back_size=None)
¶
Set up iSCSI target.
Creates and manages iSCSI target: - Creates target with IQN - Sets up ACLs if needed - Creates LUNs if needed - Manages cleanup
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t_iqn
|
str | None
|
Target IQN |
None
|
i_iqn
|
str | None
|
Initiator IQN |
None
|
n_luns
|
int
|
Number of LUNs |
0
|
back_size
|
int | None
|
Backstore size in bytes |
None
|
Yields:
| Type | Description |
|---|---|
Iscsi
|
iSCSI target instance |
Example
with target_setup(t_iqn='iqn.test', n_luns=2) as target:
# Use target
assert target.exists
Source code in sts_libs/src/sts/fixtures/target_fixtures.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |