4 # Test vmdk 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/>.
26 from iotests import imgfmt
28 iotests.script_initialize(supported_fmts=['vmdk'])
30 with iotests.FilePath('t.vmdk') as disk_path, \
31 iotests.FilePath('t.vmdk.1') as extent1_path, \
32 iotests.FilePath('t.vmdk.2') as extent2_path, \
33 iotests.FilePath('t.vmdk.3') as extent3_path, \
37 # Successful image creation (defaults)
39 iotests.log("=== Successful image creation (defaults) ===")
42 size = 5 * 1024 * 1024 * 1024
45 vm.blockdev_create({ 'driver': 'file',
46 'filename': disk_path,
49 vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
50 node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
52 vm.blockdev_create({ 'driver': imgfmt,
57 iotests.img_info_log(disk_path)
60 # Successful image creation (inline blockdev-add, explicit defaults)
62 iotests.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
65 # Choose a different size to show that we got a new image
66 size = 64 * 1024 * 1024
69 vm.blockdev_create({ 'driver': 'file',
70 'filename': disk_path,
73 vm.blockdev_create({ 'driver': imgfmt,
76 'filename': disk_path,
80 'subformat': 'monolithicSparse',
81 'adapter-type': 'ide',
83 'zeroed-grain': False })
86 iotests.img_info_log(disk_path)
89 # Successful image creation (non-default options)
91 iotests.log("=== Successful image creation (with non-default options) ===")
94 # Choose a different size to show that we got a new image
95 size = 32 * 1024 * 1024
98 vm.blockdev_create({ 'driver': 'file',
99 'filename': disk_path,
102 vm.blockdev_create({ 'driver': imgfmt,
105 'filename': disk_path,
109 'subformat': 'monolithicSparse',
110 'adapter-type': 'buslogic',
111 'zeroed-grain': True })
114 iotests.img_info_log(disk_path)
117 # Invalid BlockdevRef
119 iotests.log("=== Invalid BlockdevRef ===")
123 vm.blockdev_create({ 'driver': imgfmt,
124 'file': "this doesn't exist",
132 iotests.log("=== Adapter types ===")
135 vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
138 iotests.log("== Valid adapter types ==")
142 for adapter_type in [ 'ide', 'buslogic', 'lsilogic', 'legacyESX' ]:
143 vm.blockdev_create({ 'driver': imgfmt,
146 'adapter-type': adapter_type })
150 iotests.log("== Invalid adapter types ==")
154 for adapter_type in [ 'foo', 'IDE', 'legacyesx', 1 ]:
155 vm.blockdev_create({ 'driver': imgfmt,
158 'adapter-type': adapter_type })
164 iotests.log("=== Other subformats ===")
167 for path in [ extent1_path, extent2_path, extent3_path ]:
168 iotests.qemu_img_create('-f', imgfmt, path, '0')
170 vm.add_blockdev('driver=file,filename=%s,node-name=ext1' % (extent1_path))
171 vm.add_blockdev('driver=file,filename=%s,node-name=ext2' % (extent2_path))
172 vm.add_blockdev('driver=file,filename=%s,node-name=ext3' % (extent3_path))
175 iotests.log("== Missing extent ==")
179 vm.blockdev_create({ 'driver': imgfmt,
182 'subformat': 'monolithicFlat' })
186 iotests.log("== Correct extent ==")
190 vm.blockdev_create({ 'driver': imgfmt,
193 'subformat': 'monolithicFlat',
194 'extents': ['ext1'] })
198 iotests.log("== Extra extent ==")
202 vm.blockdev_create({ 'driver': imgfmt,
205 'subformat': 'monolithicFlat',
206 'extents': ['ext1', 'ext2', 'ext3'] })
210 iotests.log("== Split formats ==")
213 for size in [ 512, 1073741824, 2147483648, 5368709120 ]:
214 for subfmt in [ 'twoGbMaxExtentFlat', 'twoGbMaxExtentSparse' ]:
215 iotests.log("= %s %d =" % (subfmt, size))
218 num_extents = int(math.ceil(size / 2.0**31))
219 extents = [ "ext%d" % (i) for i in range(1, num_extents + 1) ]
222 vm.blockdev_create({ 'driver': imgfmt,
226 'extents': extents })
229 iotests.img_info_log(disk_path)