1cb73747eSMax Reitz#!/usr/bin/env python 2cb73747eSMax Reitz# 3cb73747eSMax Reitz# Test VPC and file image creation 4cb73747eSMax Reitz# 5cb73747eSMax Reitz# Copyright (C) 2019 Red Hat, Inc. 6cb73747eSMax Reitz# 7cb73747eSMax Reitz# This program is free software; you can redistribute it and/or modify 8cb73747eSMax Reitz# it under the terms of the GNU General Public License as published by 9cb73747eSMax Reitz# the Free Software Foundation; either version 2 of the License, or 10cb73747eSMax Reitz# (at your option) any later version. 11cb73747eSMax Reitz# 12cb73747eSMax Reitz# This program is distributed in the hope that it will be useful, 13cb73747eSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 14cb73747eSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15cb73747eSMax Reitz# GNU General Public License for more details. 16cb73747eSMax Reitz# 17cb73747eSMax Reitz# You should have received a copy of the GNU General Public License 18cb73747eSMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 19cb73747eSMax Reitz# 20cb73747eSMax Reitz 21cb73747eSMax Reitzimport iotests 22cb73747eSMax Reitzfrom iotests import imgfmt 23cb73747eSMax Reitz 24cb73747eSMax Reitz 25cb73747eSMax Reitz# Successful image creation (defaults) 26cb73747eSMax Reitzdef implicit_defaults(vm, file_path): 27cb73747eSMax Reitz iotests.log("=== Successful image creation (defaults) ===") 28cb73747eSMax Reitz iotests.log("") 29cb73747eSMax Reitz 30cb73747eSMax Reitz # 8 heads, 964 cyls/head, 17 secs/cyl 31cb73747eSMax Reitz # (Close to 64 MB) 32cb73747eSMax Reitz size = 8 * 964 * 17 * 512 33cb73747eSMax Reitz 34*de1ff674SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 35cb73747eSMax Reitz 'file': 'protocol-node', 36cb73747eSMax Reitz 'size': size }) 37cb73747eSMax Reitz 38cb73747eSMax Reitz 39cb73747eSMax Reitz# Successful image creation (explicit defaults) 40cb73747eSMax Reitzdef explicit_defaults(vm, file_path): 41cb73747eSMax Reitz iotests.log("=== Successful image creation (explicit defaults) ===") 42cb73747eSMax Reitz iotests.log("") 43cb73747eSMax Reitz 44cb73747eSMax Reitz # 16 heads, 964 cyls/head, 17 secs/cyl 45cb73747eSMax Reitz # (Close to 128 MB) 46cb73747eSMax Reitz size = 16 * 964 * 17 * 512 47cb73747eSMax Reitz 48*de1ff674SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 49cb73747eSMax Reitz 'file': 'protocol-node', 50cb73747eSMax Reitz 'size': size, 51cb73747eSMax Reitz 'subformat': 'dynamic', 52cb73747eSMax Reitz 'force-size': False }) 53cb73747eSMax Reitz 54cb73747eSMax Reitz 55cb73747eSMax Reitz# Successful image creation (non-default options) 56cb73747eSMax Reitzdef non_defaults(vm, file_path): 57cb73747eSMax Reitz iotests.log("=== Successful image creation (non-default options) ===") 58cb73747eSMax Reitz iotests.log("") 59cb73747eSMax Reitz 60cb73747eSMax Reitz # Not representable in CHS (fine with force-size=True) 61cb73747eSMax Reitz size = 1048576 62cb73747eSMax Reitz 63*de1ff674SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 64cb73747eSMax Reitz 'file': 'protocol-node', 65cb73747eSMax Reitz 'size': size, 66cb73747eSMax Reitz 'subformat': 'fixed', 67cb73747eSMax Reitz 'force-size': True }) 68cb73747eSMax Reitz 69cb73747eSMax Reitz 70cb73747eSMax Reitz# Size not representable in CHS with force-size=False 71cb73747eSMax Reitzdef non_chs_size_without_force(vm, file_path): 72cb73747eSMax Reitz iotests.log("=== Size not representable in CHS ===") 73cb73747eSMax Reitz iotests.log("") 74cb73747eSMax Reitz 75cb73747eSMax Reitz # Not representable in CHS (will not work with force-size=False) 76cb73747eSMax Reitz size = 1048576 77cb73747eSMax Reitz 78*de1ff674SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 79cb73747eSMax Reitz 'file': 'protocol-node', 80cb73747eSMax Reitz 'size': size, 81cb73747eSMax Reitz 'force-size': False }) 82cb73747eSMax Reitz 83cb73747eSMax Reitz 84cb73747eSMax Reitz# Zero size 85cb73747eSMax Reitzdef zero_size(vm, file_path): 86cb73747eSMax Reitz iotests.log("=== Zero size===") 87cb73747eSMax Reitz iotests.log("") 88cb73747eSMax Reitz 89*de1ff674SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 90cb73747eSMax Reitz 'file': 'protocol-node', 91cb73747eSMax Reitz 'size': 0 }) 92cb73747eSMax Reitz 93cb73747eSMax Reitz 94cb73747eSMax Reitz# Maximum CHS size 95cb73747eSMax Reitzdef maximum_chs_size(vm, file_path): 96cb73747eSMax Reitz iotests.log("=== Maximum CHS size===") 97cb73747eSMax Reitz iotests.log("") 98cb73747eSMax Reitz 99*de1ff674SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 100cb73747eSMax Reitz 'file': 'protocol-node', 101cb73747eSMax Reitz 'size': 16 * 65535 * 255 * 512 }) 102cb73747eSMax Reitz 103cb73747eSMax Reitz 104cb73747eSMax Reitz# Actual maximum size 105cb73747eSMax Reitzdef maximum_size(vm, file_path): 106cb73747eSMax Reitz iotests.log("=== Actual maximum size===") 107cb73747eSMax Reitz iotests.log("") 108cb73747eSMax Reitz 109*de1ff674SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 110cb73747eSMax Reitz 'file': 'protocol-node', 111cb73747eSMax Reitz 'size': 0xff000000 * 512, 112cb73747eSMax Reitz 'force-size': True }) 113cb73747eSMax Reitz 114cb73747eSMax Reitz 115cb73747eSMax Reitzdef main(): 116cb73747eSMax Reitz for test_func in [implicit_defaults, explicit_defaults, non_defaults, 117cb73747eSMax Reitz non_chs_size_without_force, zero_size, maximum_chs_size, 118cb73747eSMax Reitz maximum_size]: 119cb73747eSMax Reitz 120cb73747eSMax Reitz with iotests.FilePath('t.vpc') as file_path, \ 121cb73747eSMax Reitz iotests.VM() as vm: 122cb73747eSMax Reitz 123cb73747eSMax Reitz vm.launch() 124cb73747eSMax Reitz 125cb73747eSMax Reitz iotests.log('--- Creating empty file ---') 126*de1ff674SKevin Wolf vm.blockdev_create({ 'driver': 'file', 127cb73747eSMax Reitz 'filename': file_path, 128cb73747eSMax Reitz 'size': 0 }) 129cb73747eSMax Reitz 130cb73747eSMax Reitz vm.qmp_log('blockdev-add', driver='file', filename=file_path, 131cb73747eSMax Reitz node_name='protocol-node', 132cb73747eSMax Reitz filters=[iotests.filter_qmp_testfiles]) 133cb73747eSMax Reitz iotests.log('') 134cb73747eSMax Reitz 135cb73747eSMax Reitz print_info = test_func(vm, file_path) 136cb73747eSMax Reitz iotests.log('') 137cb73747eSMax Reitz 138cb73747eSMax Reitz vm.shutdown() 139cb73747eSMax Reitz iotests.img_info_log(file_path) 140cb73747eSMax Reitz 141cb73747eSMax Reitz 142cb73747eSMax Reitziotests.script_main(main, 143cb73747eSMax Reitz supported_fmts=['vpc'], 144cb73747eSMax Reitz supported_protocols=['file']) 145