3 # This test covers what happens when a mirror block job is cancelled
4 # in various phases of its existence.
6 # Note that this test only checks the emitted events (i.e.
7 # BLOCK_JOB_COMPLETED vs. BLOCK_JOB_CANCELLED), it does not compare
8 # whether the target is in sync with the source when the
9 # BLOCK_JOB_COMPLETED event occurs. This is covered by other tests
12 # Copyright (C) 2018 Red Hat, Inc.
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
30 from iotests import log
32 iotests.verify_platform(['linux'])
35 # Launches the VM, adds two null-co nodes (source and target), and
36 # starts a blockdev-mirror job on them.
38 # Either both or none of speed and buf_size must be given.
40 def start_mirror(vm, speed=None, buf_size=None):
43 ret = vm.qmp('blockdev-add',
47 assert ret['return'] == {}
49 ret = vm.qmp('blockdev-add',
53 assert ret['return'] == {}
56 ret = vm.qmp('blockdev-mirror',
64 ret = vm.qmp('blockdev-mirror',
70 assert ret['return'] == {}
74 log('=== Cancel mirror job before convergence ===')
77 log('--- force=false ---')
80 with iotests.VM() as vm:
81 # Low speed so it does not converge
82 start_mirror(vm, 65536, 65536)
85 log(vm.qmp('block-job-cancel', device='mirror', force=False))
87 log(vm.event_wait('BLOCK_JOB_CANCELLED'),
88 filters=[iotests.filter_qmp_event])
91 log('--- force=true ---')
94 with iotests.VM() as vm:
95 # Low speed so it does not converge
96 start_mirror(vm, 65536, 65536)
99 log(vm.qmp('block-job-cancel', device='mirror', force=True))
101 log(vm.event_wait('BLOCK_JOB_CANCELLED'),
102 filters=[iotests.filter_qmp_event])
106 log('=== Cancel mirror job after convergence ===')
109 log('--- force=false ---')
112 with iotests.VM() as vm:
115 log(vm.event_wait('BLOCK_JOB_READY'),
116 filters=[iotests.filter_qmp_event])
118 log('Cancelling job')
119 log(vm.qmp('block-job-cancel', device='mirror', force=False))
121 log(vm.event_wait('BLOCK_JOB_COMPLETED'),
122 filters=[iotests.filter_qmp_event])
125 log('--- force=true ---')
128 with iotests.VM() as vm:
131 log(vm.event_wait('BLOCK_JOB_READY'),
132 filters=[iotests.filter_qmp_event])
134 log('Cancelling job')
135 log(vm.qmp('block-job-cancel', device='mirror', force=True))
137 log(vm.event_wait('BLOCK_JOB_CANCELLED'),
138 filters=[iotests.filter_qmp_event])