summaryrefslogtreecommitdiffstats
path: root/tests/qemu-iotests/281
blob: 956698083f03a7d80f2076cc18c113e36f411a0b (plain) (blame)
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env python3
# group: rw quick
#
# Test cases for blockdev + IOThread interactions
#
# Copyright (C) 2019 Red Hat, Inc.
#
# 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 os
import iotests
from iotests import qemu_img

image_len = 64 * 1024 * 1024

# Test for RHBZ#1782175
class TestDirtyBitmapIOThread(iotests.QMPTestCase):
    drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
    images = { 'drive0': drive0_img }

    def setUp(self):
        for name in self.images:
            qemu_img('create', '-f', iotests.imgfmt,
                     self.images[name], str(image_len))

        self.vm = iotests.VM()
        self.vm.add_object('iothread,id=iothread0')

        for name in self.images:
            self.vm.add_blockdev('driver=file,filename=%s,node-name=file_%s'
                                 % (self.images[name], name))
            self.vm.add_blockdev('driver=qcow2,file=file_%s,node-name=%s'
                                 % (name, name))

        self.vm.launch()
        self.vm.qmp('x-blockdev-set-iothread',
                    node_name='drive0', iothread='iothread0',
                    force=True)

    def tearDown(self):
        self.vm.shutdown()
        for name in self.images:
            os.remove(self.images[name])

    def test_add_dirty_bitmap(self):
        result = self.vm.qmp(
            'block-dirty-bitmap-add',
            node='drive0',
            name='bitmap1',
            persistent=True,
        )

        self.assert_qmp(result, 'return', {})


# Test for RHBZ#1746217 & RHBZ#1773517
class TestNBDMirrorIOThread(iotests.QMPTestCase):
    nbd_sock = os.path.join(iotests.sock_dir, 'nbd.sock')
    drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
    mirror_img = os.path.join(iotests.test_dir, 'mirror.img')
    images = { 'drive0': drive0_img, 'mirror': mirror_img }

    def setUp(self):
        for name in self.images:
            qemu_img('create', '-f', iotests.imgfmt,
                     self.images[name], str(image_len))

        self.vm_src = iotests.VM(path_suffix='src')
        self.vm_src.add_object('iothread,id=iothread0')
        self.vm_src.add_blockdev('driver=file,filename=%s,node-name=file0'
                          % (self.drive0_img))
        self.vm_src.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
        self.vm_src.launch()
        self.vm_src.qmp('x-blockdev-set-iothread',
                        node_name='drive0', iothread='iothread0',
                        force=True)

        self.vm_tgt = iotests.VM(path_suffix='tgt')
        self.vm_tgt.add_object('iothread,id=iothread0')
        self.vm_tgt.add_blockdev('driver=file,filename=%s,node-name=file0'
                          % (self.mirror_img))
        self.vm_tgt.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
        self.vm_tgt.launch()
        self.vm_tgt.qmp('x-blockdev-set-iothread',
                        node_name='drive0', iothread='iothread0',
                        force=True)

    def tearDown(self):
        self.vm_src.shutdown()
        self.vm_tgt.shutdown()
        for name in self.images:
            os.remove(self.images[name])

    def test_nbd_mirror(self):
        result = self.vm_tgt.qmp(
            'nbd-server-start',
            addr={
                'type': 'unix',
                'data': { 'path': self.nbd_sock }
            }
        )
        self.assert_qmp(result, 'return', {})

        result = self.vm_tgt.qmp(
            'nbd-server-add',
            device='drive0',
            writable=True
        )
        self.assert_qmp(result, 'return', {})

        result = self.vm_src.qmp(
            'drive-mirror',
            device='drive0',
            target='nbd+unix:///drive0?socket=' + self.nbd_sock,
            sync='full',
            mode='existing',
            speed=64*1024*1024,
            job_id='j1'
        )
        self.assert_qmp(result, 'return', {})

        self.vm_src.event_wait(name="BLOCK_JOB_READY")


