3 # Tests that "bdrv_drain_all" doesn't drain block jobs
5 # Copyright (C) 2015 Red Hat, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class TestStopWithBlockJob(iotests.QMPTestCase):
26 test_img = os.path.join(iotests.test_dir, 'test.img')
27 target_img = os.path.join(iotests.test_dir, 'target.img')
28 base_img = os.path.join(iotests.test_dir, 'base.img')
31 iotests.qemu_img('create', '-f', iotests.imgfmt, self.base_img, "1G")
32 iotests.qemu_img('create', '-f', iotests.imgfmt, self.test_img, "-b", self.base_img)
33 iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 1M 128M', self.test_img)
34 self.vm = iotests.VM().add_drive(self.test_img)
38 params = {"device": "drive0",
46 result = self.vm.qmp("block_set_io_throttle", conv_keys=False,
50 def do_test_stop(self, cmd, **args):
51 """Test 'stop' while block job is running on a throttled drive.
52 The 'stop' command shouldn't drain the job"""
53 params = {"device": "drive0",
61 result = self.vm.qmp("block_set_io_throttle", conv_keys=False,
63 self.assert_qmp(result, 'return', {})
64 result = self.vm.qmp(cmd, **args)
65 self.assert_qmp(result, 'return', {})
66 result = self.vm.qmp("stop")
67 self.assert_qmp(result, 'return', {})
68 result = self.vm.qmp("query-block-jobs")
69 self.assert_qmp(result, 'return[0]/busy', True)
70 self.assert_qmp(result, 'return[0]/ready', False)
72 def test_drive_mirror(self):
73 self.do_test_stop("drive-mirror", device="drive0",
74 target=self.target_img,
77 def test_drive_backup(self):
78 self.do_test_stop("drive-backup", device="drive0",
79 target=self.target_img,
82 def test_block_commit(self):
83 self.do_test_stop("block-commit", device="drive0")
85 if __name__ == '__main__':
86 iotests.main(supported_fmts=["qcow2"],
87 supported_protocols=["file"])