gitlab: fix inconsistent indentation
[qemu/ar7.git] / tests / qemu-iotests / 281
blob956698083f03a7d80f2076cc18c113e36f411a0b
1 #!/usr/bin/env python3
2 # group: rw quick
4 # Test cases for blockdev + IOThread interactions
6 # Copyright (C) 2019 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 import os
23 import iotests
24 from iotests import qemu_img
26 image_len = 64 * 1024 * 1024
28 # Test for RHBZ#1782175
29 class TestDirtyBitmapIOThread(iotests.QMPTestCase):
30     drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
31     images = { 'drive0': drive0_img }
33     def setUp(self):
34         for name in self.images:
35             qemu_img('create', '-f', iotests.imgfmt,
36                      self.images[name], str(image_len))
38         self.vm = iotests.VM()
39         self.vm.add_object('iothread,id=iothread0')
41         for name in self.images:
42             self.vm.add_blockdev('driver=file,filename=%s,node-name=file_%s'
43                                  % (self.images[name], name))
44             self.vm.add_blockdev('driver=qcow2,file=file_%s,node-name=%s'
45                                  % (name, name))
47         self.vm.launch()
48         self.vm.qmp('x-blockdev-set-iothread',
49                     node_name='drive0', iothread='iothread0',
50                     force=True)
52     def tearDown(self):
53         self.vm.shutdown()
54         for name in self.images:
55             os.remove(self.images[name])
57     def test_add_dirty_bitmap(self):
58         result = self.vm.qmp(
59             'block-dirty-bitmap-add',
60             node='drive0',
61             name='bitmap1',
62             persistent=True,
63         )
65         self.assert_qmp(result, 'return', {})
68 # Test for RHBZ#1746217 & RHBZ#1773517
69 class TestNBDMirrorIOThread(iotests.QMPTestCase):
70     nbd_sock = os.path.join(iotests.sock_dir, 'nbd.sock')
71     drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
72     mirror_img = os.path.join(iotests.test_dir, 'mirror.img')
73     images = { 'drive0': drive0_img, 'mirror': mirror_img }
75     def setUp(self):
76         for name in self.images:
77             qemu_img('create', '-f', iotests.imgfmt,
78                      self.images[name], str(image_len))
80         self.vm_src = iotests.VM(path_suffix='src')
81         self.vm_src.add_object('iothread,id=iothread0')
82         self.vm_src.add_blockdev('driver=file,filename=%s,node-name=file0'
83                           % (self.drive0_img))
84         self.vm_src.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
85         self.vm_src.launch()
86         self.vm_src.qmp('x-blockdev-set-iothread',
87                         node_name='drive0', iothread='iothread0',
88                         force=True)
90         self.vm_tgt = iotests.VM(path_suffix='tgt')
91         self.vm_tgt.add_object('iothread,id=iothread0')
92         self.vm_tgt.add_blockdev('driver=file,filename=%s,node-name=file0'
93                           % (self.mirror_img))
94         self.vm_tgt.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
95         self.vm_tgt.launch()
96         self.vm_tgt.qmp('x-blockdev-set-iothread',
97                         node_name='drive0', iothread='iothread0',
98                         force=True)
100     def tearDown(self):
101         self.vm_src.shutdown()
102         self.vm_tgt.shutdown()
103         for name in self.images:
104             os.remove(self.images[name])
106     def test_nbd_mirror(self):
107         result = self.vm_tgt.qmp(
108             'nbd-server-start',
109             addr={
110                 'type': 'unix',
111                 'data': { 'path': self.nbd_sock }
112             }
113         )
114         self.assert_qmp(result, 'return', {})
116         result = self.vm_tgt.qmp(
117             'nbd-server-add',
118             device='drive0',
119             writable=True
120         )
121         self.assert_qmp(result, 'return', {})
123         result = self.vm_src.qmp(
124             'drive-mirror',
125             device='drive0',
126             target='nbd+unix:///drive0?socket=' + self.nbd_sock,
127             sync='full',
128             mode='existing',
129             speed=64*1024*1024,
130             job_id='j1'
131         )
132         self.assert_qmp(result, 'return', {})
134         self.vm_src.event_wait(name="BLOCK_JOB_READY")
137 # Test for RHBZ#1779036
138 class TestExternalSnapshotAbort(iotests.QMPTestCase):
139     drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
140     snapshot_img = os.path.join(iotests.test_dir, 'snapshot.img')
141     images = { 'drive0': drive0_img, 'snapshot': snapshot_img }
143     def setUp(self):
144         for name in self.images:
145             qemu_img('create', '-f', iotests.imgfmt,
146                      self.images[name], str(image_len))
148         self.vm = iotests.VM()
149         self.vm.add_object('iothread,id=iothread0')
150         self.vm.add_blockdev('driver=file,filename=%s,node-name=file0'
151                           % (self.drive0_img))
152         self.vm.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
153         self.vm.launch()
154         self.vm.qmp('x-blockdev-set-iothread',
155                     node_name='drive0', iothread='iothread0',
156                     force=True)
158     def tearDown(self):
159         self.vm.shutdown()
160         for name in self.images:
161             os.remove(self.images[name])
163     def test_external_snapshot_abort(self):
164         # Use a two actions transaction with a bogus values on the second
165         # one to trigger an abort of the transaction.
166         result = self.vm.qmp('transaction', actions=[
167             {
168                 'type': 'blockdev-snapshot-sync',
169                 'data': { 'node-name': 'drive0',
170                           'snapshot-file': self.snapshot_img,
171                           'snapshot-node-name': 'snap1',
172                           'mode': 'absolute-paths',
173                           'format': 'qcow2' }
174             },
175             {
176                 'type': 'blockdev-snapshot-sync',
177                 'data': { 'node-name': 'drive0',
178                           'snapshot-file': '/fakesnapshot',
179                           'snapshot-node-name': 'snap2',
180                           'mode': 'absolute-paths',
181                           'format': 'qcow2' }
182             },
183         ])
185         # Crashes on failure, we expect this error.
186         self.assert_qmp(result, 'error/class', 'GenericError')
189 # Test for RHBZ#1782111
190 class TestBlockdevBackupAbort(iotests.QMPTestCase):
191     drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
192     drive1_img = os.path.join(iotests.test_dir, 'drive1.img')
193     snap0_img = os.path.join(iotests.test_dir, 'snap0.img')
194     snap1_img = os.path.join(iotests.test_dir, 'snap1.img')
195     images = { 'drive0': drive0_img,
196                'drive1': drive1_img,
197                'snap0': snap0_img,
198                'snap1': snap1_img }
200     def setUp(self):
201         for name in self.images:
202             qemu_img('create', '-f', iotests.imgfmt,
203                      self.images[name], str(image_len))
205         self.vm = iotests.VM()
206         self.vm.add_object('iothread,id=iothread0')
207         self.vm.add_device('virtio-scsi,iothread=iothread0')
209         for name in self.images:
210             self.vm.add_blockdev('driver=file,filename=%s,node-name=file_%s'
211                                  % (self.images[name], name))
212             self.vm.add_blockdev('driver=qcow2,file=file_%s,node-name=%s'
213                                  % (name, name))
215         self.vm.add_device('scsi-hd,drive=drive0')
216         self.vm.add_device('scsi-hd,drive=drive1')
217         self.vm.launch()
219     def tearDown(self):
220         self.vm.shutdown()
221         for name in self.images:
222             os.remove(self.images[name])
224     def test_blockdev_backup_abort(self):
225         # Use a two actions transaction with a bogus values on the second
226         # one to trigger an abort of the transaction.
227         result = self.vm.qmp('transaction', actions=[
228             {
229                 'type': 'blockdev-backup',
230                 'data': { 'device': 'drive0',
231                           'target': 'snap0',
232                           'sync': 'full',
233                           'job-id': 'j1' }
234             },
235             {
236                 'type': 'blockdev-backup',
237                 'data': { 'device': 'drive1',
238                           'target': 'snap1',
239                           'sync': 'full' }
240             },
241         ])
243         # Hangs on failure, we expect this error.
244         self.assert_qmp(result, 'error/class', 'GenericError')
246 if __name__ == '__main__':
247     iotests.main(supported_fmts=['qcow2'],
248                  supported_protocols=['file'])