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

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