3 # Test VDI 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
=['vdi'])
27 iotests
.verify_protocol(supported
=['file'])
29 def blockdev_create(vm
, options
):
30 result
= vm
.qmp_log('blockdev-create', job_id
='job0', options
=options
)
32 if 'return' in result
:
33 assert result
['return'] == {}
37 with iotests
.FilePath('t.vdi') as disk_path
, \
41 # Successful image creation (defaults)
43 iotests
.log("=== Successful image creation (defaults) ===")
46 size
= 128 * 1024 * 1024
49 blockdev_create(vm
, { 'driver': 'file',
50 'filename': disk_path
,
53 vm
.qmp_log('blockdev-add', driver
='file', filename
=disk_path
,
56 blockdev_create(vm
, { 'driver': imgfmt
,
61 iotests
.img_info_log(disk_path
)
62 iotests
.log(iotests
.qemu_img_pipe('map', '--output=json', disk_path
))
65 # Successful image creation (explicit defaults)
67 iotests
.log("=== Successful image creation (explicit defaults) ===")
70 size
= 64 * 1024 * 1024
73 blockdev_create(vm
, { 'driver': 'file',
74 'filename': disk_path
,
76 blockdev_create(vm
, { 'driver': imgfmt
,
79 'filename': disk_path
,
82 'preallocation': 'off' })
85 iotests
.img_info_log(disk_path
)
86 iotests
.log(iotests
.qemu_img_pipe('map', '--output=json', disk_path
))
89 # Successful image creation (with non-default options)
91 iotests
.log("=== Successful image creation (with non-default options) ===")
94 size
= 32 * 1024 * 1024
97 blockdev_create(vm
, { 'driver': 'file',
98 'filename': disk_path
,
100 blockdev_create(vm
, { 'driver': imgfmt
,
103 'filename': disk_path
,
106 'preallocation': 'metadata' })
109 iotests
.img_info_log(disk_path
)
110 iotests
.log(iotests
.qemu_img_pipe('map', '--output=json', disk_path
))
113 # Invalid BlockdevRef
115 iotests
.log("=== Invalid BlockdevRef ===")
119 blockdev_create(vm
, { '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 blockdev_create(vm
, { 'driver': imgfmt
,
137 iotests
.img_info_log(disk_path
)
142 iotests
.log("=== Maximum size ===")
146 blockdev_create(vm
, { 'driver': imgfmt
,
148 'size': 562949819203584 })
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. 0x1fffff8000001 (one byte more than maximum image size for VDI)
165 iotests
.log("=== Invalid sizes ===")
169 for size
in [ 18446744073709551104, 9223372036854775808, 562949819203585 ]:
170 blockdev_create(vm
, { 'driver': imgfmt
,