3 # Test vhdx and file image creation
5 # Copyright (C) 2018 Red Hat, Inc.
7 # Creator/Owner: Kevin Wolf <kwolf@redhat.com>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 from iotests
import imgfmt
26 iotests
.verify_image_format(supported_fmts
=['vhdx'])
27 iotests
.verify_protocol(supported
=['file'])
29 def blockdev_create(vm
, options
):
30 result
= vm
.qmp_log('blockdev-create', job_id
='job0', options
=options
,
31 filters
=[iotests
.filter_qmp_testfiles
])
33 if 'return' in result
:
34 assert result
['return'] == {}
38 with iotests
.FilePath('t.vhdx') as disk_path
, \
42 # Successful image creation (defaults)
44 iotests
.log("=== Successful image creation (defaults) ===")
47 size
= 128 * 1024 * 1024
50 blockdev_create(vm
, { 'driver': 'file',
51 'filename': disk_path
,
54 vm
.qmp_log('blockdev-add', driver
='file', filename
=disk_path
,
55 node_name
='imgfile', filters
=[iotests
.filter_qmp_testfiles
])
57 blockdev_create(vm
, { 'driver': imgfmt
,
62 iotests
.img_info_log(disk_path
)
65 # Successful image creation (explicit defaults)
67 iotests
.log("=== Successful image creation (explicit defaults) ===")
70 # Choose a different size to show that we got a new image
71 size
= 64 * 1024 * 1024
74 blockdev_create(vm
, { 'driver': 'file',
75 'filename': disk_path
,
77 blockdev_create(vm
, { 'driver': imgfmt
,
80 'filename': disk_path
,
84 'block-size': 8388608,
85 'subformat': 'dynamic',
86 'block-state-zero': True })
89 iotests
.img_info_log(disk_path
)
92 # Successful image creation (with non-default options)
94 iotests
.log("=== Successful image creation (with non-default options) ===")
97 # Choose a different size to show that we got a new image
98 size
= 32 * 1024 * 1024
101 blockdev_create(vm
, { 'driver': 'file',
102 'filename': disk_path
,
104 blockdev_create(vm
, { 'driver': imgfmt
,
107 'filename': disk_path
,
111 'block-size': 268435456,
112 'subformat': 'fixed',
113 'block-state-zero': False })
116 iotests
.img_info_log(disk_path
)
119 # Invalid BlockdevRef
121 iotests
.log("=== Invalid BlockdevRef ===")
125 blockdev_create(vm
, { 'driver': imgfmt
,
126 'file': "this doesn't exist",
133 iotests
.log("=== Zero size ===")
136 vm
.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path
))
138 blockdev_create(vm
, { 'driver': imgfmt
,
143 iotests
.img_info_log(disk_path
)
148 iotests
.log("=== Maximum size ===")
152 blockdev_create(vm
, { 'driver': imgfmt
,
154 'size': 70368744177664 })
157 iotests
.img_info_log(disk_path
)
163 # TODO Negative image sizes aren't handled correctly, but this is a problem
164 # with QAPI's implementation of the 'size' type and affects other commands
165 # as well. Once this is fixed, we may want to add a test case here.
168 # 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
169 # 3. 2^63 - 512 (generally valid, but with the image header the file will
171 # 4. 2^46 + 1 (one byte more than maximum image size)
173 iotests
.log("=== Invalid sizes ===")
177 for size
in [ 18446744073709551104, 9223372036854775808,
178 9223372036854775296, 70368744177665 ]:
179 blockdev_create(vm
, { 'driver': imgfmt
,
187 iotests
.log("=== Invalid block size ===")
191 for bsize
in [ 1234567, 128, 3145728, 536870912, 0 ]:
192 blockdev_create(vm
, { 'driver': imgfmt
,
195 'block-size': bsize
})
201 iotests
.log("=== Invalid log size ===")
205 for lsize
in [ 1234567, 128, 4294967296, 0 ]:
206 blockdev_create(vm
, { 'driver': imgfmt
,