Skip to content

Commit 153bced

Browse files
committed
test(vhost-user-blk): switch to crosvm backend in functional tests
Unfortunately this change cannot be split into multiple commits due to high level of entanglement of the changes. Reason for the change: the Qemu backend uses direct IO when working with the disk file which makes it scale very poorly. That results in intermittent test failures, because our functional integration tests run in parallel, and our ssh connection timeouts expire if the microVM does not boot in time. Switching from the Qemu to crosvm backend comes with the challenge that crosvm locks the disk file exclusively when opening it as rw (which makes sense). We have to make copies of the disk files before we give them to crosvm if we don't configure crosvm as readonly. One of the ripples of the above is an existing race condition in the partuuid_and_disk_path_host fixture over the disk file kicks in. We are removing this fixture altogether because now we use per microVM copies of the disks. Finally, this change explicitly configures performance tests to switch to the Qemu backend to preserve the status quo. We may switch them to the crosvm backend too at a later stage. Signed-off-by: Nikita Kalyazin <[email protected]>
1 parent f155c8f commit 153bced

File tree

3 files changed

+42
-48
lines changed

3 files changed

+42
-48
lines changed

tests/framework/utils_drive.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ def partuuid_and_disk_path(rootfs_ubuntu_22, disk_path):
5050

5151

5252
def spawn_vhost_user_backend(
53-
vm, host_mem_path, socket_path, readonly=False, backend=VhostUserBlkBackendType.QEMU
53+
vm,
54+
host_mem_path,
55+
socket_path,
56+
readonly=False,
57+
backend=VhostUserBlkBackendType.CROSVM,
5458
):
5559
"""Spawn vhost-user-blk backend."""
5660

tests/integration_tests/functional/test_drive_vhost_user.py

+29-45
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,14 @@
33
"""Tests for vhost-user-block device."""
44

55
import os
6-
7-
import pytest
6+
import shutil
7+
from pathlib import Path
88

99
import host_tools.drive as drive_tools
10-
from framework import utils
11-
from framework.defs import LOCAL_BUILD_PATH
1210
from framework.utils_drive import partuuid_and_disk_path, spawn_vhost_user_backend
1311
from host_tools.metrics import FcDeviceMetrics
1412

1513

