#!/usr/bin/env python3
#
# Test VDI 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.script_initialize(
    supported_fmts=['vdi'],
    supported_protocols=['file'],
)

def blockdev_create(vm, options):
    error = vm.blockdev_create(options)
    if error and 'Could not allocate bmap' in error:
        iotests.notrun('Insufficient memory')

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

    #
    # 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', filters=[iotests.filter_qmp_testfiles])

    blockdev_create(vm, { 'driver': imgfmt,
                          'file': 'imgfile',
                          'size': size })
    vm.shutdown()

    iotests.img_info_log(disk_path)
    iotests.log(iotests.qemu_img_pipe('map', '--output=json', disk_path))

    #
    # Successful image creation (explicit defaults)
    #
    iotests.log("=== Successful image creation (explicit defaults) ===")
    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,
                          'preallocation': 'off' })
    vm.shutdown()

    iotests.img_info_log(disk_path)
    iotests.log(iotests.qemu_img_pipe('map', '--output=json', disk_path))

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

    size = 32 * 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,
                          'preallocation': 'metadata' })
    vm.shutdown()

    iotests.img_info_log(disk_path)
    iotests.log(iotests.qemu_img_pipe('map', '--output=json', disk_path))

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

    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',
                          'size': 0 })
    vm.shutdown()

    iotests.img_info_log(disk_path)

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

    vm.launch()
    blockdev_create(vm, { 'driver': imgfmt,
                          'file': 'node0',
                          'size': 562949819203584 })
    vm.shutdown()

    iotests.img_info_log(disk_path)

    #
    # 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. 0x1fffff8000001 (one byte more than maximum image size for VDI)

    iotests.log("=== Invalid sizes ===")
    iotests.log("")

    vm.launch()
    for size in [ 18446744073709551104, 9223372036854775808, 562949819203585 ]:
        blockdev_create(vm, { 'driver': imgfmt,
                              'file': 'node0',
                              'size': size })
    vm.shutdown()
