1*317438e6SAlberto Garcia#!/usr/bin/env python 2*317438e6SAlberto Garcia# 3*317438e6SAlberto Garcia# Test that snapshots move the throttling configuration to the active 4*317438e6SAlberto Garcia# layer 5*317438e6SAlberto Garcia# 6*317438e6SAlberto Garcia# Copyright (C) 2015 Igalia, S.L. 7*317438e6SAlberto Garcia# 8*317438e6SAlberto Garcia# This program is free software; you can redistribute it and/or modify 9*317438e6SAlberto Garcia# it under the terms of the GNU General Public License as published by 10*317438e6SAlberto Garcia# the Free Software Foundation; either version 2 of the License, or 11*317438e6SAlberto Garcia# (at your option) any later version. 12*317438e6SAlberto Garcia# 13*317438e6SAlberto Garcia# This program is distributed in the hope that it will be useful, 14*317438e6SAlberto Garcia# but WITHOUT ANY WARRANTY; without even the implied warranty of 15*317438e6SAlberto Garcia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*317438e6SAlberto Garcia# GNU General Public License for more details. 17*317438e6SAlberto Garcia# 18*317438e6SAlberto Garcia# You should have received a copy of the GNU General Public License 19*317438e6SAlberto Garcia# along with this program. If not, see <http://www.gnu.org/licenses/>. 20*317438e6SAlberto Garcia# 21*317438e6SAlberto Garcia 22*317438e6SAlberto Garciaimport iotests 23*317438e6SAlberto Garciaimport os 24*317438e6SAlberto Garcia 25*317438e6SAlberto Garciaclass TestLiveSnapshot(iotests.QMPTestCase): 26*317438e6SAlberto Garcia base_img = os.path.join(iotests.test_dir, 'base.img') 27*317438e6SAlberto Garcia target_img = os.path.join(iotests.test_dir, 'target.img') 28*317438e6SAlberto Garcia group = 'mygroup' 29*317438e6SAlberto Garcia iops = 6000 30*317438e6SAlberto Garcia iops_size = 1024 31*317438e6SAlberto Garcia 32*317438e6SAlberto Garcia def setUp(self): 33*317438e6SAlberto Garcia opts = [] 34*317438e6SAlberto Garcia opts.append('node-name=base') 35*317438e6SAlberto Garcia opts.append('throttling.group=%s' % self.group) 36*317438e6SAlberto Garcia opts.append('throttling.iops-total=%d' % self.iops) 37*317438e6SAlberto Garcia opts.append('throttling.iops-size=%d' % self.iops_size) 38*317438e6SAlberto Garcia iotests.qemu_img('create', '-f', iotests.imgfmt, self.base_img, '100M') 39*317438e6SAlberto Garcia self.vm = iotests.VM().add_drive(self.base_img, ','.join(opts)) 40*317438e6SAlberto Garcia self.vm.launch() 41*317438e6SAlberto Garcia 42*317438e6SAlberto Garcia def tearDown(self): 43*317438e6SAlberto Garcia self.vm.shutdown() 44*317438e6SAlberto Garcia os.remove(self.base_img) 45*317438e6SAlberto Garcia os.remove(self.target_img) 46*317438e6SAlberto Garcia 47*317438e6SAlberto Garcia def checkConfig(self, active_layer): 48*317438e6SAlberto Garcia result = self.vm.qmp('query-named-block-nodes') 49*317438e6SAlberto Garcia for r in result['return']: 50*317438e6SAlberto Garcia if r['node-name'] == active_layer: 51*317438e6SAlberto Garcia self.assertEqual(r['group'], self.group) 52*317438e6SAlberto Garcia self.assertEqual(r['iops'], self.iops) 53*317438e6SAlberto Garcia self.assertEqual(r['iops_size'], self.iops_size) 54*317438e6SAlberto Garcia else: 55*317438e6SAlberto Garcia self.assertFalse(r.has_key('group')) 56*317438e6SAlberto Garcia self.assertEqual(r['iops'], 0) 57*317438e6SAlberto Garcia self.assertFalse(r.has_key('iops_size')) 58*317438e6SAlberto Garcia 59*317438e6SAlberto Garcia def testSnapshot(self): 60*317438e6SAlberto Garcia self.checkConfig('base') 61*317438e6SAlberto Garcia self.vm.qmp('blockdev-snapshot-sync', 62*317438e6SAlberto Garcia node_name = 'base', 63*317438e6SAlberto Garcia snapshot_node_name = 'target', 64*317438e6SAlberto Garcia snapshot_file = self.target_img, 65*317438e6SAlberto Garcia format = iotests.imgfmt) 66*317438e6SAlberto Garcia self.checkConfig('target') 67*317438e6SAlberto Garcia 68*317438e6SAlberto Garciaif __name__ == '__main__': 69*317438e6SAlberto Garcia iotests.main(supported_fmts=['qcow2']) 70