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