blob: 10b0a0b87cd1c38c4f675472f5609189ec497b2a [file] [log] [blame]
Philippe Mathieu-Daudé7c477522020-01-30 17:32:30 +01001#!/usr/bin/env python3
Vladimir Sementsov-Ogievskiy9dd003a2021-01-16 16:44:19 +03002# group: rw
Kevin Wolfd06195e2018-03-02 18:38:14 +01003#
4# Test luks and file image creation
5#
6# Copyright (C) 2018 Red Hat, Inc.
7#
Kevin Wolf5ba141d2018-05-23 18:19:00 +02008# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
9#
Kevin Wolfd06195e2018-03-02 18:38:14 +010010# 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.
14#
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.
19#
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/>.
22#
23
Kevin Wolf5ba141d2018-05-23 18:19:00 +020024import iotests
25from iotests import imgfmt
Kevin Wolfd06195e2018-03-02 18:38:14 +010026
John Snow7d814052020-03-30 20:00:11 -040027iotests.script_initialize(
28 supported_fmts=['luks'],
29 supported_protocols=['file'],
30)
Kevin Wolfd06195e2018-03-02 18:38:14 +010031
Kevin Wolf5ba141d2018-05-23 18:19:00 +020032with iotests.FilePath('t.luks') as disk_path, \
33 iotests.VM() as vm:
Kevin Wolfd06195e2018-03-02 18:38:14 +010034
Kevin Wolf5ba141d2018-05-23 18:19:00 +020035 vm.add_object('secret,id=keysec0,data=foo')
Kevin Wolfd06195e2018-03-02 18:38:14 +010036
Kevin Wolf5ba141d2018-05-23 18:19:00 +020037 #
38 # Successful image creation (defaults)
39 #
40 iotests.log("=== Successful image creation (defaults) ===")
41 iotests.log("")
Kevin Wolfd06195e2018-03-02 18:38:14 +010042
Kevin Wolf5ba141d2018-05-23 18:19:00 +020043 size = 128 * 1024 * 1024
Kevin Wolfd06195e2018-03-02 18:38:14 +010044
Kevin Wolf5ba141d2018-05-23 18:19:00 +020045 vm.launch()
Kevin Wolfe55c2412019-12-16 17:57:19 +010046 vm.blockdev_create({ 'driver': 'file',
47 'filename': disk_path,
48 'size': 0 })
Kevin Wolfd06195e2018-03-02 18:38:14 +010049
Kevin Wolf5ba141d2018-05-23 18:19:00 +020050 vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
Max Reitz250c04f2019-02-10 15:57:27 +010051 node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
Kevin Wolfd06195e2018-03-02 18:38:14 +010052
Kevin Wolfe55c2412019-12-16 17:57:19 +010053 vm.blockdev_create({ 'driver': imgfmt,
54 'file': 'imgfile',
55 'key-secret': 'keysec0',
56 'size': size,
57 'iter-time': 10 })
Kevin Wolf5ba141d2018-05-23 18:19:00 +020058 vm.shutdown()
Kevin Wolfd06195e2018-03-02 18:38:14 +010059
Kevin Wolf5ba141d2018-05-23 18:19:00 +020060 # TODO Proper support for images to be used with imgopts and/or protocols
61 iotests.img_info_log(
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'],
Vladimir Sementsov-Ogievskiy3bd2b942021-12-23 17:01:26 +010065 use_image_opts=True)
Kevin Wolfd06195e2018-03-02 18:38:14 +010066
Kevin Wolf5ba141d2018-05-23 18:19:00 +020067 #
68 # Successful image creation (with non-default options)
69 #
70 iotests.log("=== Successful image creation (with non-default options) ===")
71 iotests.log("")
Kevin Wolfd06195e2018-03-02 18:38:14 +010072
Kevin Wolf5ba141d2018-05-23 18:19:00 +020073 size = 64 * 1024 * 1024
Kevin Wolfd06195e2018-03-02 18:38:14 +010074
Kevin Wolf5ba141d2018-05-23 18:19:00 +020075 vm.launch()
Kevin Wolfe55c2412019-12-16 17:57:19 +010076 vm.blockdev_create({ 'driver': 'file',
77 'filename': disk_path,
78 'size': 0 })
79 vm.blockdev_create({ 'driver': imgfmt,
80 'file': {
81 'driver': 'file',
82 'filename': disk_path,
83 },
84 'size': size,
85 'key-secret': 'keysec0',
Hanna Reitzcb5a24d2021-11-17 16:17:06 +010086 'cipher-alg': 'aes-128',
87 'cipher-mode': 'cbc',
Kevin Wolfe55c2412019-12-16 17:57:19 +010088 'ivgen-alg': 'plain64',
89 'ivgen-hash-alg': 'md5',
90 'hash-alg': 'sha1',
91 'iter-time': 10 })
Kevin Wolf5ba141d2018-05-23 18:19:00 +020092 vm.shutdown()
Kevin Wolfd06195e2018-03-02 18:38:14 +010093
Kevin Wolf5ba141d2018-05-23 18:19:00 +020094 # TODO Proper support for images to be used with imgopts and/or protocols
95 iotests.img_info_log(
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'],
Vladimir Sementsov-Ogievskiy3bd2b942021-12-23 17:01:26 +010099 use_image_opts=True)
Kevin Wolfd06195e2018-03-02 18:38:14 +0100100
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200101 #
102 # Invalid BlockdevRef
103 #
104 iotests.log("=== Invalid BlockdevRef ===")
105 iotests.log("")
Kevin Wolfd06195e2018-03-02 18:38:14 +0100106
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200107 size = 64 * 1024 * 1024
Kevin Wolfd06195e2018-03-02 18:38:14 +0100108
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200109 vm.launch()
Kevin Wolfe55c2412019-12-16 17:57:19 +0100110 vm.blockdev_create({ 'driver': imgfmt,
111 'file': "this doesn't exist",
112 'size': size })
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200113 vm.shutdown()
Kevin Wolfd06195e2018-03-02 18:38:14 +0100114
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200115 #
116 # Zero size
117 #
118 iotests.log("=== Zero size ===")
119 iotests.log("")
Kevin Wolfd06195e2018-03-02 18:38:14 +0100120
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200121 vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
122 vm.launch()
Kevin Wolfe55c2412019-12-16 17:57:19 +0100123 vm.blockdev_create({ 'driver': imgfmt,
124 'file': 'node0',
125 'key-secret': 'keysec0',
126 'size': 0,
127 'iter-time': 10 })
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200128 vm.shutdown()
Kevin Wolfd06195e2018-03-02 18:38:14 +0100129
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200130 # 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'],
Vladimir Sementsov-Ogievskiy3bd2b942021-12-23 17:01:26 +0100135 use_image_opts=True)
Kevin Wolfd06195e2018-03-02 18:38:14 +0100136
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200137 #
138 # Invalid sizes
139 #
Kevin Wolfd06195e2018-03-02 18:38:14 +0100140
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200141 # 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.
Kevin Wolfd06195e2018-03-02 18:38:14 +0100144
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200145 # 1. 2^64 - 512
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
148 # exceed 63 bits)
149 iotests.log("=== Invalid sizes ===")
150 iotests.log("")
Kevin Wolfd06195e2018-03-02 18:38:14 +0100151
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200152 vm.launch()
153 for size in [ 18446744073709551104, 9223372036854775808, 9223372036854775296 ]:
Kevin Wolfe55c2412019-12-16 17:57:19 +0100154 vm.blockdev_create({ 'driver': imgfmt,
155 'file': 'node0',
156 'key-secret': 'keysec0',
157 'size': size })
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200158 vm.shutdown()
Kevin Wolf50880f22018-03-20 16:42:12 +0100159
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200160 #
161 # Resize image with invalid sizes
162 #
163 iotests.log("=== Resize image with invalid sizes ===")
164 iotests.log("")
Kevin Wolf50880f22018-03-20 16:42:12 +0100165
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200166 vm.add_blockdev('driver=luks,file=node0,key-secret=keysec0,node-name=node1')
167 vm.launch()
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)
172 vm.shutdown()
Kevin Wolf50880f22018-03-20 16:42:12 +0100173
Kevin Wolf5ba141d2018-05-23 18:19:00 +0200174 # 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'],
Vladimir Sementsov-Ogievskiy3bd2b942021-12-23 17:01:26 +0100179 use_image_opts=True)