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-named-block-nodes')
49 for r
in result
['return']:
50 if r
['node-name'] == active_layer
:
51 self
.assertEqual(r
['group'], self
.group
)
52 self
.assertEqual(r
['iops'], self
.iops
)
53 self
.assertEqual(r
['iops_size'], self
.iops_size
)
55 self
.assertFalse(r
.has_key('group'))
56 self
.assertEqual(r
['iops'], 0)
57 self
.assertFalse(r
.has_key('iops_size'))
59 def testSnapshot(self
):
60 self
.checkConfig('base')
61 self
.vm
.qmp('blockdev-snapshot-sync',
63 snapshot_node_name
= 'target',
64 snapshot_file
= self
.target_img
,
65 format
= iotests
.imgfmt
)
66 self
.checkConfig('target')
68 if __name__
== '__main__':
69 iotests
.main(supported_fmts
=['qcow2'])