xref: /openbmc/qemu/tests/qemu-iotests/237 (revision 9ca9c893)
1#!/usr/bin/env python3
2# group: rw quick
3#
4# Test vmdk 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
24import math
25import iotests
26from iotests import imgfmt
27
28iotests.script_initialize(supported_fmts=['vmdk'])
29
30with iotests.FilePath('t.vmdk') as disk_path, \
31     iotests.FilePath('t.vmdk.1') as extent1_path, \
32     iotests.FilePath('t.vmdk.2') as extent2_path, \
33     iotests.FilePath('t.vmdk.3') as extent3_path, \
34     iotests.VM() as vm:
35
36    #
37    # Successful image creation (defaults)
38    #
39    iotests.log("=== Successful image creation (defaults) ===")
40    iotests.log("")
41
42    size = 5 * 1024 * 1024 * 1024
43
44    vm.launch()
45    vm.blockdev_create({ 'driver': 'file',
46                         'filename': disk_path,
47                         'size': 0 })
48
49    vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
50               node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
51
52    vm.blockdev_create({ 'driver': imgfmt,
53                         'file': 'imgfile',
54                         'size': size })
55    vm.shutdown()
56
57    iotests.img_info_log(disk_path)
58
59    #
60    # Successful image creation (inline blockdev-add, explicit defaults)
61    #
62    iotests.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
63    iotests.log("")
64
65    # Choose a different size to show that we got a new image
66    size = 64 * 1024 * 1024
67
68    vm.launch()
69    vm.blockdev_create({ 'driver': 'file',
70                         'filename': disk_path,
71                         'size': 0 })
72
73    vm.blockdev_create({ 'driver': imgfmt,
74                         'file': {
75                             'driver': 'file',
76                             'filename': disk_path,
77                         },
78                         'size': size,
79                         'extents': [],
80                         'subformat': 'monolithicSparse',
81                         'adapter-type': 'ide',
82                         'hwversion': '4',
83                         'zeroed-grain': False })
84    vm.shutdown()
85
86    iotests.img_info_log(disk_path)
87
88    #
89    # Successful image creation (non-default options)
90    #
91    iotests.log("=== Successful image creation (with non-default options) ===")
92    iotests.log("")
93
94    # Choose a different size to show that we got a new image
95    size = 32 * 1024 * 1024
96
97    vm.launch()
98    vm.blockdev_create({ 'driver': 'file',
99                         'filename': disk_path,
100                         'size': 0 })
101
102    vm.blockdev_create({ 'driver': imgfmt,
103                         'file': {
104                             'driver': 'file',
105                             'filename': disk_path,
106                         },
107                         'size': size,
108                         'extents': [],
109                         'subformat': 'monolithicSparse',
110                         'adapter-type': 'buslogic',
111                         'zeroed-grain': True })
112    vm.shutdown()
113
114    iotests.img_info_log(disk_path)
115
116    #
117    # Invalid BlockdevRef
118    #
119    iotests.log("=== Invalid BlockdevRef ===")
120    iotests.log("")
121
122    vm.launch()
123    vm.blockdev_create({ 'driver': imgfmt,
124                         'file': "this doesn't exist",
125                         'size': size })
126    vm.shutdown()
127
128    #
129    # Adapter types
130    #
131
132    iotests.log("=== Adapter types ===")
133    iotests.log("")
134
135    vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
136
137    # Valid
138    iotests.log("== Valid adapter types ==")
139    iotests.log("")
140
141    vm.launch()
142    for adapter_type in [ 'ide', 'buslogic', 'lsilogic', 'legacyESX' ]:
143        vm.blockdev_create({ 'driver': imgfmt,
144                             'file': 'node0',
145                             'size': size,
146                             'adapter-type': adapter_type })
147    vm.shutdown()
148
149    # Invalid
150    iotests.log("== Invalid adapter types ==")
151    iotests.log("")
152
153    vm.launch()
154    for adapter_type in [ 'foo', 'IDE', 'legacyesx', 1 ]:
155        vm.blockdev_create({ 'driver': imgfmt,
156                             'file': 'node0',
157                             'size': size,
158                             'adapter-type': adapter_type })
159    vm.shutdown()
160
161    #
162    # Other subformats
163    #
164    iotests.log("=== Other subformats ===")
165    iotests.log("")
166
167    for path in [ extent1_path, extent2_path, extent3_path ]:
168        iotests.qemu_img_create('-f', imgfmt, path, '0')
169
170    vm.add_blockdev('driver=file,filename=%s,node-name=ext1' % (extent1_path))
171    vm.add_blockdev('driver=file,filename=%s,node-name=ext2' % (extent2_path))
172    vm.add_blockdev('driver=file,filename=%s,node-name=ext3' % (extent3_path))
173
174    # Missing extent
175    iotests.log("== Missing extent ==")
176    iotests.log("")
177
178    vm.launch()
179    vm.blockdev_create({ 'driver': imgfmt,
180                         'file': 'node0',
181                         'size': size,
182                         'subformat': 'monolithicFlat' })
183    vm.shutdown()
184
185    # Correct extent
186    iotests.log("== Correct extent ==")
187    iotests.log("")
188
189    vm.launch()
190    vm.blockdev_create({ 'driver': imgfmt,
191                         'file': 'node0',
192                         'size': size,
193                         'subformat': 'monolithicFlat',
194                         'extents': ['ext1'] })
195    vm.shutdown()
196
197    # Extra extent
198    iotests.log("== Extra extent ==")
199    iotests.log("")
200
201    vm.launch()
202    vm.blockdev_create({ 'driver': imgfmt,
203                         'file': 'node0',
204                         'size': 512,
205                         'subformat': 'monolithicFlat',
206                         'extents': ['ext1', 'ext2', 'ext3'] })
207    vm.shutdown()
208
209    # Split formats
210    iotests.log("== Split formats ==")
211    iotests.log("")
212
213    for size in [ 512, 1073741824, 2147483648, 5368709120 ]:
214        for subfmt in [ 'twoGbMaxExtentFlat', 'twoGbMaxExtentSparse' ]:
215            iotests.log("= %s %d =" % (subfmt, size))
216            iotests.log("")
217
218            num_extents = int(math.ceil(size / 2.0**31))
219            extents = [ "ext%d" % (i) for i in range(1, num_extents + 1) ]
220
221            vm.launch()
222            vm.blockdev_create({ 'driver': imgfmt,
223                                 'file': 'node0',
224                                 'size': size,
225                                 'subformat': subfmt,
226                                 'extents': extents })
227            vm.shutdown()
228
229            iotests.img_info_log(disk_path)
230