Blame SOURCES/kvm-iotests-add-222-to-test-basic-fleecing.patch

383d26
From 561418d66933d9262f1678fda614dc0bde2a8f45 Mon Sep 17 00:00:00 2001
383d26
From: John Snow <jsnow@redhat.com>
383d26
Date: Tue, 24 Jul 2018 12:25:31 +0200
383d26
Subject: [PATCH 62/89] iotests: add 222 to test basic fleecing
383d26
383d26
RH-Author: John Snow <jsnow@redhat.com>
383d26
Message-id: <20180718225511.14878-12-jsnow@redhat.com>
383d26
Patchwork-id: 81407
383d26
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 11/35] iotests: add 222 to test basic fleecing
383d26
Bugzilla: 1207657
383d26
RH-Acked-by: Eric Blake <eblake@redhat.com>
383d26
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
383d26
RH-Acked-by: Fam Zheng <famz@redhat.com>
383d26
383d26
Signed-off-by: John Snow <jsnow@redhat.com>
383d26
Message-Id: <20180702194630.9360-3-jsnow@redhat.com>
383d26
Reviewed-by: Eric Blake <eblake@redhat.com>
383d26
Signed-off-by: Eric Blake <eblake@redhat.com>
383d26
(cherry picked from commit bacebdedbf921a2c641a34486ff543089d338f32)
383d26
Signed-off-by: John Snow <jsnow@redhat.com>
383d26
---
383d26
 tests/qemu-iotests/222     | 155 +++++++++++++++++++++++++++++++++++++++++++++
383d26
 tests/qemu-iotests/222.out |  67 ++++++++++++++++++++
383d26
 tests/qemu-iotests/group   |   1 +
383d26
 3 files changed, 223 insertions(+)
383d26
 create mode 100644 tests/qemu-iotests/222
383d26
 create mode 100644 tests/qemu-iotests/222.out
