Blame SOURCES/kvm-iotests-Test-mirror-with-temporarily-disabled-target.patch

22c213
From 239f7bdeef48a3c0b07098617371b9955dc55348 Mon Sep 17 00:00:00 2001
22c213
From: Kevin Wolf <kwolf@redhat.com>
22c213
Date: Fri, 13 Mar 2020 12:34:36 +0000
22c213
Subject: [PATCH 16/20] iotests: Test mirror with temporarily disabled target
22c213
 backing file
22c213
22c213
RH-Author: Kevin Wolf <kwolf@redhat.com>
22c213
Message-id: <20200313123439.10548-11-kwolf@redhat.com>
22c213
Patchwork-id: 94288
22c213
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 10/13] iotests: Test mirror with temporarily disabled target backing file
22c213
Bugzilla: 1790482 1805143
22c213
RH-Acked-by: John Snow <jsnow@redhat.com>
22c213
RH-Acked-by: Daniel P. Berrange <berrange@redhat.com>
22c213
RH-Acked-by: Peter Krempa <pkrempa@redhat.com>
22c213
22c213
The newly tested scenario is a common live storage migration scenario:
22c213
The target node is opened without a backing file so that the active
22c213
layer is mirrored while its backing chain can be copied in the
22c213
background.
22c213
22c213
The backing chain should be attached to the mirror target node when
22c213
finalising the job, just before switching the users of the source node
22c213
to the new copy (at which point the mirror job still has a reference to
22c213
the node). drive-mirror did this automatically, but with blockdev-mirror
22c213
this is the job of the QMP client.
22c213
22c213
This patch adds test cases for two ways to achieve the desired result,
22c213
using either x-blockdev-reopen or blockdev-snapshot.
22c213
22c213
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22c213
Message-Id: <20200310113831.27293-5-kwolf@redhat.com>
22c213
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
22c213
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22c213
(cherry picked from commit 8bdee9f10eac2aefdcc5095feef756354c87bdec)
22c213
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
---
22c213
 tests/qemu-iotests/155     | 56 +++++++++++++++++++++++++++++++++++++++++-----
22c213
 tests/qemu-iotests/155.out |  4 ++--
22c213
 2 files changed, 53 insertions(+), 7 deletions(-)
22c213
22c213
diff --git a/tests/qemu-iotests/155 b/tests/qemu-iotests/155
22c213
index d7ef257..3053e50 100755
22c213
--- a/tests/qemu-iotests/155
22c213
+++ b/tests/qemu-iotests/155
22c213
@@ -45,10 +45,15 @@ target_img = os.path.join(iotests.test_dir, 'target.' + iotests.imgfmt)
22c213
 #                      image during runtime, only makes sense if
22c213
 #                      target_blockdev_backing is not None
22c213
 #                      (None: same as target_backing)
22c213
+# target_open_with_backing: If True, the target image is added with its backing
22c213
+#                           chain opened right away. If False, blockdev-add
22c213
+#                           opens it without a backing file and job completion
22c213
+#                           is supposed to open the backing chain.
22c213
 
22c213
 class BaseClass(iotests.QMPTestCase):
22c213
     target_blockdev_backing = None
22c213
     target_real_backing = None
22c213
+    target_open_with_backing = True
22c213
 
22c213
     def setUp(self):
22c213
         qemu_img('create', '-f', iotests.imgfmt, back0_img, '1440K')
22c213
@@ -80,9 +85,13 @@ class BaseClass(iotests.QMPTestCase):
22c213
                 options = { 'node-name': 'target',
22c213
                             'driver': iotests.imgfmt,
22c213
                             'file': { 'driver': 'file',
22c213
+                                      'node-name': 'target-file',
22c213
                                       'filename': target_img } }
22c213
-                if self.target_blockdev_backing:
22c213
-                    options['backing'] = self.target_blockdev_backing
22c213
+
22c213
+                if not self.target_open_with_backing:
22c213
+                        options['backing'] = None
22c213
+                elif self.target_blockdev_backing:
22c213
+                        options['backing'] = self.target_blockdev_backing
22c213
 
22c213
                 result = self.vm.qmp('blockdev-add', **options)
22c213
                 self.assert_qmp(result, 'return', {})
