thebeanogamer / rpms / qemu-kvm

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