3 # Test that snapshots move the throttling configuration to the active
6 # Copyright (C) 2015 Igalia, S.L.
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.
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.
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/>.
25 class 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')
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))
44 os.remove(self.base_img)
45 os.remove(self.target_img)
47 def checkConfig(self, active_layer):
48 result = self.vm.qmp('query-block')
49 for r in result['return']:
51 if r['node-name'] == active_layer:
52 self.assertEqual(r['group'], self.group)
53 self.assertEqual(r['iops'], self.iops)
54 self.assertEqual(r['iops_size'], self.iops_size)
56 self.assertFalse('group' in r)
57 self.assertEqual(r['iops'], 0)
58 self.assertFalse('iops_size' in r)
60 def testSnapshot(self):
61 self.checkConfig('base')
62 self.vm.qmp('blockdev-snapshot-sync',
64 snapshot_node_name = 'target',
65 snapshot_file = self.target_img,
66 format = iotests.imgfmt)
67 self.checkConfig('target')
69 if __name__ == '__main__':
70 iotests.main(supported_fmts=['qcow2'],
71 supported_protocols=['file'])