OSDN Git Service

iotests: Test active commit with iothread and background I/O
[qmiga/qemu.git] / tests / qemu-iotests / 248
1 #!/usr/bin/env python3
2 # group: rw quick
3 #
4 # Test resume mirror after auto pause on ENOSPC
5 #
6 # Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved.
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21
22 import iotests
23 from iotests import qemu_img_create, qemu_io, file_path, filter_qmp_testfiles
24
25 iotests.script_initialize(supported_fmts=['qcow2'])
26
27 source, target = file_path('source', 'target')
28 size = 5 * 1024 * 1024
29 limit = 2 * 1024 * 1024
30
31 qemu_img_create('-f', iotests.imgfmt, source, str(size))
32 qemu_img_create('-f', iotests.imgfmt, target, str(size))
33 qemu_io('-c', 'write 0 {}'.format(size), source)
34
35 # raw format don't like empty files
36 qemu_io('-c', 'write 0 {}'.format(size), target)
37
38 vm = iotests.VM().add_drive(source)
39 vm.launch()
40
41 blockdev_opts = {
42     'driver': iotests.imgfmt,
43     'node-name': 'target',
44     'file': {
45         'driver': 'raw',
46         'size': limit,
47         'file': {
48             'driver': 'file',
49             'filename': target
50         }
51     }
52 }
53 vm.qmp_log('blockdev-add', filters=[filter_qmp_testfiles], **blockdev_opts)
54
55 vm.qmp_log('blockdev-mirror', device='drive0', sync='full', target='target',
56            on_target_error='enospc')
57
58 vm.event_wait('JOB_STATUS_CHANGE', timeout=3.0,
59               match={'data': {'status': 'paused'}})
60
61 # drop other cached events, to not interfere with further wait for 'running'
62 vm.get_qmp_events()
63
64 del blockdev_opts['file']['size']
65 vm.qmp_log('blockdev-reopen', filters=[filter_qmp_testfiles],
66            options = [ blockdev_opts ])
67
68 vm.qmp_log('block-job-resume', device='drive0')
69 vm.event_wait('JOB_STATUS_CHANGE', timeout=1.0,
70               match={'data': {'status': 'running'}})
71
72 vm.shutdown()