xref: /openbmc/qemu/tests/qemu-iotests/237 (revision 7c4775260807f1428484a5cebc7bc360c46a872d)
1*7c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3
21c4e7b64SKevin Wolf#
31c4e7b64SKevin Wolf# Test vmdk and file image creation
41c4e7b64SKevin Wolf#
51c4e7b64SKevin Wolf# Copyright (C) 2018 Red Hat, Inc.
61c4e7b64SKevin Wolf#
71c4e7b64SKevin Wolf# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
81c4e7b64SKevin Wolf#
91c4e7b64SKevin Wolf# This program is free software; you can redistribute it and/or modify
101c4e7b64SKevin Wolf# it under the terms of the GNU General Public License as published by
111c4e7b64SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
121c4e7b64SKevin Wolf# (at your option) any later version.
131c4e7b64SKevin Wolf#
141c4e7b64SKevin Wolf# This program is distributed in the hope that it will be useful,
151c4e7b64SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
161c4e7b64SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
171c4e7b64SKevin Wolf# GNU General Public License for more details.
181c4e7b64SKevin Wolf#
191c4e7b64SKevin Wolf# You should have received a copy of the GNU General Public License
201c4e7b64SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
211c4e7b64SKevin Wolf#
221c4e7b64SKevin Wolf
234a960eceSKevin Wolfimport math
241c4e7b64SKevin Wolfimport iotests
251c4e7b64SKevin Wolffrom iotests import imgfmt
261c4e7b64SKevin Wolf
271c4e7b64SKevin Wolfiotests.verify_image_format(supported_fmts=['vmdk'])
281c4e7b64SKevin Wolf
291c4e7b64SKevin Wolfwith iotests.FilePath('t.vmdk') as disk_path, \
301c4e7b64SKevin Wolf     iotests.FilePath('t.vmdk.1') as extent1_path, \
311c4e7b64SKevin Wolf     iotests.FilePath('t.vmdk.2') as extent2_path, \
321c4e7b64SKevin Wolf     iotests.FilePath('t.vmdk.3') as extent3_path, \
331c4e7b64SKevin Wolf     iotests.VM() as vm:
341c4e7b64SKevin Wolf
351c4e7b64SKevin Wolf    #
361c4e7b64SKevin Wolf    # Successful image creation (defaults)
371c4e7b64SKevin Wolf    #
381c4e7b64SKevin Wolf    iotests.log("=== Successful image creation (defaults) ===")
391c4e7b64SKevin Wolf    iotests.log("")
401c4e7b64SKevin Wolf
411c4e7b64SKevin Wolf    size = 5 * 1024 * 1024 * 1024
421c4e7b64SKevin Wolf
431c4e7b64SKevin Wolf    vm.launch()
4459f61afaSKevin Wolf    vm.blockdev_create({ 'driver': 'file',
451c4e7b64SKevin Wolf                         'filename': disk_path,
461c4e7b64SKevin Wolf                         'size': 0 })
471c4e7b64SKevin Wolf
481c4e7b64SKevin Wolf    vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
49250c04f5SMax Reitz               node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
501c4e7b64SKevin Wolf
5159f61afaSKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
521c4e7b64SKevin Wolf                         'file': 'imgfile',
531c4e7b64SKevin Wolf                         'size': size })
541c4e7b64SKevin Wolf    vm.shutdown()
551c4e7b64SKevin Wolf
561c4e7b64SKevin Wolf    iotests.img_info_log(disk_path)
571c4e7b64SKevin Wolf
581c4e7b64SKevin Wolf    #
591c4e7b64SKevin Wolf    # Successful image creation (inline blockdev-add, explicit defaults)
601c4e7b64SKevin Wolf    #
611c4e7b64SKevin Wolf    iotests.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
621c4e7b64SKevin Wolf    iotests.log("")
631c4e7b64SKevin Wolf
641c4e7b64SKevin Wolf    # Choose a different size to show that we got a new image
651c4e7b64SKevin Wolf    size = 64 * 1024 * 1024
661c4e7b64SKevin Wolf
671c4e7b64SKevin Wolf    vm.launch()
6859f61afaSKevin Wolf    vm.blockdev_create({ 'driver': 'file',
691c4e7b64SKevin Wolf                         'filename': disk_path,
701c4e7b64SKevin Wolf                         'size': 0 })
711c4e7b64SKevin Wolf
7259f61afaSKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
731c4e7b64SKevin Wolf                         'file': {
741c4e7b64SKevin Wolf                             'driver': 'file',
751c4e7b64SKevin Wolf                             'filename': disk_path,
761c4e7b64SKevin Wolf                         },
771c4e7b64SKevin Wolf                         'size': size,
781c4e7b64SKevin Wolf                         'extents': [],
791c4e7b64SKevin Wolf                         'subformat': 'monolithicSparse',
801c4e7b64SKevin Wolf                         'adapter-type': 'ide',
811c4e7b64SKevin Wolf                         'hwversion': '4',
821c4e7b64SKevin Wolf                         'zeroed-grain': False })
831c4e7b64SKevin Wolf    vm.shutdown()
841c4e7b64SKevin Wolf
851c4e7b64SKevin Wolf    iotests.img_info_log(disk_path)
861c4e7b64SKevin Wolf
871c4e7b64SKevin Wolf    #
881c4e7b64SKevin Wolf    # Successful image creation (non-default options)
891c4e7b64SKevin Wolf    #
901c4e7b64SKevin Wolf    iotests.log("=== Successful image creation (with non-default options) ===")
911c4e7b64SKevin Wolf    iotests.log("")
921c4e7b64SKevin Wolf
931c4e7b64SKevin Wolf    # Choose a different size to show that we got a new image
941c4e7b64SKevin Wolf    size = 32 * 1024 * 1024
951c4e7b64SKevin Wolf
961c4e7b64SKevin Wolf    vm.launch()
9759f61afaSKevin Wolf    vm.blockdev_create({ 'driver': 'file',
981c4e7b64SKevin Wolf                         'filename': disk_path,
991c4e7b64SKevin Wolf                         'size': 0 })
1001c4e7b64SKevin Wolf
10159f61afaSKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
1021c4e7b64SKevin Wolf                         'file': {
1031c4e7b64SKevin Wolf                             'driver': 'file',
1041c4e7b64SKevin Wolf                             'filename': disk_path,
1051c4e7b64SKevin Wolf                         },
1061c4e7b64SKevin Wolf                         'size': size,
1071c4e7b64SKevin Wolf                         'extents': [],
1081c4e7b64SKevin Wolf                         'subformat': 'monolithicSparse',
1091c4e7b64SKevin Wolf                         'adapter-type': 'buslogic',
1101c4e7b64SKevin Wolf                         'zeroed-grain': True })
1111c4e7b64SKevin Wolf    vm.shutdown()
1121c4e7b64SKevin Wolf
1131c4e7b64SKevin Wolf    iotests.img_info_log(disk_path)
1141c4e7b64SKevin Wolf
1151c4e7b64SKevin Wolf    #
1161c4e7b64SKevin Wolf    # Invalid BlockdevRef
1171c4e7b64SKevin Wolf    #
1181c4e7b64SKevin Wolf    iotests.log("=== Invalid BlockdevRef ===")
1191c4e7b64SKevin Wolf    iotests.log("")
1201c4e7b64SKevin Wolf
1211c4e7b64SKevin Wolf    vm.launch()
12259f61afaSKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
1231c4e7b64SKevin Wolf                         'file': "this doesn't exist",
1241c4e7b64SKevin Wolf                         'size': size })
1251c4e7b64SKevin Wolf    vm.shutdown()
1261c4e7b64SKevin Wolf
1271c4e7b64SKevin Wolf    #
1281c4e7b64SKevin Wolf    # Adapter types
1291c4e7b64SKevin Wolf    #
1301c4e7b64SKevin Wolf
1311c4e7b64SKevin Wolf    iotests.log("=== Adapter types ===")
1321c4e7b64SKevin Wolf    iotests.log("")
1331c4e7b64SKevin Wolf
1341c4e7b64SKevin Wolf    vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
1351c4e7b64SKevin Wolf
1361c4e7b64SKevin Wolf    # Valid
1371c4e7b64SKevin Wolf    iotests.log("== Valid adapter types ==")
1381c4e7b64SKevin Wolf    iotests.log("")
1391c4e7b64SKevin Wolf
1401c4e7b64SKevin Wolf    vm.launch()
1411c4e7b64SKevin Wolf    for adapter_type in [ 'ide', 'buslogic', 'lsilogic', 'legacyESX' ]:
14259f61afaSKevin Wolf        vm.blockdev_create({ 'driver': imgfmt,
1431c4e7b64SKevin Wolf                             'file': 'node0',
1441c4e7b64SKevin Wolf                             'size': size,
1451c4e7b64SKevin Wolf                             'adapter-type': adapter_type })
1461c4e7b64SKevin Wolf    vm.shutdown()
1471c4e7b64SKevin Wolf
1481c4e7b64SKevin Wolf    # Invalid
1491c4e7b64SKevin Wolf    iotests.log("== Invalid adapter types ==")
1501c4e7b64SKevin Wolf    iotests.log("")
1511c4e7b64SKevin Wolf
1521c4e7b64SKevin Wolf    vm.launch()
1531c4e7b64SKevin Wolf    for adapter_type in [ 'foo', 'IDE', 'legacyesx', 1 ]:
15459f61afaSKevin Wolf        vm.blockdev_create({ 'driver': imgfmt,
1551c4e7b64SKevin Wolf                             'file': 'node0',
1561c4e7b64SKevin Wolf                             'size': size,
1571c4e7b64SKevin Wolf                             'adapter-type': adapter_type })
1581c4e7b64SKevin Wolf    vm.shutdown()
1591c4e7b64SKevin Wolf
1601c4e7b64SKevin Wolf    #
1611c4e7b64SKevin Wolf    # Other subformats
1621c4e7b64SKevin Wolf    #
1631c4e7b64SKevin Wolf    iotests.log("=== Other subformats ===")
1641c4e7b64SKevin Wolf    iotests.log("")
1651c4e7b64SKevin Wolf
1661c4e7b64SKevin Wolf    for path in [ extent1_path, extent2_path, extent3_path ]:
1671c4e7b64SKevin Wolf        msg = iotests.qemu_img_pipe('create', '-f', imgfmt, path, '0')
1681c4e7b64SKevin Wolf        iotests.log(msg, [iotests.filter_testfiles])
1691c4e7b64SKevin Wolf
1701c4e7b64SKevin Wolf    vm.add_blockdev('driver=file,filename=%s,node-name=ext1' % (extent1_path))
1711c4e7b64SKevin Wolf    vm.add_blockdev('driver=file,filename=%s,node-name=ext2' % (extent2_path))
1721c4e7b64SKevin Wolf    vm.add_blockdev('driver=file,filename=%s,node-name=ext3' % (extent3_path))
1731c4e7b64SKevin Wolf
1741c4e7b64SKevin Wolf    # Missing extent
1751c4e7b64SKevin Wolf    iotests.log("== Missing extent ==")
1761c4e7b64SKevin Wolf    iotests.log("")
1771c4e7b64SKevin Wolf
1781c4e7b64SKevin Wolf    vm.launch()
17959f61afaSKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
1801c4e7b64SKevin Wolf                         'file': 'node0',
1811c4e7b64SKevin Wolf                         'size': size,
1821c4e7b64SKevin Wolf                         'subformat': 'monolithicFlat' })
1831c4e7b64SKevin Wolf    vm.shutdown()
1841c4e7b64SKevin Wolf
1851c4e7b64SKevin Wolf    # Correct extent
1861c4e7b64SKevin Wolf    iotests.log("== Correct extent ==")
1871c4e7b64SKevin Wolf    iotests.log("")
1881c4e7b64SKevin Wolf
1891c4e7b64SKevin Wolf    vm.launch()
19059f61afaSKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
1911c4e7b64SKevin Wolf                         'file': 'node0',
1921c4e7b64SKevin Wolf                         'size': size,
1931c4e7b64SKevin Wolf                         'subformat': 'monolithicFlat',
1941c4e7b64SKevin Wolf                         'extents': ['ext1'] })
1951c4e7b64SKevin Wolf    vm.shutdown()
1961c4e7b64SKevin Wolf
1971c4e7b64SKevin Wolf    # Extra extent
1981c4e7b64SKevin Wolf    iotests.log("== Extra extent ==")
1991c4e7b64SKevin Wolf    iotests.log("")
2001c4e7b64SKevin Wolf
2011c4e7b64SKevin Wolf    vm.launch()
20259f61afaSKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
2031c4e7b64SKevin Wolf                         'file': 'node0',
2041c4e7b64SKevin Wolf                         'size': 512,
2051c4e7b64SKevin Wolf                         'subformat': 'monolithicFlat',
2061c4e7b64SKevin Wolf                         'extents': ['ext1', 'ext2', 'ext3'] })
2071c4e7b64SKevin Wolf    vm.shutdown()
2081c4e7b64SKevin Wolf
2091c4e7b64SKevin Wolf    # Split formats
2101c4e7b64SKevin Wolf    iotests.log("== Split formats ==")
2111c4e7b64SKevin Wolf    iotests.log("")
2121c4e7b64SKevin Wolf
2131c4e7b64SKevin Wolf    for size in [ 512, 1073741824, 2147483648, 5368709120 ]:
2141c4e7b64SKevin Wolf        for subfmt in [ 'twoGbMaxExtentFlat', 'twoGbMaxExtentSparse' ]:
2151c4e7b64SKevin Wolf            iotests.log("= %s %d =" % (subfmt, size))
2161c4e7b64SKevin Wolf            iotests.log("")
2171c4e7b64SKevin Wolf
21810ba68d1SMax Reitz            num_extents = int(math.ceil(size / 2.0**31))
2194a960eceSKevin Wolf            extents = [ "ext%d" % (i) for i in range(1, num_extents + 1) ]
2204a960eceSKevin Wolf
2211c4e7b64SKevin Wolf            vm.launch()
22259f61afaSKevin Wolf            vm.blockdev_create({ 'driver': imgfmt,
2231c4e7b64SKevin Wolf                                 'file': 'node0',
2241c4e7b64SKevin Wolf                                 'size': size,
2251c4e7b64SKevin Wolf                                 'subformat': subfmt,
2264a960eceSKevin Wolf                                 'extents': extents })
2271c4e7b64SKevin Wolf            vm.shutdown()
2281c4e7b64SKevin Wolf
2291c4e7b64SKevin Wolf            iotests.img_info_log(disk_path)
230