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') 30*55557b02SMax Reitz overlay_img = os.path.join(iotests.test_dir, 'overlay.img') 31e62303a4SFam Zheng 32e62303a4SFam Zheng def setUp(self): 33e62303a4SFam Zheng iotests.qemu_img('create', '-f', iotests.imgfmt, self.base_img, "1G") 34b66ff2c2SEric Blake iotests.qemu_img('create', '-f', iotests.imgfmt, self.test_img, 35b66ff2c2SEric Blake "-b", self.base_img, '-F', iotests.imgfmt) 36e62303a4SFam Zheng iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 1M 128M', self.test_img) 37a1933dacSMax Reitz self.vm = iotests.VM() 38a1933dacSMax Reitz self.vm.add_object('throttle-group,id=tg0,x-bps-total=1024') 39a1933dacSMax Reitz 40a1933dacSMax Reitz source_drive = 'driver=throttle,' \ 41*55557b02SMax Reitz 'node-name=source,' \ 42a1933dacSMax Reitz 'throttle-group=tg0,' \ 43a1933dacSMax Reitz f'file.driver={iotests.imgfmt},' \ 44a1933dacSMax Reitz f'file.file.filename={self.test_img}' 45a1933dacSMax Reitz 46a1933dacSMax Reitz self.vm.add_drive(None, source_drive) 47e62303a4SFam Zheng self.vm.launch() 48e62303a4SFam Zheng 49e62303a4SFam Zheng def tearDown(self): 50e62303a4SFam Zheng self.vm.shutdown() 51*55557b02SMax Reitz for img in (self.test_img, self.target_img, self.base_img, 52*55557b02SMax Reitz self.overlay_img): 5320e2580eSMax Reitz iotests.try_remove(img) 54e62303a4SFam Zheng 55e62303a4SFam Zheng def do_test_stop(self, cmd, **args): 56e62303a4SFam Zheng """Test 'stop' while block job is running on a throttled drive. 57e62303a4SFam Zheng The 'stop' command shouldn't drain the job""" 58e62303a4SFam Zheng result = self.vm.qmp(cmd, **args) 59e62303a4SFam Zheng self.assert_qmp(result, 'return', {}) 60a1933dacSMax Reitz 61e62303a4SFam Zheng result = self.vm.qmp("stop") 62e62303a4SFam Zheng self.assert_qmp(result, 'return', {}) 63e62303a4SFam Zheng result = self.vm.qmp("query-block-jobs") 64a1933dacSMax Reitz 65f9a6256bSMax Reitz self.assert_qmp(result, 'return[0]/status', 'running') 66e62303a4SFam Zheng self.assert_qmp(result, 'return[0]/ready', False) 67e62303a4SFam Zheng 68e62303a4SFam Zheng def test_drive_mirror(self): 69e62303a4SFam Zheng self.do_test_stop("drive-mirror", device="drive0", 70a1933dacSMax Reitz target=self.target_img, format=iotests.imgfmt, 71e62303a4SFam Zheng sync="full") 72e62303a4SFam Zheng 73e62303a4SFam Zheng def test_drive_backup(self): 74e62303a4SFam Zheng self.do_test_stop("drive-backup", device="drive0", 75a1933dacSMax Reitz target=self.target_img, format=iotests.imgfmt, 76e62303a4SFam Zheng sync="full") 77e62303a4SFam Zheng 78e62303a4SFam Zheng def test_block_commit(self): 79*55557b02SMax Reitz # Add overlay above the source node so that we actually use a 80*55557b02SMax Reitz # commit job instead of a mirror job 81*55557b02SMax Reitz 82*55557b02SMax Reitz iotests.qemu_img('create', '-f', iotests.imgfmt, self.overlay_img, 83*55557b02SMax Reitz '1G') 84*55557b02SMax Reitz 85*55557b02SMax Reitz result = self.vm.qmp('blockdev-add', **{ 86*55557b02SMax Reitz 'node-name': 'overlay', 87*55557b02SMax Reitz 'driver': iotests.imgfmt, 88*55557b02SMax Reitz 'file': { 89*55557b02SMax Reitz 'driver': 'file', 90*55557b02SMax Reitz 'filename': self.overlay_img 91*55557b02SMax Reitz } 92*55557b02SMax Reitz }) 93*55557b02SMax Reitz self.assert_qmp(result, 'return', {}) 94*55557b02SMax Reitz 95*55557b02SMax Reitz result = self.vm.qmp('blockdev-snapshot', 96*55557b02SMax Reitz node='source', overlay='overlay') 97*55557b02SMax Reitz self.assert_qmp(result, 'return', {}) 98*55557b02SMax Reitz 99*55557b02SMax Reitz self.do_test_stop('block-commit', device='drive0', top_node='source') 100e62303a4SFam Zheng 101e62303a4SFam Zhengif __name__ == '__main__': 102103cbc77SMax Reitz iotests.main(supported_fmts=["qcow2"], 103103cbc77SMax Reitz supported_protocols=["file"]) 104