16-
@pytest.fixture
17-
def partuuid_and_disk_path_host(rootfs_ubuntu_22):
18-
"""
19-
We create a new file on the host, get its partuuid and use it as a rootfs.
20-
"""
21-
disk_path = LOCAL_BUILD_PATH / "img" / "disk.img"
22-
yield partuuid_and_disk_path(rootfs_ubuntu_22, disk_path)
23-
disk_path.unlink()
24-
25-
2614
def _check_block_size(ssh_connection, dev_path, size):
2715
"""
2816
Checks the size of the block device.
@@ -56,11 +44,8 @@ def test_vhost_user_block(microvm_factory, guest_kernel, rootfs_ubuntu_22):
5644

5745
vm = microvm_factory.build(guest_kernel, None, monitor_memory=False)
5846

59-
# Converting path from tmpfs ("./srv/..") to local
60-
# path on the host ("../build/..")
61-
rootfs_path = utils.to_local_dir_path(str(rootfs_ubuntu_22))
6247
# Launching vhost-user-block backend
63-
_backend = spawn_vhost_user_backend(vm, rootfs_path, vhost_user_socket, True)
48+
_backend = spawn_vhost_user_backend(vm, rootfs_ubuntu_22, vhost_user_socket, True)
6449

6550
# We need to setup ssh keys manually because we did not specify rootfs
6651
# in microvm_factory.build method
@@ -102,18 +87,20 @@ def test_vhost_user_block_read_write(microvm_factory, guest_kernel, rootfs_ubunt
10287

10388
vm = microvm_factory.build(guest_kernel, None, monitor_memory=False)
10489

105-
# Converting path from tmpfs ("./srv/..") to local
106-
# path on the host ("../build/..")
107-
rootfs_path = utils.to_local_dir_path(str(rootfs_ubuntu_22))
108-
# Launching vhost-user-block backend
109-
_backend = spawn_vhost_user_backend(vm, rootfs_path, vhost_user_socket, False)
110-
11190
# We need to setup ssh keys manually because we did not specify rootfs
11291
# in microvm_factory.build method
11392
ssh_key = rootfs_ubuntu_22.with_suffix(".id_rsa")
11493
vm.ssh_key = ssh_key
11594
vm.spawn()
11695
vm.basic_config(add_root_device=False)
96+
97+
# Create a rw rootfs file that is unique to the microVM
98+
rootfs_rw = Path(vm.chroot()) / "rootfs"
99+
shutil.copy(rootfs_ubuntu_22, rootfs_rw)
100+
101+
# Launching vhost-user-block backend
102+
_backend = spawn_vhost_user_backend(vm, rootfs_rw, vhost_user_socket, False)
103+
117104
vm.add_vhost_user_drive("rootfs", vhost_user_socket, is_root_device=True)
118105
vm.add_net_iface()
119106
vm.start()
@@ -141,11 +128,8 @@ def test_vhost_user_block_disconnect(microvm_factory, guest_kernel, rootfs_ubunt
141128

142129
vm = microvm_factory.build(guest_kernel, None, monitor_memory=False)
143130

144-
# Converting path from tmpfs ("./srv/..") to local
145-
# path on the host ("../build/..")
146-
rootfs_path = utils.to_local_dir_path(str(rootfs_ubuntu_22))
147131
# Launching vhost-user-block backend
148-
_backend = spawn_vhost_user_backend(vm, rootfs_path, vhost_user_socket, True)
132+
_backend = spawn_vhost_user_backend(vm, rootfs_ubuntu_22, vhost_user_socket, True)
149133

150134
# We need to set up ssh keys manually because we did not specify rootfs
151135
# in microvm_factory.build method
@@ -182,11 +166,8 @@ def test_device_ordering(microvm_factory, guest_kernel, rootfs_ubuntu_22):
182166

183167
vm = microvm_factory.build(guest_kernel, None, monitor_memory=False)
184168

185-
# Converting path from tmpfs ("./srv/..") to local
186-
# path on the host ("../build/..")
187-
rootfs_path = utils.to_local_dir_path(str(rootfs_ubuntu_22))
188169
# Launching vhost-user-block backend
189-
_backend = spawn_vhost_user_backend(vm, rootfs_path, vhost_user_socket_1, True)
170+
_backend = spawn_vhost_user_backend(vm, rootfs_ubuntu_22, vhost_user_socket_1, True)
190171

191172
# We need to setup ssh keys manually because we did not specify rootfs
192173
# in microvm_factory.build method
@@ -207,8 +188,12 @@ def test_device_ordering(microvm_factory, guest_kernel, rootfs_ubuntu_22):
207188
fs2 = drive_tools.FilesystemFile(os.path.join(vm.fsfiles, "scratch2"), size=512)
208189
vm.add_drive("scratch2", fs2.path)
209190

191+
# Create a rw rootfs file that is unique to the microVM
192+
rootfs_rw = Path(vm.chroot()) / "rootfs"
193+
shutil.copy(rootfs_ubuntu_22, rootfs_rw)
194+
210195
# Launching vhost-user-block backend
211-
_backend2 = spawn_vhost_user_backend(vm, rootfs_path, vhost_user_socket_2, False)
196+
_backend2 = spawn_vhost_user_backend(vm, rootfs_rw, vhost_user_socket_2, False)
212197
# Adding forth block device.
213198
vm.add_vhost_user_drive("dummy_rootfs", vhost_user_socket_2)
214199

@@ -251,28 +236,30 @@ def test_partuuid_boot(
251236
microvm_factory,
252237
guest_kernel,
253238
rootfs_ubuntu_22,
254-
partuuid_and_disk_path_host,
255239
):
256240
"""
257241
Test the output reported by blockdev when booting with PARTUUID.
258242
"""
259243

260244
vhost_user_socket = "/vub.socket"
261245

262-
partuuid = partuuid_and_disk_path_host[0]
263-
disk_path = partuuid_and_disk_path_host[1]
264-
265246
vm = microvm_factory.build(guest_kernel, None, monitor_memory=False)
266247

267-
# Launching vhost-user-block backend
268-
_backend = spawn_vhost_user_backend(vm, disk_path, vhost_user_socket, True)
269-
270248
# We need to setup ssh keys manually because we did not specify rootfs
271249
# in microvm_factory.build method
272250
ssh_key = rootfs_ubuntu_22.with_suffix(".id_rsa")
273251
vm.ssh_key = ssh_key
274252
vm.spawn()
275253
vm.basic_config(add_root_device=False)
254+
255+
# Create a rootfs with partuuid unique to this microVM
256+
partuuid, disk_path = partuuid_and_disk_path(
257+
rootfs_ubuntu_22, Path(vm.chroot()) / "disk.img"
258+
)
259+
260+
# Launching vhost-user-block backend
261+
_backend = spawn_vhost_user_backend(vm, disk_path, vhost_user_socket, True)
262+
276263
vm.add_vhost_user_drive(
277264
"1", vhost_user_socket, is_root_device=True, partuuid=partuuid
278265
)
@@ -303,11 +290,8 @@ def test_partuuid_update(microvm_factory, guest_kernel, rootfs_ubuntu_22):
303290

304291
vm = microvm_factory.build(guest_kernel, None, monitor_memory=False)
305292

306-
# Converting path from tmpfs ("./srv/..") to local
307-
# path on the host ("../build/..")
308-
rootfs_path = utils.to_local_dir_path(str(rootfs_ubuntu_22))
309293
# Launching vhost-user-block backend
310-
_backend = spawn_vhost_user_backend(vm, rootfs_path, vhost_user_socket_1, True)
294+
_backend = spawn_vhost_user_backend(vm, rootfs_ubuntu_22, vhost_user_socket_1, True)
311295

312296
# We need to setup ssh keys manually because we did not specify rootfs
313297
# in microvm_factory.build method
@@ -325,7 +309,7 @@ def test_partuuid_update(microvm_factory, guest_kernel, rootfs_ubuntu_22):
325309
# We need to craete new backend with another socket because when we updated
326310
# vhost-user-block device, old connection is closed, and qemu backend will
327311
# stop after connection is closed.
328-
_backend = spawn_vhost_user_backend(vm, rootfs_path, vhost_user_socket_2, True)
312+
_backend = spawn_vhost_user_backend(vm, rootfs_ubuntu_22, vhost_user_socket_2, True)
329313
vm.add_vhost_user_drive("rootfs", vhost_user_socket_2, is_root_device=True)
330314

331315
vhost_user_block_metrics = FcDeviceMetrics(

tests/integration_tests/performance/test_block_performance.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
run_cmd,
2424
summarize_cpu_percent,
2525
)
26-
from framework.utils_drive import spawn_vhost_user_backend
26+
from framework.utils_drive import VhostUserBlkBackendType, spawn_vhost_user_backend
2727
from integration_tests.performance.configs import defs
2828

2929
TEST_ID = "block_performance"
@@ -370,7 +370,13 @@ def test_block_vhost_user_performance(
370370
# Add a secondary block device for benchmark tests.
371371
fs = drive_tools.FilesystemFile(size=BLOCK_DEVICE_SIZE_MB)
372372
vhost_user_socket = "/vub.socket"
373-
backend = spawn_vhost_user_backend(vm, fs.path, vhost_user_socket, readonly=False)
373+
backend = spawn_vhost_user_backend(
374+
vm,
375+
fs.path,
376+
vhost_user_socket,
377+
readonly=False,
378+
backend=VhostUserBlkBackendType.QEMU,
379+
)
374380
vm.add_vhost_user_drive("scratch", vhost_user_socket)
375381
vm.start()
376382

0 commit comments

Comments
 (0)