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/>.
25 from iotests
import imgfmt
27 iotests
.verify_image_format(supported_fmts
=['vmdk'])
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.vmdk') as disk_path
, \
39 iotests
.FilePath('t.vmdk.1') as extent1_path
, \
40 iotests
.FilePath('t.vmdk.2') as extent2_path
, \
41 iotests
.FilePath('t.vmdk.3') as extent3_path
, \
45 # Successful image creation (defaults)
47 iotests
.log("=== Successful image creation (defaults) ===")
50 size
= 5 * 1024 * 1024 * 1024
53 blockdev_create(vm
, { 'driver': 'file',
54 'filename': disk_path
,
57 vm
.qmp_log('blockdev-add', driver
='file', filename
=disk_path
,
58 node_name
='imgfile', filters
=[iotests
.filter_qmp_testfiles
])
60 blockdev_create(vm
, { 'driver': imgfmt
,
65 iotests
.img_info_log(disk_path
)
68 # Successful image creation (inline blockdev-add, explicit defaults)
70 iotests
.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
73 # Choose a different size to show that we got a new image
74 size
= 64 * 1024 * 1024
77 blockdev_create(vm
, { 'driver': 'file',
78 'filename': disk_path
,
81 blockdev_create(vm
, { 'driver': imgfmt
,
84 'filename': disk_path
,
88 'subformat': 'monolithicSparse',
89 'adapter-type': 'ide',
91 'zeroed-grain': False })
94 iotests
.img_info_log(disk_path
)
97 # Successful image creation (non-default options)
99 iotests
.log("=== Successful image creation (with non-default options) ===")
102 # Choose a different size to show that we got a new image
103 size
= 32 * 1024 * 1024
106 blockdev_create(vm
, { 'driver': 'file',
107 'filename': disk_path
,
110 blockdev_create(vm
, { 'driver': imgfmt
,
113 'filename': disk_path
,
117 'subformat': 'monolithicSparse',
118 'adapter-type': 'buslogic',
119 'zeroed-grain': True })
122 iotests
.img_info_log(disk_path
)
125 # Invalid BlockdevRef
127 iotests
.log("=== Invalid BlockdevRef ===")
131 blockdev_create(vm
, { 'driver': imgfmt
,
132 'file': "this doesn't exist",
140 iotests
.log("=== Adapter types ===")
143 vm
.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path
))
146 iotests
.log("== Valid adapter types ==")
150 for adapter_type
in [ 'ide', 'buslogic', 'lsilogic', 'legacyESX' ]:
151 blockdev_create(vm
, { 'driver': imgfmt
,
154 'adapter-type': adapter_type
})
158 iotests
.log("== Invalid adapter types ==")
162 for adapter_type
in [ 'foo', 'IDE', 'legacyesx', 1 ]:
163 blockdev_create(vm
, { 'driver': imgfmt
,
166 'adapter-type': adapter_type
})
172 iotests
.log("=== Other subformats ===")
175 for path
in [ extent1_path
, extent2_path
, extent3_path
]:
176 msg
= iotests
.qemu_img_pipe('create', '-f', imgfmt
, path
, '0')
177 iotests
.log(msg
, [iotests
.filter_testfiles
])
179 vm
.add_blockdev('driver=file,filename=%s,node-name=ext1' % (extent1_path
))
180 vm
.add_blockdev('driver=file,filename=%s,node-name=ext2' % (extent2_path
))
181 vm
.add_blockdev('driver=file,filename=%s,node-name=ext3' % (extent3_path
))
184 iotests
.log("== Missing extent ==")
188 blockdev_create(vm
, { 'driver': imgfmt
,
191 'subformat': 'monolithicFlat' })
195 iotests
.log("== Correct extent ==")
199 blockdev_create(vm
, { 'driver': imgfmt
,
202 'subformat': 'monolithicFlat',
203 'extents': ['ext1'] })
207 iotests
.log("== Extra extent ==")
211 blockdev_create(vm
, { 'driver': imgfmt
,
214 'subformat': 'monolithicFlat',
215 'extents': ['ext1', 'ext2', 'ext3'] })
219 iotests
.log("== Split formats ==")
222 for size
in [ 512, 1073741824, 2147483648, 5368709120 ]:
223 for subfmt
in [ 'twoGbMaxExtentFlat', 'twoGbMaxExtentSparse' ]:
224 iotests
.log("= %s %d =" % (subfmt
, size
))
227 num_extents
= int(math
.ceil(size
/ 2.0**31))
228 extents
= [ "ext%d" % (i
) for i
in range(1, num_extents
+ 1) ]
231 blockdev_create(vm
, { 'driver': imgfmt
,
235 'extents': extents
})
238 iotests
.img_info_log(disk_path
)