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) 36*a1933dacSMax Reitz self.vm = iotests.VM() 37*a1933dacSMax Reitz self.vm.add_object('throttle-group,id=tg0,x-bps-total=1024') 38*a1933dacSMax Reitz 39*a1933dacSMax Reitz source_drive = 'driver=throttle,' \ 40*a1933dacSMax Reitz 'throttle-group=tg0,' \ 41*a1933dacSMax Reitz f'file.driver={iotests.imgfmt},' \ 42*a1933dacSMax Reitz f'file.file.filename={self.test_img}' 43*a1933dacSMax Reitz 44*a1933dacSMax Reitz self.vm.add_drive(None, source_drive) 45e62303a4SFam Zheng self.vm.launch() 46e62303a4SFam Zheng 47e62303a4SFam Zheng def tearDown(self): 48e62303a4SFam Zheng self.vm.shutdown() 4920e2580eSMax Reitz for img in (self.test_img, self.target_img, self.base_img): 5020e2580eSMax Reitz iotests.try_remove(img) 51e62303a4SFam Zheng 52e62303a4SFam Zheng def do_test_stop(self, cmd, **args): 53e62303a4SFam Zheng """Test 'stop' while block job is running on a throttled drive. 54e62303a4SFam Zheng The 'stop' command shouldn't drain the job""" 55e62303a4SFam Zheng result = self.vm.qmp(cmd, **args) 56e62303a4SFam Zheng self.assert_qmp(result, 'return', {}) 57*a1933dacSMax Reitz 58e62303a4SFam Zheng result = self.vm.qmp("stop") 59e62303a4SFam Zheng self.assert_qmp(result, 'return', {}) 60e62303a4SFam Zheng result = self.vm.qmp("query-block-jobs") 61*a1933dacSMax Reitz 62f9a6256bSMax Reitz self.assert_qmp(result, 'return[0]/status', 'running') 63e62303a4SFam Zheng self.assert_qmp(result, 'return[0]/ready', False) 64e62303a4SFam Zheng 65e62303a4SFam Zheng def test_drive_mirror(self): 66e62303a4SFam Zheng self.do_test_stop("drive-mirror", device="drive0", 67*a1933dacSMax Reitz target=self.target_img, format=iotests.imgfmt, 68e62303a4SFam Zheng sync="full") 69e62303a4SFam Zheng 70e62303a4SFam Zheng def test_drive_backup(self): 71e62303a4SFam Zheng self.do_test_stop("drive-backup", device="drive0", 72*a1933dacSMax Reitz target=self.target_img, format=iotests.imgfmt, 73e62303a4SFam Zheng sync="full") 74e62303a4SFam Zheng 75e62303a4SFam Zheng def test_block_commit(self): 76e62303a4SFam Zheng self.do_test_stop("block-commit", device="drive0") 77e62303a4SFam Zheng 78e62303a4SFam Zhengif __name__ == '__main__': 79103cbc77SMax Reitz iotests.main(supported_fmts=["qcow2"], 80103cbc77SMax Reitz supported_protocols=["file"]) 81