Merge tag 'v9.0.0-rc3'
[qemu/ar7.git] / tests / qemu-iotests / 237
blob5ea13eb01fc288d080fc1152db5acbfcae3fd5f8
1 #!/usr/bin/env python3
2 # group: rw quick
4 # Test vmdk and file image creation
6 # Copyright (C) 2018 Red Hat, Inc.
8 # Creator/Owner: Kevin Wolf <kwolf@redhat.com>
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.
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.
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/>.
24 import math
25 import iotests
26 from iotests import imgfmt
28 iotests.script_initialize(supported_fmts=['vmdk'])
30 with 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:
36     #
37     # Successful image creation (defaults)
38     #
39     iotests.log("=== Successful image creation (defaults) ===")
40     iotests.log("")
42     size = 5 * 1024 * 1024 * 1024
44     vm.launch()
45     vm.blockdev_create({ 'driver': 'file',
46                          'filename': disk_path,
47                          'size': 0 })
49     vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
50                node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
52     vm.blockdev_create({ 'driver': imgfmt,
53                          'file': 'imgfile',
54                          'size': size })
55     vm.shutdown()
57     iotests.img_info_log(disk_path)
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("")
65     # Choose a different size to show that we got a new image
66     size = 64 * 1024 * 1024
68     vm.launch()
69     vm.blockdev_create({ 'driver': 'file',
70                          'filename': disk_path,
71                          'size': 0 })
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()
86     iotests.img_info_log(disk_path)
88     #
89     # Successful image creation (non-default options)
90     #
91     iotests.log("=== Successful image creation (with non-default options) ===")
92     iotests.log("")
94     # Choose a different size to show that we got a new image
95     size = 32 * 1024 * 1024
97     vm.launch()
98     vm.blockdev_create({ 'driver': 'file',
99                          'filename': disk_path,
100                          'size': 0 })
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()
114     iotests.img_info_log(disk_path)
116     #
117     # Invalid BlockdevRef
118     #
119     iotests.log("=== Invalid BlockdevRef ===")
120     iotests.log("")
122     vm.launch()
123     vm.blockdev_create({ 'driver': imgfmt,
124                          'file': "this doesn't exist",
125                          'size': size })
126     vm.shutdown()
128     #
129     # Adapter types
130     #
132     iotests.log("=== Adapter types ===")
133     iotests.log("")
135     vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
137     # Valid
138     iotests.log("== Valid adapter types ==")
139     iotests.log("")
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()
149     # Invalid
150     iotests.log("== Invalid adapter types ==")
151     iotests.log("")
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()
161     #
162     # Other subformats
163     #
164     iotests.log("=== Other subformats ===")
165     iotests.log("")
167     for path in [ extent1_path, extent2_path, extent3_path ]:
168         iotests.qemu_img_create('-f', imgfmt, path, '0')
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))
174     # Missing extent
175     iotests.log("== Missing extent ==")
176     iotests.log("")
178     vm.launch()
179     vm.blockdev_create({ 'driver': imgfmt,
180                          'file': 'node0',
181                          'size': size,
182                          'subformat': 'monolithicFlat' })
183     vm.shutdown()
185     # Correct extent
186     iotests.log("== Correct extent ==")
187     iotests.log("")
189     vm.launch()
190     vm.blockdev_create({ 'driver': imgfmt,
191                          'file': 'node0',
192                          'size': size,
193                          'subformat': 'monolithicFlat',
194                          'extents': ['ext1'] })
195     vm.shutdown()
197     # Extra extent
198     iotests.log("== Extra extent ==")
199     iotests.log("")
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()
209     # Split formats
210     iotests.log("== Split formats ==")
211     iotests.log("")
213     for size in [ 512, 1073741824, 2147483648, 5368709120 ]:
214         for subfmt in [ 'twoGbMaxExtentFlat', 'twoGbMaxExtentSparse' ]:
215             iotests.log("= %s %d =" % (subfmt, size))
216             iotests.log("")
218             num_extents = int(math.ceil(size / 2.0**31))
219             extents = [ "ext%d" % (i) for i in range(1, num_extents + 1) ]
221             vm.launch()
222             vm.blockdev_create({ 'driver': imgfmt,
223                                  'file': 'node0',
224                                  'size': size,
225                                  'subformat': subfmt,
226                                  'extents': extents })
227             vm.shutdown()
229             iotests.img_info_log(disk_path)