target/riscv: Enable the Hypervisor extension by default
[qemu/ar7.git] / tests / qemu-iotests / 280
blob628f3c33cacf1f45587cd61d9902ca77b68c7937
1 #!/usr/bin/env python3
2 # group: rw migration quick
4 # Copyright (C) 2019 Red Hat, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 # Creator/Owner: Kevin Wolf <kwolf@redhat.com>
21 # Test migration to file for taking an external snapshot with VM state.
23 import iotests
24 import os
26 iotests.script_initialize(
27     supported_fmts=['qcow2'],
28     supported_protocols=['file'],
29     supported_platforms=['linux'],
32 with iotests.FilePath('base') as base_path , \
33      iotests.FilePath('top') as top_path, \
34      iotests.VM() as vm:
36     iotests.qemu_img_log('create', '-f', iotests.imgfmt, base_path, '64M')
38     iotests.log('=== Launch VM ===')
39     vm.add_object('iothread,id=iothread0')
40     vm.add_blockdev('file,filename=%s,node-name=base-file' % (base_path))
41     vm.add_blockdev('%s,file=base-file,node-name=base-fmt' % (iotests.imgfmt))
42     vm.add_device('virtio-blk,drive=base-fmt,iothread=iothread0,id=vda')
43     vm.launch()
45     vm.enable_migration_events('VM')
47     iotests.log('\n=== Migrate to file ===')
48     vm.qmp_log('migrate', uri='exec:cat > /dev/null')
50     with iotests.Timeout(3, 'Migration does not complete'):
51         vm.wait_migration('postmigrate')
53     iotests.log('\nVM is now stopped:')
54     iotests.log(vm.qmp('query-migrate')['return']['status'])
55     vm.qmp_log('query-status')
57     iotests.log('\n=== Create a snapshot of the disk image ===')
58     vm.blockdev_create({
59         'driver': 'file',
60         'filename': top_path,
61         'size': 0,
62     })
63     vm.qmp_log('blockdev-add', node_name='top-file',
64                driver='file', filename=top_path,
65                filters=[iotests.filter_qmp_testfiles])
67     vm.blockdev_create({
68         'driver': iotests.imgfmt,
69         'file': 'top-file',
70         'size': 1024 * 1024,
71     })
72     vm.qmp_log('blockdev-add', node_name='top-fmt',
73                driver=iotests.imgfmt, file='top-file')
75     vm.qmp_log('blockdev-snapshot', node='base-fmt', overlay='top-fmt')
77     iotests.log('\n=== Resume the VM and simulate a write request ===')
78     vm.qmp_log('cont')
79     iotests.log(vm.hmp_qemu_io('-d vda/virtio-backend', 'write 4k 4k'))
81     iotests.log('\n=== Commit it to the backing file ===')
82     result = vm.qmp_log('block-commit', job_id='job0', auto_dismiss=False,
83                         device='top-fmt', top_node='top-fmt',
84                         filters=[iotests.filter_qmp_testfiles])
85     if 'return' in result:
86         vm.run_job('job0')