#!/usr/bin/env python
#
# Test that snapshots move the throttling configuration to the active
# layer
#
# Copyright (C) 2015 Igalia, S.L.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import iotests
import os

class TestLiveSnapshot(iotests.QMPTestCase):
    base_img = os.path.join(iotests.test_dir, 'base.img')
    target_img = os.path.join(iotests.test_dir, 'target.img')
    group = 'mygroup'
    iops = 6000
    iops_size = 1024

    def setUp(self):
        opts = []
        opts.append('node-name=base')
        opts.append('throttling.group=%s' % self.group)
        opts.append('throttling.iops-total=%d' % self.iops)
        opts.append('throttling.iops-size=%d' % self.iops_size)
        iotests.qemu_img('create', '-f', iotests.imgfmt, self.base_img, '100M')
        self.vm = iotests.VM().add_drive(self.base_img, ','.join(opts))
        self.vm.launch()

    def tearDown(self):
        self.vm.shutdown()
        os.remove(self.base_img)
        os.remove(self.target_img)

    def checkConfig(self, active_layer):
        result = self.vm.qmp('query-block')
        for r in result['return']:
            r = r['inserted']
            if r['node-name'] == active_layer:
                self.assertEqual(r['group'], self.group)
                self.assertEqual(r['iops'], self.iops)
                self.assertEqual(r['iops_size'], self.iops_size)
            else:
                self.assertFalse('group' in r)
                self.assertEqual(r['iops'], 0)
                self.assertFalse('iops_size' in r)

    def testSnapshot(self):
        self.checkConfig('base')
        self.vm.qmp('blockdev-snapshot-sync',
                    node_name = 'base',
                    snapshot_node_name = 'target',
                    snapshot_file = self.target_img,
                    format = iotests.imgfmt)
        self.checkConfig('target')

if __name__ == '__main__':
    iotests.main(supported_fmts=['qcow2'])
