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