xref: /openbmc/qemu/tests/qemu-iotests/237 (revision 1c4e7b640ba250edf0f7469ec8588a1df6dc95e5)
1*1c4e7b64SKevin Wolf#!/usr/bin/env python
2*1c4e7b64SKevin Wolf#
3*1c4e7b64SKevin Wolf# Test vmdk and file image creation
4*1c4e7b64SKevin Wolf#
5*1c4e7b64SKevin Wolf# Copyright (C) 2018 Red Hat, Inc.
6*1c4e7b64SKevin Wolf#
7*1c4e7b64SKevin Wolf# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
8*1c4e7b64SKevin Wolf#
9*1c4e7b64SKevin Wolf# This program is free software; you can redistribute it and/or modify
10*1c4e7b64SKevin Wolf# it under the terms of the GNU General Public License as published by
11*1c4e7b64SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
12*1c4e7b64SKevin Wolf# (at your option) any later version.
13*1c4e7b64SKevin Wolf#
14*1c4e7b64SKevin Wolf# This program is distributed in the hope that it will be useful,
15*1c4e7b64SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
16*1c4e7b64SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*1c4e7b64SKevin Wolf# GNU General Public License for more details.
18*1c4e7b64SKevin Wolf#
19*1c4e7b64SKevin Wolf# You should have received a copy of the GNU General Public License
20*1c4e7b64SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21*1c4e7b64SKevin Wolf#
22*1c4e7b64SKevin Wolf
23*1c4e7b64SKevin Wolfimport iotests
24*1c4e7b64SKevin Wolffrom iotests import imgfmt
25*1c4e7b64SKevin Wolf
26*1c4e7b64SKevin Wolfiotests.verify_image_format(supported_fmts=['vmdk'])
27*1c4e7b64SKevin Wolf
28*1c4e7b64SKevin Wolfdef blockdev_create(vm, options):
29*1c4e7b64SKevin Wolf    result = vm.qmp_log('blockdev-create', job_id='job0', options=options)
30*1c4e7b64SKevin Wolf
31*1c4e7b64SKevin Wolf    if 'return' in result:
32*1c4e7b64SKevin Wolf        assert result['return'] == {}
33*1c4e7b64SKevin Wolf        vm.run_job('job0')
34*1c4e7b64SKevin Wolf    iotests.log("")
35*1c4e7b64SKevin Wolf
36*1c4e7b64SKevin Wolfwith iotests.FilePath('t.vmdk') as disk_path, \
37*1c4e7b64SKevin Wolf     iotests.FilePath('t.vmdk.1') as extent1_path, \
38*1c4e7b64SKevin Wolf     iotests.FilePath('t.vmdk.2') as extent2_path, \
39*1c4e7b64SKevin Wolf     iotests.FilePath('t.vmdk.3') as extent3_path, \
40*1c4e7b64SKevin Wolf     iotests.VM() as vm:
41*1c4e7b64SKevin Wolf
42*1c4e7b64SKevin Wolf    #
43*1c4e7b64SKevin Wolf    # Successful image creation (defaults)
44*1c4e7b64SKevin Wolf    #
45*1c4e7b64SKevin Wolf    iotests.log("=== Successful image creation (defaults) ===")
46*1c4e7b64SKevin Wolf    iotests.log("")
47*1c4e7b64SKevin Wolf
48*1c4e7b64SKevin Wolf    size = 5 * 1024 * 1024 * 1024
49*1c4e7b64SKevin Wolf
50*1c4e7b64SKevin Wolf    vm.launch()
51*1c4e7b64SKevin Wolf    blockdev_create(vm, { 'driver': 'file',
52*1c4e7b64SKevin Wolf                          'filename': disk_path,
53*1c4e7b64SKevin Wolf                          'size': 0 })
54*1c4e7b64SKevin Wolf
55*1c4e7b64SKevin Wolf    vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
56*1c4e7b64SKevin Wolf               node_name='imgfile')
57*1c4e7b64SKevin Wolf
58*1c4e7b64SKevin Wolf    blockdev_create(vm, { 'driver': imgfmt,
59*1c4e7b64SKevin Wolf                          'file': 'imgfile',
60*1c4e7b64SKevin Wolf                          'size': size })
61*1c4e7b64SKevin Wolf    vm.shutdown()
62*1c4e7b64SKevin Wolf
63*1c4e7b64SKevin Wolf    iotests.img_info_log(disk_path)
64*1c4e7b64SKevin Wolf
65*1c4e7b64SKevin Wolf    #
66*1c4e7b64SKevin Wolf    # Successful image creation (inline blockdev-add, explicit defaults)
67*1c4e7b64SKevin Wolf    #
68*1c4e7b64SKevin Wolf    iotests.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
69*1c4e7b64SKevin Wolf    iotests.log("")
70*1c4e7b64SKevin Wolf
71*1c4e7b64SKevin Wolf    # Choose a different size to show that we got a new image
72*1c4e7b64SKevin Wolf    size = 64 * 1024 * 1024
73*1c4e7b64SKevin Wolf
74*1c4e7b64SKevin Wolf    vm.launch()
75*1c4e7b64SKevin Wolf    blockdev_create(vm, { 'driver': 'file',
76*1c4e7b64SKevin Wolf                          'filename': disk_path,
77*1c4e7b64SKevin Wolf                          'size': 0 })
78*1c4e7b64SKevin Wolf
79*1c4e7b64SKevin Wolf    blockdev_create(vm, { 'driver': imgfmt,
80*1c4e7b64SKevin Wolf                          'file': {
81*1c4e7b64SKevin Wolf                              'driver': 'file',
82*1c4e7b64SKevin Wolf                              'filename': disk_path,
83*1c4e7b64SKevin Wolf                          },
84*1c4e7b64SKevin Wolf                          'size': size,
85*1c4e7b64SKevin Wolf                          'extents': [],
86*1c4e7b64SKevin Wolf                          'subformat': 'monolithicSparse',
87*1c4e7b64SKevin Wolf                          'adapter-type': 'ide',
88*1c4e7b64SKevin Wolf                          'hwversion': '4',
89*1c4e7b64SKevin Wolf                          'zeroed-grain': False })
90*1c4e7b64SKevin Wolf    vm.shutdown()
91*1c4e7b64SKevin Wolf
92*1c4e7b64SKevin Wolf    iotests.img_info_log(disk_path)
93*1c4e7b64SKevin Wolf
94*1c4e7b64SKevin Wolf    #
95*1c4e7b64SKevin Wolf    # Successful image creation (non-default options)
96*1c4e7b64SKevin Wolf    #
97*1c4e7b64SKevin Wolf    iotests.log("=== Successful image creation (with non-default options) ===")
98*1c4e7b64SKevin Wolf    iotests.log("")
99*1c4e7b64SKevin Wolf
100*1c4e7b64SKevin Wolf    # Choose a different size to show that we got a new image
101*1c4e7b64SKevin Wolf    size = 32 * 1024 * 1024
102*1c4e7b64SKevin Wolf
103*1c4e7b64SKevin Wolf    vm.launch()
104*1c4e7b64SKevin Wolf    blockdev_create(vm, { 'driver': 'file',
105*1c4e7b64SKevin Wolf                          'filename': disk_path,
106*1c4e7b64SKevin Wolf                          'size': 0 })
107*1c4e7b64SKevin Wolf
108*1c4e7b64SKevin Wolf    blockdev_create(vm, { 'driver': imgfmt,
109*1c4e7b64SKevin Wolf                          'file': {
110*1c4e7b64SKevin Wolf                              'driver': 'file',
111*1c4e7b64SKevin Wolf                              'filename': disk_path,
112*1c4e7b64SKevin Wolf                          },
113*1c4e7b64SKevin Wolf                          'size': size,
114*1c4e7b64SKevin Wolf                          'extents': [],
115*1c4e7b64SKevin Wolf                          'subformat': 'monolithicSparse',
116*1c4e7b64SKevin Wolf                          'adapter-type': 'buslogic',
117*1c4e7b64SKevin Wolf                          'zeroed-grain': True })
118*1c4e7b64SKevin Wolf    vm.shutdown()
119*1c4e7b64SKevin Wolf
120*1c4e7b64SKevin Wolf    iotests.img_info_log(disk_path)
121*1c4e7b64SKevin Wolf
122*1c4e7b64SKevin Wolf    #
123*1c4e7b64SKevin Wolf    # Invalid BlockdevRef
124*1c4e7b64SKevin Wolf    #
125*1c4e7b64SKevin Wolf    iotests.log("=== Invalid BlockdevRef ===")
126*1c4e7b64SKevin Wolf    iotests.log("")
127*1c4e7b64SKevin Wolf
128*1c4e7b64SKevin Wolf    vm.launch()
129*1c4e7b64SKevin Wolf    blockdev_create(vm, { 'driver': imgfmt,
130*1c4e7b64SKevin Wolf                          'file': "this doesn't exist",
131*1c4e7b64SKevin Wolf                          'size': size })
132*1c4e7b64SKevin Wolf    vm.shutdown()
133*1c4e7b64SKevin Wolf
134*1c4e7b64SKevin Wolf    #
135*1c4e7b64SKevin Wolf    # Adapter types
136*1c4e7b64SKevin Wolf    #
137*1c4e7b64SKevin Wolf
138*1c4e7b64SKevin Wolf    iotests.log("=== Adapter types ===")
139*1c4e7b64SKevin Wolf    iotests.log("")
140*1c4e7b64SKevin Wolf
141*1c4e7b64SKevin Wolf    vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
142*1c4e7b64SKevin Wolf
143*1c4e7b64SKevin Wolf    # Valid
144*1c4e7b64SKevin Wolf    iotests.log("== Valid adapter types ==")
145*1c4e7b64SKevin Wolf    iotests.log("")
146*1c4e7b64SKevin Wolf
147*1c4e7b64SKevin Wolf    vm.launch()
148*1c4e7b64SKevin Wolf    for adapter_type in [ 'ide', 'buslogic', 'lsilogic', 'legacyESX' ]:
149*1c4e7b64SKevin Wolf        blockdev_create(vm, { 'driver': imgfmt,
150*1c4e7b64SKevin Wolf                              'file': 'node0',
151*1c4e7b64SKevin Wolf                              'size': size,
152*1c4e7b64SKevin Wolf                              'adapter-type': adapter_type })
153*1c4e7b64SKevin Wolf    vm.shutdown()
154*1c4e7b64SKevin Wolf
155*1c4e7b64SKevin Wolf    # Invalid
156*1c4e7b64SKevin Wolf    iotests.log("== Invalid adapter types ==")
157*1c4e7b64SKevin Wolf    iotests.log("")
158*1c4e7b64SKevin Wolf
159*1c4e7b64SKevin Wolf    vm.launch()
160*1c4e7b64SKevin Wolf    for adapter_type in [ 'foo', 'IDE', 'legacyesx', 1 ]:
161*1c4e7b64SKevin Wolf        blockdev_create(vm, { 'driver': imgfmt,
162*1c4e7b64SKevin Wolf                              'file': 'node0',
163*1c4e7b64SKevin Wolf                              'size': size,
164*1c4e7b64SKevin Wolf                              'adapter-type': adapter_type })
165*1c4e7b64SKevin Wolf    vm.shutdown()
166*1c4e7b64SKevin Wolf
167*1c4e7b64SKevin Wolf    #
168*1c4e7b64SKevin Wolf    # Other subformats
169*1c4e7b64SKevin Wolf    #
170*1c4e7b64SKevin Wolf    iotests.log("=== Other subformats ===")
171*1c4e7b64SKevin Wolf    iotests.log("")
172*1c4e7b64SKevin Wolf
173*1c4e7b64SKevin Wolf    for path in [ extent1_path, extent2_path, extent3_path ]:
174*1c4e7b64SKevin Wolf        msg = iotests.qemu_img_pipe('create', '-f', imgfmt, path, '0')
175*1c4e7b64SKevin Wolf        iotests.log(msg, [iotests.filter_testfiles])
176*1c4e7b64SKevin Wolf
177*1c4e7b64SKevin Wolf    vm.add_blockdev('driver=file,filename=%s,node-name=ext1' % (extent1_path))
178*1c4e7b64SKevin Wolf    vm.add_blockdev('driver=file,filename=%s,node-name=ext2' % (extent2_path))
179*1c4e7b64SKevin Wolf    vm.add_blockdev('driver=file,filename=%s,node-name=ext3' % (extent3_path))
180*1c4e7b64SKevin Wolf
181*1c4e7b64SKevin Wolf    # Missing extent
182*1c4e7b64SKevin Wolf    iotests.log("== Missing extent ==")
183*1c4e7b64SKevin Wolf    iotests.log("")
184*1c4e7b64SKevin Wolf
185*1c4e7b64SKevin Wolf    vm.launch()
186*1c4e7b64SKevin Wolf    blockdev_create(vm, { 'driver': imgfmt,
187*1c4e7b64SKevin Wolf                          'file': 'node0',
188*1c4e7b64SKevin Wolf                          'size': size,
189*1c4e7b64SKevin Wolf                          'subformat': 'monolithicFlat' })
190*1c4e7b64SKevin Wolf    vm.shutdown()
191*1c4e7b64SKevin Wolf
192*1c4e7b64SKevin Wolf    # Correct extent
193*1c4e7b64SKevin Wolf    iotests.log("== Correct extent ==")
194*1c4e7b64SKevin Wolf    iotests.log("")
195*1c4e7b64SKevin Wolf
196*1c4e7b64SKevin Wolf    vm.launch()
197*1c4e7b64SKevin Wolf    blockdev_create(vm, { 'driver': imgfmt,
198*1c4e7b64SKevin Wolf                          'file': 'node0',
199*1c4e7b64SKevin Wolf                          'size': size,
200*1c4e7b64SKevin Wolf                          'subformat': 'monolithicFlat',
201*1c4e7b64SKevin Wolf                          'extents': ['ext1'] })
202*1c4e7b64SKevin Wolf    vm.shutdown()
203*1c4e7b64SKevin Wolf
204*1c4e7b64SKevin Wolf    # Extra extent
205*1c4e7b64SKevin Wolf    iotests.log("== Extra extent ==")
206*1c4e7b64SKevin Wolf    iotests.log("")
207*1c4e7b64SKevin Wolf
208*1c4e7b64SKevin Wolf    vm.launch()
209*1c4e7b64SKevin Wolf    blockdev_create(vm, { 'driver': imgfmt,
210*1c4e7b64SKevin Wolf                          'file': 'node0',
211*1c4e7b64SKevin Wolf                          'size': 512,
212*1c4e7b64SKevin Wolf                          'subformat': 'monolithicFlat',
213*1c4e7b64SKevin Wolf                          'extents': ['ext1', 'ext2', 'ext3'] })
214*1c4e7b64SKevin Wolf    vm.shutdown()
215*1c4e7b64SKevin Wolf
216*1c4e7b64SKevin Wolf    # Split formats
217*1c4e7b64SKevin Wolf    iotests.log("== Split formats ==")
218*1c4e7b64SKevin Wolf    iotests.log("")
219*1c4e7b64SKevin Wolf
220*1c4e7b64SKevin Wolf    for size in [ 512, 1073741824, 2147483648, 5368709120 ]:
221*1c4e7b64SKevin Wolf        for subfmt in [ 'twoGbMaxExtentFlat', 'twoGbMaxExtentSparse' ]:
222*1c4e7b64SKevin Wolf            iotests.log("= %s %d =" % (subfmt, size))
223*1c4e7b64SKevin Wolf            iotests.log("")
224*1c4e7b64SKevin Wolf
225*1c4e7b64SKevin Wolf            vm.launch()
226*1c4e7b64SKevin Wolf            blockdev_create(vm, { 'driver': imgfmt,
227*1c4e7b64SKevin Wolf                                  'file': 'node0',
228*1c4e7b64SKevin Wolf                                  'size': size,
229*1c4e7b64SKevin Wolf                                  'subformat': subfmt,
230*1c4e7b64SKevin Wolf                                  'extents': ['ext1', 'ext2', 'ext3'] })
231*1c4e7b64SKevin Wolf            vm.shutdown()
232*1c4e7b64SKevin Wolf
233*1c4e7b64SKevin Wolf            iotests.img_info_log(disk_path)
234