# Test for RHBZ#1779036
class TestExternalSnapshotAbort(iotests.QMPTestCase):
    drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
    snapshot_img = os.path.join(iotests.test_dir, 'snapshot.img')
    images = { 'drive0': drive0_img, 'snapshot': snapshot_img }

    def setUp(self):
        for name in self.images:
            qemu_img('create', '-f', iotests.imgfmt,
                     self.images[name], str(image_len))

        self.vm = iotests.VM()
        self.vm.add_object('iothread,id=iothread0')
        self.vm.add_blockdev('driver=file,filename=%s,node-name=file0'
                          % (self.drive0_img))
        self.vm.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
        self.vm.launch()
        self.vm.qmp('x-blockdev-set-iothread',
                    node_name='drive0', iothread='iothread0',
                    force=True)

    def tearDown(self):
        self.vm.shutdown()
        for name in self.images:
            os.remove(self.images[name])

    def test_external_snapshot_abort(self):
        # Use a two actions transaction with a bogus values on the second
        # one to trigger an abort of the transaction.
        result = self.vm.qmp('transaction', actions=[
            {
                'type': 'blockdev-snapshot-sync',
                'data': { 'node-name': 'drive0',
                          'snapshot-file': self.snapshot_img,
                          'snapshot-node-name': 'snap1',
                          'mode': 'absolute-paths',
                          'format': 'qcow2' }
            },
            {
                'type': 'blockdev-snapshot-sync',
                'data': { 'node-name': 'drive0',
                          'snapshot-file': '/fakesnapshot',
                          'snapshot-node-name': 'snap2',
                          'mode': 'absolute-paths',
                          'format': 'qcow2' }
            },
        ])

        # Crashes on failure, we expect this error.
        self.assert_qmp(result, 'error/class', 'GenericError')


# Test for RHBZ#1782111
class TestBlockdevBackupAbort(iotests.QMPTestCase):
    drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
    drive1_img = os.path.join(iotests.test_dir, 'drive1.img')
    snap0_img = os.path.join(iotests.test_dir, 'snap0.img')
    snap1_img = os.path.join(iotests.test_dir, 'snap1.img')
    images = { 'drive0': drive0_img,
               'drive1': drive1_img,
               'snap0': snap0_img,
               'snap1': snap1_img }

    def setUp(self):
        for name in self.images:
            qemu_img('create', '-f', iotests.imgfmt,
                     self.images[name], str(image_len))

        self.vm = iotests.VM()
        self.vm.add_object('iothread,id=iothread0')
        self.vm.add_device('virtio-scsi,iothread=iothread0')

        for name in self.images:
            self.vm.add_blockdev('driver=file,filename=%s,node-name=file_%s'
                                 % (self.images[name], name))
            self.vm.add_blockdev('driver=qcow2,file=file_%s,node-name=%s'
                                 % (name, name))

        self.vm.add_device('scsi-hd,drive=drive0')
        self.vm.add_device('scsi-hd,drive=drive1')
        self.vm.launch()

    def tearDown(self):
        self.vm.shutdown()
        for name in self.images:
            os.remove(self.images[name])

    def test_blockdev_backup_abort(self):
        # Use a two actions transaction with a bogus values on the second
        # one to trigger an abort of the transaction.
        result = self.vm.qmp('transaction', actions=[
            {
                'type': 'blockdev-backup',
                'data': { 'device': 'drive0',
                          'target': 'snap0',
                          'sync': 'full',
                          'job-id': 'j1' }
            },
            {
                'type': 'blockdev-backup',
                'data': { 'device': 'drive1',
                          'target': 'snap1',
                          'sync': 'full' }
            },
        ])

        # Hangs on failure, we expect this error.
        self.assert_qmp(result, 'error/class', 'GenericError')

if __name__ == '__main__':
    iotests.main(supported_fmts=['qcow2'],
                 supported_protocols=['file'])