4 # This test covers what happens when a mirror block job is cancelled
5 # in various phases of its existence.
7 # Note that this test only checks the emitted events (i.e.
8 # BLOCK_JOB_COMPLETED vs. BLOCK_JOB_CANCELLED), it does not compare
9 # whether the target is in sync with the source when the
10 # BLOCK_JOB_COMPLETED event occurs. This is covered by other tests
13 # Copyright (C) 2018 Red Hat, Inc.
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 # Creator/Owner: Hanna Reitz <hreitz@redhat.com>
31 from iotests import log, qemu_img, qemu_io
33 iotests.script_initialize(supported_fmts=['qcow2', 'raw'])
36 # Launches the VM, adds two null-co nodes (source and target), and
37 # starts a blockdev-mirror job on them.
39 # Either both or none of speed and buf_size must be given.
41 def start_mirror(vm, speed=None, buf_size=None):
44 ret = vm.qmp('blockdev-add',
48 assert ret['return'] == {}
50 ret = vm.qmp('blockdev-add',
54 assert ret['return'] == {}
57 ret = vm.qmp('blockdev-mirror',
65 ret = vm.qmp('blockdev-mirror',
71 assert ret['return'] == {}
75 log('=== Cancel mirror job before convergence ===')
78 log('--- force=false ---')
81 with iotests.VM() as vm:
82 # Low speed so it does not converge
83 start_mirror(vm, 65536, 65536)
86 log(vm.qmp('block-job-cancel', device='mirror', force=False))
88 log(vm.event_wait('BLOCK_JOB_CANCELLED'),
89 filters=[iotests.filter_qmp_event])
92 log('--- force=true ---')
95 with iotests.VM() as vm:
96 # Low speed so it does not converge
97 start_mirror(vm, 65536, 65536)
100 log(vm.qmp('block-job-cancel', device='mirror', force=True))
102 log(vm.event_wait('BLOCK_JOB_CANCELLED'),
103 filters=[iotests.filter_qmp_event])
107 log('=== Cancel mirror job after convergence ===')
110 log('--- force=false ---')
113 with iotests.VM() as vm:
116 log(vm.event_wait('BLOCK_JOB_READY'),
117 filters=[iotests.filter_qmp_event])
119 log('Cancelling job')
120 log(vm.qmp('block-job-cancel', device='mirror', force=False))
122 log(vm.event_wait('BLOCK_JOB_COMPLETED'),
123 filters=[iotests.filter_qmp_event])
126 log('--- force=true ---')
129 with iotests.VM() as vm:
132 log(vm.event_wait('BLOCK_JOB_READY'),
133 filters=[iotests.filter_qmp_event])
135 log('Cancelling job')
136 log(vm.qmp('block-job-cancel', device='mirror', force=True))
138 log(vm.event_wait('BLOCK_JOB_CANCELLED'),
139 filters=[iotests.filter_qmp_event])
142 log('=== Cancel mirror job from throttled node by quitting ===')
145 with iotests.VM() as vm, \
146 iotests.FilePath('src.img') as src_img_path:
148 qemu_img('create', '-f', iotests.imgfmt, src_img_path, '64M')
149 qemu_io('-f', iotests.imgfmt, src_img_path, '-c', 'write -P 42 0M 64M')
153 ret = vm.qmp('object-add', qom_type='throttle-group', id='tg',
154 limits={'bps-read': 4096})
155 assert ret['return'] == {}
157 ret = vm.qmp('blockdev-add',
159 driver=iotests.imgfmt,
162 'filename': src_img_path
164 assert ret['return'] == {}
166 ret = vm.qmp('blockdev-add',
167 node_name='throttled-source',
171 assert ret['return'] == {}
173 ret = vm.qmp('blockdev-add',
177 assert ret['return'] == {}
179 ret = vm.qmp('blockdev-mirror',
181 device='throttled-source',
184 assert ret['return'] == {}
188 with iotests.Timeout(5, 'Timeout waiting for VM to quit'):