1#!/usr/bin/env python3 2# group: rw quick 3# 4# Tests that "bdrv_drain_all" doesn't drain block jobs 5# 6# Copyright (C) 2015 Red Hat, Inc. 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 os 23import iotests 24import time 25 26class TestStopWithBlockJob(iotests.QMPTestCase): 27 test_img = os.path.join(iotests.test_dir, 'test.img') 28 target_img = os.path.join(iotests.test_dir, 'target.img') 29 base_img = os.path.join(iotests.test_dir, 'base.img') 30 31 def setUp(self): 32 iotests.qemu_img('create', '-f', iotests.imgfmt, self.base_img, "1G") 33 iotests.qemu_img('create', '-f', iotests.imgfmt, self.test_img, 34 "-b", self.base_img, '-F', iotests.imgfmt) 35 iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 1M 128M', self.test_img) 36 self.vm = iotests.VM().add_drive(self.test_img) 37 self.vm.launch() 38 39 def tearDown(self): 40 params = {"device": "drive0", 41 "bps": 0, 42 "bps_rd": 0, 43 "bps_wr": 0, 44 "iops": 0, 45 "iops_rd": 0, 46 "iops_wr": 0, 47 } 48 result = self.vm.qmp("block_set_io_throttle", conv_keys=False, 49 **params) 50 self.vm.shutdown() 51 52 def do_test_stop(self, cmd, **args): 53 """Test 'stop' while block job is running on a throttled drive. 54 The 'stop' command shouldn't drain the job""" 55 params = {"device": "drive0", 56 "bps": 1024, 57 "bps_rd": 0, 58 "bps_wr": 0, 59 "iops": 0, 60 "iops_rd": 0, 61 "iops_wr": 0, 62 } 63 result = self.vm.qmp("block_set_io_throttle", conv_keys=False, 64 **params) 65 self.assert_qmp(result, 'return', {}) 66 result = self.vm.qmp(cmd, **args) 67 self.assert_qmp(result, 'return', {}) 68 result = self.vm.qmp("stop") 69 self.assert_qmp(result, 'return', {}) 70 result = self.vm.qmp("query-block-jobs") 71 self.assert_qmp(result, 'return[0]/busy', True) 72 self.assert_qmp(result, 'return[0]/ready', False) 73 74 def test_drive_mirror(self): 75 self.do_test_stop("drive-mirror", device="drive0", 76 target=self.target_img, 77 sync="full") 78 79 def test_drive_backup(self): 80 self.do_test_stop("drive-backup", device="drive0", 81 target=self.target_img, 82 sync="full") 83 84 def test_block_commit(self): 85 self.do_test_stop("block-commit", device="drive0") 86 87if __name__ == '__main__': 88 iotests.main(supported_fmts=["qcow2"], 89 supported_protocols=["file"]) 90