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 <mreitz@redhat.com>
---
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
On 8/9/18 5:31 PM, Max Reitz wrote: > 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 <mreitz@redhat.com> > --- > tests/qemu-iotests/041 | 124 +++++++++++++++++++++++++++++++++++++ > tests/qemu-iotests/041.out | 4 +- > 2 files changed, 126 insertions(+), 2 deletions(-) > With your followup amendments to allow qed testing (hmm, you mention you'd be posting a v3), Reviewed-by: Eric Blake <eblake@redhat.com> -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
On 2018-08-10 00:31, Max Reitz wrote: > 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 <mreitz@redhat.com> > --- > tests/qemu-iotests/041 | 124 +++++++++++++++++++++++++++++++++++++ > tests/qemu-iotests/041.out | 4 +- > 2 files changed, 126 insertions(+), 2 deletions(-) Sometimes, I hate myself a little bit. I totally forgot to run the test with QED. So: > 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): [...] > + 'driver': 'qcow2', [...] > + 'driver': 'qcow2', [...] > + 'driver': 'qcow2', Imagine these to be "'driver': iotests.imgfmt". With that, it passes. (I won't send a v3 specifically for this, but it will be included in v3. Eventually.) Max
© 2016 - 2025 Red Hat, Inc.