| 1 | #!/usr/bin/env python3 |
| 2 | # group: rw quick |
| 3 | # |
| 4 | # Test parallels and file image creation |
| 5 | # |
| 6 | # Copyright (C) 2018 Red Hat, Inc. |
| 7 | # |
| 8 | # Creator/Owner: Kevin Wolf <kwolf@redhat.com> |
| 9 | # |
| 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 | |
| 24 | import iotests |
| 25 | from iotests import imgfmt |
| 26 | |
| 27 | iotests.script_initialize( |
| 28 | supported_fmts=['parallels'], |
| 29 | supported_protocols=['file'], |
| 30 | ) |
| 31 | |
| 32 | with iotests.FilePath('t.parallels') as disk_path, \ |
| 33 | iotests.VM() as vm: |
| 34 | |
| 35 | # |
| 36 | # Successful image creation (defaults) |
| 37 | # |
| 38 | iotests.log("=== Successful image creation (defaults) ===") |
| 39 | iotests.log("") |
| 40 | |
| 41 | size = 128 * 1024 * 1024 |
| 42 | |
| 43 | vm.launch() |
| 44 | vm.blockdev_create({ 'driver': 'file', |
| 45 | 'filename': disk_path, |
| 46 | 'size': 0 }) |
| 47 | |
| 48 | vm.qmp_log('blockdev-add', driver='file', filename=disk_path, |
| 49 | node_name='imgfile', filters=[iotests.filter_qmp_testfiles]) |
| 50 | |
| 51 | vm.blockdev_create({ 'driver': imgfmt, |
| 52 | 'file': 'imgfile', |
| 53 | 'size': size }) |
| 54 | vm.shutdown() |
| 55 | |
| 56 | iotests.img_info_log(disk_path) |
| 57 | |
| 58 | # |
| 59 | # Successful image creation (explicit defaults) |
| 60 | # |
| 61 | iotests.log("=== Successful image creation (explicit defaults) ===") |
| 62 | iotests.log("") |
| 63 | |
| 64 | # Choose a different size to show that we got a new image |
| 65 | size = 64 * 1024 * 1024 |
| 66 | |
| 67 | vm.launch() |
| 68 | vm.blockdev_create({ 'driver': 'file', |
| 69 | 'filename': disk_path, |
| 70 | 'size': 0 }) |
| 71 | vm.blockdev_create({ 'driver': imgfmt, |
| 72 | 'file': { |
| 73 | 'driver': 'file', |
| 74 | 'filename': disk_path, |
| 75 | }, |
| 76 | 'size': size, |
| 77 | 'cluster-size': 1048576 }) |
| 78 | vm.shutdown() |
| 79 | |
| 80 | iotests.img_info_log(disk_path) |
| 81 | |
| 82 | # |
| 83 | # Successful image creation (with non-default options) |
| 84 | # |
| 85 | iotests.log("=== Successful image creation (with non-default options) ===") |
| 86 | iotests.log("") |
| 87 | |
| 88 | # Choose a different size to show that we got a new image |
| 89 | size = 32 * 1024 * 1024 |
| 90 | |
| 91 | vm.launch() |
| 92 | vm.blockdev_create({ 'driver': 'file', |
| 93 | 'filename': disk_path, |
| 94 | 'size': 0 }) |
| 95 | vm.blockdev_create({ 'driver': imgfmt, |
| 96 | 'file': { |
| 97 | 'driver': 'file', |
| 98 | 'filename': disk_path, |
| 99 | }, |
| 100 | 'size': size, |
| 101 | 'cluster-size': 65536 }) |
| 102 | vm.shutdown() |
| 103 | |
| 104 | iotests.img_info_log(disk_path) |
| 105 | |
| 106 | # |
| 107 | # Invalid BlockdevRef |
| 108 | # |
| 109 | iotests.log("=== Invalid BlockdevRef ===") |
| 110 | iotests.log("") |
| 111 | |
| 112 | vm.launch() |
| 113 | vm.blockdev_create({ 'driver': imgfmt, |
| 114 | 'file': "this doesn't exist", |
| 115 | 'size': size }) |
| 116 | vm.shutdown() |
| 117 | |
| 118 | # |
| 119 | # Zero size |
| 120 | # |
| 121 | iotests.log("=== Zero size ===") |
| 122 | iotests.log("") |
| 123 | |
| 124 | vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path)) |
| 125 | vm.launch() |
| 126 | vm.blockdev_create({ 'driver': imgfmt, |
| 127 | 'file': 'node0', |
| 128 | 'size': 0 }) |
| 129 | vm.shutdown() |
| 130 | |
| 131 | iotests.img_info_log(disk_path) |
| 132 | |
| 133 | # |
| 134 | # Maximum size |
| 135 | # |
| 136 | # Largest catalog parallels_open() can address. |
| 137 | # |
| 138 | iotests.log("=== Maximum size ===") |
| 139 | iotests.log("") |
| 140 | |
| 141 | vm.launch() |
| 142 | vm.blockdev_create({ 'driver': imgfmt, |
| 143 | 'file': 'node0', |
| 144 | 'size': 562949952372736}) |
| 145 | vm.shutdown() |
| 146 | |
| 147 | iotests.img_info_log(disk_path) |
| 148 | |
| 149 | # |
| 150 | # Invalid sizes |
| 151 | # |
| 152 | |
| 153 | # TODO Negative image sizes aren't handled correctly, but this is a problem |
| 154 | # with QAPI's implementation of the 'size' type and affects other commands |
| 155 | # as well. Once this is fixed, we may want to add a test case here. |
| 156 | |
| 157 | # 1. Misaligned image size |
| 158 | # 2. 2^64 - 512 |
| 159 | # 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this) |
| 160 | # 4. 2^63 - 512 (generally valid, but with the image header the file will |
| 161 | # exceed 63 bits) |
| 162 | # 5. 2^52 (512 bytes more than maximum image size) |
| 163 | # 6. 2^52 - 512 (wraps bat_entries to 0 at the default 1 MiB cluster size) |
| 164 | |
| 165 | iotests.log("=== Invalid sizes ===") |
| 166 | iotests.log("") |
| 167 | |
| 168 | vm.launch() |
| 169 | for size in [ 1234, 18446744073709551104, 9223372036854775808, |
| 170 | 9223372036854775296, 4503599627370497, |
| 171 | 4503599627369984 ]: |
| 172 | vm.blockdev_create({ 'driver': imgfmt, |
| 173 | 'file': 'node0', |
| 174 | 'size': size }) |
| 175 | vm.shutdown() |
| 176 | |
| 177 | # |
| 178 | # Invalid cluster size |
| 179 | # |
| 180 | iotests.log("=== Invalid cluster size ===") |
| 181 | iotests.log("") |
| 182 | |
| 183 | vm.launch() |
| 184 | for csize in [ 1234, 128, 4294967296, 9223372036854775808, |
| 185 | 18446744073709551104, 0 ]: |
| 186 | vm.blockdev_create({ 'driver': imgfmt, |
| 187 | 'file': 'node0', |
| 188 | 'size': 67108864, |
| 189 | 'cluster-size': csize }) |
| 190 | vm.blockdev_create({ 'driver': imgfmt, |
| 191 | 'file': 'node0', |
| 192 | 'size': 281474976710656, |
| 193 | 'cluster-size': 512 }) |
| 194 | vm.shutdown() |