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