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.script_initialize(supported_fmts=['vmdk'])
29 with iotests.FilePath('t.vmdk') as disk_path, \
30 iotests.FilePath('t.vmdk.1') as extent1_path, \
31 iotests.FilePath('t.vmdk.2') as extent2_path, \
32 iotests.FilePath('t.vmdk.3') as extent3_path, \
36 # Successful image creation (defaults)
38 iotests.log("=== Successful image creation (defaults) ===")
41 size = 5 * 1024 * 1024 * 1024
44 vm.blockdev_create({ 'driver': 'file',
45 'filename': disk_path,
48 vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
49 node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
51 vm.blockdev_create({ 'driver': imgfmt,
56 iotests.img_info_log(disk_path)
59 # Successful image creation (inline blockdev-add, explicit defaults)
61 iotests.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
64 # Choose a different size to show that we got a new image
65 size = 64 * 1024 * 1024
68 vm.blockdev_create({ 'driver': 'file',
69 'filename': disk_path,
72 vm.blockdev_create({ 'driver': imgfmt,
75 'filename': disk_path,
79 'subformat': 'monolithicSparse',
80 'adapter-type': 'ide',
82 'zeroed-grain': False })
85 iotests.img_info_log(disk_path)
88 # Successful image creation (non-default options)
90 iotests.log("=== Successful image creation (with non-default options) ===")
93 # Choose a different size to show that we got a new image
94 size = 32 * 1024 * 1024
97 vm.blockdev_create({ 'driver': 'file',
98 'filename': disk_path,
101 vm.blockdev_create({ 'driver': imgfmt,
104 'filename': disk_path,
108 'subformat': 'monolithicSparse',
109 'adapter-type': 'buslogic',
110 'zeroed-grain': True })
113 iotests.img_info_log(disk_path)
116 # Invalid BlockdevRef
118 iotests.log("=== Invalid BlockdevRef ===")
122 vm.blockdev_create({ 'driver': imgfmt,
123 'file': "this doesn't exist",
131 iotests.log("=== Adapter types ===")
134 vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
137 iotests.log("== Valid adapter types ==")
141 for adapter_type in [ 'ide', 'buslogic', 'lsilogic', 'legacyESX' ]:
142 vm.blockdev_create({ 'driver': imgfmt,
145 'adapter-type': adapter_type })
149 iotests.log("== Invalid adapter types ==")
153 for adapter_type in [ 'foo', 'IDE', 'legacyesx', 1 ]:
154 vm.blockdev_create({ 'driver': imgfmt,
157 'adapter-type': adapter_type })
163 iotests.log("=== Other subformats ===")
166 for path in [ extent1_path, extent2_path, extent3_path ]:
167 msg = iotests.qemu_img_pipe('create', '-f', imgfmt, path, '0')
168 iotests.log(msg, [iotests.filter_testfiles])
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)