@@ -133,6 +133,21 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
133
133
)
134
134
self .assert_qmp (result , 'return' , {})
135
135
136
+
137
+ ###########################################################################
138
+ # add virtio-blk consumer for a block device
139
+ def addImageUser (self , vm , id , disk_id , share_rw = False ):
140
+ result = vm .qmp ('device_add' , **
141
+ {
142
+ 'driver' : 'virtio-blk' ,
143
+ 'id' : id ,
144
+ 'drive' : disk_id ,
145
+ 'share-rw' : share_rw
146
+ }
147
+ )
148
+
149
+ iotests .log (result )
150
+
136
151
# close the encrypted block device
137
152
def closeImageQmp (self , vm , id ):
138
153
result = vm .qmp ('blockdev-del' , ** { 'node-name' : id })
@@ -159,7 +174,7 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
159
174
vm .run_job ('job0' )
160
175
161
176
# test that when the image opened by two qemu processes,
162
- # neither of them can update the image
177
+ # neither of them can update the encryption keys
163
178
def test1 (self ):
164
179
self .createImg (test_img , self .secrets [0 ]);
165
180
@@ -193,6 +208,9 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
193
208
os .remove (test_img )
194
209
195
210
211
+ # test that when the image opened by two qemu processes,
212
+ # even if first VM opens it read-only, the second can't update encryption
213
+ # keys
196
214
def test2 (self ):
197
215
self .createImg (test_img , self .secrets [0 ]);
198
216
@@ -226,6 +244,30 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
226
244
self .closeImageQmp (self .vm1 , "testdev" )
227
245
os .remove (test_img )
228
246
247
+ # test that two VMs can't open the same luks image by default
248
+ # and attach it to a guest device
249
+ def test3 (self ):
250
+ self .createImg (test_img , self .secrets [0 ]);
251
+
252
+ self .openImageQmp (self .vm1 , "testdev" , test_img , self .secrets [0 ])
253
+ self .addImageUser (self .vm1 , "testctrl" , "testdev" )
254
+
255
+ self .openImageQmp (self .vm2 , "testdev" , test_img , self .secrets [0 ])
256
+ self .addImageUser (self .vm2 , "testctrl" , "testdev" )
257
+
258
+
259
+ # test that two VMs can attach the same luks image to a guest device,
260
+ # if both use share-rw=on
261
+ def test4 (self ):
262
+ self .createImg (test_img , self .secrets [0 ]);
263
+
264
+ self .openImageQmp (self .vm1 , "testdev" , test_img , self .secrets [0 ])
265
+ self .addImageUser (self .vm1 , "testctrl" , "testdev" , share_rw = True )
266
+
267
+ self .openImageQmp (self .vm2 , "testdev" , test_img , self .secrets [0 ])
268
+ self .addImageUser (self .vm2 , "testctrl" , "testdev" , share_rw = True )
269
+
270
+
229
271
230
272
if __name__ == '__main__' :
231
273
# support only raw luks since luks encrypted qcow2 is a proper
0 commit comments