1903cb1bfSPhilippe Mathieu-Daudé#!/usr/bin/env python3 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick 3e62303a4SFam Zheng# 4e62303a4SFam Zheng# Tests that "bdrv_drain_all" doesn't drain block jobs 5e62303a4SFam Zheng# 6e62303a4SFam Zheng# Copyright (C) 2015 Red Hat, Inc. 7e62303a4SFam Zheng# 8e62303a4SFam Zheng# This program is free software; you can redistribute it and/or modify 9e62303a4SFam Zheng# it under the terms of the GNU General Public License as published by 10e62303a4SFam Zheng# the Free Software Foundation; either version 2 of the License, or 11e62303a4SFam Zheng# (at your option) any later version. 12e62303a4SFam Zheng# 13e62303a4SFam Zheng# This program is distributed in the hope that it will be useful, 14e62303a4SFam Zheng# but WITHOUT ANY WARRANTY; without even the implied warranty of 15e62303a4SFam Zheng# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16e62303a4SFam Zheng# GNU General Public License for more details. 17e62303a4SFam Zheng# 18e62303a4SFam Zheng# You should have received a copy of the GNU General Public License 19e62303a4SFam Zheng# along with this program. If not, see <http://www.gnu.org/licenses/>. 20e62303a4SFam Zheng# 21e62303a4SFam Zheng 22e62303a4SFam Zhengimport os 23e62303a4SFam Zhengimport iotests 24e62303a4SFam Zhengimport time 25e62303a4SFam Zheng 26e62303a4SFam Zhengclass TestStopWithBlockJob(iotests.QMPTestCase): 27e62303a4SFam Zheng test_img = os.path.join(iotests.test_dir, 'test.img') 28e62303a4SFam Zheng target_img = os.path.join(iotests.test_dir, 'target.img') 29e62303a4SFam Zheng base_img = os.path.join(iotests.test_dir, 'base.img') 30e62303a4SFam Zheng 31e62303a4SFam Zheng def setUp(self): 32e62303a4SFam Zheng iotests.qemu_img('create', '-f', iotests.imgfmt, self.base_img, "1G") 33b66ff2c2SEric Blake iotests.qemu_img('create', '-f', iotests.imgfmt, self.test_img, 34b66ff2c2SEric Blake "-b", self.base_img, '-F', iotests.imgfmt) 35e62303a4SFam Zheng iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 1M 128M', self.test_img) 36e62303a4SFam Zheng self.vm = iotests.VM().add_drive(self.test_img) 37e62303a4SFam Zheng self.vm.launch() 38e62303a4SFam Zheng 39e62303a4SFam Zheng def tearDown(self): 40e62303a4SFam Zheng params = {"device": "drive0", 41e62303a4SFam Zheng "bps": 0, 42e62303a4SFam Zheng "bps_rd": 0, 43e62303a4SFam Zheng "bps_wr": 0, 44e62303a4SFam Zheng "iops": 0, 45e62303a4SFam Zheng "iops_rd": 0, 46e62303a4SFam Zheng "iops_wr": 0, 47e62303a4SFam Zheng } 48e62303a4SFam Zheng result = self.vm.qmp("block_set_io_throttle", conv_keys=False, 49e62303a4SFam Zheng **params) 50e62303a4SFam Zheng self.vm.shutdown() 5120e2580eSMax Reitz for img in (self.test_img, self.target_img, self.base_img): 5220e2580eSMax Reitz iotests.try_remove(img) 53e62303a4SFam Zheng 54e62303a4SFam Zheng def do_test_stop(self, cmd, **args): 55e62303a4SFam Zheng """Test 'stop' while block job is running on a throttled drive. 56e62303a4SFam Zheng The 'stop' command shouldn't drain the job""" 57e62303a4SFam Zheng params = {"device": "drive0", 58e62303a4SFam Zheng "bps": 1024, 59e62303a4SFam Zheng "bps_rd": 0, 60e62303a4SFam Zheng "bps_wr": 0, 61e62303a4SFam Zheng "iops": 0, 62e62303a4SFam Zheng "iops_rd": 0, 63e62303a4SFam Zheng "iops_wr": 0, 64e62303a4SFam Zheng } 65e62303a4SFam Zheng result = self.vm.qmp("block_set_io_throttle", conv_keys=False, 66e62303a4SFam Zheng **params) 67e62303a4SFam Zheng self.assert_qmp(result, 'return', {}) 68e62303a4SFam Zheng result = self.vm.qmp(cmd, **args) 69e62303a4SFam Zheng self.assert_qmp(result, 'return', {}) 70e62303a4SFam Zheng result = self.vm.qmp("stop") 71e62303a4SFam Zheng self.assert_qmp(result, 'return', {}) 72e62303a4SFam Zheng result = self.vm.qmp("query-block-jobs") 73*f9a6256bSMax Reitz self.assert_qmp(result, 'return[0]/status', 'running') 74e62303a4SFam Zheng self.assert_qmp(result, 'return[0]/ready', False) 75e62303a4SFam Zheng 76e62303a4SFam Zheng def test_drive_mirror(self): 77e62303a4SFam Zheng self.do_test_stop("drive-mirror", device="drive0", 78e62303a4SFam Zheng target=self.target_img, 79e62303a4SFam Zheng sync="full") 80e62303a4SFam Zheng 81e62303a4SFam Zheng def test_drive_backup(self): 82e62303a4SFam Zheng self.do_test_stop("drive-backup", device="drive0", 83e62303a4SFam Zheng target=self.target_img, 84e62303a4SFam Zheng sync="full") 85e62303a4SFam Zheng 86e62303a4SFam Zheng def test_block_commit(self): 87e62303a4SFam Zheng self.do_test_stop("block-commit", device="drive0") 88e62303a4SFam Zheng 89e62303a4SFam Zhengif __name__ == '__main__': 90103cbc77SMax Reitz iotests.main(supported_fmts=["qcow2"], 91103cbc77SMax Reitz supported_protocols=["file"]) 92