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