xref: /qemu/tests/qemu-iotests/212 (revision 08b171380c1ac6875f585691c9ef7fa837ad1ef1)
12d7abfbeSKevin Wolf#!/usr/bin/env python
2e8f6ea6fSKevin Wolf#
3e8f6ea6fSKevin Wolf# Test parallels and file image creation
4e8f6ea6fSKevin Wolf#
5e8f6ea6fSKevin Wolf# Copyright (C) 2018 Red Hat, Inc.
6e8f6ea6fSKevin Wolf#
72d7abfbeSKevin Wolf# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
82d7abfbeSKevin Wolf#
9e8f6ea6fSKevin Wolf# This program is free software; you can redistribute it and/or modify
10e8f6ea6fSKevin Wolf# it under the terms of the GNU General Public License as published by
11e8f6ea6fSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
12e8f6ea6fSKevin Wolf# (at your option) any later version.
13e8f6ea6fSKevin Wolf#
14e8f6ea6fSKevin Wolf# This program is distributed in the hope that it will be useful,
15e8f6ea6fSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
16e8f6ea6fSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17e8f6ea6fSKevin Wolf# GNU General Public License for more details.
18e8f6ea6fSKevin Wolf#
19e8f6ea6fSKevin Wolf# You should have received a copy of the GNU General Public License
20e8f6ea6fSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21e8f6ea6fSKevin Wolf#
22e8f6ea6fSKevin Wolf
232d7abfbeSKevin Wolfimport iotests
242d7abfbeSKevin Wolffrom iotests import imgfmt
25e8f6ea6fSKevin Wolf
262d7abfbeSKevin Wolfiotests.verify_image_format(supported_fmts=['parallels'])
272d7abfbeSKevin Wolfiotests.verify_protocol(supported=['file'])
28e8f6ea6fSKevin Wolf
292d7abfbeSKevin Wolfwith iotests.FilePath('t.parallels') as disk_path, \
302d7abfbeSKevin Wolf     iotests.VM() as vm:
31e8f6ea6fSKevin Wolf
322d7abfbeSKevin Wolf    #
332d7abfbeSKevin Wolf    # Successful image creation (defaults)
342d7abfbeSKevin Wolf    #
352d7abfbeSKevin Wolf    iotests.log("=== Successful image creation (defaults) ===")
362d7abfbeSKevin Wolf    iotests.log("")
37e8f6ea6fSKevin Wolf
382d7abfbeSKevin Wolf    size = 128 * 1024 * 1024
39e8f6ea6fSKevin Wolf
402d7abfbeSKevin Wolf    vm.launch()
41*08b17138SKevin Wolf    vm.blockdev_create({ 'driver': 'file',
422d7abfbeSKevin Wolf                         'filename': disk_path,
432d7abfbeSKevin Wolf                         'size': 0 })
44e8f6ea6fSKevin Wolf
452d7abfbeSKevin Wolf    vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
46250c04f5SMax Reitz               node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
47e8f6ea6fSKevin Wolf
48*08b17138SKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
492d7abfbeSKevin Wolf                         'file': 'imgfile',
502d7abfbeSKevin Wolf                         'size': size })
512d7abfbeSKevin Wolf    vm.shutdown()
52e8f6ea6fSKevin Wolf
532d7abfbeSKevin Wolf    iotests.img_info_log(disk_path)
54e8f6ea6fSKevin Wolf
552d7abfbeSKevin Wolf    #
562d7abfbeSKevin Wolf    # Successful image creation (explicit defaults)
572d7abfbeSKevin Wolf    #
582d7abfbeSKevin Wolf    iotests.log("=== Successful image creation (explicit defaults) ===")
592d7abfbeSKevin Wolf    iotests.log("")
60e8f6ea6fSKevin Wolf
61e8f6ea6fSKevin Wolf    # Choose a different size to show that we got a new image
622d7abfbeSKevin Wolf    size = 64 * 1024 * 1024
63e8f6ea6fSKevin Wolf
642d7abfbeSKevin Wolf    vm.launch()
65*08b17138SKevin Wolf    vm.blockdev_create({ 'driver': 'file',
662d7abfbeSKevin Wolf                         'filename': disk_path,
672d7abfbeSKevin Wolf                         'size': 0 })
68*08b17138SKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
692d7abfbeSKevin Wolf                         'file': {
702d7abfbeSKevin Wolf                             'driver': 'file',
712d7abfbeSKevin Wolf                             'filename': disk_path,
72e8f6ea6fSKevin Wolf                         },
732d7abfbeSKevin Wolf                         'size': size,
742d7abfbeSKevin Wolf                         'cluster-size': 1048576 })
752d7abfbeSKevin Wolf    vm.shutdown()
76e8f6ea6fSKevin Wolf
772d7abfbeSKevin Wolf    iotests.img_info_log(disk_path)
78e8f6ea6fSKevin Wolf
792d7abfbeSKevin Wolf    #
802d7abfbeSKevin Wolf    # Successful image creation (with non-default options)
812d7abfbeSKevin Wolf    #
822d7abfbeSKevin Wolf    iotests.log("=== Successful image creation (with non-default options) ===")
832d7abfbeSKevin Wolf    iotests.log("")
84e8f6ea6fSKevin Wolf
85e8f6ea6fSKevin Wolf    # Choose a different size to show that we got a new image
862d7abfbeSKevin Wolf    size = 32 * 1024 * 1024
87e8f6ea6fSKevin Wolf
882d7abfbeSKevin Wolf    vm.launch()
89*08b17138SKevin Wolf    vm.blockdev_create({ 'driver': 'file',
902d7abfbeSKevin Wolf                         'filename': disk_path,
912d7abfbeSKevin Wolf                         'size': 0 })
92*08b17138SKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
932d7abfbeSKevin Wolf                         'file': {
942d7abfbeSKevin Wolf                             'driver': 'file',
952d7abfbeSKevin Wolf                             'filename': disk_path,
96e8f6ea6fSKevin Wolf                         },
972d7abfbeSKevin Wolf                         'size': size,
982d7abfbeSKevin Wolf                         'cluster-size': 65536 })
992d7abfbeSKevin Wolf    vm.shutdown()
100e8f6ea6fSKevin Wolf
1012d7abfbeSKevin Wolf    iotests.img_info_log(disk_path)
102e8f6ea6fSKevin Wolf
1032d7abfbeSKevin Wolf    #
1042d7abfbeSKevin Wolf    # Invalid BlockdevRef
1052d7abfbeSKevin Wolf    #
1062d7abfbeSKevin Wolf    iotests.log("=== Invalid BlockdevRef ===")
1072d7abfbeSKevin Wolf    iotests.log("")
108e8f6ea6fSKevin Wolf
1092d7abfbeSKevin Wolf    vm.launch()
110*08b17138SKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
1112d7abfbeSKevin Wolf                         'file': "this doesn't exist",
1122d7abfbeSKevin Wolf                         'size': size })
1132d7abfbeSKevin Wolf    vm.shutdown()
114e8f6ea6fSKevin Wolf
1152d7abfbeSKevin Wolf    #
1162d7abfbeSKevin Wolf    # Zero size
1172d7abfbeSKevin Wolf    #
1182d7abfbeSKevin Wolf    iotests.log("=== Zero size ===")
1192d7abfbeSKevin Wolf    iotests.log("")
120e8f6ea6fSKevin Wolf
1212d7abfbeSKevin Wolf    vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
1222d7abfbeSKevin Wolf    vm.launch()
123*08b17138SKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
1242d7abfbeSKevin Wolf                         'file': 'node0',
1252d7abfbeSKevin Wolf                         'size': 0 })
1262d7abfbeSKevin Wolf    vm.shutdown()
127e8f6ea6fSKevin Wolf
1282d7abfbeSKevin Wolf    iotests.img_info_log(disk_path)
129e8f6ea6fSKevin Wolf
1302d7abfbeSKevin Wolf    #
1312d7abfbeSKevin Wolf    # Maximum size
1322d7abfbeSKevin Wolf    #
1332d7abfbeSKevin Wolf    iotests.log("=== Maximum size ===")
1342d7abfbeSKevin Wolf    iotests.log("")
135e8f6ea6fSKevin Wolf
1362d7abfbeSKevin Wolf    vm.launch()
137*08b17138SKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
1382d7abfbeSKevin Wolf                         'file': 'node0',
1392d7abfbeSKevin Wolf                         'size': 4503599627369984})
1402d7abfbeSKevin Wolf    vm.shutdown()
141e8f6ea6fSKevin Wolf
1422d7abfbeSKevin Wolf    iotests.img_info_log(disk_path)
143e8f6ea6fSKevin Wolf
1442d7abfbeSKevin Wolf    #
1452d7abfbeSKevin Wolf    # Invalid sizes
1462d7abfbeSKevin Wolf    #
147e8f6ea6fSKevin Wolf
148e8f6ea6fSKevin Wolf    # TODO Negative image sizes aren't handled correctly, but this is a problem
1492d7abfbeSKevin Wolf    # with QAPI's implementation of the 'size' type and affects other commands
1502d7abfbeSKevin Wolf    # as well. Once this is fixed, we may want to add a test case here.
151e8f6ea6fSKevin Wolf
152e8f6ea6fSKevin Wolf    # 1. Misaligned image size
153e8f6ea6fSKevin Wolf    # 2. 2^64 - 512
154e8f6ea6fSKevin Wolf    # 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
155e8f6ea6fSKevin Wolf    # 4. 2^63 - 512 (generally valid, but with the image header the file will
156e8f6ea6fSKevin Wolf    #                exceed 63 bits)
157e8f6ea6fSKevin Wolf    # 5. 2^52 (512 bytes more than maximum image size)
158e8f6ea6fSKevin Wolf
1592d7abfbeSKevin Wolf    iotests.log("=== Invalid sizes ===")
1602d7abfbeSKevin Wolf    iotests.log("")
161e8f6ea6fSKevin Wolf
1622d7abfbeSKevin Wolf    vm.launch()
1632d7abfbeSKevin Wolf    for size in [ 1234, 18446744073709551104, 9223372036854775808,
1642d7abfbeSKevin Wolf                  9223372036854775296, 4503599627370497 ]:
165*08b17138SKevin Wolf        vm.blockdev_create({ 'driver': imgfmt,
1662d7abfbeSKevin Wolf                             'file': 'node0',
1672d7abfbeSKevin Wolf                             'size': size })
1682d7abfbeSKevin Wolf    vm.shutdown()
169e8f6ea6fSKevin Wolf
1702d7abfbeSKevin Wolf    #
1712d7abfbeSKevin Wolf    # Invalid cluster size
1722d7abfbeSKevin Wolf    #
1732d7abfbeSKevin Wolf    iotests.log("=== Invalid cluster size ===")
1742d7abfbeSKevin Wolf    iotests.log("")
175e8f6ea6fSKevin Wolf
1762d7abfbeSKevin Wolf    vm.launch()
1772d7abfbeSKevin Wolf    for csize in [ 1234, 128, 4294967296, 9223372036854775808,
1782d7abfbeSKevin Wolf                   18446744073709551104, 0 ]:
179*08b17138SKevin Wolf        vm.blockdev_create({ 'driver': imgfmt,
1802d7abfbeSKevin Wolf                             'file': 'node0',
1812d7abfbeSKevin Wolf                             'size': 67108864,
1822d7abfbeSKevin Wolf                             'cluster-size': csize })
183*08b17138SKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
1842d7abfbeSKevin Wolf                         'file': 'node0',
1852d7abfbeSKevin Wolf                         'size': 281474976710656,
1862d7abfbeSKevin Wolf                         'cluster-size': 512 })
1872d7abfbeSKevin Wolf    vm.shutdown()
188