]>
git.proxmox.com Git - mirror_qemu.git/blob - tests/qemu-iotests/040
3 # Tests for image block commit.
5 # Copyright (C) 2012 IBM, Corp.
6 # Copyright (C) 2012 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/>.
21 # Test for live block commit
22 # Derived from Image Streaming Test 030
27 from iotests
import qemu_img
, qemu_io
31 backing_img
= os
.path
.join(iotests
.test_dir
, 'backing.img')
32 mid_img
= os
.path
.join(iotests
.test_dir
, 'mid.img')
33 test_img
= os
.path
.join(iotests
.test_dir
, 'test.img')
35 class ImageCommitTestCase(iotests
.QMPTestCase
):
36 '''Abstract base class for image commit test cases'''
38 def assert_no_active_commit(self
):
39 result
= self
.vm
.qmp('query-block-jobs')
40 self
.assert_qmp(result
, 'return', [])
42 def run_commit_test(self
, top
, base
):
43 self
.assert_no_active_commit()
44 result
= self
.vm
.qmp('block-commit', device
='drive0', top
=top
, base
=base
)
45 self
.assert_qmp(result
, 'return', {})
49 for event
in self
.vm
.get_qmp_events(wait
=True):
50 if event
['event'] == 'BLOCK_JOB_COMPLETED':
51 self
.assert_qmp(event
, 'data/type', 'commit')
52 self
.assert_qmp(event
, 'data/device', 'drive0')
53 self
.assert_qmp(event
, 'data/offset', self
.image_len
)
54 self
.assert_qmp(event
, 'data/len', self
.image_len
)
56 elif event
['event'] == 'BLOCK_JOB_READY':
57 self
.assert_qmp(event
, 'data/type', 'commit')
58 self
.assert_qmp(event
, 'data/device', 'drive0')
59 self
.assert_qmp(event
, 'data/len', self
.image_len
)
60 self
.vm
.qmp('block-job-complete', device
='drive0')
62 self
.assert_no_active_commit()
65 class TestSingleDrive(ImageCommitTestCase
):
66 image_len
= 1 * 1024 * 1024
67 test_len
= 1 * 1024 * 256
70 iotests
.create_image(backing_img
, TestSingleDrive
.image_len
)
71 qemu_img('create', '-f', iotests
.imgfmt
, '-o', 'backing_file=%s' % backing_img
, mid_img
)
72 qemu_img('create', '-f', iotests
.imgfmt
, '-o', 'backing_file=%s' % mid_img
, test_img
)
73 qemu_io('-c', 'write -P 0xab 0 524288', backing_img
)
74 qemu_io('-c', 'write -P 0xef 524288 524288', mid_img
)
75 self
.vm
= iotests
.VM().add_drive(test_img
)
82 os
.remove(backing_img
)
84 def test_commit(self
):
85 self
.run_commit_test(mid_img
, backing_img
)
86 self
.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', backing_img
).find("verification failed"))
87 self
.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img
).find("verification failed"))
89 def test_device_not_found(self
):
90 result
= self
.vm
.qmp('block-commit', device
='nonexistent', top
='%s' % mid_img
)
91 self
.assert_qmp(result
, 'error/class', 'DeviceNotFound')
93 def test_top_same_base(self
):
94 self
.assert_no_active_commit()
95 result
= self
.vm
.qmp('block-commit', device
='drive0', top
='%s' % backing_img
, base
='%s' % backing_img
)
96 self
.assert_qmp(result
, 'error/class', 'GenericError')
97 self
.assert_qmp(result
, 'error/desc', 'Base \'%s\' not found' % backing_img
)
99 def test_top_invalid(self
):
100 self
.assert_no_active_commit()
101 result
= self
.vm
.qmp('block-commit', device
='drive0', top
='badfile', base
='%s' % backing_img
)
102 self
.assert_qmp(result
, 'error/class', 'GenericError')
103 self
.assert_qmp(result
, 'error/desc', 'Top image file badfile not found')
105 def test_base_invalid(self
):
106 self
.assert_no_active_commit()
107 result
= self
.vm
.qmp('block-commit', device
='drive0', top
='%s' % mid_img
, base
='badfile')
108 self
.assert_qmp(result
, 'error/class', 'GenericError')
109 self
.assert_qmp(result
, 'error/desc', 'Base \'badfile\' not found')
111 def test_top_is_active(self
):
112 self
.run_commit_test(test_img
, backing_img
)
113 self
.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', backing_img
).find("verification failed"))
114 self
.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img
).find("verification failed"))
116 def test_top_and_base_reversed(self
):
117 self
.assert_no_active_commit()
118 result
= self
.vm
.qmp('block-commit', device
='drive0', top
='%s' % backing_img
, base
='%s' % mid_img
)
119 self
.assert_qmp(result
, 'error/class', 'GenericError')
120 self
.assert_qmp(result
, 'error/desc', 'Base \'%s\' not found' % mid_img
)
122 def test_top_omitted(self
):
123 self
.assert_no_active_commit()
124 result
= self
.vm
.qmp('block-commit', device
='drive0')
125 self
.assert_qmp(result
, 'error/class', 'GenericError')
126 self
.assert_qmp(result
, 'error/desc', "Parameter 'top' is missing")
128 class TestRelativePaths(ImageCommitTestCase
):
129 image_len
= 1 * 1024 * 1024
130 test_len
= 1 * 1024 * 256
136 test_img
= os
.path
.join(iotests
.test_dir
, dir3
, 'test.img')
137 mid_img
= "../mid.img"
138 backing_img
= "../dir1/backing.img"
140 backing_img_abs
= os
.path
.join(iotests
.test_dir
, dir1
, 'backing.img')
141 mid_img_abs
= os
.path
.join(iotests
.test_dir
, dir2
, 'mid.img')
145 os
.mkdir(os
.path
.join(iotests
.test_dir
, self
.dir1
))
146 os
.mkdir(os
.path
.join(iotests
.test_dir
, self
.dir2
))
147 os
.mkdir(os
.path
.join(iotests
.test_dir
, self
.dir3
))
148 except OSError as exception
:
149 if exception
.errno
!= errno
.EEXIST
:
151 iotests
.create_image(self
.backing_img_abs
, TestRelativePaths
.image_len
)
152 qemu_img('create', '-f', iotests
.imgfmt
, '-o', 'backing_file=%s' % self
.backing_img_abs
, self
.mid_img_abs
)
153 qemu_img('create', '-f', iotests
.imgfmt
, '-o', 'backing_file=%s' % self
.mid_img_abs
, self
.test_img
)
154 qemu_img('rebase', '-u', '-b', self
.backing_img
, self
.mid_img_abs
)
155 qemu_img('rebase', '-u', '-b', self
.mid_img
, self
.test_img
)
156 qemu_io('-c', 'write -P 0xab 0 524288', self
.backing_img_abs
)
157 qemu_io('-c', 'write -P 0xef 524288 524288', self
.mid_img_abs
)
158 self
.vm
= iotests
.VM().add_drive(self
.test_img
)
163 os
.remove(self
.test_img
)
164 os
.remove(self
.mid_img_abs
)
165 os
.remove(self
.backing_img_abs
)
167 os
.rmdir(os
.path
.join(iotests
.test_dir
, self
.dir1
))
168 os
.rmdir(os
.path
.join(iotests
.test_dir
, self
.dir3
))
169 os
.rmdir(os
.path
.join(iotests
.test_dir
, self
.dir2
))
170 except OSError as exception
:
171 if exception
.errno
!= errno
.EEXIST
and exception
.errno
!= errno
.ENOTEMPTY
:
174 def test_commit(self
):
175 self
.run_commit_test(self
.mid_img
, self
.backing_img
)
176 self
.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', self
.backing_img_abs
).find("verification failed"))
177 self
.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', self
.backing_img_abs
).find("verification failed"))
179 def test_device_not_found(self
):
180 result
= self
.vm
.qmp('block-commit', device
='nonexistent', top
='%s' % self
.mid_img
)
181 self
.assert_qmp(result
, 'error/class', 'DeviceNotFound')
183 def test_top_same_base(self
):
184 self
.assert_no_active_commit()
185 result
= self
.vm
.qmp('block-commit', device
='drive0', top
='%s' % self
.mid_img
, base
='%s' % self
.mid_img
)
186 self
.assert_qmp(result
, 'error/class', 'GenericError')
187 self
.assert_qmp(result
, 'error/desc', 'Base \'%s\' not found' % self
.mid_img
)
189 def test_top_invalid(self
):
190 self
.assert_no_active_commit()
191 result
= self
.vm
.qmp('block-commit', device
='drive0', top
='badfile', base
='%s' % self
.backing_img
)
192 self
.assert_qmp(result
, 'error/class', 'GenericError')
193 self
.assert_qmp(result
, 'error/desc', 'Top image file badfile not found')
195 def test_base_invalid(self
):
196 self
.assert_no_active_commit()
197 result
= self
.vm
.qmp('block-commit', device
='drive0', top
='%s' % self
.mid_img
, base
='badfile')
198 self
.assert_qmp(result
, 'error/class', 'GenericError')
199 self
.assert_qmp(result
, 'error/desc', 'Base \'badfile\' not found')
201 def test_top_is_active(self
):
202 self
.run_commit_test(self
.test_img
, self
.backing_img
)
203 self
.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', self
.backing_img_abs
).find("verification failed"))
204 self
.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', self
.backing_img_abs
).find("verification failed"))
206 def test_top_and_base_reversed(self
):
207 self
.assert_no_active_commit()
208 result
= self
.vm
.qmp('block-commit', device
='drive0', top
='%s' % self
.backing_img
, base
='%s' % self
.mid_img
)
209 self
.assert_qmp(result
, 'error/class', 'GenericError')
210 self
.assert_qmp(result
, 'error/desc', 'Base \'%s\' not found' % self
.mid_img
)
213 class TestSetSpeed(ImageCommitTestCase
):
214 image_len
= 80 * 1024 * 1024 # MB
217 qemu_img('create', backing_img
, str(TestSetSpeed
.image_len
))
218 qemu_img('create', '-f', iotests
.imgfmt
, '-o', 'backing_file=%s' % backing_img
, mid_img
)
219 qemu_img('create', '-f', iotests
.imgfmt
, '-o', 'backing_file=%s' % mid_img
, test_img
)
220 qemu_io('-c', 'write -P 0x1 0 512', test_img
)
221 qemu_io('-c', 'write -P 0xef 524288 524288', mid_img
)
222 self
.vm
= iotests
.VM().add_drive(test_img
)
229 os
.remove(backing_img
)
231 def test_set_speed(self
):
232 self
.assert_no_active_commit()
234 self
.vm
.pause_drive('drive0')
235 result
= self
.vm
.qmp('block-commit', device
='drive0', top
=mid_img
, speed
=1024 * 1024)
236 self
.assert_qmp(result
, 'return', {})
238 # Ensure the speed we set was accepted
239 result
= self
.vm
.qmp('query-block-jobs')
240 self
.assert_qmp(result
, 'return[0]/device', 'drive0')
241 self
.assert_qmp(result
, 'return[0]/speed', 1024 * 1024)
243 self
.cancel_and_wait(resume
=True)
246 if __name__
== '__main__':
247 iotests
.main(supported_fmts
=['qcow2', 'qed'])