Philippe Mathieu-Daudé | 7c47752 | 2020-01-30 17:32:30 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Vladimir Sementsov-Ogievskiy | 9dd003a | 2021-01-16 16:44:19 +0300 | [diff] [blame] | 2 | # group: rw |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 3 | # |
| 4 | # Test luks and file image creation |
| 5 | # |
| 6 | # Copyright (C) 2018 Red Hat, Inc. |
| 7 | # |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 8 | # Creator/Owner: Kevin Wolf <kwolf@redhat.com> |
| 9 | # |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 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. |
| 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 Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 24 | import iotests |
| 25 | from iotests import imgfmt |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 26 | |
John Snow | 7d81405 | 2020-03-30 20:00:11 -0400 | [diff] [blame] | 27 | iotests.script_initialize( |
| 28 | supported_fmts=['luks'], |
| 29 | supported_protocols=['file'], |
| 30 | ) |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 31 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 32 | with iotests.FilePath('t.luks') as disk_path, \ |
| 33 | iotests.VM() as vm: |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 34 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 35 | vm.add_object('secret,id=keysec0,data=foo') |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 36 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 37 | # |
| 38 | # Successful image creation (defaults) |
| 39 | # |
| 40 | iotests.log("=== Successful image creation (defaults) ===") |
| 41 | iotests.log("") |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 42 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 43 | size = 128 * 1024 * 1024 |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 44 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 45 | vm.launch() |
Kevin Wolf | e55c241 | 2019-12-16 17:57:19 +0100 | [diff] [blame] | 46 | vm.blockdev_create({ 'driver': 'file', |
| 47 | 'filename': disk_path, |
| 48 | 'size': 0 }) |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 49 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 50 | vm.qmp_log('blockdev-add', driver='file', filename=disk_path, |
Max Reitz | 250c04f | 2019-02-10 15:57:27 +0100 | [diff] [blame] | 51 | node_name='imgfile', filters=[iotests.filter_qmp_testfiles]) |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 52 | |
Kevin Wolf | e55c241 | 2019-12-16 17:57:19 +0100 | [diff] [blame] | 53 | vm.blockdev_create({ 'driver': imgfmt, |
| 54 | 'file': 'imgfile', |
| 55 | 'key-secret': 'keysec0', |
| 56 | 'size': size, |
| 57 | 'iter-time': 10 }) |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 58 | vm.shutdown() |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 59 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 60 | # 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-Ogievskiy | 3bd2b94 | 2021-12-23 17:01:26 +0100 | [diff] [blame] | 65 | use_image_opts=True) |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 66 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 67 | # |
| 68 | # Successful image creation (with non-default options) |
| 69 | # |
| 70 | iotests.log("=== Successful image creation (with non-default options) ===") |
| 71 | iotests.log("") |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 72 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 73 | size = 64 * 1024 * 1024 |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 74 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 75 | vm.launch() |
Kevin Wolf | e55c241 | 2019-12-16 17:57:19 +0100 | [diff] [blame] | 76 | 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 Reitz | cb5a24d | 2021-11-17 16:17:06 +0100 | [diff] [blame] | 86 | 'cipher-alg': 'aes-128', |
| 87 | 'cipher-mode': 'cbc', |
Kevin Wolf | e55c241 | 2019-12-16 17:57:19 +0100 | [diff] [blame] | 88 | 'ivgen-alg': 'plain64', |
| 89 | 'ivgen-hash-alg': 'md5', |
| 90 | 'hash-alg': 'sha1', |
| 91 | 'iter-time': 10 }) |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 92 | vm.shutdown() |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 93 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 94 | # 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-Ogievskiy | 3bd2b94 | 2021-12-23 17:01:26 +0100 | [diff] [blame] | 99 | use_image_opts=True) |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 100 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 101 | # |
| 102 | # Invalid BlockdevRef |
| 103 | # |
| 104 | iotests.log("=== Invalid BlockdevRef ===") |
| 105 | iotests.log("") |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 106 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 107 | size = 64 * 1024 * 1024 |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 108 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 109 | vm.launch() |
Kevin Wolf | e55c241 | 2019-12-16 17:57:19 +0100 | [diff] [blame] | 110 | vm.blockdev_create({ 'driver': imgfmt, |
| 111 | 'file': "this doesn't exist", |
| 112 | 'size': size }) |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 113 | vm.shutdown() |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 114 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 115 | # |
| 116 | # Zero size |
| 117 | # |
| 118 | iotests.log("=== Zero size ===") |
| 119 | iotests.log("") |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 120 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 121 | vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path)) |
| 122 | vm.launch() |
Kevin Wolf | e55c241 | 2019-12-16 17:57:19 +0100 | [diff] [blame] | 123 | vm.blockdev_create({ 'driver': imgfmt, |
| 124 | 'file': 'node0', |
| 125 | 'key-secret': 'keysec0', |
| 126 | 'size': 0, |
| 127 | 'iter-time': 10 }) |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 128 | vm.shutdown() |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 129 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 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'], |
Vladimir Sementsov-Ogievskiy | 3bd2b94 | 2021-12-23 17:01:26 +0100 | [diff] [blame] | 135 | use_image_opts=True) |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 136 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 137 | # |
| 138 | # Invalid sizes |
| 139 | # |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 140 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 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. |
Kevin Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 144 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 145 | # 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 Wolf | d06195e | 2018-03-02 18:38:14 +0100 | [diff] [blame] | 151 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 152 | vm.launch() |
| 153 | for size in [ 18446744073709551104, 9223372036854775808, 9223372036854775296 ]: |
Kevin Wolf | e55c241 | 2019-12-16 17:57:19 +0100 | [diff] [blame] | 154 | vm.blockdev_create({ 'driver': imgfmt, |
| 155 | 'file': 'node0', |
| 156 | 'key-secret': 'keysec0', |
| 157 | 'size': size }) |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 158 | vm.shutdown() |
Kevin Wolf | 50880f2 | 2018-03-20 16:42:12 +0100 | [diff] [blame] | 159 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 160 | # |
| 161 | # Resize image with invalid sizes |
| 162 | # |
| 163 | iotests.log("=== Resize image with invalid sizes ===") |
| 164 | iotests.log("") |
Kevin Wolf | 50880f2 | 2018-03-20 16:42:12 +0100 | [diff] [blame] | 165 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 166 | 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 Wolf | 50880f2 | 2018-03-20 16:42:12 +0100 | [diff] [blame] | 173 | |
Kevin Wolf | 5ba141d | 2018-05-23 18:19:00 +0200 | [diff] [blame] | 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'], |
Vladimir Sementsov-Ogievskiy | 3bd2b94 | 2021-12-23 17:01:26 +0100 | [diff] [blame] | 179 | use_image_opts=True) |