4 # Test vhdx and file image creation
6 # Copyright (C) 2018 Red Hat, Inc.
8 # Creator/Owner: Kevin Wolf <kwolf@redhat.com>
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 from iotests import imgfmt
27 iotests.script_initialize(
28 supported_fmts=['vhdx'],
29 supported_protocols=['file'],
32 with iotests.FilePath('t.vhdx') as disk_path, \
36 # Successful image creation (defaults)
38 iotests.log("=== Successful image creation (defaults) ===")
41 size = 128 * 1024 * 1024
44 vm.blockdev_create({ 'driver': 'file',
45 'filename': disk_path,
48 vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
49 node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
51 vm.blockdev_create({ 'driver': imgfmt,
56 iotests.img_info_log(disk_path)
59 # Successful image creation (explicit defaults)
61 iotests.log("=== Successful image creation (explicit defaults) ===")
64 # Choose a different size to show that we got a new image
65 size = 64 * 1024 * 1024
68 vm.blockdev_create({ 'driver': 'file',
69 'filename': disk_path,
71 vm.blockdev_create({ 'driver': imgfmt,
74 'filename': disk_path,
78 'block-size': 8388608,
79 'subformat': 'dynamic',
80 'block-state-zero': True })
83 iotests.img_info_log(disk_path)
86 # Successful image creation (with non-default options)
88 iotests.log("=== Successful image creation (with non-default options) ===")
91 # Choose a different size to show that we got a new image
92 size = 32 * 1024 * 1024
95 vm.blockdev_create({ 'driver': 'file',
96 'filename': disk_path,
98 vm.blockdev_create({ 'driver': imgfmt,
101 'filename': disk_path,
105 'block-size': 268435456,
106 'subformat': 'fixed',
107 'block-state-zero': False })
110 iotests.img_info_log(disk_path)
113 # Invalid BlockdevRef
115 iotests.log("=== Invalid BlockdevRef ===")
119 vm.blockdev_create({ 'driver': imgfmt,
120 'file': "this doesn't exist",
127 iotests.log("=== Zero size ===")
130 vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
132 vm.blockdev_create({ 'driver': imgfmt,
137 iotests.img_info_log(disk_path)
142 iotests.log("=== Maximum size ===")
146 vm.blockdev_create({ 'driver': imgfmt,
148 'size': 70368744177664 })
151 iotests.img_info_log(disk_path)
157 # TODO Negative image sizes aren't handled correctly, but this is a problem
158 # with QAPI's implementation of the 'size' type and affects other commands
159 # as well. Once this is fixed, we may want to add a test case here.
162 # 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
163 # 3. 2^63 - 512 (generally valid, but with the image header the file will
165 # 4. 2^46 + 1 (one byte more than maximum image size)
167 iotests.log("=== Invalid sizes ===")
171 for size in [ 18446744073709551104, 9223372036854775808,
172 9223372036854775296, 70368744177665 ]:
173 vm.blockdev_create({ 'driver': imgfmt,
181 iotests.log("=== Invalid block size ===")
185 for bsize in [ 1234567, 128, 3145728, 536870912, 0 ]:
186 vm.blockdev_create({ 'driver': imgfmt,
189 'block-size': bsize })
195 iotests.log("=== Invalid log size ===")
199 for lsize in [ 1234567, 128, 4294967296, 0 ]:
200 vm.blockdev_create({ 'driver': imgfmt,