Skip to content

Commit 25e3dbf

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 6704797 commit 25e3dbf

File tree

2 files changed

+51
-21
lines changed

2 files changed

+51
-21
lines changed

tests/integration_tests/functional/test_api.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_drive_io_engine(test_microvm_with_api):
9292
assert test_microvm.api.vm_config.get().json()["drives"][0]["io_engine"] == "Sync"
9393

9494

95-
def test_api_put_update_pre_boot(test_microvm_with_api):
95+
def test_api_put_update_pre_boot(test_microvm_with_api, io_engine):
9696
"""
9797
Test that PUT updates are allowed before the microvm boots.
9898
@@ -111,6 +111,7 @@ def test_api_put_update_pre_boot(test_microvm_with_api):
111111
path_on_host=test_microvm.create_jailed_resource(fs1.path),
112112
is_root_device=False,
113113
is_read_only=False,
114+
io_engine=io_engine,
114115
)
115116

116117
# Updates to `kernel_image_path` with an invalid path are not allowed.
@@ -132,6 +133,7 @@ def test_api_put_update_pre_boot(test_microvm_with_api):
132133
path_on_host="foo.bar",
133134
is_read_only=True,
134135
is_root_device=True,
136+
io_engine=io_engine,
135137
)
136138

137139
# Updates to `is_root_device` that result in two root block devices are not
@@ -142,6 +144,7 @@ def test_api_put_update_pre_boot(test_microvm_with_api):
142144
path_on_host=test_microvm.get_jailed_resource(fs1.path),
143145
is_read_only=False,
144146
is_root_device=True,
147+
io_engine=io_engine,
145148
)
146149

147150
# Valid updates to `path_on_host` and `is_read_only` are allowed.
@@ -151,6 +154,7 @@ def test_api_put_update_pre_boot(test_microvm_with_api):
151154
path_on_host=test_microvm.create_jailed_resource(fs2.path),
152155
is_read_only=True,
153156
is_root_device=False,
157+
io_engine=io_engine,
154158
)
155159

156160
# Valid updates to all fields in the machine configuration are allowed.
@@ -473,7 +477,7 @@ def test_api_cpu_config(test_microvm_with_api, custom_cpu_template):
473477
test_microvm.api.cpu_config.put(**custom_cpu_template["template"])
474478

475479

476-
def test_api_put_update_post_boot(test_microvm_with_api):
480+
def test_api_put_update_post_boot(test_microvm_with_api, io_engine):
477481
"""
478482
Test that PUT updates are rejected after the microvm boots.
479483
"""
@@ -520,6 +524,7 @@ def test_api_put_update_post_boot(test_microvm_with_api):
520524
path_on_host=test_microvm.jailer.jailed_path(test_microvm.rootfs_file),
521525
is_read_only=False,
522526
is_root_device=True,
527+
io_engine=io_engine,
523528
)
524529

525530
# MMDS config is not allowed post-boot.
@@ -532,7 +537,7 @@ def test_api_put_update_post_boot(test_microvm_with_api):
532537
test_microvm.api.mmds_config.put(**mmds_config)
533538

534539

535-
def test_rate_limiters_api_config(test_microvm_with_api):
540+
def test_rate_limiters_api_config(test_microvm_with_api, io_engine):
536541
"""
537542
Test the IO rate limiter API config.
538543
"""
@@ -549,6 +554,7 @@ def test_rate_limiters_api_config(test_microvm_with_api):
549554
is_read_only=False,
550555
is_root_device=False,
551556
rate_limiter={"bandwidth": {"size": 1000000, "refill_time": 100}},
557+
io_engine=io_engine,
552558
)
553559

554560
# Test drive with ops rate-limiting.
@@ -559,6 +565,7 @@ def test_rate_limiters_api_config(test_microvm_with_api):
559565
is_read_only=False,
560566
is_root_device=False,
561567
rate_limiter={"ops": {"size": 1, "refill_time": 100}},
568+
io_engine=io_engine,
562569
)
563570

564571
# Test drive with bw and ops rate-limiting.
@@ -572,6 +579,7 @@ def test_rate_limiters_api_config(test_microvm_with_api):
572579
"bandwidth": {"size": 1000000, "refill_time": 100},
573580
"ops": {"size": 1, "refill_time": 100},
574581
},
582+
io_engine=io_engine,
575583
)
576584

577585
# Test drive with 'empty' rate-limiting (same as not specifying the field)
@@ -582,6 +590,7 @@ def test_rate_limiters_api_config(test_microvm_with_api):
582590
is_read_only=False,
583591
is_root_device=False,
584592
rate_limiter={},
593+
io_engine=io_engine,
585594
)
586595

587596
# Test the NET rate limiting API.
@@ -636,7 +645,7 @@ def test_rate_limiters_api_config(test_microvm_with_api):
636645
)
637646

638647

639-
def test_api_patch_pre_boot(test_microvm_with_api):
648+
def test_api_patch_pre_boot(test_microvm_with_api, io_engine):
640649
"""
641650
Test that PATCH updates are not allowed before the microvm boots.
642651
"""
@@ -654,6 +663,7 @@ def test_api_patch_pre_boot(test_microvm_with_api):
654663
path_on_host=test_microvm.create_jailed_resource(fs1.path),
655664
is_root_device=False,
656665
is_read_only=False,
666+
io_engine=io_engine,
657667
)
658668

659669
iface_id = "1"
@@ -685,7 +695,7 @@ def test_api_patch_pre_boot(test_microvm_with_api):
685695
test_microvm.api.network.patch(iface_id=iface_id)
686696

687697

688-
def test_negative_api_patch_post_boot(test_microvm_with_api):
698+
def test_negative_api_patch_post_boot(test_microvm_with_api, io_engine):
689699
"""
690700
Test PATCH updates that are not allowed after the microvm boots.
691701
"""
@@ -702,6 +712,7 @@ def test_negative_api_patch_post_boot(test_microvm_with_api):
702712
path_on_host=test_microvm.create_jailed_resource(fs1.path),
703713
is_root_device=False,
704714
is_read_only=False,
715+
io_engine=io_engine,
705716
)
706717

707718
iface_id = "1"

tests/integration_tests/functional/test_drive_virtio.py

Lines changed: 35 additions & 16 deletions
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)