Skip to content

Commit 4b783e4

Browse files
author
Kamil Gierszewski
committed
tests: refactor fault injection test
Signed-off-by: Kamil Gierszewski <kamil.gierszewski@huawei.com>
1 parent b380ca9 commit 4b783e4

File tree

1 file changed

+123
-59
lines changed

1 file changed

+123
-59
lines changed

test/functional/tests/fault_injection/test_fault_injection_interrupts.py

Lines changed: 123 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -25,102 +25,138 @@
2525
from test_tools.udev import Udev
2626
from type_def.size import Size, Unit
2727
from tests.lazy_writes.recovery.recovery_tests_methods import compare_files
28+
from test_utils.filesystem.file import File
2829

2930
mount_point = "/mnt/cas"
3031
test_file_path = f"{mount_point}/test_file"
3132
iterations_per_config = 10
32-
cache_size = Size(16, Unit.GibiByte)
33+
cache_size = Size(2, Unit.GibiByte)
3334

3435

35-
@pytest.mark.parametrizex("filesystem", Filesystem)
3636
@pytest.mark.parametrizex("cache_mode", CacheMode.with_traits(CacheModeTrait.LazyWrites))
37+
@pytest.mark.parametrizex("filesystem", Filesystem)
3738
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
3839
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
39-
def test_interrupt_core_flush(cache_mode, filesystem):
40+
def test_interrupt_core_flush(cache_mode: CacheMode, filesystem: Filesystem):
4041
"""
41-
title: Test if OpenCAS works correctly after core's flushing interruption.
42+
title: Test for core's flush interruption.
4243
description: |
43-
Negative test of the ability of OpenCAS to handle core flushing interruption.
44+
Test the ability to handle core flush interruption.
4445
pass_criteria:
4546
- No system crash.
4647
- Flushing would be stopped after interruption.
4748
- Md5sum are correct during all test steps.
4849
- Dirty blocks quantity after interruption is equal or lower but non-zero.
4950
"""
50-
with TestRun.step("Prepare cache and core."):
51-
cache_part, core_part = prepare()
51+
cache_size = Size(2, Unit.GibiByte)
52+
iterations_per_config = 10
53+
54+
with TestRun.step("Prepare cache and core devices"):
55+
cache_dev = TestRun.disks["cache"]
56+
core_dev = TestRun.disks["core"]
57+
58+
cache_dev.create_partitions([cache_size])
59+
core_dev.create_partitions([cache_size * 2])
60+
61+
cache_part = cache_dev.partitions[0]
62+
core_part = core_dev.partitions[0]
63+
64+
with TestRun.step("Disable udev"):
65+
Udev.disable()
5266

5367
for _ in TestRun.iteration(
5468
range(iterations_per_config), f"Reload cache configuration {iterations_per_config} times."
5569
):
5670

57-
with TestRun.step("Start cache."):
58-
cache = casadm.start_cache(cache_part, cache_mode, force=True)
71+
with TestRun.step("Start cache"):
72+
cache = casadm.start_cache(cache_dev=cache_part, cache_mode=cache_mode, force=True)
5973

60-
with TestRun.step("Set cleaning policy to NOP."):
74+
with TestRun.step("Disable cleaning"):
6175
cache.set_cleaning_policy(CleaningPolicy.nop)
6276

63-
with TestRun.step(f"Add core device with {filesystem} filesystem and mount it."):
64-
core_part.create_filesystem(filesystem)
77+
with TestRun.step(f"Create {filesystem} filesystem on core device"):
78+
core_part.create_filesystem(fs_type=filesystem)
79+
80+
with TestRun.step("Add core to the cache"):
6581
core = cache.add_core(core_part)
82+
83+
with TestRun.step(f"Mount core"):
6684
core.mount(mount_point)
6785

68-
with TestRun.step(f"Create test file in mount point of exported object."):
69-
test_file = create_test_file()
86+
with TestRun.step("Create test file in mount point of exported object"):
87+
bs = Size(512, Unit.KibiByte)
88+
count = int(cache_size.value / bs.value)
89+
test_file = File.create_file(test_file_path)
7090

71-
with TestRun.step("Check md5 sum of test file."):
91+
dd = (
92+
Dd()
93+
.input("/dev/zero")
94+
.output(test_file_path)
95+
.block_size(bs)
96+
.count(count)
97+
.oflag("direct")
98+
)
99+
dd.run()
100+
101+
test_file.refresh_item()
102+
103+
with TestRun.step("Calculate checksum of test file"):
72104
test_file_md5sum_before = test_file.md5sum()
73105

74-
with TestRun.step("Get number of dirty data on exported object before interruption."):
106+
with TestRun.step("Get number of dirty data on exported object before interruption"):
75107
sync()
76108
drop_caches(DropCachesMode.ALL)
77109
core_dirty_blocks_before = core.get_dirty_blocks()
78110