383d26
383d26
diff --git a/tests/qemu-iotests/222 b/tests/qemu-iotests/222
383d26
new file mode 100644
383d26
index 0000000..ff3bfc1
383d26
--- /dev/null
383d26
+++ b/tests/qemu-iotests/222
383d26
@@ -0,0 +1,155 @@
383d26
+#!/usr/bin/env python
383d26
+#
383d26
+# This test covers the basic fleecing workflow, which provides a
383d26
+# point-in-time snapshot of a node that can be queried over NBD.
383d26
+#
383d26
+# Copyright (C) 2018 Red Hat, Inc.
383d26
+# John helped, too.
383d26
+#
383d26
+# This program is free software; you can redistribute it and/or modify
383d26
+# it under the terms of the GNU General Public License as published by
383d26
+# the Free Software Foundation; either version 2 of the License, or
383d26
+# (at your option) any later version.
383d26
+#
383d26
+# This program is distributed in the hope that it will be useful,
383d26
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
383d26
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
383d26
+# GNU General Public License for more details.
383d26
+#
383d26
+# You should have received a copy of the GNU General Public License
383d26
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
383d26
+#
383d26
+# Creator/Owner: John Snow <jsnow@redhat.com>
383d26
+
383d26
+import iotests
383d26
+from iotests import log, qemu_img, qemu_io, qemu_io_silent
383d26
+
383d26
+iotests.verify_platform(['linux'])
383d26
+
383d26
+patterns = [("0x5d", "0",         "64k"),
383d26
+            ("0xd5", "1M",        "64k"),
383d26
+            ("0xdc", "32M",       "64k"),
383d26
+            ("0xcd", "0x3ff0000", "64k")]  # 64M - 64K
383d26
+
383d26
+overwrite = [("0xab", "0",         "64k"), # Full overwrite
383d26
+             ("0xad", "0x00f8000", "64k"), # Partial-left (1M-32K)
383d26
+             ("0x1d", "0x2008000", "64k"), # Partial-right (32M+32K)
383d26
+             ("0xea", "0x3fe0000", "64k")] # Adjacent-left (64M - 128K)
383d26
+
383d26
+zeroes = [("0", "0x00f8000", "32k"), # Left-end of partial-left (1M-32K)
383d26
+          ("0", "0x2010000", "32k"), # Right-end of partial-right (32M+64K)
383d26
+          ("0", "0x3fe0000", "64k")] # overwrite[3]
383d26
+
383d26
+remainder = [("0xd5", "0x108000",  "32k"), # Right-end of partial-left [1]
383d26
+             ("0xdc", "32M",       "32k"), # Left-end of partial-right [2]
383d26
+             ("0xcd", "0x3ff0000", "64k")] # patterns[3]
383d26
+
383d26
+with iotests.FilePath('base.img') as base_img_path, \
383d26
+     iotests.FilePath('fleece.img') as fleece_img_path, \
383d26
+     iotests.FilePath('nbd.sock') as nbd_sock_path, \
383d26
+     iotests.VM() as vm:
383d26
+
383d26
+    log('--- Setting up images ---')
383d26
+    log('')
383d26
+
383d26
+    assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0
383d26
+    assert qemu_img('create', '-f', "qcow2", fleece_img_path, '64M') == 0
383d26
+
383d26
+    for p in patterns:
383d26
+        qemu_io('-f', iotests.imgfmt,
383d26
+                '-c', 'write -P%s %s %s' % p, base_img_path)
383d26
+
383d26
+    log('Done')
383d26
+
383d26
+    log('')
383d26
+    log('--- Launching VM ---')
383d26
+    log('')
383d26
+
383d26
+    vm.add_drive(base_img_path)
383d26
+    vm.launch()
383d26
+    log('Done')
383d26
+
383d26
+    log('')
383d26
+    log('--- Setting up Fleecing Graph ---')
383d26
+    log('')
383d26
+
383d26
+    src_node = "drive0"
383d26
+    tgt_node = "fleeceNode"
383d26
+
383d26
+    # create tgt_node backed by src_node
383d26
+    log(vm.qmp("blockdev-add", **{
383d26
+        "driver": "qcow2",
383d26
+        "node-name": tgt_node,
383d26
+        "file": {
383d26
+            "driver": "file",
383d26
+            "filename": fleece_img_path,
383d26
+        },
383d26
+        "backing": src_node,
383d26
+    }))
383d26
+
383d26
+    # Establish COW from source to fleecing node
383d26
+    log(vm.qmp("blockdev-backup",
383d26
+               device=src_node,
383d26
+               target=tgt_node,
383d26
+               sync="none"))
383d26
+
383d26
+    log('')
383d26
+    log('--- Setting up NBD Export ---')
383d26
+    log('')
383d26
+
383d26
+    nbd_uri = 'nbd+unix:///%s?socket=%s' % (tgt_node, nbd_sock_path)
383d26
+    log(vm.qmp("nbd-server-start",
383d26
+               **{"addr": { "type": "unix",
383d26
+                            "data": { "path": nbd_sock_path } } }))
383d26
+
383d26
+    log(vm.qmp("nbd-server-add", device=tgt_node))
383d26
+
383d26
+    log('')
383d26
+    log('--- Sanity Check ---')
383d26
+    log('')
383d26
+
383d26
+    for p in (patterns + zeroes):
383d26
+        cmd = "read -P%s %s %s" % p
383d26
+        log(cmd)
383d26
+        assert qemu_io_silent('-r', '-f', 'raw', '-c', cmd, nbd_uri) == 0
383d26
+
383d26
+    log('')
383d26
+    log('--- Testing COW ---')
383d26
+    log('')
383d26
+
383d26
+    for p in overwrite:
383d26
+        cmd = "write -P%s %s %s" % p
383d26
+        log(cmd)
383d26
+        log(vm.hmp_qemu_io(src_node, cmd))
383d26
+
383d26
+    log('')
383d26
+    log('--- Verifying Data ---')
383d26
+    log('')
383d26
+
383d26
+    for p in (patterns + zeroes):
383d26
+        cmd = "read -P%s %s %s" % p
383d26
+        log(cmd)
383d26
+        assert qemu_io_silent('-r', '-f', 'raw', '-c', cmd, nbd_uri) == 0
383d26
+
383d26
+    log('')
383d26
+    log('--- Cleanup ---')
383d26
+    log('')
383d26
+
383d26
+    log(vm.qmp('block-job-cancel', device=src_node))
383d26
+    log(vm.event_wait('BLOCK_JOB_CANCELLED'),
383d26
+        filters=[iotests.filter_qmp_event])
383d26
+    log(vm.qmp('nbd-server-stop'))
383d26
+    log(vm.qmp('blockdev-del', node_name=tgt_node))
383d26
+    vm.shutdown()
383d26
+
383d26
+    log('')
383d26
+    log('--- Confirming writes ---')
383d26
+    log('')
383d26
+
383d26
+    for p in (overwrite + remainder):
383d26
+        cmd = "read -P%s %s %s" % p
383d26
+        log(cmd)
383d26
+        assert qemu_io_silent(base_img_path, '-c', cmd) == 0
383d26
+
383d26
+    log('')
383d26
+    log('Done')
383d26
diff --git a/tests/qemu-iotests/222.out b/tests/qemu-iotests/222.out
383d26
new file mode 100644
383d26
index 0000000..48f336a
383d26
--- /dev/null
383d26
+++ b/tests/qemu-iotests/222.out
383d26
@@ -0,0 +1,67 @@
383d26
+--- Setting up images ---
383d26
+
383d26
+Done
383d26
+
383d26
+--- Launching VM ---
383d26
+
383d26
+Done
383d26
+
383d26
+--- Setting up Fleecing Graph ---
383d26
+
383d26
+{u'return': {}}
383d26
+{u'return': {}}
383d26
+
383d26
+--- Setting up NBD Export ---
383d26
+
383d26
+{u'return': {}}
383d26
+{u'return': {}}
383d26
+
383d26
+--- Sanity Check ---
383d26
+
383d26
+read -P0x5d 0 64k
383d26
+read -P0xd5 1M 64k
383d26
+read -P0xdc 32M 64k
383d26
+read -P0xcd 0x3ff0000 64k
383d26
+read -P0 0x00f8000 32k
383d26
+read -P0 0x2010000 32k
383d26
+read -P0 0x3fe0000 64k
383d26
+
383d26
+--- Testing COW ---
383d26
+
383d26
+write -P0xab 0 64k
383d26
+{u'return': u''}
383d26
+write -P0xad 0x00f8000 64k
383d26
+{u'return': u''}
383d26
+write -P0x1d 0x2008000 64k
383d26
+{u'return': u''}
383d26
+write -P0xea 0x3fe0000 64k
383d26
+{u'return': u''}
383d26
+
383d26
+--- Verifying Data ---
383d26
+
383d26
+read -P0x5d 0 64k
383d26
+read -P0xd5 1M 64k
383d26
+read -P0xdc 32M 64k
383d26
+read -P0xcd 0x3ff0000 64k
383d26
+read -P0 0x00f8000 32k
383d26
+read -P0 0x2010000 32k
383d26
+read -P0 0x3fe0000 64k
383d26
+
383d26
+--- Cleanup ---
383d26
+
383d26
+{u'return': {}}
383d26
+{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'drive0', u'type': u'backup', u'speed': 0, u'len': 67108864, u'offset': 393216}, u'event': u'BLOCK_JOB_CANCELLED'}
383d26
+{u'return': {}}
383d26
+{u'return': {}}
383d26
+
383d26
+--- Confirming writes ---
383d26
+
383d26
+read -P0xab 0 64k
383d26
+read -P0xad 0x00f8000 64k
383d26
+read -P0x1d 0x2008000 64k
383d26
+read -P0xea 0x3fe0000 64k
383d26
+read -P0xd5 0x108000 32k
383d26
+read -P0xdc 32M 32k
383d26
+read -P0xcd 0x3ff0000 64k
383d26
+
383d26
+Done
383d26
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
383d26
index 11498fd..be55905 100644
383d26
--- a/tests/qemu-iotests/group
383d26
+++ b/tests/qemu-iotests/group
383d26
@@ -218,4 +218,5 @@
383d26
 217 rw auto quick
383d26
 218 rw auto quick
383d26
 219 rw auto
383d26
+222 rw auto quick
383d26
 226 auto quick
383d26
-- 
383d26
1.8.3.1
383d26