Skip to content

Commit f529b3f

Browse files
committed
test(virtio-block): test also async engine
So far, tests for virtio block devices only used the synchronous engine for testing. This commit, uses the "io_engine" fixture which returns both "Sync" and "Async" (for the kernels > 4.14). It also adds a test the we can mount devices after patching the backing file on the host. Signed-off-by: Babis Chalios <[email protected]>
1 parent 3d18abc commit f529b3f

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

tests/integration_tests/functional/test_drive_virtio.py

+35-16
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def partuuid_and_disk_path_tmpfs(rootfs_ubuntu_22, tmp_path):
2323
disk_path.unlink()
2424

2525

26-
def test_rescan_file(test_microvm_with_api):
26+
def test_rescan_file(test_microvm_with_api, io_engine):
2727
"""
2828
Verify that rescan works with a file-backed virtio device.
2929
"""
@@ -39,7 +39,7 @@ def test_rescan_file(test_microvm_with_api):
3939
fs = drive_tools.FilesystemFile(
4040
os.path.join(test_microvm.fsfiles, "scratch"), size=block_size
4141
)
42-
test_microvm.add_drive("scratch", fs.path)
42+
test_microvm.add_drive("scratch", fs.path, io_engine=io_engine)
4343

4444
test_microvm.start()
4545

@@ -64,7 +64,7 @@ def test_rescan_file(test_microvm_with_api):
6464
_check_block_size(test_microvm.ssh, "/dev/vdb", fs.size())
6565

6666

