ddf19c
From 38b0cff9703fc740c30f5874973ac1be88f94d9f Mon Sep 17 00:00:00 2001
ddf19c
From: Kevin Wolf <kwolf@redhat.com>
ddf19c
Date: Fri, 7 Feb 2020 11:24:03 +0000
ddf19c
Subject: [PATCH 06/18] iotests: Test external snapshot with VM state
ddf19c
ddf19c
RH-Author: Kevin Wolf <kwolf@redhat.com>
ddf19c
Message-id: <20200207112404.25198-6-kwolf@redhat.com>
ddf19c
Patchwork-id: 93752
ddf19c
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 5/6] iotests: Test external snapshot with VM state
ddf19c
Bugzilla: 1781637
ddf19c
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
ddf19c
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ddf19c
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
ddf19c
This tests creating an external snapshot with VM state (which results in
ddf19c
an active overlay over an inactive backing file, which is also the root
ddf19c
node of an inactive BlockBackend), re-activating the images and
ddf19c
performing some operations to test that the re-activation worked as
ddf19c
intended.
ddf19c
ddf19c
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
(cherry picked from commit f62f08ab7a9d902da70078992248ec5c98f652ad)
ddf19c
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 tests/qemu-iotests/280     | 83 ++++++++++++++++++++++++++++++++++++++++++++++
ddf19c
 tests/qemu-iotests/280.out | 50 ++++++++++++++++++++++++++++
ddf19c
 tests/qemu-iotests/group   |  1 +
ddf19c
 3 files changed, 134 insertions(+)
ddf19c
 create mode 100755 tests/qemu-iotests/280
ddf19c
 create mode 100644 tests/qemu-iotests/280.out
