cryptospore / rpms / qemu-kvm

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