xref: /openbmc/qemu/tests/qemu-iotests/248 (revision 6016b7b4)
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
22import iotests
23from iotests import qemu_img_create, qemu_io, file_path, filter_qmp_testfiles
24
25iotests.script_initialize(supported_fmts=['qcow2'])
26
27source, target = file_path('source', 'target')
28size = 5 * 1024 * 1024
29limit = 2 * 1024 * 1024
30
31qemu_img_create('-f', iotests.imgfmt, source, str(size))
32qemu_img_create('-f', iotests.imgfmt, target, str(size))
33qemu_io('-c', 'write 0 {}'.format(size), source)
34
35# raw format don't like empty files
36qemu_io('-c', 'write 0 {}'.format(size), target)
37
38vm = iotests.VM().add_drive(source)
39vm.launch()
40
41blockdev_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}
53vm.qmp_log('blockdev-add', filters=[filter_qmp_testfiles], **blockdev_opts)
54
55vm.qmp_log('blockdev-mirror', device='drive0', sync='full', target='target',
56           on_target_error='enospc')
57
58vm.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'
62vm.get_qmp_events()
63
64del blockdev_opts['file']['size']
65vm.qmp_log('blockdev-reopen', filters=[filter_qmp_testfiles],
66           options = [ blockdev_opts ])
67
68vm.qmp_log('block-job-resume', device='drive0')
69vm.event_wait('JOB_STATUS_CHANGE', timeout=1.0,
70              match={'data': {'status': 'running'}})
71
72vm.shutdown()
73