Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2019-07-15' into staging
[qemu/ar7.git] / tests / qemu-iotests / 206
blob5bb738bf23cab447dca32a86c67e1154164e1d13
1 #!/usr/bin/env python
3 # Test qcow2 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=['qcow2'])
28 def blockdev_create(vm, options):
29 result = vm.qmp_log('blockdev-create',
30 filters=[iotests.filter_qmp_testfiles],
31 job_id='job0', options=options)
33 if 'return' in result:
34 assert result['return'] == {}
35 vm.run_job('job0')
36 iotests.log("")
38 with iotests.FilePath('t.qcow2') as disk_path, \
39 iotests.FilePath('t.qcow2.base') as backing_path, \
40 iotests.VM() as vm:
42 vm.add_object('secret,id=keysec0,data=foo')
45 # Successful image creation (defaults)
47 iotests.log("=== Successful image creation (defaults) ===")
48 iotests.log("")
50 size = 128 * 1024 * 1024
52 vm.launch()
53 blockdev_create(vm, { 'driver': 'file',
54 'filename': disk_path,
55 'size': 0 })
57 vm.qmp_log('blockdev-add',
58 filters=[iotests.filter_qmp_testfiles],
59 driver='file', filename=disk_path,
60 node_name='imgfile')
62 blockdev_create(vm, { 'driver': imgfmt,
63 'file': 'imgfile',
64 'size': size })
65 vm.shutdown()
67 iotests.img_info_log(disk_path)
70 # Successful image creation (inline blockdev-add, explicit defaults)
72 iotests.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
73 iotests.log("")
75 # Choose a different size to show that we got a new image
76 size = 64 * 1024 * 1024
78 vm.launch()
79 blockdev_create(vm, { 'driver': 'file',
80 'filename': disk_path,
81 'size': 0,
82 'preallocation': 'off',
83 'nocow': False })
85 blockdev_create(vm, { 'driver': imgfmt,
86 'file': {
87 'driver': 'file',
88 'filename': disk_path,
90 'size': size,
91 'version': 'v3',
92 'cluster-size': 65536,
93 'preallocation': 'off',
94 'lazy-refcounts': False,
95 'refcount-bits': 16 })
96 vm.shutdown()
98 iotests.img_info_log(disk_path)
101 # Successful image creation (v3 non-default options)
103 iotests.log("=== Successful image creation (v3 non-default options) ===")
104 iotests.log("")
106 # Choose a different size to show that we got a new image
107 size = 32 * 1024 * 1024
109 vm.launch()
110 blockdev_create(vm, { 'driver': 'file',
111 'filename': disk_path,
112 'size': 0,
113 'preallocation': 'falloc',
114 'nocow': True })
116 blockdev_create(vm, { 'driver': imgfmt,
117 'file': {
118 'driver': 'file',
119 'filename': disk_path,
121 'size': size,
122 'version': 'v3',
123 'cluster-size': 2097152,
124 'preallocation': 'metadata',
125 'lazy-refcounts': True,
126 'refcount-bits': 1 })
127 vm.shutdown()
129 iotests.img_info_log(disk_path)
132 # Successful image creation (v2 non-default options)
134 iotests.log("=== Successful image creation (v2 non-default options) ===")
135 iotests.log("")
137 vm.launch()
138 blockdev_create(vm, { 'driver': 'file',
139 'filename': disk_path,
140 'size': 0 })
142 blockdev_create(vm, { 'driver': imgfmt,
143 'file': {
144 'driver': 'file',
145 'filename': disk_path,
147 'size': size,
148 'backing-file': backing_path,
149 'backing-fmt': 'qcow2',
150 'version': 'v2',
151 'cluster-size': 512 })
152 vm.shutdown()
154 iotests.img_info_log(disk_path)
157 # Successful image creation (encrypted)
159 iotests.log("=== Successful image creation (encrypted) ===")
160 iotests.log("")
162 vm.launch()
163 blockdev_create(vm, { 'driver': imgfmt,
164 'file': {
165 'driver': 'file',
166 'filename': disk_path,
168 'size': size,
169 'encrypt': {
170 'format': 'luks',
171 'key-secret': 'keysec0',
172 'cipher-alg': 'twofish-128',
173 'cipher-mode': 'ctr',
174 'ivgen-alg': 'plain64',
175 'ivgen-hash-alg': 'md5',
176 'hash-alg': 'sha1',
177 'iter-time': 10,
179 vm.shutdown()
181 iotests.img_info_log(disk_path)
184 # Invalid BlockdevRef
186 iotests.log("=== Invalid BlockdevRef ===")
187 iotests.log("")
189 vm.launch()
190 blockdev_create(vm, { 'driver': imgfmt,
191 'file': "this doesn't exist",
192 'size': size })
193 vm.shutdown()
196 # Invalid sizes
198 iotests.log("=== Invalid sizes ===")
200 # TODO Negative image sizes aren't handled correctly, but this is a problem
201 # with QAPI's implementation of the 'size' type and affects other commands
202 # as well. Once this is fixed, we may want to add a test case here.
204 # 1. Misaligned image size
205 # 2. 2^64 - 512
206 # 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
207 # 4. 2^63 - 512 (generally valid, but qcow2 can't handle images this size)
209 vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
211 vm.launch()
212 for size in [ 1234, 18446744073709551104, 9223372036854775808,
213 9223372036854775296 ]:
214 blockdev_create(vm, { 'driver': imgfmt,
215 'file': 'node0',
216 'size': size })
217 vm.shutdown()
220 # Invalid version
222 iotests.log("=== Invalid version ===")
224 vm.launch()
225 blockdev_create(vm, { 'driver': imgfmt,
226 'file': 'node0',
227 'size': 67108864,
228 'version': 'v1' })
229 blockdev_create(vm, { 'driver': imgfmt,
230 'file': 'node0',
231 'size': 67108864,
232 'version': 'v2',
233 'lazy-refcounts': True })
234 blockdev_create(vm, { 'driver': imgfmt,
235 'file': 'node0',
236 'size': 67108864,
237 'version': 'v2',
238 'refcount-bits': 8 })
239 vm.shutdown()
242 # Invalid backing file options
244 iotests.log("=== Invalid backing file options ===")
246 vm.launch()
247 blockdev_create(vm, { 'driver': imgfmt,
248 'file': 'node0',
249 'size': 67108864,
250 'backing-file': '/dev/null',
251 'preallocation': 'full' })
252 blockdev_create(vm, { 'driver': imgfmt,
253 'file': 'node0',
254 'size': 67108864,
255 'backing-fmt': imgfmt })
256 vm.shutdown()
259 # Invalid cluster size
261 iotests.log("=== Invalid cluster size ===")
263 vm.launch()
264 for csize in [ 1234, 128, 4194304, 0 ]:
265 blockdev_create(vm, { 'driver': imgfmt,
266 'file': 'node0',
267 'size': 67108864,
268 'cluster-size': csize })
269 blockdev_create(vm, { 'driver': imgfmt,
270 'file': 'node0',
271 'size': 281474976710656,
272 'cluster-size': 512 })
273 vm.shutdown()
276 # Invalid refcount width
278 iotests.log("=== Invalid refcount width ===")
280 vm.launch()
281 for refcount_bits in [ 128, 0, 7 ]:
282 blockdev_create(vm, { 'driver': imgfmt,
283 'file': 'node0',
284 'size': 67108864,
285 'refcount-bits': refcount_bits })
286 vm.shutdown()