3 # Test vmdk 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
=['vmdk'])
28 def blockdev_create(vm
, options
):
29 result
= vm
.qmp_log('blockdev-create', job_id
='job0', options
=options
)
31 if 'return' in result
:
32 assert result
['return'] == {}
36 with iotests
.FilePath('t.vmdk') as disk_path
, \
37 iotests
.FilePath('t.vmdk.1') as extent1_path
, \
38 iotests
.FilePath('t.vmdk.2') as extent2_path
, \
39 iotests
.FilePath('t.vmdk.3') as extent3_path
, \
43 # Successful image creation (defaults)
45 iotests
.log("=== Successful image creation (defaults) ===")
48 size
= 5 * 1024 * 1024 * 1024
51 blockdev_create(vm
, { 'driver': 'file',
52 'filename': disk_path
,
55 vm
.qmp_log('blockdev-add', driver
='file', filename
=disk_path
,
58 blockdev_create(vm
, { 'driver': imgfmt
,
63 iotests
.img_info_log(disk_path
)
66 # Successful image creation (inline blockdev-add, explicit defaults)
68 iotests
.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
71 # Choose a different size to show that we got a new image
72 size
= 64 * 1024 * 1024
75 blockdev_create(vm
, { 'driver': 'file',
76 'filename': disk_path
,
79 blockdev_create(vm
, { 'driver': imgfmt
,
82 'filename': disk_path
,
86 'subformat': 'monolithicSparse',
87 'adapter-type': 'ide',
89 'zeroed-grain': False })
92 iotests
.img_info_log(disk_path
)
95 # Successful image creation (non-default options)
97 iotests
.log("=== Successful image creation (with non-default options) ===")
100 # Choose a different size to show that we got a new image
101 size
= 32 * 1024 * 1024
104 blockdev_create(vm
, { 'driver': 'file',
105 'filename': disk_path
,
108 blockdev_create(vm
, { 'driver': imgfmt
,
111 'filename': disk_path
,
115 'subformat': 'monolithicSparse',
116 'adapter-type': 'buslogic',
117 'zeroed-grain': True })
120 iotests
.img_info_log(disk_path
)
123 # Invalid BlockdevRef
125 iotests
.log("=== Invalid BlockdevRef ===")
129 blockdev_create(vm
, { 'driver': imgfmt
,
130 'file': "this doesn't exist",
138 iotests
.log("=== Adapter types ===")
141 vm
.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path
))
144 iotests
.log("== Valid adapter types ==")
148 for adapter_type
in [ 'ide', 'buslogic', 'lsilogic', 'legacyESX' ]:
149 blockdev_create(vm
, { 'driver': imgfmt
,
152 'adapter-type': adapter_type
})
156 iotests
.log("== Invalid adapter types ==")
160 for adapter_type
in [ 'foo', 'IDE', 'legacyesx', 1 ]:
161 blockdev_create(vm
, { 'driver': imgfmt
,
164 'adapter-type': adapter_type
})
170 iotests
.log("=== Other subformats ===")
173 for path
in [ extent1_path
, extent2_path
, extent3_path
]:
174 msg
= iotests
.qemu_img_pipe('create', '-f', imgfmt
, path
, '0')
175 iotests
.log(msg
, [iotests
.filter_testfiles
])
177 vm
.add_blockdev('driver=file,filename=%s,node-name=ext1' % (extent1_path
))
178 vm
.add_blockdev('driver=file,filename=%s,node-name=ext2' % (extent2_path
))
179 vm
.add_blockdev('driver=file,filename=%s,node-name=ext3' % (extent3_path
))
182 iotests
.log("== Missing extent ==")
186 blockdev_create(vm
, { 'driver': imgfmt
,
189 'subformat': 'monolithicFlat' })
193 iotests
.log("== Correct extent ==")
197 blockdev_create(vm
, { 'driver': imgfmt
,
200 'subformat': 'monolithicFlat',
201 'extents': ['ext1'] })
205 iotests
.log("== Extra extent ==")
209 blockdev_create(vm
, { 'driver': imgfmt
,
212 'subformat': 'monolithicFlat',
213 'extents': ['ext1', 'ext2', 'ext3'] })
217 iotests
.log("== Split formats ==")
220 for size
in [ 512, 1073741824, 2147483648, 5368709120 ]:
221 for subfmt
in [ 'twoGbMaxExtentFlat', 'twoGbMaxExtentSparse' ]:
222 iotests
.log("= %s %d =" % (subfmt
, size
))
226 blockdev_create(vm
, { 'driver': imgfmt
,
230 'extents': ['ext1', 'ext2', 'ext3'] })
233 iotests
.img_info_log(disk_path
)