4 # Test luks 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/>.
25 from iotests import imgfmt
27 iotests.script_initialize(
28 supported_fmts=['luks'],
29 supported_protocols=['file'],
32 with iotests.FilePath('t.luks') as disk_path, \
35 vm.add_object('secret,id=keysec0,data=foo')
38 # Successful image creation (defaults)
40 iotests.log("=== Successful image creation (defaults) ===")
43 size = 128 * 1024 * 1024
46 vm.blockdev_create({ 'driver': 'file',
47 'filename': disk_path,
50 vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
51 node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
53 vm.blockdev_create({ 'driver': imgfmt,
55 'key-secret': 'keysec0',
60 # TODO Proper support for images to be used with imgopts and/or protocols
62 'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path),
63 filter_path=disk_path,
64 extra_args=['--object', 'secret,id=keysec0,data=foo'],
68 # Successful image creation (with non-default options)
70 iotests.log("=== Successful image creation (with non-default options) ===")
73 size = 64 * 1024 * 1024
76 vm.blockdev_create({ 'driver': 'file',
77 'filename': disk_path,
79 vm.blockdev_create({ 'driver': imgfmt,
82 'filename': disk_path,
85 'key-secret': 'keysec0',
86 'cipher-alg': 'aes-128',
88 'ivgen-alg': 'plain64',
89 'ivgen-hash-alg': 'md5',
94 # TODO Proper support for images to be used with imgopts and/or protocols
96 'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path),
97 filter_path=disk_path,
98 extra_args=['--object', 'secret,id=keysec0,data=foo'],
102 # Invalid BlockdevRef
104 iotests.log("=== Invalid BlockdevRef ===")
107 size = 64 * 1024 * 1024
110 vm.blockdev_create({ 'driver': imgfmt,
111 'file': "this doesn't exist",
118 iotests.log("=== Zero size ===")
121 vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
123 vm.blockdev_create({ 'driver': imgfmt,
125 'key-secret': 'keysec0',
130 # TODO Proper support for images to be used with imgopts and/or protocols
131 iotests.img_info_log(
132 'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path),
133 filter_path=disk_path,
134 extra_args=['--object', 'secret,id=keysec0,data=foo'],
141 # TODO Negative image sizes aren't handled correctly, but this is a problem
142 # with QAPI's implementation of the 'size' type and affects other commands as
143 # well. Once this is fixed, we may want to add a test case here.
146 # 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
147 # 3. 2^63 - 512 (generally valid, but with the crypto header the file will
149 iotests.log("=== Invalid sizes ===")
153 for size in [ 18446744073709551104, 9223372036854775808, 9223372036854775296 ]:
154 vm.blockdev_create({ 'driver': imgfmt,
156 'key-secret': 'keysec0',
161 # Resize image with invalid sizes
163 iotests.log("=== Resize image with invalid sizes ===")
166 vm.add_blockdev('driver=luks,file=node0,key-secret=keysec0,node-name=node1')
168 vm.qmp_log('block_resize', node_name='node1', size=9223372036854775296)
169 vm.qmp_log('block_resize', node_name='node1', size=9223372036854775808)
170 vm.qmp_log('block_resize', node_name='node1', size=18446744073709551104)
171 vm.qmp_log('block_resize', node_name='node1', size=-9223372036854775808)
174 # TODO Proper support for images to be used with imgopts and/or protocols
175 iotests.img_info_log(
176 'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path),
177 filter_path=disk_path,
178 extra_args=['--object', 'secret,id=keysec0,data=foo'],