[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 06/11] iotests: Add tests for mirror @replaces lo
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH v2 06/11] iotests: Add tests for mirror @replaces loops |
Date: |
Fri, 10 Aug 2018 00:31:12 +0200 |
This adds two tests for cases where our old check_to_replace_node()
function failed to detect that executing this job with these parameters
would result in a cyclic graph.
Signed-off-by: Max Reitz <address@hidden>
---
tests/qemu-iotests/041 | 124 +++++++++++++++++++++++++++++++++++++
tests/qemu-iotests/041.out | 4 +-
2 files changed, 126 insertions(+), 2 deletions(-)
diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
index c20ac7da87..186bd0f031 100755
--- a/tests/qemu-iotests/041
+++ b/tests/qemu-iotests/041
@@ -1061,5 +1061,129 @@ class TestOrphanedSource(iotests.QMPTestCase):
target='dest-ro')
self.assert_qmp(result, 'error/class', 'GenericError')
+# Various tests for the @replaces option (independent of quorum)
+class TestReplaces(iotests.QMPTestCase):
+ def setUp(self):
+ self.vm = iotests.VM()
+ self.vm.launch()
+
+ def tearDown(self):
+ self.vm.shutdown()
+
+ def test_drive_mirror_loop(self):
+ qemu_img('create', '-f', iotests.imgfmt, test_img, '1M')
+
+ result = self.vm.qmp('object-add', qom_type='throttle-group', id='tg')
+ self.assert_qmp(result, 'return', {})
+
+ result = self.vm.qmp('blockdev-add', **{
+ 'node-name': 'source',
+ 'driver': 'throttle',
+ 'throttle-group': 'tg',
+ 'file': {
+ 'node-name': 'filtered',
+ 'driver': 'qcow2',
+ 'file': {
+ 'driver': 'file',
+ 'filename': test_img
+ }
+ }
+ })
+ self.assert_qmp(result, 'return', {})
+
+ # Mirror from @source to @target in sync=none, so that @source
+ # will be @target's backing file; but replace @filtered.
+ # Then, @target's backing file will be @source, whose backing
+ # file is now @target instead of @filtered. That is a loop.
+ # (But apart from the loop, replacing @filtered instead of
+ # @source is fine, because both are just filtered versions of
+ # each other.)
+ result = self.vm.qmp('drive-mirror',
+ job_id='mirror',
+ device='source',
+ target=target_img,
+ format=iotests.imgfmt,
+ node_name='target',
+ sync='none',
+ replaces='filtered')
+ if 'error' in result:
+ # This is the correct result
+ self.assert_qmp(result, 'error/class', 'GenericError')
+ else:
+ # This is wrong, but let's run it to the bitter conclusion
+ self.complete_and_wait(drive='mirror')
+ # Fail for good measure, although qemu should have crashed
+ # anyway
+ self.fail('Loop creation was successful')
+
+ os.remove(test_img)
+ try:
+ os.remove(target_img)
+ except OSError:
+ pass
+
+ def test_blockdev_mirror_loop(self):
+ qemu_img('create', '-f', iotests.imgfmt, test_img, '1M')
+ qemu_img('create', '-f', iotests.imgfmt, target_img, '1M')
+
+ result = self.vm.qmp('object-add', qom_type='throttle-group', id='tg')
+ self.assert_qmp(result, 'return', {})
+
+ result = self.vm.qmp('blockdev-add', **{
+ 'node-name': 'source',
+ 'driver': 'throttle',
+ 'throttle-group': 'tg',
+ 'file': {
+ 'node-name': 'middle',
+ 'driver': 'throttle',
+ 'throttle-group': 'tg',
+ 'file': {
+ 'node-name': 'bottom',
+ 'driver': 'qcow2',
+ 'file': {
+ 'driver': 'file',
+ 'filename': test_img
+ }
+ }
+ }
+ })
+ self.assert_qmp(result, 'return', {})
+
+ result = self.vm.qmp('blockdev-add', **{
+ 'node-name': 'target',
+ 'driver': 'qcow2',
+ 'file': {
+ 'driver': 'file',
+ 'filename': target_img
+ },
+ 'backing': 'middle'
+ })
+
+ # Mirror from @source to @target. With blockdev-mirror, the
+ # current (old) backing file is retained (which is @middle).
+ # By replacing @bottom, @middle's file will be @target, whose
+ # backing file is @middle again. That is a loop.
+ # (But apart from the loop, replacing @bottom instead of
+ # @source is fine, because both are just filtered versions of
+ # each other.)
+ result = self.vm.qmp('blockdev-mirror',
+ job_id='mirror',
+ device='source',
+ target='target',
+ sync='full',
+ replaces='bottom')
+ if 'error' in result:
+ # This is the correct result
+ self.assert_qmp(result, 'error/class', 'GenericError')
+ else:
+ # This is wrong, but let's run it to the bitter conclusion
+ self.complete_and_wait(drive='mirror')
+ # Fail for good measure, although qemu should have crashed
+ # anyway
+ self.fail('Loop creation was successful')
+
+ os.remove(test_img)
+ os.remove(target_img)
+
if __name__ == '__main__':
iotests.main(supported_fmts=['qcow2', 'qed'])
diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out
index c28b392b87..d71481b010 100644
--- a/tests/qemu-iotests/041.out
+++ b/tests/qemu-iotests/041.out
@@ -1,5 +1,5 @@
-.....................................................................................
+.......................................................................................
----------------------------------------------------------------------
-Ran 85 tests
+Ran 87 tests
OK
--
2.17.1
- [Qemu-devel] [PATCH v2 00/11] block: Deal with filters, Max Reitz, 2018/08/09
- [Qemu-devel] [PATCH v2 01/11] block: Mark commit and mirror as filter drivers, Max Reitz, 2018/08/09
- [Qemu-devel] [PATCH v2 02/11] blockdev: Check @replaces in blockdev_mirror_common, Max Reitz, 2018/08/09
- [Qemu-devel] [PATCH v2 06/11] iotests: Add tests for mirror @replaces loops,
Max Reitz <=
- [Qemu-devel] [PATCH v2 05/11] block: Fix check_to_replace_node(), Max Reitz, 2018/08/09
- [Qemu-devel] [PATCH v2 07/11] block: Leave BDS.backing_file constant, Max Reitz, 2018/08/09
- [Qemu-devel] [PATCH v2 04/11] block: Storage child access function, Max Reitz, 2018/08/09
- [Qemu-devel] [PATCH v2 08/11] iotests: Add filter commit test cases, Max Reitz, 2018/08/09
- [Qemu-devel] [PATCH v2 09/11] iotests: Add filter mirror test cases, Max Reitz, 2018/08/09
- [Qemu-devel] [PATCH v2 11/11] iotests: Test committing to overridden backing, Max Reitz, 2018/08/09
- [Qemu-devel] [PATCH v2 03/11] block: Filtered children access functions, Max Reitz, 2018/08/09
- [Qemu-devel] [PATCH v2 10/11] iotests: Add test for commit in sub directory, Max Reitz, 2018/08/09
- Re: [Qemu-devel] [PATCH v2 00/11] block: Deal with filters, Max Reitz, 2018/08/09