15ba141dcSKevin Wolf#!/usr/bin/env python 2d06195e6SKevin Wolf# 3d06195e6SKevin Wolf# Test luks and file image creation 4d06195e6SKevin Wolf# 5d06195e6SKevin Wolf# Copyright (C) 2018 Red Hat, Inc. 6d06195e6SKevin Wolf# 75ba141dcSKevin Wolf# Creator/Owner: Kevin Wolf <kwolf@redhat.com> 85ba141dcSKevin Wolf# 9d06195e6SKevin Wolf# This program is free software; you can redistribute it and/or modify 10d06195e6SKevin Wolf# it under the terms of the GNU General Public License as published by 11d06195e6SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 12d06195e6SKevin Wolf# (at your option) any later version. 13d06195e6SKevin Wolf# 14d06195e6SKevin Wolf# This program is distributed in the hope that it will be useful, 15d06195e6SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 16d06195e6SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17d06195e6SKevin Wolf# GNU General Public License for more details. 18d06195e6SKevin Wolf# 19d06195e6SKevin Wolf# You should have received a copy of the GNU General Public License 20d06195e6SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 21d06195e6SKevin Wolf# 22d06195e6SKevin Wolf 235ba141dcSKevin Wolfimport iotests 245ba141dcSKevin Wolffrom iotests import imgfmt 25d06195e6SKevin Wolf 265ba141dcSKevin Wolfiotests.verify_image_format(supported_fmts=['luks']) 275ba141dcSKevin Wolfiotests.verify_protocol(supported=['file']) 28d06195e6SKevin Wolf 295ba141dcSKevin Wolfwith iotests.FilePath('t.luks') as disk_path, \ 305ba141dcSKevin Wolf iotests.VM() as vm: 31d06195e6SKevin Wolf 325ba141dcSKevin Wolf vm.add_object('secret,id=keysec0,data=foo') 33d06195e6SKevin Wolf 345ba141dcSKevin Wolf # 355ba141dcSKevin Wolf # Successful image creation (defaults) 365ba141dcSKevin Wolf # 375ba141dcSKevin Wolf iotests.log("=== Successful image creation (defaults) ===") 385ba141dcSKevin Wolf iotests.log("") 39d06195e6SKevin Wolf 405ba141dcSKevin Wolf size = 128 * 1024 * 1024 41d06195e6SKevin Wolf 425ba141dcSKevin Wolf vm.launch() 43*e55c2413SKevin Wolf vm.blockdev_create({ 'driver': 'file', 445ba141dcSKevin Wolf 'filename': disk_path, 455ba141dcSKevin Wolf 'size': 0 }) 46d06195e6SKevin Wolf 475ba141dcSKevin Wolf vm.qmp_log('blockdev-add', driver='file', filename=disk_path, 48250c04f5SMax Reitz node_name='imgfile', filters=[iotests.filter_qmp_testfiles]) 49d06195e6SKevin Wolf 50*e55c2413SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 515ba141dcSKevin Wolf 'file': 'imgfile', 525ba141dcSKevin Wolf 'key-secret': 'keysec0', 535ba141dcSKevin Wolf 'size': size, 545ba141dcSKevin Wolf 'iter-time': 10 }) 555ba141dcSKevin Wolf vm.shutdown() 56d06195e6SKevin Wolf 575ba141dcSKevin Wolf # TODO Proper support for images to be used with imgopts and/or protocols 585ba141dcSKevin Wolf iotests.img_info_log( 595ba141dcSKevin Wolf 'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path), 605ba141dcSKevin Wolf filter_path=disk_path, 615ba141dcSKevin Wolf extra_args=['--object', 'secret,id=keysec0,data=foo'], 625ba141dcSKevin Wolf imgopts=True) 63d06195e6SKevin Wolf 645ba141dcSKevin Wolf # 655ba141dcSKevin Wolf # Successful image creation (with non-default options) 665ba141dcSKevin Wolf # 675ba141dcSKevin Wolf iotests.log("=== Successful image creation (with non-default options) ===") 685ba141dcSKevin Wolf iotests.log("") 69d06195e6SKevin Wolf 705ba141dcSKevin Wolf size = 64 * 1024 * 1024 715ba141dcSKevin Wolf 725ba141dcSKevin Wolf vm.launch() 73*e55c2413SKevin Wolf vm.blockdev_create({ 'driver': 'file', 745ba141dcSKevin Wolf 'filename': disk_path, 755ba141dcSKevin Wolf 'size': 0 }) 76*e55c2413SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 775ba141dcSKevin Wolf 'file': { 785ba141dcSKevin Wolf 'driver': 'file', 795ba141dcSKevin Wolf 'filename': disk_path, 80d06195e6SKevin Wolf }, 815ba141dcSKevin Wolf 'size': size, 825ba141dcSKevin Wolf 'key-secret': 'keysec0', 835ba141dcSKevin Wolf 'cipher-alg': 'twofish-128', 845ba141dcSKevin Wolf 'cipher-mode': 'ctr', 855ba141dcSKevin Wolf 'ivgen-alg': 'plain64', 865ba141dcSKevin Wolf 'ivgen-hash-alg': 'md5', 875ba141dcSKevin Wolf 'hash-alg': 'sha1', 885ba141dcSKevin Wolf 'iter-time': 10 }) 895ba141dcSKevin Wolf vm.shutdown() 90d06195e6SKevin Wolf 915ba141dcSKevin Wolf # TODO Proper support for images to be used with imgopts and/or protocols 925ba141dcSKevin Wolf iotests.img_info_log( 935ba141dcSKevin Wolf 'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path), 945ba141dcSKevin Wolf filter_path=disk_path, 955ba141dcSKevin Wolf extra_args=['--object', 'secret,id=keysec0,data=foo'], 965ba141dcSKevin Wolf imgopts=True) 97d06195e6SKevin Wolf 985ba141dcSKevin Wolf # 995ba141dcSKevin Wolf # Invalid BlockdevRef 1005ba141dcSKevin Wolf # 1015ba141dcSKevin Wolf iotests.log("=== Invalid BlockdevRef ===") 1025ba141dcSKevin Wolf iotests.log("") 103d06195e6SKevin Wolf 1045ba141dcSKevin Wolf size = 64 * 1024 * 1024 105d06195e6SKevin Wolf 1065ba141dcSKevin Wolf vm.launch() 107*e55c2413SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 1085ba141dcSKevin Wolf 'file': "this doesn't exist", 1095ba141dcSKevin Wolf 'size': size }) 1105ba141dcSKevin Wolf vm.shutdown() 111d06195e6SKevin Wolf 1125ba141dcSKevin Wolf # 1135ba141dcSKevin Wolf # Zero size 1145ba141dcSKevin Wolf # 1155ba141dcSKevin Wolf iotests.log("=== Zero size ===") 1165ba141dcSKevin Wolf iotests.log("") 117d06195e6SKevin Wolf 1185ba141dcSKevin Wolf vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path)) 1195ba141dcSKevin Wolf vm.launch() 120*e55c2413SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 1215ba141dcSKevin Wolf 'file': 'node0', 1225ba141dcSKevin Wolf 'key-secret': 'keysec0', 1235ba141dcSKevin Wolf 'size': 0, 1245ba141dcSKevin Wolf 'iter-time': 10 }) 1255ba141dcSKevin Wolf vm.shutdown() 126d06195e6SKevin Wolf 1275ba141dcSKevin Wolf # TODO Proper support for images to be used with imgopts and/or protocols 1285ba141dcSKevin Wolf iotests.img_info_log( 1295ba141dcSKevin Wolf 'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path), 1305ba141dcSKevin Wolf filter_path=disk_path, 1315ba141dcSKevin Wolf extra_args=['--object', 'secret,id=keysec0,data=foo'], 1325ba141dcSKevin Wolf imgopts=True) 133d06195e6SKevin Wolf 1345ba141dcSKevin Wolf # 1355ba141dcSKevin Wolf # Invalid sizes 1365ba141dcSKevin Wolf # 137d06195e6SKevin Wolf 138d06195e6SKevin Wolf # TODO Negative image sizes aren't handled correctly, but this is a problem 139d06195e6SKevin Wolf # with QAPI's implementation of the 'size' type and affects other commands as 140d06195e6SKevin Wolf # well. Once this is fixed, we may want to add a test case here. 141d06195e6SKevin Wolf 142d06195e6SKevin Wolf # 1. 2^64 - 512 143d06195e6SKevin Wolf # 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this) 144d06195e6SKevin Wolf # 3. 2^63 - 512 (generally valid, but with the crypto header the file will 145d06195e6SKevin Wolf # exceed 63 bits) 1465ba141dcSKevin Wolf iotests.log("=== Invalid sizes ===") 1475ba141dcSKevin Wolf iotests.log("") 148d06195e6SKevin Wolf 1495ba141dcSKevin Wolf vm.launch() 1505ba141dcSKevin Wolf for size in [ 18446744073709551104, 9223372036854775808, 9223372036854775296 ]: 151*e55c2413SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 1525ba141dcSKevin Wolf 'file': 'node0', 1535ba141dcSKevin Wolf 'key-secret': 'keysec0', 1545ba141dcSKevin Wolf 'size': size }) 1555ba141dcSKevin Wolf vm.shutdown() 156d06195e6SKevin Wolf 1575ba141dcSKevin Wolf # 1585ba141dcSKevin Wolf # Resize image with invalid sizes 1595ba141dcSKevin Wolf # 1605ba141dcSKevin Wolf iotests.log("=== Resize image with invalid sizes ===") 1615ba141dcSKevin Wolf iotests.log("") 16250880f25SKevin Wolf 1635ba141dcSKevin Wolf vm.add_blockdev('driver=luks,file=node0,key-secret=keysec0,node-name=node1') 1645ba141dcSKevin Wolf vm.launch() 1655ba141dcSKevin Wolf vm.qmp_log('block_resize', node_name='node1', size=9223372036854775296) 1665ba141dcSKevin Wolf vm.qmp_log('block_resize', node_name='node1', size=9223372036854775808) 1675ba141dcSKevin Wolf vm.qmp_log('block_resize', node_name='node1', size=18446744073709551104) 1685ba141dcSKevin Wolf vm.qmp_log('block_resize', node_name='node1', size=-9223372036854775808) 1695ba141dcSKevin Wolf vm.shutdown() 17050880f25SKevin Wolf 1715ba141dcSKevin Wolf # TODO Proper support for images to be used with imgopts and/or protocols 1725ba141dcSKevin Wolf iotests.img_info_log( 1735ba141dcSKevin Wolf 'driver=luks,file.driver=file,file.filename=%s,key-secret=keysec0' % (disk_path), 1745ba141dcSKevin Wolf filter_path=disk_path, 1755ba141dcSKevin Wolf extra_args=['--object', 'secret,id=keysec0,data=foo'], 1765ba141dcSKevin Wolf imgopts=True) 177