@@ -49,10 +49,170 @@ def test_rescan(test_microvm_with_ssh, network_config):
4949 ssh_connection .close ()
5050
5151
52+ def test_non_partuuid_boot (test_microvm_with_ssh , network_config ):
53+ """ Tests the output reported by blockdev when booting from /dev/vda."""
54+ test_microvm = test_microvm_with_ssh
55+
56+ test_microvm .basic_config (vcpu_count = 1 , net_iface_count = 0 )
57+ """
58+ Sets up the microVM with 1 vCPUs, 256 MiB of RAM, 0 network ifaces and
59+ a root file system with the rw permission. The network interfaces is
60+ added after we get an unique MAC and IP.
61+ """
62+ test_microvm .basic_network_config (network_config )
63+
64+ # Add another read-only block device.
65+ response = test_microvm .api_session .put (
66+ test_microvm .blk_cfg_url + '/readonly' ,
67+ json = {
68+ 'drive_id' : 'readonly' ,
69+ 'path_on_host' : test_microvm .slot .make_fsfile (name = 'readonly' ),
70+ 'is_root_device' : False ,
71+ 'permissions' : 'ro' ,
72+ 'state' : 'Attached'
73+ }
74+ )
75+ """ Adds the root file system with rw permissions. """
76+ assert (test_microvm .api_session .is_good_response (response .status_code ))
77+
78+ test_microvm .start ()
79+
80+ # Prepare the input for doing the assertion
81+ assert_dict = {}
82+ # Keep an array of strings specifying the location where some string
83+ # from the output is located.
84+ # 1-0 means line 1, column 0.
85+ keys_array = ["1-0" , "1-8" , "2-0" ]
86+ # Keep a dictionary where the keys are the location and the values
87+ # represent the input to assert against.
88+ assert_dict [keys_array [0 ]] = "rw"
89+ assert_dict [keys_array [1 ]] = "/dev/vda"
90+ assert_dict [keys_array [2 ]] = "ro"
91+ check_drives (test_microvm , assert_dict , keys_array )
92+
93+
94+ def test_partuuid_boot (test_microvm_with_partuuid , network_config ):
95+ """ Tests the output reported by blockdev when booting with PARTUUID."""
96+ test_microvm = test_microvm_with_partuuid
97+
98+ test_microvm .basic_config (
99+ vcpu_count = 1 ,
100+ net_iface_count = 0 ,
101+ add_root_device = False
102+ )
103+ """
104+ Sets up the microVM with 1 vCPUs, 256 MiB of RAM, 0 network ifaces and
105+ a root file system with the rw permission. The network interfaces is
106+ added after we get an unique MAC and IP.
107+ """
108+ test_microvm .basic_network_config (network_config )
109+
110+ # Add the root block device specified through PARTUUID.
111+ response = test_microvm .api_session .put (
112+ test_microvm .blk_cfg_url + '/rootfs' ,
113+ json = {
114+ 'drive_id' : 'rootfs' ,
115+ 'path_on_host' : test_microvm .slot .rootfs_file ,
116+ 'is_root_device' : True ,
117+ 'partuuid' : '0eaa91a0-01' ,
118+ 'permissions' : 'rw' ,
119+ 'state' : 'Attached'
120+ }
121+ )
122+ """ Adds the root file system with rw permissions. """
123+ assert (test_microvm .api_session .is_good_response (response .status_code ))
124+
125+ test_microvm .start ()
126+
127+ assert_dict = {}
128+ keys_array = ["1-0" , "1-8" , "2-0" , "2-7" ]
129+ assert_dict [keys_array [0 ]] = "rw"
130+ assert_dict [keys_array [1 ]] = "/dev/vda"
131+ assert_dict [keys_array [2 ]] = "rw"
132+ assert_dict [keys_array [3 ]] = "/dev/vda1"
133+ check_drives (test_microvm , assert_dict , keys_array )
134+
135+
136+ def test_partuuid_update (test_microvm_with_ssh , network_config ):
137+ """
138+ Tests that switching from booting from a PARTUUID to booting from
139+ /dev/vda is successful.
140+ """
141+ test_microvm = test_microvm_with_ssh
142+ test_microvm .basic_config (
143+ vcpu_count = 1 ,
144+ net_iface_count = 0 ,
145+ add_root_device = False
146+ )
147+ """
148+ Sets up the microVM with 1 vCPUs, 256 MiB of RAM, 0 network ifaces and
149+ a root file system with the rw permission. The network interfaces is
150+ added after we get an unique MAC and IP.
151+ """
152+ test_microvm .basic_network_config (network_config )
153+
154+ # Add the root block device specified through PARTUUID.
155+ response = test_microvm .api_session .put (
156+ test_microvm .blk_cfg_url + '/rootfs' ,
157+ json = {
158+ 'drive_id' : 'rootfs' ,
159+ 'path_on_host' : test_microvm .slot .rootfs_file ,
160+ 'is_root_device' : True ,
161+ 'partuuid' : '0eaa91a0-01' ,
162+ 'permissions' : 'rw' ,
163+ 'state' : 'Attached'
164+ }
165+ )
166+ assert (test_microvm .api_session .is_good_response (response .status_code ))
167+
168+ # Update the root block device to boot from /dev/vda.
169+ response = test_microvm .api_session .put (
170+ test_microvm .blk_cfg_url + '/rootfs' ,
171+ json = {
172+ 'drive_id' : 'rootfs' ,
173+ 'path_on_host' : test_microvm .slot .rootfs_file ,
174+ 'is_root_device' : True ,
175+ 'permissions' : 'rw' ,
176+ 'state' : 'Attached'
177+ }
178+ )
179+ assert (test_microvm .api_session .is_good_response (response .status_code ))
180+
181+ test_microvm .start ()
182+
183+ # Assert that the final booting method is from /dev/vda.
184+ assert_dict = {}
185+ keys_array = ["1-0" , "1-8" ]
186+ assert_dict [keys_array [0 ]] = "rw"
187+ assert_dict [keys_array [1 ]] = "/dev/vda"
188+ check_drives (test_microvm , assert_dict , keys_array )
189+
190+
52191def _check_scratch_size (ssh_connection , size ):
53192 _ , stdout , stderr = ssh_connection .execute_command (
54193 "blockdev --getsize64 /dev/vdb"
55194 )
56195 """ The scratch block device is /dev/vdb in the guest. """
57196 assert (stderr .read ().decode ("utf-8" ) == '' )
58197 assert (stdout .readline ().strip () == str (size ))
198+
199+
200+ def process_blockdev_output (blockdev_out , assert_dict , keys_array ):
201+ blockdev_out_lines = blockdev_out .splitlines ()
202+
203+ for key in keys_array :
204+ line = int (key .split ("-" )[0 ])
205+ col = int (key .split ("-" )[1 ])
206+ blockdev_out_line = blockdev_out_lines [line ]
207+ assert (blockdev_out_line .split (" " )[col ] == assert_dict [key ])
208+
209+
210+ def check_drives (test_microvm , assert_dict , keys_array ):
211+ ssh_connection = SSHConnection (test_microvm .slot .ssh_config )
212+
213+ _ , stdout , stderr = ssh_connection .execute_command ("blockdev --report" )
214+ assert (stderr .read ().decode ("utf-8" ) == '' )
215+ process_blockdev_output (
216+ stdout .read ().decode ("utf-8" ),
217+ assert_dict ,
218+ keys_array )
0 commit comments