Skip to content

Instantly share code, notes, and snippets.

@XanClic
Created March 4, 2022 13:15
Show Gist options
  • Save XanClic/5bb8c9aee841b77ed0cc6f23b79e50d6 to your computer and use it in GitHub Desktop.
Save XanClic/5bb8c9aee841b77ed0cc6f23b79e50d6 to your computer and use it in GitHub Desktop.
diff --git a/tests/qemu-iotests/296 b/tests/qemu-iotests/296
index 099a3eeaa5..62de87bace 100755
--- a/tests/qemu-iotests/296
+++ b/tests/qemu-iotests/296
@@ -160,7 +160,7 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
###########################################################################
# add a key to an encrypted block device
- def addKeyQmp(self, vm, id, new_secret):
+ def addKeyQmp(self, vm, id, new_secret, expect_success):
args = {
'node-name': id,
@@ -174,8 +174,11 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
}
result = vm.qmp('x-blockdev-amend', **args)
- assert result['return'] == {}
- vm.run_job('job0')
+ if expect_success:
+ assert result['return'] == {}
+ vm.run_job('job0')
+ else:
+ iotests.log(result['error']['desc'])
# test that when the image opened by two qemu processes,
# neither of them can update the encryption keys
@@ -184,7 +187,7 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
# VM1 opens the image and adds a key
self.openImageQmp(self.vm1, "testdev", test_img, self.secrets[0])
- self.addKeyQmp(self.vm1, "testdev", new_secret = self.secrets[1])
+ self.addKeyQmp(self.vm1, "testdev", self.secrets[1], True)
# VM2 opens the image
@@ -192,8 +195,8 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
# neither VMs now should be able to add a key
- self.addKeyQmp(self.vm1, "testdev", new_secret = self.secrets[2])
- self.addKeyQmp(self.vm2, "testdev", new_secret = self.secrets[2])
+ self.addKeyQmp(self.vm1, "testdev", self.secrets[2], False)
+ self.addKeyQmp(self.vm2, "testdev", self.secrets[2], False)
# VM 1 closes the image
@@ -201,7 +204,7 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
# now VM2 can add the key
- self.addKeyQmp(self.vm2, "testdev", new_secret = self.secrets[2])
+ self.addKeyQmp(self.vm2, "testdev", self.secrets[2], True)
# qemu-img should also not be able to add a key
@@ -226,10 +229,10 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
self.openImageQmp(self.vm2, "testdev", test_img, self.secrets[0])
# VM1 can't add a key since image is readonly
- self.addKeyQmp(self.vm1, "testdev", new_secret = self.secrets[2])
+ self.addKeyQmp(self.vm1, "testdev", self.secrets[2], False)
# VM2 can't add a key since VM is has the image opened
- self.addKeyQmp(self.vm2, "testdev", new_secret = self.secrets[2])
+ self.addKeyQmp(self.vm2, "testdev", self.secrets[2], False)
#VM1 reopens the image read-write
@@ -237,13 +240,13 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
reOpen = True, readOnly = False)
# VM1 still can't add the key
- self.addKeyQmp(self.vm1, "testdev", new_secret = self.secrets[2])
+ self.addKeyQmp(self.vm1, "testdev", self.secrets[2], False)
# VM2 gets away
self.closeImageQmp(self.vm2, "testdev")
# VM1 now can add the key
- self.addKeyQmp(self.vm1, "testdev", new_secret = self.secrets[2])
+ self.addKeyQmp(self.vm1, "testdev", self.secrets[2], True)
self.closeImageQmp(self.vm1, "testdev")
os.remove(test_img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment