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