3
3
"""Tests for vhost-user-block device."""
4
4
5
5
import os
6
-
7
- import pytest
6
+ import shutil
7
+ from pathlib import Path
8
8
9
9
import host_tools .drive as drive_tools
10
- from framework import utils
11
- from framework .defs import LOCAL_BUILD_PATH
12
10
from framework .utils_drive import partuuid_and_disk_path , spawn_vhost_user_backend
13
11
from host_tools .metrics import FcDeviceMetrics
14
12
15
13
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
-
26
14
def _check_block_size (ssh_connection , dev_path , size ):
27
15
"""
28
16
Checks the size of the block device.
@@ -56,11 +44,8 @@ def test_vhost_user_block(microvm_factory, guest_kernel, rootfs_ubuntu_22):
56
44
57
45
vm = microvm_factory .build (guest_kernel , None , monitor_memory = False )
58
46
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 ))
62
47
# 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 )
64
49
65
50
# We need to setup ssh keys manually because we did not specify rootfs
66
51
# in microvm_factory.build method
@@ -102,18 +87,20 @@ def test_vhost_user_block_read_write(microvm_factory, guest_kernel, rootfs_ubunt
102
87
103
88
vm = microvm_factory .build (guest_kernel , None , monitor_memory = False )
104
89
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
-
111
90
# We need to setup ssh keys manually because we did not specify rootfs
112
91
# in microvm_factory.build method
113
92
ssh_key = rootfs_ubuntu_22 .with_suffix (".id_rsa" )
114
93
vm .ssh_key = ssh_key
115
94
vm .spawn ()
116
95
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
+
117
104
vm .add_vhost_user_drive ("rootfs" , vhost_user_socket , is_root_device = True )
118
105
vm .add_net_iface ()
119
106
vm .start ()
@@ -141,11 +128,8 @@ def test_vhost_user_block_disconnect(microvm_factory, guest_kernel, rootfs_ubunt
141
128
142
129
vm = microvm_factory .build (guest_kernel , None , monitor_memory = False )
143
130
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 ))
147
131
# 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 )
149
133
150
134
# We need to set up ssh keys manually because we did not specify rootfs
151
135
# in microvm_factory.build method
@@ -182,11 +166,8 @@ def test_device_ordering(microvm_factory, guest_kernel, rootfs_ubuntu_22):
182
166
183
167
vm = microvm_factory .build (guest_kernel , None , monitor_memory = False )
184
168
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 ))
188
169
# 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 )
190
171
191
172
# We need to setup ssh keys manually because we did not specify rootfs
192
173
# in microvm_factory.build method
@@ -207,8 +188,12 @@ def test_device_ordering(microvm_factory, guest_kernel, rootfs_ubuntu_22):
207
188
fs2 = drive_tools .FilesystemFile (os .path .join (vm .fsfiles , "scratch2" ), size = 512 )
208
189
vm .add_drive ("scratch2" , fs2 .path )
209
190
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
+
210
195
# 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 )
212
197
# Adding forth block device.
213
198
vm .add_vhost_user_drive ("dummy_rootfs" , vhost_user_socket_2 )
214
199
@@ -251,28 +236,30 @@ def test_partuuid_boot(
251
236
microvm_factory ,
252
237
guest_kernel ,
253
238
rootfs_ubuntu_22 ,
254
- partuuid_and_disk_path_host ,
255
239
):
256
240
"""
257
241
Test the output reported by blockdev when booting with PARTUUID.
258
242
"""
259
243
260
244
vhost_user_socket = "/vub.socket"
261
245
262
- partuuid = partuuid_and_disk_path_host [0 ]
263
- disk_path = partuuid_and_disk_path_host [1 ]
264
-
265
246
vm = microvm_factory .build (guest_kernel , None , monitor_memory = False )
266
247
267
- # Launching vhost-user-block backend
268
- _backend = spawn_vhost_user_backend (vm , disk_path , vhost_user_socket , True )
269
-
270
248
# We need to setup ssh keys manually because we did not specify rootfs
271
249
# in microvm_factory.build method
272
250
ssh_key = rootfs_ubuntu_22 .with_suffix (".id_rsa" )
273
251
vm .ssh_key = ssh_key
274
252
vm .spawn ()
275
253
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
+
276
263
vm .add_vhost_user_drive (
277
264
"1" , vhost_user_socket , is_root_device = True , partuuid = partuuid
278
265
)
@@ -303,11 +290,8 @@ def test_partuuid_update(microvm_factory, guest_kernel, rootfs_ubuntu_22):
303
290
304
291
vm = microvm_factory .build (guest_kernel , None , monitor_memory = False )
305
292
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 ))
309
293
# 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 )
311
295
312
296
# We need to setup ssh keys manually because we did not specify rootfs
313
297
# in microvm_factory.build method
@@ -325,7 +309,7 @@ def test_partuuid_update(microvm_factory, guest_kernel, rootfs_ubuntu_22):
325
309
# We need to craete new backend with another socket because when we updated
326
310
# vhost-user-block device, old connection is closed, and qemu backend will
327
311
# 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 )
329
313
vm .add_vhost_user_drive ("rootfs" , vhost_user_socket_2 , is_root_device = True )
330
314
331
315
vhost_user_block_metrics = FcDeviceMetrics (
0 commit comments