yeahuh / rpms / qemu-kvm

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