67-
def test_device_ordering(test_microvm_with_api):
67+
def test_device_ordering(test_microvm_with_api, io_engine):
6868
"""
6969
Verify device ordering.
7070
@@ -78,7 +78,7 @@ def test_device_ordering(test_microvm_with_api):
7878
fs1 = drive_tools.FilesystemFile(
7979
os.path.join(test_microvm.fsfiles, "scratch1"), size=128
8080
)
81-
test_microvm.add_drive("scratch1", fs1.path)
81+
test_microvm.add_drive("scratch1", fs1.path, io_engine=io_engine)
8282

8383
# Set up the microVM with 1 vCPUs, 256 MiB of RAM and a root file system
8484
# (this is the second block device added).
@@ -89,7 +89,7 @@ def test_device_ordering(test_microvm_with_api):
8989
fs2 = drive_tools.FilesystemFile(
9090
os.path.join(test_microvm.fsfiles, "scratch2"), size=512
9191
)
92-
test_microvm.add_drive("scratch2", fs2.path)
92+
test_microvm.add_drive("scratch2", fs2.path, io_engine=io_engine)
9393

9494
test_microvm.start()
9595

@@ -112,7 +112,7 @@ def test_device_ordering(test_microvm_with_api):
112112
_check_block_size(ssh_connection, "/dev/vdc", fs2.size())
113113

114114

115-
def test_rescan_dev(test_microvm_with_api):
115+
def test_rescan_dev(test_microvm_with_api, io_engine):
116116
"""
117117
Verify that rescan works with a device-backed virtio device.
118118
"""
@@ -125,7 +125,7 @@ def test_rescan_dev(test_microvm_with_api):
125125

126126
# Add a scratch block device.
127127
fs1 = drive_tools.FilesystemFile(os.path.join(test_microvm.fsfiles, "fs1"))
128-
test_microvm.add_drive("scratch", fs1.path)
128+
test_microvm.add_drive("scratch", fs1.path, io_engine=io_engine)
129129

130130
test_microvm.start()
131131

@@ -152,7 +152,7 @@ def test_rescan_dev(test_microvm_with_api):
152152
utils.run_cmd(["losetup", "--detach", loopback_device])
153153

154154

155-
def test_non_partuuid_boot(test_microvm_with_api):
155+
def test_non_partuuid_boot(test_microvm_with_api, io_engine):
156156
"""
157157
Test the output reported by blockdev when booting from /dev/vda.
158158
"""
@@ -165,7 +165,7 @@ def test_non_partuuid_boot(test_microvm_with_api):
165165

166166
# Add another read-only block device.
167167
fs = drive_tools.FilesystemFile(os.path.join(test_microvm.fsfiles, "readonly"))
168-
test_microvm.add_drive("scratch", fs.path, is_read_only=True)
168+
test_microvm.add_drive("scratch", fs.path, is_read_only=True, io_engine=io_engine)
169169

170170
test_microvm.start()
171171

@@ -183,7 +183,7 @@ def test_non_partuuid_boot(test_microvm_with_api):
183183
_check_drives(test_microvm, assert_dict, keys_array)
184184

185185

186-
def test_partuuid_boot(test_microvm_with_api, partuuid_and_disk_path_tmpfs):
186+
def test_partuuid_boot(test_microvm_with_api, partuuid_and_disk_path_tmpfs, io_engine):
187187
"""
188188
Test the output reported by blockdev when booting with PARTUUID.
189189
"""
@@ -204,6 +204,7 @@ def test_partuuid_boot(test_microvm_with_api, partuuid_and_disk_path_tmpfs):
204204
disk_path,
205205
is_root_device=True,
206206
partuuid=partuuid,
207+
io_engine=io_engine,
207208
)
208209
test_microvm.start()
209210

@@ -216,7 +217,7 @@ def test_partuuid_boot(test_microvm_with_api, partuuid_and_disk_path_tmpfs):
216217
_check_drives(test_microvm, assert_dict, keys_array)
217218

218219

219-
def test_partuuid_update(test_microvm_with_api):
220+
def test_partuuid_update(test_microvm_with_api, io_engine):
220221
"""
221222
Test successful switching from PARTUUID boot to /dev/vda boot.
222223
"""
@@ -229,14 +230,19 @@ def test_partuuid_update(test_microvm_with_api):
229230

230231
# Add the root block device specified through PARTUUID.
231232
test_microvm.add_drive(
232-
"rootfs", test_microvm.rootfs_file, is_root_device=True, partuuid="0eaa91a0-01"
233+
"rootfs",
234+
test_microvm.rootfs_file,
235+
is_root_device=True,
236+
partuuid="0eaa91a0-01",
237+
io_engine=io_engine,
233238
)
234239

235240
# Update the root block device to boot from /dev/vda.
236241
test_microvm.add_drive(
237242
"rootfs",
238243
test_microvm.rootfs_file,
239244
is_root_device=True,
245+
io_engine=io_engine,
240246
)
241247

242248
test_microvm.start()
@@ -249,7 +255,7 @@ def test_partuuid_update(test_microvm_with_api):
249255
_check_drives(test_microvm, assert_dict, keys_array)
250256

251257

252-
def test_patch_drive(test_microvm_with_api):
258+
def test_patch_drive(test_microvm_with_api, io_engine):
253259
"""
254260
Test replacing the backing filesystem after guest boot works.
255261
"""
@@ -261,10 +267,12 @@ def test_patch_drive(test_microvm_with_api):
261267
test_microvm.add_net_iface()
262268

263269
fs1 = drive_tools.FilesystemFile(os.path.join(test_microvm.fsfiles, "scratch"))
264-
test_microvm.add_drive("scratch", fs1.path)
270+
test_microvm.add_drive("scratch", fs1.path, io_engine=io_engine)
265271

266272
test_microvm.start()
267273

274+
_check_mount(test_microvm.ssh, "/dev/vdb")
275+
268276
# Updates to `path_on_host` with a valid path are allowed.
269277
fs2 = drive_tools.FilesystemFile(
270278
os.path.join(test_microvm.fsfiles, "otherscratch"), size=512
@@ -273,6 +281,8 @@ def test_patch_drive(test_microvm_with_api):
273281
drive_id="scratch", path_on_host=test_microvm.create_jailed_resource(fs2.path)
274282
)
275283

284+
_check_mount(test_microvm.ssh, "/dev/vdb")
285+
276286
# The `lsblk` command should output 2 lines to STDOUT: "SIZE" and the size
277287
# of the device, in bytes.
278288
blksize_cmd = "lsblk -b /dev/vdb --output SIZE"
@@ -284,7 +294,7 @@ def test_patch_drive(test_microvm_with_api):
284294
assert lines[1].strip() == size_bytes_str
285295

286296

287-
def test_no_flush(test_microvm_with_api):
297+
def test_no_flush(test_microvm_with_api, io_engine):
288298
"""
289299
Verify default block ignores flush.
290300
"""
@@ -299,6 +309,7 @@ def test_no_flush(test_microvm_with_api):
299309
"rootfs",
300310
test_microvm.rootfs_file,
301311
is_root_device=True,
312+
io_engine=io_engine,
302313
)
303314
test_microvm.start()
304315

@@ -317,7 +328,7 @@ def test_no_flush(test_microvm_with_api):
317328
assert fc_metrics["block"]["flush_count"] == 0
318329

319330

320-
def test_flush(uvm_plain_rw):
331+
def test_flush(uvm_plain_rw, io_engine):
321332
"""
322333
Verify block with flush actually flushes.
323334
"""
@@ -332,6 +343,7 @@ def test_flush(uvm_plain_rw):
332343
test_microvm.rootfs_file,
333344
is_root_device=True,
334345
cache_type="Writeback",
346+
io_engine=io_engine,
335347
)
336348
test_microvm.start()
337349

@@ -371,3 +383,10 @@ def _check_drives(test_microvm, assert_dict, keys_array):
371383
_, stdout, stderr = test_microvm.ssh.run("blockdev --report")
372384
assert stderr == ""
373385
_process_blockdev_output(stdout, assert_dict, keys_array)
386+
387+
388+
def _check_mount(ssh_connection, dev_path):
389+
_, _, stderr = ssh_connection.run(f"mount {dev_path} /tmp", timeout=30.0)
390+
assert stderr == ""
391+
_, _, stderr = ssh_connection.run("umount /tmp", timeout=30.0)
392+
assert stderr == ""

0 commit comments

Comments
 (0)