6
6
import shutil
7
7
from pathlib import Path
8
8
9
+ import pytest
10
+
9
11
import host_tools .drive as drive_tools
10
12
from framework .utils_drive import partuuid_and_disk_path
11
13
from host_tools .fcmetrics import FcDeviceMetrics
12
14
13
15
16
+ @pytest .fixture
17
+ def uvm_vhost_user_plain_any (microvm_factory , guest_kernel , pci_enabled ):
18
+ """Builds a plain VM with no root volume"""
19
+ return microvm_factory .build (
20
+ guest_kernel , None , pci = pci_enabled , monitor_memory = False
21
+ )
22
+
23
+
24
+ @pytest .fixture
25
+ def uvm_vhost_user_booted_ro (uvm_vhost_user_plain_any , rootfs ):
26
+ """Returns a VM with a vhost-user rootfs"""
27
+ vm = uvm_vhost_user_plain_any
28
+
29
+ # We need to setup ssh keys manually because we did not specify rootfs
30
+ # in microvm_factory.build method
31
+ ssh_key = rootfs .with_suffix (".id_rsa" )
32
+ vm .ssh_key = ssh_key
33
+ vm .spawn ()
34
+ vm .basic_config (add_root_device = False )
35
+ vm .add_vhost_user_drive ("rootfs" , rootfs , is_root_device = True , is_read_only = True )
36
+ vm .add_net_iface ()
37
+ vm .start ()
38
+
39
+ return vm
40
+
41
+
42
+ @pytest .fixture
43
+ def uvm_vhost_user_booted_rw (uvm_vhost_user_plain_any , rootfs ):
44
+ """Returns a VM with a vhost-user rootfs"""
45
+ vm = uvm_vhost_user_plain_any
46
+
47
+ # We need to setup ssh keys manually because we did not specify rootfs
48
+ # in microvm_factory.build method
49
+ ssh_key = rootfs .with_suffix (".id_rsa" )
50
+ vm .ssh_key = ssh_key
51
+ vm .spawn ()
52
+ vm .basic_config (add_root_device = False )
53
+ # Create a rw rootfs file that is unique to the microVM
54
+ rootfs_rw = Path (vm .chroot ()) / "rootfs"
55
+ shutil .copy (rootfs , rootfs_rw )
56
+ vm .add_vhost_user_drive (
57
+ "rootfs" , rootfs_rw , is_root_device = True , is_read_only = False
58
+ )
59
+ vm .add_net_iface ()
60
+ vm .start ()
61
+
62
+ return vm
63
+
64
+
14
65
def _check_block_size (ssh_connection , dev_path , size ):
15
66
"""
16
67
Checks the size of the block device.
@@ -34,26 +85,16 @@ def _check_drives(test_microvm, assert_dict, keys_array):
34
85
assert blockdev_out_line_cols [col ] == assert_dict [key ]
35
86
36
87
37
- def test_vhost_user_block (microvm_factory , guest_kernel , rootfs ):
88
+ def test_vhost_user_block (uvm_vhost_user_booted_ro ):
38
89
"""
39
90
This test simply tries to boot a VM with
40
91
vhost-user-block as a root device.
41
92
"""
42
93
43
- vm = microvm_factory .build (guest_kernel , None , monitor_memory = False )
44
-
45
- # We need to setup ssh keys manually because we did not specify rootfs
46
- # in microvm_factory.build method
47
- ssh_key = rootfs .with_suffix (".id_rsa" )
48
- vm .ssh_key = ssh_key
49
- vm .spawn ()
50
- vm .basic_config (add_root_device = False )
51
- vm .add_vhost_user_drive ("rootfs" , rootfs , is_root_device = True , is_read_only = True )
52
- vm .add_net_iface ()
94
+ vm = uvm_vhost_user_booted_ro
53
95
vhost_user_block_metrics = FcDeviceMetrics (
54
96
"vhost_user_block" , 1 , aggr_supported = False
55
97
)
56
- vm .start ()
57
98
58
99
# Now check that vhost-user-block with rw is last.
59
100
# 1-0 means line 1, column 0.
@@ -65,29 +106,14 @@ def test_vhost_user_block(microvm_factory, guest_kernel, rootfs):
65
106
vhost_user_block_metrics .validate (vm )
66
107
67
108
68
- def test_vhost_user_block_read_write (microvm_factory , guest_kernel , rootfs ):
109
+ def test_vhost_user_block_read_write (uvm_vhost_user_booted_rw ):
69
110
"""
70
111
This test simply tries to boot a VM with
71
112
vhost-user-block as a root device.
72
113
This test configures vhost-user-block to be read write.
73
114
"""
74
115
75
- vm = microvm_factory .build (guest_kernel , None , monitor_memory = False )
76
-
77
- # We need to setup ssh keys manually because we did not specify rootfs
78
- # in microvm_factory.build method
79
- ssh_key = rootfs .with_suffix (".id_rsa" )
80
- vm .ssh_key = ssh_key
81
- vm .spawn ()
82
- vm .basic_config (add_root_device = False )
83
-
84
- # Create a rw rootfs file that is unique to the microVM
85
- rootfs_rw = Path (vm .chroot ()) / "rootfs"
86
- shutil .copy (rootfs , rootfs_rw )
87
-
88
- vm .add_vhost_user_drive ("rootfs" , rootfs_rw , is_root_device = True )
89
- vm .add_net_iface ()
90
- vm .start ()
116
+ vm = uvm_vhost_user_booted_rw
91
117
92
118
# Now check that vhost-user-block with rw is last.
93
119
# 1-0 means line 1, column 0.
@@ -98,22 +124,12 @@ def test_vhost_user_block_read_write(microvm_factory, guest_kernel, rootfs):
98
124
_check_drives (vm , assert_dict , assert_dict .keys ())
99
125
100
126
101
- def test_vhost_user_block_disconnect (microvm_factory , guest_kernel , rootfs ):
127
+ def test_vhost_user_block_disconnect (uvm_vhost_user_booted_ro ):
102
128
"""
103
129
Test that even if backend is killed, Firecracker is still responsive.
104
130
"""
105
131
106
- vm = microvm_factory .build (guest_kernel , None , monitor_memory = False )
107
-
108
- # We need to set up ssh keys manually because we did not specify rootfs
109
- # in microvm_factory.build method
110
- ssh_key = rootfs .with_suffix (".id_rsa" )
111
- vm .ssh_key = ssh_key
112
- vm .spawn ()
113
- vm .basic_config (add_root_device = False )
114
- vm .add_vhost_user_drive ("rootfs" , rootfs , is_root_device = True , is_read_only = True )
115
- vm .add_net_iface ()
116
- vm .start ()
132
+ vm = uvm_vhost_user_booted_ro
117
133
118
134
# Killing the backend
119
135
vm .disks_vhost_user ["rootfs" ].kill ()
@@ -123,15 +139,15 @@ def test_vhost_user_block_disconnect(microvm_factory, guest_kernel, rootfs):
123
139
_config = vm .api .vm_config .get ().json ()
124
140
125
141
126
- def test_device_ordering (microvm_factory , guest_kernel , rootfs ):
142
+ def test_device_ordering (uvm_vhost_user_plain_any , rootfs ):
127
143
"""
128
144
Verify device ordering.
129
145
130
146
The root device should correspond to /dev/vda in the guest and
131
147
the order of the other devices should match their configuration order.
132
148
"""
133
149
134
- vm = microvm_factory . build ( guest_kernel , None , monitor_memory = False )
150
+ vm = uvm_vhost_user_plain_any
135
151
136
152
# We need to setup ssh keys manually because we did not specify rootfs
137
153
# in microvm_factory.build method
@@ -194,16 +210,12 @@ def test_device_ordering(microvm_factory, guest_kernel, rootfs):
194
210
vhost_user_block_metrics .validate (vm )
195
211
196
212
197
- def test_partuuid_boot (
198
- microvm_factory ,
199
- guest_kernel ,
200
- rootfs ,
201
- ):
213
+ def test_partuuid_boot (uvm_vhost_user_plain_any , rootfs ):
202
214
"""
203
215
Test the output reported by blockdev when booting with PARTUUID.
204
216
"""
205
217
206
- vm = microvm_factory . build ( guest_kernel , None , monitor_memory = False )
218
+ vm = uvm_vhost_user_plain_any
207
219
208
220
# We need to setup ssh keys manually because we did not specify rootfs
209
221
# in microvm_factory.build method
@@ -230,12 +242,12 @@ def test_partuuid_boot(
230
242
_check_drives (vm , assert_dict , assert_dict .keys ())
231
243
232
244
233
- def test_partuuid_update (microvm_factory , guest_kernel , rootfs ):
245
+ def test_partuuid_update (uvm_vhost_user_plain_any , rootfs ):
234
246
"""
235
247
Test successful switching from PARTUUID boot to /dev/vda boot.
236
248
"""
237
249
238
- vm = microvm_factory . build ( guest_kernel , None , monitor_memory = False )
250
+ vm = uvm_vhost_user_plain_any
239
251
240
252
# We need to setup ssh keys manually because we did not specify rootfs
241
253
# in microvm_factory.build method
@@ -272,7 +284,7 @@ def test_partuuid_update(microvm_factory, guest_kernel, rootfs):
272
284
vhost_user_block_metrics .validate (vm )
273
285
274
286
275
- def test_config_change (microvm_factory , guest_kernel , rootfs ):
287
+ def test_config_change (uvm_plain_any ):
276
288
"""
277
289
Verify handling of block device resize.
278
290
We expect that the guest will start reporting the updated size
@@ -283,7 +295,7 @@ def test_config_change(microvm_factory, guest_kernel, rootfs):
283
295
new_sizes = [20 , 10 , 30 ] # MB
284
296
mkfs_mount_cmd = "mkfs.ext4 /dev/vdb && mkdir -p /tmp/tmp && mount /dev/vdb /tmp/tmp && umount /tmp/tmp"
285
297
286
- vm = microvm_factory . build ( guest_kernel , rootfs , monitor_memory = False )
298
+ vm = uvm_plain_any
287
299
vm .spawn (log_level = "Info" )
288
300
vm .basic_config ()
289
301
vm .add_net_iface ()
0 commit comments