26ba25
From 8e6b5a2696e10066c65f047624c32e40ecd8ff8c Mon Sep 17 00:00:00 2001
26ba25
From: Kevin Wolf <kwolf@redhat.com>
26ba25
Date: Wed, 10 Oct 2018 13:50:55 +0100
26ba25
Subject: [PATCH 5/5] qemu-iotests: Test commit with top-node/base-node
26ba25
26ba25
RH-Author: Kevin Wolf <kwolf@redhat.com>
26ba25
Message-id: <20181010135055.3874-3-kwolf@redhat.com>
26ba25
Patchwork-id: 82568
26ba25
O-Subject: [RHEL-8 qemu-kvm PATCH 2/2] qemu-iotests: Test commit with top-node/base-node
26ba25
Bugzilla: 1637970
26ba25
RH-Acked-by: John Snow <jsnow@redhat.com>
26ba25
RH-Acked-by: Fam Zheng <famz@redhat.com>
26ba25
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
26ba25
This adds some tests for block-commit with the new options top-node and
26ba25
base-node (taking node names) instead of top and base (taking file
26ba25
names).
26ba25
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
(cherry picked from commit d57177a48fc604e5427921bf20b22ee0e6d578b3)
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 tests/qemu-iotests/040     | 52 ++++++++++++++++++++++++++++++++++++++++++++--
26ba25
 tests/qemu-iotests/040.out |  4 ++--
26ba25
 2 files changed, 52 insertions(+), 4 deletions(-)
26ba25
26ba25
diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040
26ba25
index 1beb5e6..1cb1cee 100755
26ba25
--- a/tests/qemu-iotests/040
26ba25
+++ b/tests/qemu-iotests/040
26ba25
@@ -57,9 +57,12 @@ class ImageCommitTestCase(iotests.QMPTestCase):
26ba25
         self.assert_no_active_block_jobs()
26ba25
         self.vm.shutdown()
26ba25
 
26ba25
-    def run_commit_test(self, top, base, need_ready=False):
26ba25
+    def run_commit_test(self, top, base, need_ready=False, node_names=False):
26ba25
         self.assert_no_active_block_jobs()
26ba25
-        result = self.vm.qmp('block-commit', device='drive0', top=top, base=base)
26ba25
+        if node_names:
26ba25
+            result = self.vm.qmp('block-commit', device='drive0', top_node=top, base_node=base)
26ba25
+        else:
26ba25
+            result = self.vm.qmp('block-commit', device='drive0', top=top, base=base)
26ba25
         self.assert_qmp(result, 'return', {})
26ba25
         self.wait_for_complete(need_ready)
26ba25
 
26ba25
@@ -101,6 +104,11 @@ class TestSingleDrive(ImageCommitTestCase):
26ba25
         self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img).find("verification failed"))
26ba25
         self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed"))
26ba25
 
26ba25
+    def test_commit_node(self):
26ba25
+        self.run_commit_test("mid", "base", node_names=True)
26ba25
+        self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img).find("verification failed"))
26ba25
+        self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed"))
26ba25
+
26ba25
     def test_device_not_found(self):
26ba25
         result = self.vm.qmp('block-commit', device='nonexistent', top='%s' % mid_img)
26ba25
         self.assert_qmp(result, 'error/class', 'DeviceNotFound')
26ba25
@@ -123,6 +131,30 @@ class TestSingleDrive(ImageCommitTestCase):
26ba25
         self.assert_qmp(result, 'error/class', 'GenericError')
26ba25
         self.assert_qmp(result, 'error/desc', 'Base \'badfile\' not found')
26ba25
 
26ba25
+    def test_top_node_invalid(self):
26ba25
+        self.assert_no_active_block_jobs()
26ba25
+        result = self.vm.qmp('block-commit', device='drive0', top_node='badfile', base_node='base')
26ba25
+        self.assert_qmp(result, 'error/class', 'GenericError')
26ba25
+        self.assert_qmp(result, 'error/desc', "Cannot find device= nor node_name=badfile")
26ba25
+
26ba25
+    def test_base_node_invalid(self):
26ba25
+        self.assert_no_active_block_jobs()
26ba25
+        result = self.vm.qmp('block-commit', device='drive0', top_node='mid', base_node='badfile')
26ba25
+        self.assert_qmp(result, 'error/class', 'GenericError')
26ba25
+        self.assert_qmp(result, 'error/desc', "Cannot find device= nor node_name=badfile")
26ba25
+
26ba25
+    def test_top_path_and_node(self):
26ba25
+        self.assert_no_active_block_jobs()
26ba25
+        result = self.vm.qmp('block-commit', device='drive0', top_node='mid', base_node='base', top='%s' % mid_img)
26ba25
+        self.assert_qmp(result, 'error/class', 'GenericError')
26ba25
+        self.assert_qmp(result, 'error/desc', "'top-node' and 'top' are mutually exclusive")
26ba25
+
26ba25
+    def test_base_path_and_node(self):
26ba25
+        self.assert_no_active_block_jobs()
26ba25
+        result = self.vm.qmp('block-commit', device='drive0', top_node='mid', base_node='base', base='%s' % backing_img)
26ba25
+        self.assert_qmp(result, 'error/class', 'GenericError')
26ba25
+        self.assert_qmp(result, 'error/desc', "'base-node' and 'base' are mutually exclusive")
26ba25
+
26ba25
     def test_top_is_active(self):
26ba25
         self.run_commit_test(test_img, backing_img, need_ready=True)
26ba25
         self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img).find("verification failed"))
26ba25
@@ -139,6 +171,22 @@ class TestSingleDrive(ImageCommitTestCase):
26ba25
         self.assert_qmp(result, 'error/class', 'GenericError')
26ba25
         self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % mid_img)
26ba25
 
26ba25
+    def test_top_and_base_node_reversed(self):
26ba25
+        self.assert_no_active_block_jobs()
26ba25
+        result = self.vm.qmp('block-commit', device='drive0', top_node='base', base_node='top')
26ba25
+        self.assert_qmp(result, 'error/class', 'GenericError')
26ba25
+        self.assert_qmp(result, 'error/desc', "'top' is not in this backing file chain")
26ba25
+
26ba25
+    def test_top_node_in_wrong_chain(self):
26ba25
+        self.assert_no_active_block_jobs()
26ba25
+
26ba25
+        result = self.vm.qmp('blockdev-add', driver='null-co', node_name='null')
26ba25
+        self.assert_qmp(result, 'return', {})
26ba25
+
26ba25
+        result = self.vm.qmp('block-commit', device='drive0', top_node='null', base_node='base')
26ba25
+        self.assert_qmp(result, 'error/class', 'GenericError')
26ba25
+        self.assert_qmp(result, 'error/desc', "'null' is not in this backing file chain")
26ba25
+
26ba25
     # When the job is running on a BB that is automatically deleted on hot
26ba25
     # unplug, the job is cancelled when the device disappears
26ba25
     def test_hot_unplug(self):
26ba25
diff --git a/tests/qemu-iotests/040.out b/tests/qemu-iotests/040.out
26ba25
index e20a75c..802ffaa 100644
26ba25
--- a/tests/qemu-iotests/040.out
26ba25
+++ b/tests/qemu-iotests/040.out
26ba25
@@ -1,5 +1,5 @@
26ba25
-.............................
26ba25
+...........................................
26ba25
 ----------------------------------------------------------------------
26ba25
-Ran 29 tests
26ba25
+Ran 43 tests
26ba25
 
26ba25
 OK
26ba25
-- 
26ba25
1.8.3.1
26ba25