docs: rstfy vfio-ap documentation
[qemu/ar7.git] / tests / qemu-iotests / 237
blob50ba364a3eb9ba1717765eee0545bfdfe7a7d69a
1 #!/usr/bin/env python3
3 # Test vmdk and file image creation
5 # Copyright (C) 2018 Red Hat, Inc.
7 # Creator/Owner: Kevin Wolf <kwolf@redhat.com>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 import math
24 import iotests
25 from iotests import imgfmt
27 iotests.verify_image_format(supported_fmts=['vmdk'])
29 with iotests.FilePath('t.vmdk') as disk_path, \
30      iotests.FilePath('t.vmdk.1') as extent1_path, \
31      iotests.FilePath('t.vmdk.2') as extent2_path, \
32      iotests.FilePath('t.vmdk.3') as extent3_path, \
33      iotests.VM() as vm:
35     #
36     # Successful image creation (defaults)
37     #
38     iotests.log("=== Successful image creation (defaults) ===")
39     iotests.log("")
41     size = 5 * 1024 * 1024 * 1024
43     vm.launch()
44     vm.blockdev_create({ 'driver': 'file',
45                          'filename': disk_path,
46                          'size': 0 })
48     vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
49                node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
51     vm.blockdev_create({ 'driver': imgfmt,
52                          'file': 'imgfile',
53                          'size': size })
54     vm.shutdown()
56     iotests.img_info_log(disk_path)
58     #
59     # Successful image creation (inline blockdev-add, explicit defaults)
60     #
61     iotests.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
62     iotests.log("")
64     # Choose a different size to show that we got a new image
65     size = 64 * 1024 * 1024
67     vm.launch()
68     vm.blockdev_create({ 'driver': 'file',
69                          'filename': disk_path,
70                          'size': 0 })
72     vm.blockdev_create({ 'driver': imgfmt,
73                          'file': {
74                              'driver': 'file',
75                              'filename': disk_path,
76                          },
77                          'size': size,
78                          'extents': [],
79                          'subformat': 'monolithicSparse',
80                          'adapter-type': 'ide',
81                          'hwversion': '4',
82                          'zeroed-grain': False })
83     vm.shutdown()
85     iotests.img_info_log(disk_path)
87     #
88     # Successful image creation (non-default options)
89     #
90     iotests.log("=== Successful image creation (with non-default options) ===")
91     iotests.log("")
93     # Choose a different size to show that we got a new image
94     size = 32 * 1024 * 1024
96     vm.launch()
97     vm.blockdev_create({ 'driver': 'file',
98                          'filename': disk_path,
99                          'size': 0 })
101     vm.blockdev_create({ 'driver': imgfmt,
102                          'file': {
103                              'driver': 'file',
104                              'filename': disk_path,
105                          },
106                          'size': size,
107                          'extents': [],
108                          'subformat': 'monolithicSparse',
109                          'adapter-type': 'buslogic',
110                          'zeroed-grain': True })
111     vm.shutdown()
113     iotests.img_info_log(disk_path)
115     #
116     # Invalid BlockdevRef
117     #
118     iotests.log("=== Invalid BlockdevRef ===")
119     iotests.log("")
121     vm.launch()
122     vm.blockdev_create({ 'driver': imgfmt,
123                          'file': "this doesn't exist",
124                          'size': size })
125     vm.shutdown()
127     #
128     # Adapter types
129     #
131     iotests.log("=== Adapter types ===")
132     iotests.log("")
134     vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
136     # Valid
137     iotests.log("== Valid adapter types ==")
138     iotests.log("")
140     vm.launch()
141     for adapter_type in [ 'ide', 'buslogic', 'lsilogic', 'legacyESX' ]:
142         vm.blockdev_create({ 'driver': imgfmt,
143                              'file': 'node0',
144                              'size': size,
145                              'adapter-type': adapter_type })
146     vm.shutdown()
148     # Invalid
149     iotests.log("== Invalid adapter types ==")
150     iotests.log("")
152     vm.launch()
153     for adapter_type in [ 'foo', 'IDE', 'legacyesx', 1 ]:
154         vm.blockdev_create({ 'driver': imgfmt,
155                              'file': 'node0',
156                              'size': size,
157                              'adapter-type': adapter_type })
158     vm.shutdown()
160     #
161     # Other subformats
162     #
163     iotests.log("=== Other subformats ===")
164     iotests.log("")
166     for path in [ extent1_path, extent2_path, extent3_path ]:
167         msg = iotests.qemu_img_pipe('create', '-f', imgfmt, path, '0')
168         iotests.log(msg, [iotests.filter_testfiles])
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)