xref: /openbmc/qemu/tests/qemu-iotests/218 (revision dc885fff972c447f51572afc4c921a26b880731b)
1*dc885fffSMax Reitz#!/usr/bin/env python
2*dc885fffSMax Reitz#
3*dc885fffSMax Reitz# This test covers what happens when a mirror block job is cancelled
4*dc885fffSMax Reitz# in various phases of its existence.
5*dc885fffSMax Reitz#
6*dc885fffSMax Reitz# Note that this test only checks the emitted events (i.e.
7*dc885fffSMax Reitz# BLOCK_JOB_COMPLETED vs. BLOCK_JOB_CANCELLED), it does not compare
8*dc885fffSMax Reitz# whether the target is in sync with the source when the
9*dc885fffSMax Reitz# BLOCK_JOB_COMPLETED event occurs.  This is covered by other tests
10*dc885fffSMax Reitz# (such as 041).
11*dc885fffSMax Reitz#
12*dc885fffSMax Reitz# Copyright (C) 2018 Red Hat, Inc.
13*dc885fffSMax Reitz#
14*dc885fffSMax Reitz# This program is free software; you can redistribute it and/or modify
15*dc885fffSMax Reitz# it under the terms of the GNU General Public License as published by
16*dc885fffSMax Reitz# the Free Software Foundation; either version 2 of the License, or
17*dc885fffSMax Reitz# (at your option) any later version.
18*dc885fffSMax Reitz#
19*dc885fffSMax Reitz# This program is distributed in the hope that it will be useful,
20*dc885fffSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
21*dc885fffSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22*dc885fffSMax Reitz# GNU General Public License for more details.
23*dc885fffSMax Reitz#
24*dc885fffSMax Reitz# You should have received a copy of the GNU General Public License
25*dc885fffSMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
26*dc885fffSMax Reitz#
27*dc885fffSMax Reitz# Creator/Owner: Max Reitz <mreitz@redhat.com>
28*dc885fffSMax Reitz
29*dc885fffSMax Reitzimport iotests
30*dc885fffSMax Reitzfrom iotests import log
31*dc885fffSMax Reitz
32*dc885fffSMax Reitziotests.verify_platform(['linux'])
33*dc885fffSMax Reitz
34*dc885fffSMax Reitz
35*dc885fffSMax Reitz# Launches the VM, adds two null-co nodes (source and target), and
36*dc885fffSMax Reitz# starts a blockdev-mirror job on them.
37*dc885fffSMax Reitz#
38*dc885fffSMax Reitz# Either both or none of speed and buf_size must be given.
39*dc885fffSMax Reitz
40*dc885fffSMax Reitzdef start_mirror(vm, speed=None, buf_size=None):
41*dc885fffSMax Reitz    vm.launch()
42*dc885fffSMax Reitz
43*dc885fffSMax Reitz    ret = vm.qmp('blockdev-add',
44*dc885fffSMax Reitz                     node_name='source',
45*dc885fffSMax Reitz                     driver='null-co',
46*dc885fffSMax Reitz                     size=1048576)
47*dc885fffSMax Reitz    assert ret['return'] == {}
48*dc885fffSMax Reitz
49*dc885fffSMax Reitz    ret = vm.qmp('blockdev-add',
50*dc885fffSMax Reitz                     node_name='target',
51*dc885fffSMax Reitz                     driver='null-co',
52*dc885fffSMax Reitz                     size=1048576)
53*dc885fffSMax Reitz    assert ret['return'] == {}
54*dc885fffSMax Reitz
55*dc885fffSMax Reitz    if speed is not None:
56*dc885fffSMax Reitz        ret = vm.qmp('blockdev-mirror',
57*dc885fffSMax Reitz                         job_id='mirror',
58*dc885fffSMax Reitz                         device='source',
59*dc885fffSMax Reitz                         target='target',
60*dc885fffSMax Reitz                         sync='full',
61*dc885fffSMax Reitz                         speed=speed,
62*dc885fffSMax Reitz                         buf_size=buf_size)
63*dc885fffSMax Reitz    else:
64*dc885fffSMax Reitz        ret = vm.qmp('blockdev-mirror',
65*dc885fffSMax Reitz                         job_id='mirror',
66*dc885fffSMax Reitz                         device='source',
67*dc885fffSMax Reitz                         target='target',
68*dc885fffSMax Reitz                         sync='full')
69*dc885fffSMax Reitz
70*dc885fffSMax Reitz    assert ret['return'] == {}
71*dc885fffSMax Reitz
72*dc885fffSMax Reitz
73*dc885fffSMax Reitzlog('')
74*dc885fffSMax Reitzlog('=== Cancel mirror job before convergence ===')
75*dc885fffSMax Reitzlog('')
76*dc885fffSMax Reitz
77*dc885fffSMax Reitzlog('--- force=false ---')
78*dc885fffSMax Reitzlog('')
79*dc885fffSMax Reitz
80*dc885fffSMax Reitzwith iotests.VM() as vm:
81*dc885fffSMax Reitz    # Low speed so it does not converge
82*dc885fffSMax Reitz    start_mirror(vm, 65536, 65536)
83*dc885fffSMax Reitz
84*dc885fffSMax Reitz    log('Cancelling job')
85*dc885fffSMax Reitz    log(vm.qmp('block-job-cancel', device='mirror', force=False))
86*dc885fffSMax Reitz
87*dc885fffSMax Reitz    log(vm.event_wait('BLOCK_JOB_CANCELLED'),
88*dc885fffSMax Reitz        filters=[iotests.filter_qmp_event])
89*dc885fffSMax Reitz
90*dc885fffSMax Reitzlog('')
91*dc885fffSMax Reitzlog('--- force=true ---')
92*dc885fffSMax Reitzlog('')
93*dc885fffSMax Reitz
94*dc885fffSMax Reitzwith iotests.VM() as vm:
95*dc885fffSMax Reitz    # Low speed so it does not converge
96*dc885fffSMax Reitz    start_mirror(vm, 65536, 65536)
97*dc885fffSMax Reitz
98*dc885fffSMax Reitz    log('Cancelling job')
99*dc885fffSMax Reitz    log(vm.qmp('block-job-cancel', device='mirror', force=True))
100*dc885fffSMax Reitz
101*dc885fffSMax Reitz    log(vm.event_wait('BLOCK_JOB_CANCELLED'),
102*dc885fffSMax Reitz        filters=[iotests.filter_qmp_event])
103*dc885fffSMax Reitz
104*dc885fffSMax Reitz
105*dc885fffSMax Reitzlog('')
106*dc885fffSMax Reitzlog('=== Cancel mirror job after convergence ===')
107*dc885fffSMax Reitzlog('')
108*dc885fffSMax Reitz
109*dc885fffSMax Reitzlog('--- force=false ---')
110*dc885fffSMax Reitzlog('')
111*dc885fffSMax Reitz
112*dc885fffSMax Reitzwith iotests.VM() as vm:
113*dc885fffSMax Reitz    start_mirror(vm)
114*dc885fffSMax Reitz
115*dc885fffSMax Reitz    log(vm.event_wait('BLOCK_JOB_READY'),
116*dc885fffSMax Reitz        filters=[iotests.filter_qmp_event])
117*dc885fffSMax Reitz
118*dc885fffSMax Reitz    log('Cancelling job')
119*dc885fffSMax Reitz    log(vm.qmp('block-job-cancel', device='mirror', force=False))
120*dc885fffSMax Reitz
121*dc885fffSMax Reitz    log(vm.event_wait('BLOCK_JOB_COMPLETED'),
122*dc885fffSMax Reitz        filters=[iotests.filter_qmp_event])
123*dc885fffSMax Reitz
124*dc885fffSMax Reitzlog('')
125*dc885fffSMax Reitzlog('--- force=true ---')
126*dc885fffSMax Reitzlog('')
127*dc885fffSMax Reitz
128*dc885fffSMax Reitzwith iotests.VM() as vm:
129*dc885fffSMax Reitz    start_mirror(vm)
130*dc885fffSMax Reitz
131*dc885fffSMax Reitz    log(vm.event_wait('BLOCK_JOB_READY'),
132*dc885fffSMax Reitz        filters=[iotests.filter_qmp_event])
133*dc885fffSMax Reitz
134*dc885fffSMax Reitz    log('Cancelling job')
135*dc885fffSMax Reitz    log(vm.qmp('block-job-cancel', device='mirror', force=True))
136*dc885fffSMax Reitz
137*dc885fffSMax Reitz    log(vm.event_wait('BLOCK_JOB_CANCELLED'),
138*dc885fffSMax Reitz        filters=[iotests.filter_qmp_event])
139