79-
with TestRun.step("Start flushing core device."):
111+
with TestRun.step("Start flushing core device"):
80112
flush_pid = TestRun.executor.run_in_background(
81113
cli.flush_core_cmd(str(cache.cache_id), str(core.core_id))
82114
)
83115

84-
with TestRun.step("Interrupt core flushing."):
85-
wait_for_flushing(cache, core)
86-
percentage = casadm_parser.get_flushing_progress(cache.cache_id, core.core_id)
116+
with TestRun.step("Interrupt core flushing"):
117+
wait_for_flushing(cache=cache, core=core)
118+
percentage = casadm_parser.get_flushing_progress(
119+
cache_id=cache.cache_id, core_id=core.core_id
120+
)
121+
87122
while percentage < 50:
88123
percentage = casadm_parser.get_flushing_progress(cache.cache_id, core.core_id)
89-
TestRun.executor.run(f"kill -s SIGINT {flush_pid}")
90124

91-
with TestRun.step("Check number of dirty data on exported object after interruption."):
125+
TestRun.executor.kill_process(pid=flush_pid)
126+
127+
with TestRun.step("Check number of dirty data on exported object after interruption"):
92128
core_dirty_blocks_after = core.get_dirty_blocks()
93129
if core_dirty_blocks_after >= core_dirty_blocks_before:
94130
TestRun.LOGGER.error(
95-
"Quantity of dirty lines after core flush interruption " "should be lower."
131+
"Quantity of dirty lines after core flush interruption should be lower."
96132
)
97-
if int(core_dirty_blocks_after) == 0:
133+
if core_dirty_blocks_after == Size.zero():
98134
TestRun.LOGGER.error(
99-
"Quantity of dirty lines after core flush interruption " "should not be zero."
135+
"Quantity of dirty lines after core flush interruption should not be zero."
100136
)
101137

102-
with TestRun.step("Unmount core and stop cache."):
138+
with TestRun.step("Unmount core and stop cache"):
103139
core.unmount()
104140
cache.stop()
105141

106-
with TestRun.step("Mount core device."):
142+
with TestRun.step("Mount core device"):
107143
core_part.mount(mount_point)
108144

109-
with TestRun.step("Check md5 sum of test file again."):
145+
with TestRun.step("Compare checksum of test file"):
110146
if test_file_md5sum_before != test_file.md5sum():
111147
TestRun.LOGGER.error(
112-
"Md5 sums before and after interrupting core flush are different."
148+
"Checksum before and after interrupting core flush are different."
113149
)
114150

115-
with TestRun.step("Unmount core device."):
151+
with TestRun.step("Unmount core device"):
116152
core_part.unmount()
117153

118154

119155
@pytest.mark.parametrizex("filesystem", Filesystem)
120156
@pytest.mark.parametrizex("cache_mode", CacheMode.with_traits(CacheModeTrait.LazyWrites))
121157
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
122158
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
123-
def test_interrupt_cache_flush(cache_mode, filesystem):
159+
def test_interrupt_cache_flush(cache_mode: CacheMode, filesystem: Filesystem):
124160
"""
125161
title: Test if OpenCAS works correctly after cache's flushing interruption.
126162
description: |
@@ -131,70 +167,101 @@ def test_interrupt_cache_flush(cache_mode, filesystem):
131167
- Md5sum are correct during all test steps.
132168
- Dirty blocks quantity after interruption is equal or lower but non-zero.
133169
"""
134-
with TestRun.step("Prepare cache and core."):
135-
cache_part, core_part = prepare()
170+
cache_size = Size(2, Unit.GibiByte)
171+
iterations_per_config = 10
172+
173+
with TestRun.step("Prepare cache and core"):
174+
cache_dev = TestRun.disks["cache"]
175+
core_dev = TestRun.disks["core"]
176+
177+
cache_dev.create_partitions([cache_size])
178+
core_dev.create_partitions([cache_size * 2])
179+
180+
cache_part = cache_dev.partitions[0]
181+
core_part = core_dev.partitions[0]
182+
183+
with TestRun.step("Disable udev"):
184+
Udev.disable()
136185

137186
for _ in TestRun.iteration(
138-
range(iterations_per_config), f"Reload cache configuration {iterations_per_config} times."
187+
range(iterations_per_config), f"Reload cache configuration {iterations_per_config} times"
139188
):
140189

141-
with TestRun.step("Start cache."):
142-
cache = casadm.start_cache(cache_part, cache_mode, force=True)
190+
with TestRun.step("Start cache"):
191+
cache = casadm.start_cache(cache_dev=cache_part, cache_mode=cache_mode, force=True)
143192

