master
text 87 lines 2.95 KB
Raw
1 #!/usr/bin/env python3
2 # group: rw migration quick
3 #
4 # Copyright (C) 2019 Red Hat, Inc.
5 #
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.
10 #
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.
15 #
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/>.
18 #
19 # Creator/Owner: Kevin Wolf <kwolf@redhat.com>
20 #
21 # Test migration to file for taking an external snapshot with VM state.
22
23 import iotests
24 import os
25
26 iotests.script_initialize(
27 supported_fmts=['qcow2'],
28 supported_protocols=['file'],
29 supported_platforms=['linux'],
30 require_hmp=True,
31 )
32
33 with iotests.FilePath('base') as base_path , \
34 iotests.FilePath('top') as top_path, \
35 iotests.VM() as vm:
36
37 iotests.qemu_img_create('-f', iotests.imgfmt, base_path, '64M')
38
39 iotests.log('=== Launch VM ===')
40 vm.add_object('iothread,id=iothread0')
41 vm.add_blockdev('file,filename=%s,node-name=base-file' % (base_path))
42 vm.add_blockdev('%s,file=base-file,node-name=base-fmt' % (iotests.imgfmt))
43 vm.add_device('virtio-blk,drive=base-fmt,iothread=iothread0,id=vda')
44 vm.launch()
45
46 vm.enable_migration_events('VM')
47
48 iotests.log('\n=== Migrate to file ===')
49 vm.qmp_log('migrate', uri='exec:cat > /dev/null')
50
51 with iotests.Timeout(3, 'Migration does not complete'):
52 vm.wait_migration('postmigrate')
53
54 iotests.log('\nVM is now stopped:')
55 iotests.log(vm.qmp('query-migrate')['return']['status'])
56 vm.qmp_log('query-status')
57
58 iotests.log('\n=== Create a snapshot of the disk image ===')
59 vm.blockdev_create({
60 'driver': 'file',
61 'filename': top_path,
62 'size': 0,
63 })
64 vm.qmp_log('blockdev-add', node_name='top-file',
65 driver='file', filename=top_path,
66 filters=[iotests.filter_qmp_testfiles])
67
68 vm.blockdev_create({
69 'driver': iotests.imgfmt,
70 'file': 'top-file',
71 'size': 1024 * 1024,
72 })
73 vm.qmp_log('blockdev-add', node_name='top-fmt',
74 driver=iotests.imgfmt, file='top-file')
75
76 vm.qmp_log('blockdev-snapshot', node='base-fmt', overlay='top-fmt')
77
78 iotests.log('\n=== Resume the VM and simulate a write request ===')
79 vm.qmp_log('cont')
80 iotests.log(vm.hmp_qemu_io('-d vda/virtio-backend', 'write 4k 4k'))
81
82 iotests.log('\n=== Commit it to the backing file ===')
83 result = vm.qmp_log('block-commit', job_id='job0', auto_dismiss=False,
84 device='top-fmt', top_node='top-fmt',
85 filters=[iotests.filter_qmp_testfiles])
86 if 'return' in result:
87 vm.run_job('job0')