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