3 # Test luks 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/>.
24 from iotests
import imgfmt
26 iotests
.verify_image_format(supported_fmts
=['luks'])
27 iotests
.verify_protocol(supported
=['file'])
29 with iotests
.FilePath('t.luks') as disk_path
, \
32 vm
.add_object('secret,id=keysec0,data=foo')
35 # Successful image creation (defaults)
37 iotests
.log("=== Successful image creation (defaults) ===")
40 size
= 128 * 1024 * 1024
43 vm
.blockdev_create({ 'driver': 'file',
44 'filename': disk_path
,
47 vm
.qmp_log('blockdev-add', driver
='file', filename
=disk_path
,
48 node_name
='imgfile', filters
=[iotests
.filter_qmp_testfiles
])
50 vm
.blockdev_create({ 'driver': imgfmt
,
52 'key-secret': 'keysec0',
57 # TODO Proper support for images to be used with imgopts and/or protocols
59 'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path
),
60 filter_path
=disk_path
,
61 extra_args
=['--object', 'secret,id=keysec0,data=foo'],
65 # Successful image creation (with non-default options)
67 iotests
.log("=== Successful image creation (with non-default options) ===")
70 size
= 64 * 1024 * 1024
73 vm
.blockdev_create({ 'driver': 'file',
74 'filename': disk_path
,
76 vm
.blockdev_create({ 'driver': imgfmt
,
79 'filename': disk_path
,
82 'key-secret': 'keysec0',
83 'cipher-alg': 'twofish-128',
85 'ivgen-alg': 'plain64',
86 'ivgen-hash-alg': 'md5',
91 # TODO Proper support for images to be used with imgopts and/or protocols
93 'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path
),
94 filter_path
=disk_path
,
95 extra_args
=['--object', 'secret,id=keysec0,data=foo'],
101 iotests
.log("=== Invalid BlockdevRef ===")
104 size
= 64 * 1024 * 1024
107 vm
.blockdev_create({ 'driver': imgfmt
,
108 'file': "this doesn't exist",
115 iotests
.log("=== Zero size ===")
118 vm
.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path
))
120 vm
.blockdev_create({ 'driver': imgfmt
,
122 'key-secret': 'keysec0',
127 # TODO Proper support for images to be used with imgopts and/or protocols
128 iotests
.img_info_log(
129 'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path
),
130 filter_path
=disk_path
,
131 extra_args
=['--object', 'secret,id=keysec0,data=foo'],
138 # TODO Negative image sizes aren't handled correctly, but this is a problem
139 # with QAPI's implementation of the 'size' type and affects other commands as
140 # well. Once this is fixed, we may want to add a test case here.
143 # 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
144 # 3. 2^63 - 512 (generally valid, but with the crypto header the file will
146 iotests
.log("=== Invalid sizes ===")
150 for size
in [ 18446744073709551104, 9223372036854775808, 9223372036854775296 ]:
151 vm
.blockdev_create({ 'driver': imgfmt
,
153 'key-secret': 'keysec0',
158 # Resize image with invalid sizes
160 iotests
.log("=== Resize image with invalid sizes ===")
163 vm
.add_blockdev('driver=luks,file=node0,key-secret=keysec0,node-name=node1')
165 vm
.qmp_log('block_resize', node_name
='node1', size
=9223372036854775296)
166 vm
.qmp_log('block_resize', node_name
='node1', size
=9223372036854775808)
167 vm
.qmp_log('block_resize', node_name
='node1', size
=18446744073709551104)
168 vm
.qmp_log('block_resize', node_name
='node1', size
=-9223372036854775808)
171 # TODO Proper support for images to be used with imgopts and/or protocols
172 iotests
.img_info_log(
173 'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path
),
174 filter_path
=disk_path
,
175 extra_args
=['--object', 'secret,id=keysec0,data=foo'],