144-
with TestRun.step("Set cleaning policy to NOP."):
193+
with TestRun.step("Set cleaning policy to NOP"):
145194
cache.set_cleaning_policy(CleaningPolicy.nop)
146195

147-
with TestRun.step(f"Add core device with {filesystem} filesystem and mount it."):
148-
core_part.create_filesystem(filesystem)
196+
with TestRun.step(f"Create {filesystem} filesystem on core device"):
197+
core_part.create_filesystem(fs_type=filesystem)
198+
199+
with TestRun.step("Add core to the cache"):
149200
core = cache.add_core(core_part)
201+
202+
with TestRun.step(f"Mount core"):
150203
core.mount(mount_point)
151204

152-
with TestRun.step(f"Create test file in mount point of exported object."):
153-
test_file = create_test_file()
205+
with TestRun.step("Create test file in mount point of exported object"):
206+
bs = Size(512, Unit.KibiByte)
207+
count = int(cache_size.value / bs.value)
208+
test_file = File.create_file(test_file_path)
209+
210+
dd = (
211+
Dd()
212+
.input("/dev/zero")
213+
.output(test_file_path)
214+
.block_size(bs)
215+
.count(count)
216+
.oflag("direct")
217+
)
218+
dd.run()
219+
220+
test_file.refresh_item()
154221

155-
with TestRun.step("Check md5 sum of test file."):
222+
with TestRun.step("Check checksum of test file"):
156223
test_file_md5sum_before = test_file.md5sum()
157224

158-
with TestRun.step("Get number of dirty data on exported object before interruption."):
225+
with TestRun.step("Get number of dirty data on exported object before interruption"):
159226
sync()
160227
drop_caches(DropCachesMode.ALL)
161228
cache_dirty_blocks_before = cache.get_dirty_blocks()
162229

163-
with TestRun.step("Start flushing cache."):
230+
with TestRun.step("Start flushing cache"):
164231
flush_pid = TestRun.executor.run_in_background(cli.flush_cache_cmd(str(cache.cache_id)))
165232

166233
with TestRun.step("Interrupt cache flushing"):
167234
wait_for_flushing(cache, core)
168235
percentage = casadm_parser.get_flushing_progress(cache.cache_id, core.core_id)
169-
while percentage < 50:
236+
while percentage < 20:
170237
percentage = casadm_parser.get_flushing_progress(cache.cache_id, core.core_id)
171-
TestRun.executor.run(f"kill -s SIGINT {flush_pid}")
238+
TestRun.executor.kill_process(pid=flush_pid)
172239

173-
with TestRun.step("Check number of dirty data on exported object after interruption."):
240+
with TestRun.step("Check number of dirty data on exported object after interruption"):
174241
cache_dirty_blocks_after = cache.get_dirty_blocks()
175242
if cache_dirty_blocks_after >= cache_dirty_blocks_before:
176243
TestRun.LOGGER.error(
177-
"Quantity of dirty lines after cache flush interruption " "should be lower."
244+
"Quantity of dirty lines after cache flush interruption should be lower."
178245
)
179-
if int(cache_dirty_blocks_after) == 0:
246+
if cache_dirty_blocks_after == Size.zero():
180247
TestRun.LOGGER.error(
181-
"Quantity of dirty lines after cache flush interruption " "should not be zero."
248+
"Quantity of dirty lines after cache flush interruption should not be zero."
182249
)
183250

184-
with TestRun.step("Unmount core and stop cache."):
251+
with TestRun.step("Unmount core and stop cache"):
185252
core.unmount()
186253
cache.stop()
187254

188-
with TestRun.step("Mount core device."):
255+
with TestRun.step("Mount core device"):
189256
core_part.mount(mount_point)
190257

191-
with TestRun.step("Check md5 sum of test file again."):
258+
with TestRun.step("Check checksum of test file again"):
192259
if test_file_md5sum_before != test_file.md5sum():
193260
TestRun.LOGGER.error(
194-
"Md5 sums before and after interrupting cache flush are different."
261+
"Checksum before and after interrupting cache flush are different."
195262
)
196263

197-
with TestRun.step("Unmount core device."):
264+
with TestRun.step("Unmount core device"):
198265
core_part.unmount()
199266

200267

@@ -527,10 +594,7 @@ def test_interrupt_attach(cache_mode):
527594

528595
with TestRun.step("Start attaching cache in background"):
529596
cache_attach_pid = TestRun.executor.run_in_background(
530-
attach_cache_cmd(
531-
cache_id=str(cache.cache_id),
532-
cache_dev=cache_dev.path
533-
)
597+
attach_cache_cmd(cache_id=str(cache.cache_id), cache_dev=cache_dev.path)
534598
)
535599

536600
with TestRun.step("Try to interrupt cache attaching"):

0 commit comments

Comments
 (0)