xref: /openbmc/qemu/tests/qemu-iotests/096 (revision ba632924)
1#!/usr/bin/env python
2#
3# Test that snapshots move the throttling configuration to the active
4# layer
5#
6# Copyright (C) 2015 Igalia, S.L.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20#
21
22import iotests
23import os
24
25class TestLiveSnapshot(iotests.QMPTestCase):
26    base_img = os.path.join(iotests.test_dir, 'base.img')
27    target_img = os.path.join(iotests.test_dir, 'target.img')
28    group = 'mygroup'
29    iops = 6000
30    iops_size = 1024
31
32    def setUp(self):
33        opts = []
34        opts.append('node-name=base')
35        opts.append('throttling.group=%s' % self.group)
36        opts.append('throttling.iops-total=%d' % self.iops)
37        opts.append('throttling.iops-size=%d' % self.iops_size)
38        iotests.qemu_img('create', '-f', iotests.imgfmt, self.base_img, '100M')
39        self.vm = iotests.VM().add_drive(self.base_img, ','.join(opts))
40        self.vm.launch()
41
42    def tearDown(self):
43        self.vm.shutdown()
44        os.remove(self.base_img)
45        os.remove(self.target_img)
46
47    def checkConfig(self, active_layer):
48        result = self.vm.qmp('query-block')
49        for r in result['return']:
50            r = r['inserted']
51            if r['node-name'] == active_layer:
52                self.assertEqual(r['group'], self.group)
53                self.assertEqual(r['iops'], self.iops)
54                self.assertEqual(r['iops_size'], self.iops_size)
55            else:
56                self.assertFalse('group' in r)
57                self.assertEqual(r['iops'], 0)
58                self.assertFalse('iops_size' in r)
59
60    def testSnapshot(self):
61        self.checkConfig('base')
62        self.vm.qmp('blockdev-snapshot-sync',
63                    node_name = 'base',
64                    snapshot_node_name = 'target',
65                    snapshot_file = self.target_img,
66                    format = iotests.imgfmt)
67        self.checkConfig('target')
68
69if __name__ == '__main__':
70    iotests.main(supported_fmts=['qcow2'])
71