xref: /openbmc/qemu/tests/qemu-iotests/237 (revision 9d36d5f7e0dc905d8cb3dd437e479eb536417d3b)
17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick
31c4e7b64SKevin Wolf#
41c4e7b64SKevin Wolf# Test vmdk and file image creation
51c4e7b64SKevin Wolf#
61c4e7b64SKevin Wolf# Copyright (C) 2018 Red Hat, Inc.
71c4e7b64SKevin Wolf#
81c4e7b64SKevin Wolf# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
91c4e7b64SKevin Wolf#
101c4e7b64SKevin Wolf# This program is free software; you can redistribute it and/or modify
111c4e7b64SKevin Wolf# it under the terms of the GNU General Public License as published by
121c4e7b64SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
131c4e7b64SKevin Wolf# (at your option) any later version.
141c4e7b64SKevin Wolf#
151c4e7b64SKevin Wolf# This program is distributed in the hope that it will be useful,
161c4e7b64SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
171c4e7b64SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
181c4e7b64SKevin Wolf# GNU General Public License for more details.
191c4e7b64SKevin Wolf#
201c4e7b64SKevin Wolf# You should have received a copy of the GNU General Public License
211c4e7b64SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
221c4e7b64SKevin Wolf#
231c4e7b64SKevin Wolf
244a960eceSKevin Wolfimport math
251c4e7b64SKevin Wolfimport iotests
261c4e7b64SKevin Wolffrom iotests import imgfmt
271c4e7b64SKevin Wolf
287d814059SJohn Snowiotests.script_initialize(supported_fmts=['vmdk'])
291c4e7b64SKevin Wolf
301c4e7b64SKevin Wolfwith iotests.FilePath('t.vmdk') as disk_path, \
311c4e7b64SKevin Wolf     iotests.FilePath('t.vmdk.1') as extent1_path, \
321c4e7b64SKevin Wolf     iotests.FilePath('t.vmdk.2') as extent2_path, \
331c4e7b64SKevin Wolf     iotests.FilePath('t.vmdk.3') as extent3_path, \
341c4e7b64SKevin Wolf     iotests.VM() as vm:
351c4e7b64SKevin Wolf
361c4e7b64SKevin Wolf    #
371c4e7b64SKevin Wolf    # Successful image creation (defaults)
381c4e7b64SKevin Wolf    #
391c4e7b64SKevin Wolf    iotests.log("=== Successful image creation (defaults) ===")
401c4e7b64SKevin Wolf    iotests.log("")
411c4e7b64SKevin Wolf
421c4e7b64SKevin Wolf    size = 5 * 1024 * 1024 * 1024
431c4e7b64SKevin Wolf
441c4e7b64SKevin Wolf    vm.launch()
4559f61afaSKevin Wolf    vm.blockdev_create({ 'driver': 'file',
461c4e7b64SKevin Wolf                         'filename': disk_path,
471c4e7b64SKevin Wolf                         'size': 0 })
481c4e7b64SKevin Wolf
491c4e7b64SKevin Wolf    vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
50250c04f5SMax Reitz               node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
511c4e7b64SKevin Wolf
5259f61afaSKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
531c4e7b64SKevin Wolf                         'file': 'imgfile',
541c4e7b64SKevin Wolf                         'size': size })
551c4e7b64SKevin Wolf    vm.shutdown()
561c4e7b64SKevin Wolf
571c4e7b64SKevin Wolf    iotests.img_info_log(disk_path)
581c4e7b64SKevin Wolf
591c4e7b64SKevin Wolf    #
601c4e7b64SKevin Wolf    # Successful image creation (inline blockdev-add, explicit defaults)
611c4e7b64SKevin Wolf    #
621c4e7b64SKevin Wolf    iotests.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
631c4e7b64SKevin Wolf    iotests.log("")
641c4e7b64SKevin Wolf
651c4e7b64SKevin Wolf    # Choose a different size to show that we got a new image
661c4e7b64SKevin Wolf    size = 64 * 1024 * 1024
671c4e7b64SKevin Wolf
681c4e7b64SKevin Wolf    vm.launch()
6959f61afaSKevin Wolf    vm.blockdev_create({ 'driver': 'file',
701c4e7b64SKevin Wolf                         'filename': disk_path,
711c4e7b64SKevin Wolf                         'size': 0 })
721c4e7b64SKevin Wolf
7359f61afaSKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
741c4e7b64SKevin Wolf                         'file': {
751c4e7b64SKevin Wolf                             'driver': 'file',
761c4e7b64SKevin Wolf                             'filename': disk_path,
771c4e7b64SKevin Wolf                         },
781c4e7b64SKevin Wolf                         'size': size,
791c4e7b64SKevin Wolf                         'extents': [],
801c4e7b64SKevin Wolf                         'subformat': 'monolithicSparse',
811c4e7b64SKevin Wolf                         'adapter-type': 'ide',
821c4e7b64SKevin Wolf                         'hwversion': '4',
831c4e7b64SKevin Wolf                         'zeroed-grain': False })
841c4e7b64SKevin Wolf    vm.shutdown()
851c4e7b64SKevin Wolf
861c4e7b64SKevin Wolf    iotests.img_info_log(disk_path)
871c4e7b64SKevin Wolf
881c4e7b64SKevin Wolf    #
891c4e7b64SKevin Wolf    # Successful image creation (non-default options)
901c4e7b64SKevin Wolf    #
911c4e7b64SKevin Wolf    iotests.log("=== Successful image creation (with non-default options) ===")
921c4e7b64SKevin Wolf    iotests.log("")
931c4e7b64SKevin Wolf
941c4e7b64SKevin Wolf    # Choose a different size to show that we got a new image
951c4e7b64SKevin Wolf    size = 32 * 1024 * 1024
961c4e7b64SKevin Wolf
971c4e7b64SKevin Wolf    vm.launch()
9859f61afaSKevin Wolf    vm.blockdev_create({ 'driver': 'file',
991c4e7b64SKevin Wolf                         'filename': disk_path,
1001c4e7b64SKevin Wolf                         'size': 0 })
1011c4e7b64SKevin Wolf
10259f61afaSKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
1031c4e7b64SKevin Wolf                         'file': {
1041c4e7b64SKevin Wolf                             'driver': 'file',
1051c4e7b64SKevin Wolf                             'filename': disk_path,
1061c4e7b64SKevin Wolf                         },
1071c4e7b64SKevin Wolf                         'size': size,
1081c4e7b64SKevin Wolf                         'extents': [],
1091c4e7b64SKevin Wolf                         'subformat': 'monolithicSparse',
1101c4e7b64SKevin Wolf                         'adapter-type': 'buslogic',
1111c4e7b64SKevin Wolf                         'zeroed-grain': True })
1121c4e7b64SKevin Wolf    vm.shutdown()
1131c4e7b64SKevin Wolf
1141c4e7b64SKevin Wolf    iotests.img_info_log(disk_path)
1151c4e7b64SKevin Wolf
1161c4e7b64SKevin Wolf    #
1171c4e7b64SKevin Wolf    # Invalid BlockdevRef
1181c4e7b64SKevin Wolf    #
1191c4e7b64SKevin Wolf    iotests.log("=== Invalid BlockdevRef ===")
1201c4e7b64SKevin Wolf    iotests.log("")
1211c4e7b64SKevin Wolf
1221c4e7b64SKevin Wolf    vm.launch()
12359f61afaSKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
1241c4e7b64SKevin Wolf                         'file': "this doesn't exist",
1251c4e7b64SKevin Wolf                         'size': size })
1261c4e7b64SKevin Wolf    vm.shutdown()
1271c4e7b64SKevin Wolf
1281c4e7b64SKevin Wolf    #
1291c4e7b64SKevin Wolf    # Adapter types
1301c4e7b64SKevin Wolf    #
1311c4e7b64SKevin Wolf
1321c4e7b64SKevin Wolf    iotests.log("=== Adapter types ===")
1331c4e7b64SKevin Wolf    iotests.log("")
1341c4e7b64SKevin Wolf
1351c4e7b64SKevin Wolf    vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
1361c4e7b64SKevin Wolf
1371c4e7b64SKevin Wolf    # Valid
1381c4e7b64SKevin Wolf    iotests.log("== Valid adapter types ==")
1391c4e7b64SKevin Wolf    iotests.log("")
1401c4e7b64SKevin Wolf
1411c4e7b64SKevin Wolf    vm.launch()
1421c4e7b64SKevin Wolf    for adapter_type in [ 'ide', 'buslogic', 'lsilogic', 'legacyESX' ]:
14359f61afaSKevin Wolf        vm.blockdev_create({ 'driver': imgfmt,
1441c4e7b64SKevin Wolf                             'file': 'node0',
1451c4e7b64SKevin Wolf                             'size': size,
1461c4e7b64SKevin Wolf                             'adapter-type': adapter_type })
1471c4e7b64SKevin Wolf    vm.shutdown()
1481c4e7b64SKevin Wolf
1491c4e7b64SKevin Wolf    # Invalid
1501c4e7b64SKevin Wolf    iotests.log("== Invalid adapter types ==")
1511c4e7b64SKevin Wolf    iotests.log("")
1521c4e7b64SKevin Wolf
1531c4e7b64SKevin Wolf    vm.launch()
1541c4e7b64SKevin Wolf    for adapter_type in [ 'foo', 'IDE', 'legacyesx', 1 ]:
15559f61afaSKevin Wolf        vm.blockdev_create({ 'driver': imgfmt,
1561c4e7b64SKevin Wolf                             'file': 'node0',
1571c4e7b64SKevin Wolf                             'size': size,
1581c4e7b64SKevin Wolf                             'adapter-type': adapter_type })
1591c4e7b64SKevin Wolf    vm.shutdown()
1601c4e7b64SKevin Wolf
1611c4e7b64SKevin Wolf    #
1621c4e7b64SKevin Wolf    # Other subformats
1631c4e7b64SKevin Wolf    #
1641c4e7b64SKevin Wolf    iotests.log("=== Other subformats ===")
1651c4e7b64SKevin Wolf    iotests.log("")
1661c4e7b64SKevin Wolf
1671c4e7b64SKevin Wolf    for path in [ extent1_path, extent2_path, extent3_path ]:
168*4cf661f2SJohn Snow        iotests.qemu_img_create('-f', imgfmt, path, '0')
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