root / tests / qemu-iotests / 040 @ 5b43dbb6
History | View | Annotate | Download (10.9 kB)
1 | 747051cd | Jeff Cody | #!/usr/bin/env python |
---|---|---|---|
2 | 747051cd | Jeff Cody | # |
3 | 747051cd | Jeff Cody | # Tests for image block commit. |
4 | 747051cd | Jeff Cody | # |
5 | 747051cd | Jeff Cody | # Copyright (C) 2012 IBM, Corp. |
6 | 747051cd | Jeff Cody | # Copyright (C) 2012 Red Hat, Inc. |
7 | 747051cd | Jeff Cody | # |
8 | 747051cd | Jeff Cody | # This program is free software; you can redistribute it and/or modify |
9 | 747051cd | Jeff Cody | # it under the terms of the GNU General Public License as published by |
10 | 747051cd | Jeff Cody | # the Free Software Foundation; either version 2 of the License, or |
11 | 747051cd | Jeff Cody | # (at your option) any later version. |
12 | 747051cd | Jeff Cody | # |
13 | 747051cd | Jeff Cody | # This program is distributed in the hope that it will be useful, |
14 | 747051cd | Jeff Cody | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | 747051cd | Jeff Cody | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | 747051cd | Jeff Cody | # GNU General Public License for more details. |
17 | 747051cd | Jeff Cody | # |
18 | 747051cd | Jeff Cody | # You should have received a copy of the GNU General Public License |
19 | 747051cd | Jeff Cody | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | 747051cd | Jeff Cody | # |
21 | 747051cd | Jeff Cody | # Test for live block commit |
22 | 747051cd | Jeff Cody | # Derived from Image Streaming Test 030 |
23 | 747051cd | Jeff Cody | |
24 | 747051cd | Jeff Cody | import time |
25 | 747051cd | Jeff Cody | import os |
26 | 747051cd | Jeff Cody | import iotests |
27 | 747051cd | Jeff Cody | from iotests import qemu_img, qemu_io |
28 | 747051cd | Jeff Cody | import struct |
29 | 6bf0d1f4 | Jeff Cody | import errno |
30 | 747051cd | Jeff Cody | |
31 | 747051cd | Jeff Cody | backing_img = os.path.join(iotests.test_dir, 'backing.img') |
32 | 747051cd | Jeff Cody | mid_img = os.path.join(iotests.test_dir, 'mid.img') |
33 | 747051cd | Jeff Cody | test_img = os.path.join(iotests.test_dir, 'test.img') |
34 | 747051cd | Jeff Cody | |
35 | 747051cd | Jeff Cody | class ImageCommitTestCase(iotests.QMPTestCase): |
36 | 747051cd | Jeff Cody | '''Abstract base class for image commit test cases''' |
37 | 747051cd | Jeff Cody | |
38 | 747051cd | Jeff Cody | def assert_no_active_commit(self): |
39 | 747051cd | Jeff Cody | result = self.vm.qmp('query-block-jobs') |
40 | 747051cd | Jeff Cody | self.assert_qmp(result, 'return', []) |
41 | 747051cd | Jeff Cody | |
42 | 747051cd | Jeff Cody | class TestSingleDrive(ImageCommitTestCase): |
43 | 747051cd | Jeff Cody | image_len = 1 * 1024 * 1024 |
44 | 747051cd | Jeff Cody | test_len = 1 * 1024 * 256 |
45 | 747051cd | Jeff Cody | |
46 | 747051cd | Jeff Cody | def setUp(self): |
47 | 915365a9 | Fam Zheng | iotests.create_image(backing_img, TestSingleDrive.image_len) |
48 | 747051cd | Jeff Cody | qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, mid_img) |
49 | 747051cd | Jeff Cody | qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % mid_img, test_img) |
50 | 747051cd | Jeff Cody | qemu_io('-c', 'write -P 0xab 0 524288', backing_img) |
51 | 747051cd | Jeff Cody | qemu_io('-c', 'write -P 0xef 524288 524288', mid_img) |
52 | 747051cd | Jeff Cody | self.vm = iotests.VM().add_drive(test_img) |
53 | 747051cd | Jeff Cody | self.vm.launch() |
54 | 747051cd | Jeff Cody | |
55 | 747051cd | Jeff Cody | def tearDown(self): |
56 | 747051cd | Jeff Cody | self.vm.shutdown() |
57 | 747051cd | Jeff Cody | os.remove(test_img) |
58 | 747051cd | Jeff Cody | os.remove(mid_img) |
59 | 747051cd | Jeff Cody | os.remove(backing_img) |
60 | 747051cd | Jeff Cody | |
61 | 747051cd | Jeff Cody | def test_commit(self): |
62 | 747051cd | Jeff Cody | self.assert_no_active_commit() |
63 | 747051cd | Jeff Cody | result = self.vm.qmp('block-commit', device='drive0', top='%s' % mid_img) |
64 | 747051cd | Jeff Cody | self.assert_qmp(result, 'return', {}) |
65 | 747051cd | Jeff Cody | |
66 | 747051cd | Jeff Cody | completed = False |
67 | 747051cd | Jeff Cody | while not completed: |
68 | 747051cd | Jeff Cody | for event in self.vm.get_qmp_events(wait=True): |
69 | 747051cd | Jeff Cody | if event['event'] == 'BLOCK_JOB_COMPLETED': |
70 | 747051cd | Jeff Cody | self.assert_qmp(event, 'data/type', 'commit') |
71 | 747051cd | Jeff Cody | self.assert_qmp(event, 'data/device', 'drive0') |
72 | 747051cd | Jeff Cody | self.assert_qmp(event, 'data/offset', self.image_len) |
73 | 747051cd | Jeff Cody | self.assert_qmp(event, 'data/len', self.image_len) |
74 | 747051cd | Jeff Cody | completed = True |
75 | 747051cd | Jeff Cody | |
76 | 747051cd | Jeff Cody | self.assert_no_active_commit() |
77 | 747051cd | Jeff Cody | self.vm.shutdown() |
78 | 747051cd | Jeff Cody | |
79 | 747051cd | Jeff Cody | self.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', backing_img).find("verification failed")) |
80 | 747051cd | Jeff Cody | self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed")) |
81 | 747051cd | Jeff Cody | |
82 | 747051cd | Jeff Cody | def test_device_not_found(self): |
83 | 747051cd | Jeff Cody | result = self.vm.qmp('block-commit', device='nonexistent', top='%s' % mid_img) |
84 | 747051cd | Jeff Cody | self.assert_qmp(result, 'error/class', 'DeviceNotFound') |
85 | 747051cd | Jeff Cody | |
86 | 747051cd | Jeff Cody | def test_top_same_base(self): |
87 | 747051cd | Jeff Cody | self.assert_no_active_commit() |
88 | 747051cd | Jeff Cody | result = self.vm.qmp('block-commit', device='drive0', top='%s' % backing_img, base='%s' % backing_img) |
89 | 747051cd | Jeff Cody | self.assert_qmp(result, 'error/class', 'GenericError') |
90 | d5208c45 | Jeff Cody | self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % backing_img) |
91 | 747051cd | Jeff Cody | |
92 | 747051cd | Jeff Cody | def test_top_invalid(self): |
93 | 747051cd | Jeff Cody | self.assert_no_active_commit() |
94 | 747051cd | Jeff Cody | result = self.vm.qmp('block-commit', device='drive0', top='badfile', base='%s' % backing_img) |
95 | 747051cd | Jeff Cody | self.assert_qmp(result, 'error/class', 'GenericError') |
96 | 747051cd | Jeff Cody | self.assert_qmp(result, 'error/desc', 'Top image file badfile not found') |
97 | 747051cd | Jeff Cody | |
98 | 747051cd | Jeff Cody | def test_base_invalid(self): |
99 | 747051cd | Jeff Cody | self.assert_no_active_commit() |
100 | 747051cd | Jeff Cody | result = self.vm.qmp('block-commit', device='drive0', top='%s' % mid_img, base='badfile') |
101 | 747051cd | Jeff Cody | self.assert_qmp(result, 'error/class', 'GenericError') |
102 | 747051cd | Jeff Cody | self.assert_qmp(result, 'error/desc', 'Base \'badfile\' not found') |
103 | 747051cd | Jeff Cody | |
104 | 747051cd | Jeff Cody | def test_top_is_active(self): |
105 | 747051cd | Jeff Cody | self.assert_no_active_commit() |
106 | 747051cd | Jeff Cody | result = self.vm.qmp('block-commit', device='drive0', top='%s' % test_img, base='%s' % backing_img) |
107 | 747051cd | Jeff Cody | self.assert_qmp(result, 'error/class', 'GenericError') |
108 | 747051cd | Jeff Cody | self.assert_qmp(result, 'error/desc', 'Top image as the active layer is currently unsupported') |
109 | 747051cd | Jeff Cody | |
110 | 747051cd | Jeff Cody | def test_top_and_base_reversed(self): |
111 | 747051cd | Jeff Cody | self.assert_no_active_commit() |
112 | 747051cd | Jeff Cody | result = self.vm.qmp('block-commit', device='drive0', top='%s' % backing_img, base='%s' % mid_img) |
113 | 747051cd | Jeff Cody | self.assert_qmp(result, 'error/class', 'GenericError') |
114 | d5208c45 | Jeff Cody | self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % mid_img) |
115 | 747051cd | Jeff Cody | |
116 | 747051cd | Jeff Cody | def test_top_omitted(self): |
117 | 747051cd | Jeff Cody | self.assert_no_active_commit() |
118 | 747051cd | Jeff Cody | result = self.vm.qmp('block-commit', device='drive0') |
119 | 747051cd | Jeff Cody | self.assert_qmp(result, 'error/class', 'GenericError') |
120 | 747051cd | Jeff Cody | self.assert_qmp(result, 'error/desc', "Parameter 'top' is missing") |
121 | 747051cd | Jeff Cody | |
122 | 6bf0d1f4 | Jeff Cody | class TestRelativePaths(ImageCommitTestCase): |
123 | 6bf0d1f4 | Jeff Cody | image_len = 1 * 1024 * 1024 |
124 | 6bf0d1f4 | Jeff Cody | test_len = 1 * 1024 * 256 |
125 | 6bf0d1f4 | Jeff Cody | |
126 | 6bf0d1f4 | Jeff Cody | dir1 = "dir1" |
127 | 6bf0d1f4 | Jeff Cody | dir2 = "dir2/" |
128 | 6bf0d1f4 | Jeff Cody | dir3 = "dir2/dir3/" |
129 | 6bf0d1f4 | Jeff Cody | |
130 | 6bf0d1f4 | Jeff Cody | test_img = os.path.join(iotests.test_dir, dir3, 'test.img') |
131 | 6bf0d1f4 | Jeff Cody | mid_img = "../mid.img" |
132 | 6bf0d1f4 | Jeff Cody | backing_img = "../dir1/backing.img" |
133 | 6bf0d1f4 | Jeff Cody | |
134 | 6bf0d1f4 | Jeff Cody | backing_img_abs = os.path.join(iotests.test_dir, dir1, 'backing.img') |
135 | 6bf0d1f4 | Jeff Cody | mid_img_abs = os.path.join(iotests.test_dir, dir2, 'mid.img') |
136 | 6bf0d1f4 | Jeff Cody | |
137 | 6bf0d1f4 | Jeff Cody | def setUp(self): |
138 | 6bf0d1f4 | Jeff Cody | try: |
139 | 6bf0d1f4 | Jeff Cody | os.mkdir(os.path.join(iotests.test_dir, self.dir1)) |
140 | 6bf0d1f4 | Jeff Cody | os.mkdir(os.path.join(iotests.test_dir, self.dir2)) |
141 | 6bf0d1f4 | Jeff Cody | os.mkdir(os.path.join(iotests.test_dir, self.dir3)) |
142 | 6bf0d1f4 | Jeff Cody | except OSError as exception: |
143 | 6bf0d1f4 | Jeff Cody | if exception.errno != errno.EEXIST: |
144 | 6bf0d1f4 | Jeff Cody | raise |
145 | 915365a9 | Fam Zheng | iotests.create_image(self.backing_img_abs, TestRelativePaths.image_len) |
146 | 6bf0d1f4 | Jeff Cody | qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % self.backing_img_abs, self.mid_img_abs) |
147 | 6bf0d1f4 | Jeff Cody | qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % self.mid_img_abs, self.test_img) |
148 | 6bf0d1f4 | Jeff Cody | qemu_img('rebase', '-u', '-b', self.backing_img, self.mid_img_abs) |
149 | 6bf0d1f4 | Jeff Cody | qemu_img('rebase', '-u', '-b', self.mid_img, self.test_img) |
150 | 6bf0d1f4 | Jeff Cody | qemu_io('-c', 'write -P 0xab 0 524288', self.backing_img_abs) |
151 | 6bf0d1f4 | Jeff Cody | qemu_io('-c', 'write -P 0xef 524288 524288', self.mid_img_abs) |
152 | 6bf0d1f4 | Jeff Cody | self.vm = iotests.VM().add_drive(self.test_img) |
153 | 6bf0d1f4 | Jeff Cody | self.vm.launch() |
154 | 6bf0d1f4 | Jeff Cody | |
155 | 6bf0d1f4 | Jeff Cody | def tearDown(self): |
156 | 6bf0d1f4 | Jeff Cody | self.vm.shutdown() |
157 | 6bf0d1f4 | Jeff Cody | os.remove(self.test_img) |
158 | 6bf0d1f4 | Jeff Cody | os.remove(self.mid_img_abs) |
159 | 6bf0d1f4 | Jeff Cody | os.remove(self.backing_img_abs) |
160 | 6bf0d1f4 | Jeff Cody | try: |
161 | 6bf0d1f4 | Jeff Cody | os.rmdir(os.path.join(iotests.test_dir, self.dir1)) |
162 | 6bf0d1f4 | Jeff Cody | os.rmdir(os.path.join(iotests.test_dir, self.dir3)) |
163 | 6bf0d1f4 | Jeff Cody | os.rmdir(os.path.join(iotests.test_dir, self.dir2)) |
164 | 6bf0d1f4 | Jeff Cody | except OSError as exception: |
165 | 6bf0d1f4 | Jeff Cody | if exception.errno != errno.EEXIST and exception.errno != errno.ENOTEMPTY: |
166 | 6bf0d1f4 | Jeff Cody | raise |
167 | 6bf0d1f4 | Jeff Cody | |
168 | 6bf0d1f4 | Jeff Cody | def test_commit(self): |
169 | 6bf0d1f4 | Jeff Cody | self.assert_no_active_commit() |
170 | 6bf0d1f4 | Jeff Cody | result = self.vm.qmp('block-commit', device='drive0', top='%s' % self.mid_img) |
171 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(result, 'return', {}) |
172 | 6bf0d1f4 | Jeff Cody | |
173 | 6bf0d1f4 | Jeff Cody | completed = False |
174 | 6bf0d1f4 | Jeff Cody | while not completed: |
175 | 6bf0d1f4 | Jeff Cody | for event in self.vm.get_qmp_events(wait=True): |
176 | 6bf0d1f4 | Jeff Cody | if event['event'] == 'BLOCK_JOB_COMPLETED': |
177 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(event, 'data/type', 'commit') |
178 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(event, 'data/device', 'drive0') |
179 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(event, 'data/offset', self.image_len) |
180 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(event, 'data/len', self.image_len) |
181 | 6bf0d1f4 | Jeff Cody | completed = True |
182 | 6bf0d1f4 | Jeff Cody | |
183 | 6bf0d1f4 | Jeff Cody | self.assert_no_active_commit() |
184 | 6bf0d1f4 | Jeff Cody | self.vm.shutdown() |
185 | 6bf0d1f4 | Jeff Cody | |
186 | 6bf0d1f4 | Jeff Cody | self.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', self.backing_img_abs).find("verification failed")) |
187 | 6bf0d1f4 | Jeff Cody | self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', self.backing_img_abs).find("verification failed")) |
188 | 6bf0d1f4 | Jeff Cody | |
189 | 6bf0d1f4 | Jeff Cody | def test_device_not_found(self): |
190 | 6bf0d1f4 | Jeff Cody | result = self.vm.qmp('block-commit', device='nonexistent', top='%s' % self.mid_img) |
191 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(result, 'error/class', 'DeviceNotFound') |
192 | 6bf0d1f4 | Jeff Cody | |
193 | 6bf0d1f4 | Jeff Cody | def test_top_same_base(self): |
194 | 6bf0d1f4 | Jeff Cody | self.assert_no_active_commit() |
195 | 6bf0d1f4 | Jeff Cody | result = self.vm.qmp('block-commit', device='drive0', top='%s' % self.mid_img, base='%s' % self.mid_img) |
196 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(result, 'error/class', 'GenericError') |
197 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % self.mid_img) |
198 | 6bf0d1f4 | Jeff Cody | |
199 | 6bf0d1f4 | Jeff Cody | def test_top_invalid(self): |
200 | 6bf0d1f4 | Jeff Cody | self.assert_no_active_commit() |
201 | 6bf0d1f4 | Jeff Cody | result = self.vm.qmp('block-commit', device='drive0', top='badfile', base='%s' % self.backing_img) |
202 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(result, 'error/class', 'GenericError') |
203 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(result, 'error/desc', 'Top image file badfile not found') |
204 | 6bf0d1f4 | Jeff Cody | |
205 | 6bf0d1f4 | Jeff Cody | def test_base_invalid(self): |
206 | 6bf0d1f4 | Jeff Cody | self.assert_no_active_commit() |
207 | 6bf0d1f4 | Jeff Cody | result = self.vm.qmp('block-commit', device='drive0', top='%s' % self.mid_img, base='badfile') |
208 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(result, 'error/class', 'GenericError') |
209 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(result, 'error/desc', 'Base \'badfile\' not found') |
210 | 6bf0d1f4 | Jeff Cody | |
211 | 6bf0d1f4 | Jeff Cody | def test_top_is_active(self): |
212 | 6bf0d1f4 | Jeff Cody | self.assert_no_active_commit() |
213 | 6bf0d1f4 | Jeff Cody | result = self.vm.qmp('block-commit', device='drive0', top='%s' % self.test_img, base='%s' % self.backing_img) |
214 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(result, 'error/class', 'GenericError') |
215 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(result, 'error/desc', 'Top image as the active layer is currently unsupported') |
216 | 6bf0d1f4 | Jeff Cody | |
217 | 6bf0d1f4 | Jeff Cody | def test_top_and_base_reversed(self): |
218 | 6bf0d1f4 | Jeff Cody | self.assert_no_active_commit() |
219 | 6bf0d1f4 | Jeff Cody | result = self.vm.qmp('block-commit', device='drive0', top='%s' % self.backing_img, base='%s' % self.mid_img) |
220 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(result, 'error/class', 'GenericError') |
221 | 6bf0d1f4 | Jeff Cody | self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % self.mid_img) |
222 | 6bf0d1f4 | Jeff Cody | |
223 | 747051cd | Jeff Cody | |
224 | 747051cd | Jeff Cody | class TestSetSpeed(ImageCommitTestCase): |
225 | 747051cd | Jeff Cody | image_len = 80 * 1024 * 1024 # MB |
226 | 747051cd | Jeff Cody | |
227 | 747051cd | Jeff Cody | def setUp(self): |
228 | 747051cd | Jeff Cody | qemu_img('create', backing_img, str(TestSetSpeed.image_len)) |
229 | 747051cd | Jeff Cody | qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, mid_img) |
230 | 747051cd | Jeff Cody | qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % mid_img, test_img) |
231 | 747051cd | Jeff Cody | self.vm = iotests.VM().add_drive(test_img) |
232 | 747051cd | Jeff Cody | self.vm.launch() |
233 | 747051cd | Jeff Cody | |
234 | 747051cd | Jeff Cody | def tearDown(self): |
235 | 747051cd | Jeff Cody | self.vm.shutdown() |
236 | 747051cd | Jeff Cody | os.remove(test_img) |
237 | 747051cd | Jeff Cody | os.remove(mid_img) |
238 | 747051cd | Jeff Cody | os.remove(backing_img) |
239 | 747051cd | Jeff Cody | |
240 | 747051cd | Jeff Cody | def test_set_speed(self): |
241 | 747051cd | Jeff Cody | self.assert_no_active_commit() |
242 | 747051cd | Jeff Cody | |
243 | 747051cd | Jeff Cody | result = self.vm.qmp('block-commit', device='drive0', top=mid_img, speed=1024 * 1024) |
244 | 747051cd | Jeff Cody | self.assert_qmp(result, 'return', {}) |
245 | 747051cd | Jeff Cody | |
246 | 747051cd | Jeff Cody | # Ensure the speed we set was accepted |
247 | 747051cd | Jeff Cody | result = self.vm.qmp('query-block-jobs') |
248 | 747051cd | Jeff Cody | self.assert_qmp(result, 'return[0]/device', 'drive0') |
249 | 747051cd | Jeff Cody | self.assert_qmp(result, 'return[0]/speed', 1024 * 1024) |
250 | 747051cd | Jeff Cody | |
251 | 747051cd | Jeff Cody | self.cancel_and_wait() |
252 | 747051cd | Jeff Cody | |
253 | 747051cd | Jeff Cody | |
254 | 747051cd | Jeff Cody | if __name__ == '__main__': |
255 | 747051cd | Jeff Cody | iotests.main(supported_fmts=['qcow2', 'qed']) |