ddf19c
ddf19c
diff --git a/tests/qemu-iotests/280 b/tests/qemu-iotests/280
ddf19c
new file mode 100755
ddf19c
index 0000000..0b1fa8e
ddf19c
--- /dev/null
ddf19c
+++ b/tests/qemu-iotests/280
ddf19c
@@ -0,0 +1,83 @@
ddf19c
+#!/usr/bin/env python
ddf19c
+#
ddf19c
+# Copyright (C) 2019 Red Hat, Inc.
ddf19c
+#
ddf19c
+# This program is free software; you can redistribute it and/or modify
ddf19c
+# it under the terms of the GNU General Public License as published by
ddf19c
+# the Free Software Foundation; either version 2 of the License, or
ddf19c
+# (at your option) any later version.
ddf19c
+#
ddf19c
+# This program is distributed in the hope that it will be useful,
ddf19c
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
ddf19c
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ddf19c
+# GNU General Public License for more details.
ddf19c
+#
ddf19c
+# You should have received a copy of the GNU General Public License
ddf19c
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
ddf19c
+#
ddf19c
+# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
ddf19c
+#
ddf19c
+# Test migration to file for taking an external snapshot with VM state.
ddf19c
+
ddf19c
+import iotests
ddf19c
+import os
ddf19c
+
ddf19c
+iotests.verify_image_format(supported_fmts=['qcow2'])
ddf19c
+iotests.verify_protocol(supported=['file'])
ddf19c
+iotests.verify_platform(['linux'])
ddf19c
+
ddf19c
+with iotests.FilePath('base') as base_path , \
ddf19c
+     iotests.FilePath('top') as top_path, \
ddf19c
+     iotests.VM() as vm:
ddf19c
+
ddf19c
+    iotests.qemu_img_log('create', '-f', iotests.imgfmt, base_path, '64M')
ddf19c
+
ddf19c
+    iotests.log('=== Launch VM ===')
ddf19c
+    vm.add_object('iothread,id=iothread0')
ddf19c
+    vm.add_blockdev('file,filename=%s,node-name=base-file' % (base_path))
ddf19c
+    vm.add_blockdev('%s,file=base-file,node-name=base-fmt' % (iotests.imgfmt))
ddf19c
+    vm.add_device('virtio-blk,drive=base-fmt,iothread=iothread0,id=vda')
ddf19c
+    vm.launch()
ddf19c
+
ddf19c
+    vm.enable_migration_events('VM')
ddf19c
+
ddf19c
+    iotests.log('\n=== Migrate to file ===')
ddf19c
+    vm.qmp_log('migrate', uri='exec:cat > /dev/null')
ddf19c
+
ddf19c
+    with iotests.Timeout(3, 'Migration does not complete'):
ddf19c
+        vm.wait_migration()
ddf19c
+
ddf19c
+    iotests.log('\nVM is now stopped:')
ddf19c
+    iotests.log(vm.qmp('query-migrate')['return']['status'])
ddf19c
+    vm.qmp_log('query-status')
ddf19c
+
ddf19c
+    iotests.log('\n=== Create a snapshot of the disk image ===')
ddf19c
+    vm.blockdev_create({
ddf19c
+        'driver': 'file',
ddf19c
+        'filename': top_path,
ddf19c
+        'size': 0,
ddf19c
+    })
ddf19c
+    vm.qmp_log('blockdev-add', node_name='top-file',
ddf19c
+               driver='file', filename=top_path,
ddf19c
+               filters=[iotests.filter_qmp_testfiles])
ddf19c
+
ddf19c
+    vm.blockdev_create({
ddf19c
+        'driver': iotests.imgfmt,
ddf19c
+        'file': 'top-file',
ddf19c
+        'size': 1024 * 1024,
ddf19c
+    })
ddf19c
+    vm.qmp_log('blockdev-add', node_name='top-fmt',
ddf19c
+               driver=iotests.imgfmt, file='top-file')
ddf19c
+
ddf19c
+    vm.qmp_log('blockdev-snapshot', node='base-fmt', overlay='top-fmt')
ddf19c
+
ddf19c
+    iotests.log('\n=== Resume the VM and simulate a write request ===')
ddf19c
+    vm.qmp_log('cont')
ddf19c
+    iotests.log(vm.hmp_qemu_io('-d vda/virtio-backend', 'write 4k 4k'))
ddf19c
+
ddf19c
+    iotests.log('\n=== Commit it to the backing file ===')
ddf19c
+    result = vm.qmp_log('block-commit', job_id='job0', auto_dismiss=False,
ddf19c
+                        device='top-fmt', top_node='top-fmt',
ddf19c
+                        filters=[iotests.filter_qmp_testfiles])
ddf19c
+    if 'return' in result:
ddf19c
+        vm.run_job('job0')
ddf19c
diff --git a/tests/qemu-iotests/280.out b/tests/qemu-iotests/280.out
ddf19c
new file mode 100644
ddf19c
index 0000000..5d382fa
ddf19c
--- /dev/null
ddf19c
+++ b/tests/qemu-iotests/280.out
ddf19c
@@ -0,0 +1,50 @@
ddf19c
+Formatting 'TEST_DIR/PID-base', fmt=qcow2 size=67108864 cluster_size=65536 lazy_refcounts=off refcount_bits=16
ddf19c
+
ddf19c
+=== Launch VM ===
ddf19c
+Enabling migration QMP events on VM...
ddf19c
+{"return": {}}
ddf19c
+
ddf19c
+=== Migrate to file ===
ddf19c
+{"execute": "migrate", "arguments": {"uri": "exec:cat > /dev/null"}}
ddf19c
+{"return": {}}
ddf19c
+{"data": {"status": "setup"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
ddf19c
+{"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
ddf19c
+{"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
ddf19c
+
ddf19c
+VM is now stopped:
ddf19c
+completed
ddf19c
+{"execute": "query-status", "arguments": {}}
ddf19c
+{"return": {"running": false, "singlestep": false, "status": "postmigrate"}}
ddf19c
+
ddf19c
+=== Create a snapshot of the disk image ===
ddf19c
+{"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": {"driver": "file", "filename": "TEST_DIR/PID-top", "size": 0}}}
ddf19c
+{"return": {}}
ddf19c
+{"execute": "job-dismiss", "arguments": {"id": "job0"}}
ddf19c
+{"return": {}}
ddf19c
+
ddf19c
+{"execute": "blockdev-add", "arguments": {"driver": "file", "filename": "TEST_DIR/PID-top", "node-name": "top-file"}}
ddf19c
+{"return": {}}
ddf19c
+{"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": {"driver": "qcow2", "file": "top-file", "size": 1048576}}}
ddf19c
+{"return": {}}
ddf19c
+{"execute": "job-dismiss", "arguments": {"id": "job0"}}
ddf19c
+{"return": {}}
ddf19c
+
ddf19c
+{"execute": "blockdev-add", "arguments": {"driver": "qcow2", "file": "top-file", "node-name": "top-fmt"}}
ddf19c
+{"return": {}}
ddf19c
+{"execute": "blockdev-snapshot", "arguments": {"node": "base-fmt", "overlay": "top-fmt"}}
ddf19c
+{"return": {}}
ddf19c
+
ddf19c
+=== Resume the VM and simulate a write request ===
ddf19c
+{"execute": "cont", "arguments": {}}
ddf19c
+{"return": {}}
ddf19c
+{"return": ""}
ddf19c
+
ddf19c
+=== Commit it to the backing file ===
ddf19c
+{"execute": "block-commit", "arguments": {"auto-dismiss": false, "device": "top-fmt", "job-id": "job0", "top-node": "top-fmt"}}
ddf19c
+{"return": {}}
ddf19c
+{"execute": "job-complete", "arguments": {"id": "job0"}}
ddf19c
+{"return": {}}
ddf19c
+{"data": {"device": "job0", "len": 65536, "offset": 65536, "speed": 0, "type": "commit"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
ddf19c
+{"data": {"device": "job0", "len": 65536, "offset": 65536, "speed": 0, "type": "commit"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
ddf19c
+{"execute": "job-dismiss", "arguments": {"id": "job0"}}
ddf19c
+{"return": {}}
ddf19c
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
ddf19c
index 06cc734..01301cd 100644
ddf19c
--- a/tests/qemu-iotests/group
ddf19c
+++ b/tests/qemu-iotests/group
ddf19c
@@ -286,3 +286,4 @@
ddf19c
 272 rw
ddf19c
 273 backing quick
ddf19c
 277 rw quick
ddf19c
+280 rw migration quick
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c