#!/usr/bin/env python
#
# Test luks and file image creation
#
# Copyright (C) 2018 Red Hat, Inc.
#
# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
#
# 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
from iotests import imgfmt

iotests.verify_image_format(supported_fmts=['luks'])
iotests.verify_protocol(supported=['file'])

def blockdev_create(vm, options):
    result = vm.qmp_log('blockdev-create', job_id='job0', options=options)

    if 'return' in result:
        assert result['return'] == {}
        vm.run_job('job0')
    iotests.log("")

with iotests.FilePath('t.luks') as disk_path, \
     iotests.VM() as vm:

    vm.add_object('secret,id=keysec0,data=foo')

    #
    # Successful image creation (defaults)
    #
    iotests.log("=== Successful image creation (defaults) ===")
    iotests.log("")

    size = 128 * 1024 * 1024

    vm.launch()
    blockdev_create(vm, { 'driver': 'file',
                          'filename': disk_path,
                          'size': 0 })

    vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
               node_name='imgfile')

    blockdev_create(vm, { 'driver': imgfmt,
                          'file': 'imgfile',
                          'key-secret': 'keysec0',
                          'size': size,
                          'iter-time': 10 })
    vm.shutdown()

    # TODO Proper support for images to be used with imgopts and/or protocols
    iotests.img_info_log(
        'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path),
        filter_path=disk_path,
        extra_args=['--object', 'secret,id=keysec0,data=foo'],
        imgopts=True)

    #
    # Successful image creation (with non-default options)
    #
    iotests.log("=== Successful image creation (with non-default options) ===")
    iotests.log("")

    size = 64 * 1024 * 1024

    vm.launch()
    blockdev_create(vm, { 'driver': 'file',
                          'filename': disk_path,
                          'size': 0 })
    blockdev_create(vm, { 'driver': imgfmt,
                          'file': {
                              'driver': 'file',
                              'filename': disk_path,
                          },
                          'size': size,
                          'key-secret': 'keysec0',
                          'cipher-alg': 'twofish-128',
                          'cipher-mode': 'ctr',
                          'ivgen-alg': 'plain64',
                          'ivgen-hash-alg': 'md5',
                          'hash-alg': 'sha1',
                          'iter-time': 10 })
    vm.shutdown()

    # TODO Proper support for images to be used with imgopts and/or protocols
    iotests.img_info_log(
        'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path),
        filter_path=disk_path,
        extra_args=['--object', 'secret,id=keysec0,data=foo'],
        imgopts=True)

    #
    # Invalid BlockdevRef
    #
    iotests.log("=== Invalid BlockdevRef ===")
    iotests.log("")

    size = 64 * 1024 * 1024

    vm.launch()
    blockdev_create(vm, { 'driver': imgfmt,
                          'file': "this doesn't exist",
                          'size': size })
    vm.shutdown()

    #
    # Zero size
    #
    iotests.log("=== Zero size ===")
    iotests.log("")

    vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
    vm.launch()
    blockdev_create(vm, { 'driver': imgfmt,
                          'file': 'node0',
                          'key-secret': 'keysec0',
                          'size': 0,
                          'iter-time': 10 })
    vm.shutdown()

    # TODO Proper support for images to be used with imgopts and/or protocols
    iotests.img_info_log(
        'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path),
        filter_path=disk_path,
        extra_args=['--object', 'secret,id=keysec0,data=foo'],
        imgopts=True)

    #
    # Invalid sizes
    #

    # TODO Negative image sizes aren't handled correctly, but this is a problem
    # with QAPI's implementation of the 'size' type and affects other commands as
    # well. Once this is fixed, we may want to add a test case here.

    # 1. 2^64 - 512
    # 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
    # 3. 2^63 - 512 (generally valid, but with the crypto header the file will
    #                exceed 63 bits)
    iotests.log("=== Invalid sizes ===")
    iotests.log("")

    vm.launch()
    for size in [ 18446744073709551104, 9223372036854775808, 9223372036854775296 ]:
        blockdev_create(vm, { 'driver': imgfmt,
                              'file': 'node0',
                              'key-secret': 'keysec0',
                              'size': size })
    vm.shutdown()

    #
    # Resize image with invalid sizes
    #
    iotests.log("=== Resize image with invalid sizes ===")
    iotests.log("")

    vm.add_blockdev('driver=luks,file=node0,key-secret=keysec0,node-name=node1')
    vm.launch()
    vm.qmp_log('block_resize', node_name='node1', size=9223372036854775296)
    vm.qmp_log('block_resize', node_name='node1', size=9223372036854775808)
    vm.qmp_log('block_resize', node_name='node1', size=18446744073709551104)
    vm.qmp_log('block_resize', node_name='node1', size=-9223372036854775808)
    vm.shutdown()

    # TODO Proper support for images to be used with imgopts and/or protocols
    iotests.img_info_log(
        'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path),
        filter_path=disk_path,
        extra_args=['--object', 'secret,id=keysec0,data=foo'],
        imgopts=True)
