xref: /openbmc/qemu/tests/qemu-iotests/096 (revision d7a4228ebb0150e4c97a19077f3fac81d843e2c3)
1317438e6SAlberto Garcia#!/usr/bin/env python
2317438e6SAlberto Garcia#
3317438e6SAlberto Garcia# Test that snapshots move the throttling configuration to the active
4317438e6SAlberto Garcia# layer
5317438e6SAlberto Garcia#
6317438e6SAlberto Garcia# Copyright (C) 2015 Igalia, S.L.
7317438e6SAlberto Garcia#
8317438e6SAlberto Garcia# This program is free software; you can redistribute it and/or modify
9317438e6SAlberto Garcia# it under the terms of the GNU General Public License as published by
10317438e6SAlberto Garcia# the Free Software Foundation; either version 2 of the License, or
11317438e6SAlberto Garcia# (at your option) any later version.
12317438e6SAlberto Garcia#
13317438e6SAlberto Garcia# This program is distributed in the hope that it will be useful,
14317438e6SAlberto Garcia# but WITHOUT ANY WARRANTY; without even the implied warranty of
15317438e6SAlberto Garcia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16317438e6SAlberto Garcia# GNU General Public License for more details.
17317438e6SAlberto Garcia#
18317438e6SAlberto Garcia# You should have received a copy of the GNU General Public License
19317438e6SAlberto Garcia# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20317438e6SAlberto Garcia#
21317438e6SAlberto Garcia
22317438e6SAlberto Garciaimport iotests
23317438e6SAlberto Garciaimport os
24317438e6SAlberto Garcia
25317438e6SAlberto Garciaclass TestLiveSnapshot(iotests.QMPTestCase):
26317438e6SAlberto Garcia    base_img = os.path.join(iotests.test_dir, 'base.img')
27317438e6SAlberto Garcia    target_img = os.path.join(iotests.test_dir, 'target.img')
28317438e6SAlberto Garcia    group = 'mygroup'
29317438e6SAlberto Garcia    iops = 6000
30317438e6SAlberto Garcia    iops_size = 1024
31317438e6SAlberto Garcia
32317438e6SAlberto Garcia    def setUp(self):
33317438e6SAlberto Garcia        opts = []
34317438e6SAlberto Garcia        opts.append('node-name=base')
35317438e6SAlberto Garcia        opts.append('throttling.group=%s' % self.group)
36317438e6SAlberto Garcia        opts.append('throttling.iops-total=%d' % self.iops)
37317438e6SAlberto Garcia        opts.append('throttling.iops-size=%d' % self.iops_size)
38317438e6SAlberto Garcia        iotests.qemu_img('create', '-f', iotests.imgfmt, self.base_img, '100M')
39317438e6SAlberto Garcia        self.vm = iotests.VM().add_drive(self.base_img, ','.join(opts))
40317438e6SAlberto Garcia        self.vm.launch()
41317438e6SAlberto Garcia
42317438e6SAlberto Garcia    def tearDown(self):
43317438e6SAlberto Garcia        self.vm.shutdown()
44317438e6SAlberto Garcia        os.remove(self.base_img)
45317438e6SAlberto Garcia        os.remove(self.target_img)
46317438e6SAlberto Garcia
47317438e6SAlberto Garcia    def checkConfig(self, active_layer):
4879c719b7SKevin Wolf        result = self.vm.qmp('query-block')
49317438e6SAlberto Garcia        for r in result['return']:
5079c719b7SKevin Wolf            r = r['inserted']
51317438e6SAlberto Garcia            if r['node-name'] == active_layer:
52317438e6SAlberto Garcia                self.assertEqual(r['group'], self.group)
53317438e6SAlberto Garcia                self.assertEqual(r['iops'], self.iops)
54317438e6SAlberto Garcia                self.assertEqual(r['iops_size'], self.iops_size)
55317438e6SAlberto Garcia            else:
56*d7a4228eSEduardo Habkost                self.assertFalse('group' in r)
57317438e6SAlberto Garcia                self.assertEqual(r['iops'], 0)
58*d7a4228eSEduardo Habkost                self.assertFalse('iops_size' in r)
59317438e6SAlberto Garcia
60317438e6SAlberto Garcia    def testSnapshot(self):
61317438e6SAlberto Garcia        self.checkConfig('base')
62317438e6SAlberto Garcia        self.vm.qmp('blockdev-snapshot-sync',
63317438e6SAlberto Garcia                    node_name = 'base',
64317438e6SAlberto Garcia                    snapshot_node_name = 'target',
65317438e6SAlberto Garcia                    snapshot_file = self.target_img,
66317438e6SAlberto Garcia                    format = iotests.imgfmt)
67317438e6SAlberto Garcia        self.checkConfig('target')
68317438e6SAlberto Garcia
69317438e6SAlberto Garciaif __name__ == '__main__':
70317438e6SAlberto Garcia    iotests.main(supported_fmts=['qcow2'])
71