aboutsummaryrefslogtreecommitdiff
path: root/tests/qemu-iotests/237
blob: 5b21ad3509fd53b4be371fc181cb941f634f203e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env python3
#
# Test vmdk and file image creation
#
# Copyright (C) 2018 Red Hat, Inc.
#
# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import math
import iotests
from iotests import imgfmt

iotests.script_initialize(supported_fmts=['vmdk'])

with iotests.FilePath('t.vmdk') as disk_path, \
     iotests.FilePath('t.vmdk.1') as extent1_path, \
     iotests.FilePath('t.vmdk.2') as extent2_path, \
     iotests.FilePath('t.vmdk.3') as extent3_path, \
     iotests.VM() as vm:

    #
    # Successful image creation (defaults)
    #
    iotests.log("=== Successful image creation (defaults) ===")
    iotests.log("")

    size = 5 * 1024 * 1024 * 1024

    vm.launch()
    vm.blockdev_create({ 'driver': 'file',
                         'filename': disk_path,
                         'size': 0 })

    vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
               node_name='imgfile', filters=[iotests.filter_qmp_testfiles])

    vm.blockdev_create({ 'driver': imgfmt,
                         'file': 'imgfile',
                         'size': size })
    vm.shutdown()

    iotests.img_info_log(disk_path)

    #
    # Successful image creation (inline blockdev-add, explicit defaults)
    #
    iotests.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
    iotests.log("")

    # Choose a different size to show that we got a new image
    size = 64 * 1024 * 1024

    vm.launch()
    vm.blockdev_create({ 'driver': 'file',
                         'filename': disk_path,
                         'size': 0 })

    vm.blockdev_create({ 'driver': imgfmt,
                         'file': {
                             'driver': 'file',
                             'filename': disk_path,
                         },
                         'size': size,
                         'extents': [],
                         'subformat': 'monolithicSparse',
                         'adapter-type': 'ide',
                         'hwversion': '4',
                         'zeroed-grain': False })
    vm.shutdown()

    iotests.img_info_log(disk_path)

    #
    # Successful image creation (non-default options)
    #
    iotests.log("=== Successful image creation (with non-default options) ===")
    iotests.log("")

    # Choose a different size to show that we got a new image
    size = 32 * 1024 * 1024

    vm.launch()
    vm.blockdev_create({ 'driver': 'file',
                         'filename': disk_path,
                         'size': 0 })

    vm.blockdev_create({ 'driver': imgfmt,
                         'file': {
                             'driver': 'file',
                             'filename': disk_path,
                         },
                         'size': size,
                         'extents': [],
                         'subformat': 'monolithicSparse',
                         'adapter-type': 'buslogic',
                         'zeroed-grain': True })
    vm.shutdown()

    iotests.img_info_log(disk_path)

    #
    # Invalid BlockdevRef
    #
    iotests.log("=== Invalid BlockdevRef ===")
    iotests.log("")

    vm.launch()
    vm.blockdev_create({ 'driver': imgfmt,
                         'file': "this doesn't exist",
                         'size': size })
    vm.shutdown()

    #
    # Adapter types
    #

    iotests.log("=== Adapter types ===")
    iotests.log("")

    vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))

    # Valid
    iotests.log("== Valid adapter types ==")
    iotests.log("")

    vm.launch()
    for adapter_type in [ 'ide', 'buslogic', 'lsilogic', 'legacyESX' ]:
        vm.blockdev_create({ 'driver': imgfmt,
                             'file': 'node0',
                             'size': size,
                             'adapter-type': adapter_type })
    vm.shutdown()

    # Invalid
    iotests.log("== Invalid adapter types ==")
    iotests.log("")

    vm.launch()
    for adapter_type in [ 'foo', 'IDE', 'legacyesx', 1 ]:
        vm.blockdev_create({ 'driver': imgfmt,
                             'file': 'node0',
                             'size': size,
                             'adapter-type': adapter_type })
    vm.shutdown()

    #
    # Other subformats
    #
    iotests.log("=== Other subformats ===")
    iotests.log("")

    for path in [ extent1_path, extent2_path, extent3_path ]:
        msg = iotests.qemu_img_pipe('create', '-f', imgfmt, path, '0')
        iotests.log(msg, [iotests.filter_testfiles])

    vm.add_blockdev('driver=file,filename=%s,node-name=ext1' % (extent1_path))
    vm.add_blockdev('driver=file,filename=%s,node-name=ext2' % (extent2_path))
    vm.add_blockdev('driver=file,filename=%s,node-name=ext3' % (extent3_path))

    # Missing extent
    iotests.log("== Missing extent ==")
    iotests.log("")

    vm.launch()
    vm.blockdev_create({ 'driver': imgfmt,
                         'file': 'node0',
                         'size': size,
                         'subformat': 'monolithicFlat' })
    vm.shutdown()

    # Correct extent
    iotests.log("== Correct extent ==")
    iotests.log("")

    vm.launch()
    vm.blockdev_create({ 'driver': imgfmt,
                         'file': 'node0',
                         'size': size,
                         'subformat': 'monolithicFlat',
                         'extents': ['ext1'] })
    vm.shutdown()

    # Extra extent
    iotests.log("== Extra extent ==")
    iotests.log("")

    vm.launch()
    vm.blockdev_create({ 'driver': imgfmt,
                         'file': 'node0',
                         'size': 512,
                         'subformat': 'monolithicFlat',
                         'extents': ['ext1', 'ext2', 'ext3'] })
    vm.shutdown()

    # Split formats
    iotests.log("== Split formats ==")
    iotests.log("")

    for size in [ 512, 1073741824, 2147483648, 5368709120 ]:
        for subfmt in [ 'twoGbMaxExtentFlat', 'twoGbMaxExtentSparse' ]:
            iotests.log("= %s %d =" % (subfmt, size))
            iotests.log("")

            num_extents = int(math.ceil(size / 2.0**31))
            extents = [ "ext%d" % (i) for i in range(1, num_extents + 1) ]

            vm.launch()
            vm.blockdev_create({ 'driver': imgfmt,
                                 'file': 'node0',
                                 'size': size,
                                 'subformat': subfmt,
                                 'extents': extents })
            vm.shutdown()

            iotests.img_info_log(disk_path)