iotests: Add VMDK tests for blockdev-create
[qemu.git] / tests / qemu-iotests / 237
blobe04a1ac6bea32020b19dee52e6cc9ac8973b1dd2
1 #!/usr/bin/env python
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/>.
23 import iotests
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'] == {}
33 vm.run_job('job0')
34 iotests.log("")
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, \
40 iotests.VM() as vm:
43 # Successful image creation (defaults)
45 iotests.log("=== Successful image creation (defaults) ===")
46 iotests.log("")
48 size = 5 * 1024 * 1024 * 1024
50 vm.launch()
51 blockdev_create(vm, { 'driver': 'file',
52 'filename': disk_path,
53 'size': 0 })
55 vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
56 node_name='imgfile')
58 blockdev_create(vm, { 'driver': imgfmt,
59 'file': 'imgfile',
60 'size': size })
61 vm.shutdown()
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) ===")
69 iotests.log("")
71 # Choose a different size to show that we got a new image
72 size = 64 * 1024 * 1024
74 vm.launch()
75 blockdev_create(vm, { 'driver': 'file',
76 'filename': disk_path,
77 'size': 0 })
79 blockdev_create(vm, { 'driver': imgfmt,
80 'file': {
81 'driver': 'file',
82 'filename': disk_path,
84 'size': size,
85 'extents': [],
86 'subformat': 'monolithicSparse',
87 'adapter-type': 'ide',
88 'hwversion': '4',
89 'zeroed-grain': False })
90 vm.shutdown()
92 iotests.img_info_log(disk_path)
95 # Successful image creation (non-default options)
97 iotests.log("=== Successful image creation (with non-default options) ===")
98 iotests.log("")
100 # Choose a different size to show that we got a new image
101 size = 32 * 1024 * 1024
103 vm.launch()
104 blockdev_create(vm, { 'driver': 'file',
105 'filename': disk_path,
106 'size': 0 })
108 blockdev_create(vm, { 'driver': imgfmt,
109 'file': {
110 'driver': 'file',
111 'filename': disk_path,
113 'size': size,
114 'extents': [],
115 'subformat': 'monolithicSparse',
116 'adapter-type': 'buslogic',
117 'zeroed-grain': True })
118 vm.shutdown()
120 iotests.img_info_log(disk_path)
123 # Invalid BlockdevRef
125 iotests.log("=== Invalid BlockdevRef ===")
126 iotests.log("")
128 vm.launch()
129 blockdev_create(vm, { 'driver': imgfmt,
130 'file': "this doesn't exist",
131 'size': size })
132 vm.shutdown()
135 # Adapter types
138 iotests.log("=== Adapter types ===")
139 iotests.log("")
141 vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
143 # Valid
144 iotests.log("== Valid adapter types ==")
145 iotests.log("")
147 vm.launch()
148 for adapter_type in [ 'ide', 'buslogic', 'lsilogic', 'legacyESX' ]:
149 blockdev_create(vm, { 'driver': imgfmt,
150 'file': 'node0',
151 'size': size,
152 'adapter-type': adapter_type })
153 vm.shutdown()
155 # Invalid
156 iotests.log("== Invalid adapter types ==")
157 iotests.log("")
159 vm.launch()
160 for adapter_type in [ 'foo', 'IDE', 'legacyesx', 1 ]:
161 blockdev_create(vm, { 'driver': imgfmt,
162 'file': 'node0',
163 'size': size,
164 'adapter-type': adapter_type })
165 vm.shutdown()
168 # Other subformats
170 iotests.log("=== Other subformats ===")
171 iotests.log("")
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))
181 # Missing extent
182 iotests.log("== Missing extent ==")
183 iotests.log("")
185 vm.launch()
186 blockdev_create(vm, { 'driver': imgfmt,
187 'file': 'node0',
188 'size': size,
189 'subformat': 'monolithicFlat' })
190 vm.shutdown()
192 # Correct extent
193 iotests.log("== Correct extent ==")
194 iotests.log("")
196 vm.launch()
197 blockdev_create(vm, { 'driver': imgfmt,
198 'file': 'node0',
199 'size': size,
200 'subformat': 'monolithicFlat',
201 'extents': ['ext1'] })
202 vm.shutdown()
204 # Extra extent
205 iotests.log("== Extra extent ==")
206 iotests.log("")
208 vm.launch()
209 blockdev_create(vm, { 'driver': imgfmt,
210 'file': 'node0',
211 'size': 512,
212 'subformat': 'monolithicFlat',
213 'extents': ['ext1', 'ext2', 'ext3'] })
214 vm.shutdown()
216 # Split formats
217 iotests.log("== Split formats ==")
218 iotests.log("")
220 for size in [ 512, 1073741824, 2147483648, 5368709120 ]:
221 for subfmt in [ 'twoGbMaxExtentFlat', 'twoGbMaxExtentSparse' ]:
222 iotests.log("= %s %d =" % (subfmt, size))
223 iotests.log("")
225 vm.launch()
226 blockdev_create(vm, { 'driver': imgfmt,
227 'file': 'node0',
228 'size': size,
229 'subformat': subfmt,
230 'extents': ['ext1', 'ext2', 'ext3'] })
231 vm.shutdown()
233 iotests.img_info_log(disk_path)