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