22c213
@@ -147,10 +156,14 @@ class BaseClass(iotests.QMPTestCase):
22c213
 # cmd: Mirroring command to execute, either drive-mirror or blockdev-mirror
22c213
 
22c213
 class MirrorBaseClass(BaseClass):
22c213
+    def openBacking(self):
22c213
+        pass
22c213
+
22c213
     def runMirror(self, sync):
22c213
         if self.cmd == 'blockdev-mirror':
22c213
             result = self.vm.qmp(self.cmd, job_id='mirror-job', device='source',
22c213
-                                 sync=sync, target='target')
22c213
+                                 sync=sync, target='target',
22c213
+                                 auto_finalize=False)
22c213
         else:
22c213
             if self.existing:
22c213
                 mode = 'existing'
22c213
@@ -159,11 +172,12 @@ class MirrorBaseClass(BaseClass):
22c213
             result = self.vm.qmp(self.cmd, job_id='mirror-job', device='source',
22c213
                                  sync=sync, target=target_img,
22c213
                                  format=iotests.imgfmt, mode=mode,
22c213
-                                 node_name='target')
22c213
+                                 node_name='target', auto_finalize=False)
22c213
 
22c213
         self.assert_qmp(result, 'return', {})
22c213
 
22c213
-        self.complete_and_wait('mirror-job')
22c213
+        self.vm.run_job('mirror-job', use_log=False, auto_finalize=False,
22c213
+                        pre_finalize=self.openBacking, auto_dismiss=True)
22c213
 
22c213
     def testFull(self):
22c213
         self.runMirror('full')
22c213
@@ -221,6 +235,38 @@ class TestBlockdevMirrorForcedBacking(MirrorBaseClass):
22c213
     target_blockdev_backing = { 'driver': 'null-co' }
22c213
     target_real_backing = 'null-co://'
22c213
 
22c213
+# Attach the backing chain only during completion, with blockdev-reopen
22c213
+class TestBlockdevMirrorReopen(MirrorBaseClass):
22c213
+    cmd = 'blockdev-mirror'
22c213
+    existing = True
22c213
+    target_backing = 'null-co://'
22c213
+    target_open_with_backing = False
22c213
+
22c213
+    def openBacking(self):
22c213
+        if not self.target_open_with_backing:
22c213
+            result = self.vm.qmp('blockdev-add', node_name="backing",
22c213
+                                 driver="null-co")
22c213
+            self.assert_qmp(result, 'return', {})
22c213
+            result = self.vm.qmp('x-blockdev-reopen', node_name="target",
22c213
+                                 driver=iotests.imgfmt, file="target-file",
22c213
+                                 backing="backing")
22c213
+            self.assert_qmp(result, 'return', {})
22c213
+
22c213
+# Attach the backing chain only during completion, with blockdev-snapshot
22c213
+class TestBlockdevMirrorSnapshot(MirrorBaseClass):
22c213
+    cmd = 'blockdev-mirror'
22c213
+    existing = True
22c213
+    target_backing = 'null-co://'
22c213
+    target_open_with_backing = False
22c213
+
22c213
+    def openBacking(self):
22c213
+        if not self.target_open_with_backing:
22c213
+            result = self.vm.qmp('blockdev-add', node_name="backing",
22c213
+                                 driver="null-co")
22c213
+            self.assert_qmp(result, 'return', {})
22c213
+            result = self.vm.qmp('blockdev-snapshot', node="backing",
22c213
+                                 overlay="target")
22c213
+            self.assert_qmp(result, 'return', {})
22c213
 
22c213
 class TestCommit(BaseClass):
22c213
     existing = False
22c213
diff --git a/tests/qemu-iotests/155.out b/tests/qemu-iotests/155.out
22c213
index 4176bb9..4fd1c2d 100644
22c213
--- a/tests/qemu-iotests/155.out
22c213
+++ b/tests/qemu-iotests/155.out
22c213
@@ -1,5 +1,5 @@
22c213
-...................
22c213
+.........................
22c213
 ----------------------------------------------------------------------
22c213
-Ran 19 tests
22c213
+Ran 25 tests
22c213
 
22c213
 OK
22c213
-- 
22c213
1.8.3.1
22c213