xref: /openbmc/qemu/tests/qemu-iotests/096 (revision 91bfcdb0)
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-named-block-nodes')
49        for r in result['return']:
50            if r['node-name'] == active_layer:
51                self.assertEqual(r['group'], self.group)
52                self.assertEqual(r['iops'], self.iops)
53                self.assertEqual(r['iops_size'], self.iops_size)
54            else:
55                self.assertFalse(r.has_key('group'))
56                self.assertEqual(r['iops'], 0)
57                self.assertFalse(r.has_key('iops_size'))
58
59    def testSnapshot(self):
60        self.checkConfig('base')
61        self.vm.qmp('blockdev-snapshot-sync',
62                    node_name = 'base',
63                    snapshot_node_name = 'target',
64                    snapshot_file = self.target_img,
65                    format = iotests.imgfmt)
66        self.checkConfig('target')
67
68if __name__ == '__main__':
69    iotests.main(supported_fmts=['qcow2'])
70