Skip to content

Commit 0fca43d

Browse files
Maxim LevitskyXanClic
authored andcommitted
qemu-iotests: add testcase for bz #1857490
Test that we can't write-share raw luks images by default, but we still can with share-rw=on Signed-off-by: Maxim Levitsky <[email protected]> Message-Id: <[email protected]> Signed-off-by: Max Reitz <[email protected]>
1 parent 662d0c5 commit 0fca43d

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

tests/qemu-iotests/296

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
133133
)
134134
self.assert_qmp(result, 'return', {})
135135

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+
136151
# close the encrypted block device
137152
def closeImageQmp(self, vm, id):
138153
result = vm.qmp('blockdev-del', **{ 'node-name': id })
@@ -159,7 +174,7 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
159174
vm.run_job('job0')
160175

161176
# 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
163178
def test1(self):
164179
self.createImg(test_img, self.secrets[0]);
165180

@@ -193,6 +208,9 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
193208
os.remove(test_img)
194209

195210

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
196214
def test2(self):
197215
self.createImg(test_img, self.secrets[0]);
198216

@@ -226,6 +244,30 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
226244
self.closeImageQmp(self.vm1, "testdev")
227245
os.remove(test_img)
228246

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+
229271

230272
if __name__ == '__main__':
231273
# support only raw luks since luks encrypted qcow2 is a proper

tests/qemu-iotests/296.out

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@ Job failed: Failed to get shared "consistent read" lock
2626
{"return": {}}
2727
{"execute": "job-dismiss", "arguments": {"id": "job0"}}
2828
{"return": {}}
29-
..
29+
Formatting 'TEST_DIR/test.img', fmt=luks size=1048576 key-secret=keysec0 iter-time=10
30+
31+
{"return": {}}
32+
{"error": {"class": "GenericError", "desc": "Failed to get \"write\" lock"}}
33+
Formatting 'TEST_DIR/test.img', fmt=luks size=1048576 key-secret=keysec0 iter-time=10
34+
35+
{"return": {}}
36+
{"return": {}}
37+
....
3038
----------------------------------------------------------------------
31-
Ran 2 tests
39+
Ran 4 tests
3240

3341
OK

0 commit comments

Comments
 (0)