4 # Test that snapshots move the throttling configuration to the active
7 # Copyright (C) 2015 Igalia, S.L.
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.
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.
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/>.
26 class 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')
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))
45 os.remove(self.base_img)
46 os.remove(self.target_img)
48 def checkConfig(self, active_layer):
49 result = self.vm.qmp('query-block')
50 for r in result['return']:
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)
57 self.assertFalse('group' in r)
58 self.assertEqual(r['iops'], 0)
59 self.assertFalse('iops_size' in r)
61 def testSnapshot(self):
62 self.checkConfig('base')
63 self.vm.qmp('blockdev-snapshot-sync',
65 snapshot_node_name = 'target',
66 snapshot_file = self.target_img,
67 format = iotests.imgfmt)
68 self.checkConfig('target')
70 if __name__ == '__main__':
71 iotests.main(supported_fmts=['qcow2'],
72 supported_protocols=['file'])