Merge lp:~citrix-openstack/glance/iso-boot into lp:~hudson-openstack/glance/trunk
- iso-boot
- Merge into trunk
Proposed by
Donal Lafferty
Status: | Superseded |
---|---|
Proposed branch: | lp:~citrix-openstack/glance/iso-boot |
Merge into: | lp:~hudson-openstack/glance/trunk |
Diff against target: |
730 lines (+160/-80) 7 files modified
doc/source/formats.rst (+4/-0) doc/source/glanceapi.rst (+1/-1) doc/source/registries.rst (+1/-1) glance/registry/db/api.py (+2/-1) tests/stubs.py (+18/-3) tests/unit/test_api.py (+35/-34) tests/unit/test_clients.py (+99/-40) |
To merge this branch: | bzr merge lp:~citrix-openstack/glance/iso-boot |
Related bugs: | |
Related blueprints: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jay Pipes (community) | Needs Fixing | ||
Review via email: mp+61514@code.launchpad.net |
This proposal has been superseded by a proposal from 2011-05-19.
Commit message
Description of the change
Added new disk_format type of 'iso'. Nova can use this information to identify images that have to be booted from a CDROM.
Updated unittests so that next available image id is no longer a magic number. Previously, it was not possible to add new records into the image database stub without breaking many, many tests.
To post a comment you must log in.
Revision history for this message
Donal Lafferty (donal-lafferty) wrote : | # |
Updated docs in three locations where 'raw' disk format was expalined. However, no examples of 'iso' were in headers or API calls added.
- 122. By Donal Lafferty
-
Sync with trunk.
- 123. By Donal Lafferty
-
Remove additions to FIXTURES in test/stubs.py, which requried changes elsewhere.
- 124. By Donal Lafferty
-
Fix accidental delete.
- 125. By Donal Lafferty
-
Remove changes to stub database.
- 126. By Donal Lafferty
-
Correct documentation.
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'doc/source/formats.rst' |
2 | --- doc/source/formats.rst 2011-03-05 17:04:43 +0000 |
3 | +++ doc/source/formats.rst 2011-05-19 09:49:15 +0000 |
4 | @@ -49,6 +49,10 @@ |
5 | A disk format supported by VirtualBox virtual machine monitor and the QEMU |
6 | emulator |
7 | |
8 | +* **iso** |
9 | + |
10 | + An archive format for the data contents of an optical disc (e.g. CDROM). |
11 | + |
12 | * **qcow2** |
13 | |
14 | A disk format supported by the QEMU emulator that can expand dynamically and |
15 | |
16 | === modified file 'doc/source/glanceapi.rst' |
17 | --- doc/source/glanceapi.rst 2011-04-12 21:45:16 +0000 |
18 | +++ doc/source/glanceapi.rst 2011-05-19 09:49:15 +0000 |
19 | @@ -272,7 +272,7 @@ |
20 | * ``x-image-meta-disk-format`` |
21 | |
22 | This header is optional. Valid values are one of ``aki``, ``ari``, ``ami``, |
23 | - ``raw``, ``vhd``, ``vdi``, ``qcow2``, or ``vmdk``. |
24 | + ``raw``, ``iso``, ``vhd``, ``vdi``, ``qcow2``, or ``vmdk``. |
25 | |
26 | For more information, see :doc:`About Disk and Container Formats <formats>` |
27 | |
28 | |
29 | === modified file 'doc/source/registries.rst' |
30 | --- doc/source/registries.rst 2011-02-25 14:55:26 +0000 |
31 | +++ doc/source/registries.rst 2011-05-19 09:49:15 +0000 |
32 | @@ -69,7 +69,7 @@ |
33 | **queued**, or **killed** |
34 | |
35 | * ``disk_format`` must be non-empty, and must be one of **ari**, **aki**, |
36 | - **ami**, **raw**, **vhd**, **vdi**, **qcow2**, or **vmdk** |
37 | + **ami**, **raw**, **iso**, **vhd**, **vdi**, **qcow2**, or **vmdk** |
38 | |
39 | * ``container_format`` must be non-empty, and must be on of **ari**, |
40 | **aki**, **ami**, **bare**, or **ovf** |
41 | |
42 | === modified file 'glance/registry/db/api.py' |
43 | --- glance/registry/db/api.py 2011-05-16 13:20:53 +0000 |
44 | +++ glance/registry/db/api.py 2011-05-19 09:49:15 +0000 |
45 | @@ -47,7 +47,8 @@ |
46 | 'is_public', 'location', 'checksum']) |
47 | |
48 | CONTAINER_FORMATS = ['ami', 'ari', 'aki', 'bare', 'ovf'] |
49 | -DISK_FORMATS = ['ami', 'ari', 'aki', 'vhd', 'vmdk', 'raw', 'qcow2', 'vdi'] |
50 | +DISK_FORMATS = ['ami', 'ari', 'aki', 'vhd', 'vmdk', 'raw', 'qcow2', 'vdi', |
51 | + 'iso'] |
52 | STATUSES = ['active', 'saving', 'queued', 'killed'] |
53 | |
54 | |
55 | |
56 | === modified file 'tests/stubs.py' |
57 | --- tests/stubs.py 2011-05-16 13:20:53 +0000 |
58 | +++ tests/stubs.py 2011-05-19 09:49:15 +0000 |
59 | @@ -267,7 +267,7 @@ |
60 | The "datastore" always starts with this set of image fixtures. |
61 | |
62 | :param stubs: Set of stubout stubs |
63 | - |
64 | + :return: count of items in the "datastore" |
65 | """ |
66 | class FakeDatastore(object): |
67 | |
68 | @@ -301,11 +301,25 @@ |
69 | 'checksum': None, |
70 | 'size': 19, |
71 | 'location': "file:///tmp/glance-tests/2", |
72 | - 'properties': []}] |
73 | + 'properties': []}, |
74 | + {'id': 3, |
75 | + 'name': 'fake iso image', |
76 | + 'status': 'active', |
77 | + 'disk_format': 'iso', |
78 | + 'container_format': 'bare', |
79 | + 'is_public': False, |
80 | + 'created_at': datetime.datetime.utcnow(), |
81 | + 'updated_at': datetime.datetime.utcnow(), |
82 | + 'deleted_at': None, |
83 | + 'deleted': False, |
84 | + 'checksum': None, |
85 | + 'size': 19, |
86 | + 'location': "file:///tmp/glance-tests/3", |
87 | + 'properties': {}}] |
88 | |
89 | def __init__(self): |
90 | self.images = FakeDatastore.FIXTURES |
91 | - self.next_id = 3 |
92 | + self.next_id = 4 |
93 | |
94 | def image_create(self, _context, values): |
95 | |
96 | @@ -424,3 +438,4 @@ |
97 | fake_datastore.image_get) |
98 | stubs.Set(glance.registry.db.api, 'image_get_all_public', |
99 | fake_datastore.image_get_all_public) |
100 | + return fake_datastore.next_id |
101 | |
102 | === modified file 'tests/unit/test_api.py' |
103 | --- tests/unit/test_api.py 2011-05-16 02:16:49 +0000 |
104 | +++ tests/unit/test_api.py 2011-05-19 09:49:15 +0000 |
105 | @@ -38,7 +38,7 @@ |
106 | """Establish a clean test environment""" |
107 | self.stubs = stubout.StubOutForTesting() |
108 | stubs.stub_out_registry_and_store_server(self.stubs) |
109 | - stubs.stub_out_registry_db_image_api(self.stubs) |
110 | + self.next_image_id = stubs.stub_out_registry_db_image_api(self.stubs) |
111 | stubs.stub_out_filesystem_backend() |
112 | self.api = rserver.API({'verbose': VERBOSE, |
113 | 'debug': DEBUG}) |
114 | @@ -99,7 +99,7 @@ |
115 | 'size': 19, |
116 | 'checksum': None} |
117 | |
118 | - extra_fixture = {'id': 3, |
119 | + extra_fixture = {'id': self.next_image_id, |
120 | 'status': 'active', |
121 | 'is_public': True, |
122 | 'disk_format': 'vhd', |
123 | @@ -110,7 +110,7 @@ |
124 | |
125 | glance.registry.db.api.image_create(None, extra_fixture) |
126 | |
127 | - extra_fixture = {'id': 4, |
128 | + extra_fixture = {'id': self.next_image_id + 1, |
129 | 'status': 'active', |
130 | 'is_public': True, |
131 | 'disk_format': 'vhd', |
132 | @@ -162,7 +162,7 @@ |
133 | public images that have a specific name |
134 | |
135 | """ |
136 | - extra_fixture = {'id': 3, |
137 | + extra_fixture = {'id': self.next_image_id, |
138 | 'status': 'active', |
139 | 'is_public': True, |
140 | 'disk_format': 'vhd', |
141 | @@ -173,7 +173,7 @@ |
142 | |
143 | glance.registry.db.api.image_create(None, extra_fixture) |
144 | |
145 | - extra_fixture = {'id': 4, |
146 | + extra_fixture = {'id': self.next_image_id + 1, |
147 | 'status': 'active', |
148 | 'is_public': True, |
149 | 'disk_format': 'vhd', |
150 | @@ -200,7 +200,7 @@ |
151 | public images that have a specific status |
152 | |
153 | """ |
154 | - extra_fixture = {'id': 3, |
155 | + extra_fixture = {'id': self.next_image_id, |
156 | 'status': 'saving', |
157 | 'is_public': True, |
158 | 'disk_format': 'vhd', |
159 | @@ -211,7 +211,7 @@ |
160 | |
161 | glance.registry.db.api.image_create(None, extra_fixture) |
162 | |
163 | - extra_fixture = {'id': 4, |
164 | + extra_fixture = {'id': self.next_image_id + 1, |
165 | 'status': 'active', |
166 | 'is_public': True, |
167 | 'disk_format': 'vhd', |
168 | @@ -238,7 +238,7 @@ |
169 | public images that have a specific container_format |
170 | |
171 | """ |
172 | - extra_fixture = {'id': 3, |
173 | + extra_fixture = {'id': self.next_image_id, |
174 | 'status': 'active', |
175 | 'is_public': True, |
176 | 'disk_format': 'vdi', |
177 | @@ -249,7 +249,7 @@ |
178 | |
179 | glance.registry.db.api.image_create(None, extra_fixture) |
180 | |
181 | - extra_fixture = {'id': 4, |
182 | + extra_fixture = {'id': self.next_image_id + 1, |
183 | 'status': 'active', |
184 | 'is_public': True, |
185 | 'disk_format': 'ami', |
186 | @@ -276,7 +276,7 @@ |
187 | public images that have a specific disk_format |
188 | |
189 | """ |
190 | - extra_fixture = {'id': 3, |
191 | + extra_fixture = {'id': self.next_image_id, |
192 | 'status': 'active', |
193 | 'is_public': True, |
194 | 'disk_format': 'vhd', |
195 | @@ -287,7 +287,7 @@ |
196 | |
197 | glance.registry.db.api.image_create(None, extra_fixture) |
198 | |
199 | - extra_fixture = {'id': 4, |
200 | + extra_fixture = {'id': self.next_image_id + 1, |
201 | 'status': 'active', |
202 | 'is_public': True, |
203 | 'disk_format': 'ami', |
204 | @@ -314,7 +314,7 @@ |
205 | public images that have a size greater than or equal to size_min |
206 | |
207 | """ |
208 | - extra_fixture = {'id': 3, |
209 | + extra_fixture = {'id': self.next_image_id, |
210 | 'status': 'active', |
211 | 'is_public': True, |
212 | 'disk_format': 'vhd', |
213 | @@ -325,7 +325,7 @@ |
214 | |
215 | glance.registry.db.api.image_create(None, extra_fixture) |
216 | |
217 | - extra_fixture = {'id': 4, |
218 | + extra_fixture = {'id': self.next_image_id + 1, |
219 | 'status': 'active', |
220 | 'is_public': True, |
221 | 'disk_format': 'ami', |
222 | @@ -352,7 +352,7 @@ |
223 | public images that have a size less than or equal to size_max |
224 | |
225 | """ |
226 | - extra_fixture = {'id': 3, |
227 | + extra_fixture = {'id': self.next_image_id, |
228 | 'status': 'active', |
229 | 'is_public': True, |
230 | 'disk_format': 'vhd', |
231 | @@ -363,7 +363,7 @@ |
232 | |
233 | glance.registry.db.api.image_create(None, extra_fixture) |
234 | |
235 | - extra_fixture = {'id': 4, |
236 | + extra_fixture = {'id': self.next_image_id + 1, |
237 | 'status': 'active', |
238 | 'is_public': True, |
239 | 'disk_format': 'ami', |
240 | @@ -391,7 +391,7 @@ |
241 | and greater than or equal to size_min |
242 | |
243 | """ |
244 | - extra_fixture = {'id': 3, |
245 | + extra_fixture = {'id': self.next_image_id, |
246 | 'status': 'active', |
247 | 'is_public': True, |
248 | 'disk_format': 'vhd', |
249 | @@ -402,7 +402,7 @@ |
250 | |
251 | glance.registry.db.api.image_create(None, extra_fixture) |
252 | |
253 | - extra_fixture = {'id': 4, |
254 | + extra_fixture = {'id': self.next_image_id + 1, |
255 | 'status': 'active', |
256 | 'is_public': True, |
257 | 'disk_format': 'ami', |
258 | @@ -413,7 +413,7 @@ |
259 | |
260 | glance.registry.db.api.image_create(None, extra_fixture) |
261 | |
262 | - extra_fixture = {'id': 5, |
263 | + extra_fixture = {'id': self.next_image_id + 2, |
264 | 'status': 'active', |
265 | 'is_public': True, |
266 | 'disk_format': 'ami', |
267 | @@ -440,7 +440,7 @@ |
268 | public images that have a specific custom property |
269 | |
270 | """ |
271 | - extra_fixture = {'id': 3, |
272 | + extra_fixture = {'id': self.next_image_id, |
273 | 'status': 'active', |
274 | 'is_public': True, |
275 | 'disk_format': 'vhd', |
276 | @@ -452,7 +452,7 @@ |
277 | |
278 | glance.registry.db.api.image_create(None, extra_fixture) |
279 | |
280 | - extra_fixture = {'id': 4, |
281 | + extra_fixture = {'id': self.next_image_id + 1, |
282 | 'status': 'active', |
283 | 'is_public': True, |
284 | 'disk_format': 'ami', |
285 | @@ -497,14 +497,14 @@ |
286 | self.assertEquals(v, res_dict['image'][k]) |
287 | |
288 | # Test ID auto-assigned properly |
289 | - self.assertEquals(3, res_dict['image']['id']) |
290 | + self.assertEquals(self.next_image_id, res_dict['image']['id']) |
291 | |
292 | # Test status was updated properly |
293 | self.assertEquals('active', res_dict['image']['status']) |
294 | |
295 | def test_create_image_with_bad_container_format(self): |
296 | """Tests proper exception is raised if a bad disk_format is set""" |
297 | - fixture = {'id': 3, |
298 | + fixture = {'id': self.next_image_id, |
299 | 'name': 'fake public image', |
300 | 'is_public': True, |
301 | 'disk_format': 'vhd', |
302 | @@ -521,7 +521,7 @@ |
303 | |
304 | def test_create_image_with_bad_disk_format(self): |
305 | """Tests proper exception is raised if a bad disk_format is set""" |
306 | - fixture = {'id': 3, |
307 | + fixture = {'id': self.next_image_id, |
308 | 'name': 'fake public image', |
309 | 'is_public': True, |
310 | 'disk_format': 'invalid', |
311 | @@ -555,7 +555,7 @@ |
312 | |
313 | def test_create_image_with_bad_status(self): |
314 | """Tests proper exception is raised if a bad status is set""" |
315 | - fixture = {'id': 3, |
316 | + fixture = {'id': self.next_image_id, |
317 | 'name': 'fake public image', |
318 | 'is_public': True, |
319 | 'disk_format': 'vhd', |
320 | @@ -595,7 +595,7 @@ |
321 | image""" |
322 | fixture = {'status': 'killed'} |
323 | |
324 | - req = webob.Request.blank('/images/3') |
325 | + req = webob.Request.blank('/images/' + str(self.next_image_id)) |
326 | |
327 | req.method = 'PUT' |
328 | req.body = json.dumps(dict(image=fixture)) |
329 | @@ -691,7 +691,7 @@ |
330 | """Tests proper exception is raised if attempt to delete non-existing |
331 | image""" |
332 | |
333 | - req = webob.Request.blank('/images/3') |
334 | + req = webob.Request.blank('/images/' + str(self.next_image_id)) |
335 | |
336 | req.method = 'DELETE' |
337 | |
338 | @@ -705,7 +705,7 @@ |
339 | """Establish a clean test environment""" |
340 | self.stubs = stubout.StubOutForTesting() |
341 | stubs.stub_out_registry_and_store_server(self.stubs) |
342 | - stubs.stub_out_registry_db_image_api(self.stubs) |
343 | + self.next_image_id = stubs.stub_out_registry_db_image_api(self.stubs) |
344 | stubs.stub_out_filesystem_backend() |
345 | sql_connection = os.environ.get('GLANCE_SQL_CONNECTION', "sqlite://") |
346 | options = {'verbose': VERBOSE, |
347 | @@ -805,7 +805,7 @@ |
348 | |
349 | res_body = json.loads(res.body)['image'] |
350 | self.assertEquals(res_body['location'], |
351 | - 'file:///tmp/glance-tests/3') |
352 | + 'file:///tmp/glance-tests/' + str(self.next_image_id)) |
353 | |
354 | # Test that the Location: header is set to the URI to |
355 | # edit the newly-created image, as required by APP. |
356 | @@ -813,7 +813,8 @@ |
357 | self.assertTrue('location' in res.headers, |
358 | "'location' not in response headers.\n" |
359 | "res.headerlist = %r" % res.headerlist) |
360 | - self.assertTrue('/images/3' in res.headers['location']) |
361 | + self.assertTrue('/images/' + str(self.next_image_id) |
362 | + in res.headers['location']) |
363 | |
364 | def test_image_is_checksummed(self): |
365 | """Test that the image contents are checksummed properly""" |
366 | @@ -836,9 +837,9 @@ |
367 | |
368 | res_body = json.loads(res.body)['image'] |
369 | self.assertEquals(res_body['location'], |
370 | - 'file:///tmp/glance-tests/3') |
371 | + 'file:///tmp/glance-tests/' + str(self.next_image_id)) |
372 | self.assertEquals(image_checksum, res_body['checksum'], |
373 | - "Mismatched checksum. Expected %s, got %s" % |
374 | + "Mismatched checksum. Expected %s, got %s" % |
375 | (image_checksum, res_body['checksum'])) |
376 | |
377 | def test_etag_equals_checksum_header(self): |
378 | @@ -863,7 +864,7 @@ |
379 | # HEAD the image and check the ETag equals the checksum header... |
380 | expected_headers = {'x-image-meta-checksum': image_checksum, |
381 | 'etag': image_checksum} |
382 | - req = webob.Request.blank("/images/3") |
383 | + req = webob.Request.blank("/images/" + str(self.next_image_id)) |
384 | req.method = 'HEAD' |
385 | res = req.get_response(self.api) |
386 | self.assertEquals(res.status_int, 200) |
387 | @@ -896,9 +897,9 @@ |
388 | self.assertEquals(res.status_int, webob.exc.HTTPBadRequest.code) |
389 | |
390 | # Test the image was killed... |
391 | - expected_headers = {'x-image-meta-id': '3', |
392 | + expected_headers = {'x-image-meta-id': str(self.next_image_id), |
393 | 'x-image-meta-status': 'killed'} |
394 | - req = webob.Request.blank("/images/3") |
395 | + req = webob.Request.blank("/images/" + str(self.next_image_id)) |
396 | req.method = 'HEAD' |
397 | res = req.get_response(self.api) |
398 | self.assertEquals(res.status_int, 200) |
399 | |
400 | === modified file 'tests/unit/test_clients.py' |
401 | --- tests/unit/test_clients.py 2011-05-16 02:16:49 +0000 |
402 | +++ tests/unit/test_clients.py 2011-05-19 09:49:15 +0000 |
403 | @@ -52,7 +52,7 @@ |
404 | def setUp(self): |
405 | """Establish a clean test environment""" |
406 | self.stubs = stubout.StubOutForTesting() |
407 | - stubs.stub_out_registry_db_image_api(self.stubs) |
408 | + self.next_image_id = stubs.stub_out_registry_db_image_api(self.stubs) |
409 | stubs.stub_out_registry_and_store_server(self.stubs) |
410 | self.client = rclient.RegistryClient("0.0.0.0") |
411 | |
412 | @@ -73,7 +73,7 @@ |
413 | def test_get_image_index_by_name(self): |
414 | """Test correct set of public, name-filtered image returned. This |
415 | is just a sanity check, we test the details call more in-depth.""" |
416 | - extra_fixture = {'id': 3, |
417 | + extra_fixture = {'id': self.next_image_id, |
418 | 'status': 'active', |
419 | 'is_public': True, |
420 | 'disk_format': 'vhd', |
421 | @@ -110,7 +110,7 @@ |
422 | |
423 | def test_get_image_details_by_name(self): |
424 | """Tests that a detailed call can be filtered by name""" |
425 | - extra_fixture = {'id': 3, |
426 | + extra_fixture = {'id': self.next_image_id, |
427 | 'status': 'active', |
428 | 'is_public': True, |
429 | 'disk_format': 'vhd', |
430 | @@ -129,7 +129,7 @@ |
431 | |
432 | def test_get_image_details_by_status(self): |
433 | """Tests that a detailed call can be filtered by status""" |
434 | - extra_fixture = {'id': 3, |
435 | + extra_fixture = {'id': self.next_image_id, |
436 | 'status': 'saving', |
437 | 'is_public': True, |
438 | 'disk_format': 'vhd', |
439 | @@ -148,7 +148,7 @@ |
440 | |
441 | def test_get_image_details_by_container_format(self): |
442 | """Tests that a detailed call can be filtered by container_format""" |
443 | - extra_fixture = {'id': 3, |
444 | + extra_fixture = {'id': self.next_image_id, |
445 | 'status': 'saving', |
446 | 'is_public': True, |
447 | 'disk_format': 'vhd', |
448 | @@ -167,7 +167,7 @@ |
449 | |
450 | def test_get_image_details_by_disk_format(self): |
451 | """Tests that a detailed call can be filtered by disk_format""" |
452 | - extra_fixture = {'id': 3, |
453 | + extra_fixture = {'id': self.next_image_id, |
454 | 'status': 'saving', |
455 | 'is_public': True, |
456 | 'disk_format': 'vhd', |
457 | @@ -186,7 +186,7 @@ |
458 | |
459 | def test_get_image_details_with_maximum_size(self): |
460 | """Tests that a detailed call can be filtered by size_max""" |
461 | - extra_fixture = {'id': 3, |
462 | + extra_fixture = {'id': self.next_image_id, |
463 | 'status': 'saving', |
464 | 'is_public': True, |
465 | 'disk_format': 'vhd', |
466 | @@ -205,7 +205,7 @@ |
467 | |
468 | def test_get_image_details_with_minimum_size(self): |
469 | """Tests that a detailed call can be filtered by size_min""" |
470 | - extra_fixture = {'id': 3, |
471 | + extra_fixture = {'id': self.next_image_id, |
472 | 'status': 'saving', |
473 | 'is_public': True, |
474 | 'disk_format': 'vhd', |
475 | @@ -224,7 +224,7 @@ |
476 | |
477 | def test_get_image_details_by_property(self): |
478 | """Tests that a detailed call can be filtered by a property""" |
479 | - extra_fixture = {'id': 3, |
480 | + extra_fixture = {'id': self.next_image_id, |
481 | 'status': 'saving', |
482 | 'is_public': True, |
483 | 'disk_format': 'vhd', |
484 | @@ -282,10 +282,10 @@ |
485 | new_image = self.client.add_image(fixture) |
486 | |
487 | # Test ID auto-assigned properly |
488 | - self.assertEquals(3, new_image['id']) |
489 | + self.assertEquals(self.next_image_id, new_image['id']) |
490 | |
491 | # Test all other attributes set |
492 | - data = self.client.get_image(3) |
493 | + data = self.client.get_image(self.next_image_id) |
494 | |
495 | for k, v in fixture.items(): |
496 | self.assertEquals(v, data[k]) |
497 | @@ -307,7 +307,7 @@ |
498 | new_image = self.client.add_image(fixture) |
499 | |
500 | # Test ID auto-assigned properly |
501 | - self.assertEquals(3, new_image['id']) |
502 | + self.assertEquals(self.next_image_id, new_image['id']) |
503 | |
504 | for k, v in fixture.items(): |
505 | self.assertEquals(v, new_image[k]) |
506 | @@ -334,7 +334,7 @@ |
507 | |
508 | def test_add_image_with_bad_status(self): |
509 | """Tests proper exception is raised if a bad status is set""" |
510 | - fixture = {'id': 3, |
511 | + fixture = {'id': self.next_image_id, |
512 | 'name': 'fake public image', |
513 | 'is_public': True, |
514 | 'disk_format': 'vmdk', |
515 | @@ -363,7 +363,7 @@ |
516 | |
517 | def test_update_image_not_existing(self): |
518 | """Tests non existing image update doesn't work""" |
519 | - fixture = {'id': 3, |
520 | + fixture = {'id': self.next_image_id, |
521 | 'name': 'fake public image', |
522 | 'is_public': True, |
523 | 'disk_format': 'vmdk', |
524 | @@ -373,7 +373,7 @@ |
525 | |
526 | self.assertRaises(exception.NotFound, |
527 | self.client.update_image, |
528 | - 3, |
529 | + self.next_image_id, |
530 | fixture) |
531 | |
532 | def test_delete_image(self): |
533 | @@ -395,7 +395,7 @@ |
534 | |
535 | self.assertRaises(exception.NotFound, |
536 | self.client.delete_image, |
537 | - 3) |
538 | + self.next_image_id) |
539 | |
540 | |
541 | class TestClient(unittest.TestCase): |
542 | @@ -408,7 +408,7 @@ |
543 | def setUp(self): |
544 | """Establish a clean test environment""" |
545 | self.stubs = stubout.StubOutForTesting() |
546 | - stubs.stub_out_registry_db_image_api(self.stubs) |
547 | + self.next_image_id = stubs.stub_out_registry_db_image_api(self.stubs) |
548 | stubs.stub_out_registry_and_store_server(self.stubs) |
549 | stubs.stub_out_filesystem_backend() |
550 | self.client = client.Client("0.0.0.0", doc_root="") |
551 | @@ -445,7 +445,7 @@ |
552 | |
553 | self.assertRaises(exception.NotFound, |
554 | self.client.get_image, |
555 | - 3) |
556 | + self.next_image_id) |
557 | |
558 | def test_get_image_index(self): |
559 | """Test correct set of public image returned""" |
560 | @@ -502,6 +502,23 @@ |
561 | for k, v in fixture.items(): |
562 | self.assertEquals(v, data[k]) |
563 | |
564 | + def test_get_image_iso_meta(self): |
565 | + """Tests that the detailed info about an iso image is returned""" |
566 | + fixture = {'id': 3, |
567 | + 'name': 'fake iso image', |
568 | + 'is_public': False, |
569 | + 'disk_format': 'iso', |
570 | + 'container_format': 'bare', |
571 | + 'status': 'active', |
572 | + 'size': 19, |
573 | + 'location': "file:///tmp/glance-tests/3", |
574 | + 'properties': {}} |
575 | + |
576 | + data = self.client.get_image_meta(3) |
577 | + |
578 | + for k, v in fixture.items(): |
579 | + self.assertEquals(v, data[k]) |
580 | + |
581 | def test_get_image_non_existing(self): |
582 | """Tests that NotFound is raised when getting a non-existing image""" |
583 | |
584 | @@ -533,10 +550,10 @@ |
585 | new_image_id = new_image['id'] |
586 | |
587 | # Test ID auto-assigned properly |
588 | - self.assertEquals(3, new_image_id) |
589 | + self.assertEquals(self.next_image_id, new_image_id) |
590 | |
591 | # Test all other attributes set |
592 | - data = self.client.get_image_meta(3) |
593 | + data = self.client.get_image_meta(self.next_image_id) |
594 | |
595 | for k, v in fixture.items(): |
596 | self.assertEquals(v, data[k]) |
597 | @@ -559,17 +576,59 @@ |
598 | new_image_id = new_image['id'] |
599 | |
600 | # Test ID auto-assigned properly |
601 | - self.assertEquals(3, new_image_id) |
602 | - |
603 | - # Test all other attributes set |
604 | - data = self.client.get_image_meta(3) |
605 | - |
606 | - for k, v in fixture.items(): |
607 | - self.assertEquals(v, data[k]) |
608 | - |
609 | - # Test status was updated properly |
610 | - self.assertTrue('status' in data) |
611 | - self.assertEquals('active', data['status']) |
612 | + self.assertEquals(self.next_image_id, new_image_id) |
613 | + |
614 | + # Test all other attributes set |
615 | + data = self.client.get_image_meta(self.next_image_id) |
616 | + |
617 | + for k, v in fixture.items(): |
618 | + self.assertEquals(v, data[k]) |
619 | + |
620 | + # Test status was updated properly |
621 | + self.assertTrue('status' in data) |
622 | + self.assertEquals('active', data['status']) |
623 | + |
624 | + def test_add_image_with_iso_properties(self): |
625 | + """Tests that we can add image metadata with iso disk format""" |
626 | + fixture = {'name': 'fake public iso', |
627 | + 'is_public': True, |
628 | + 'disk_format': 'iso', |
629 | + 'container_format': 'bare', |
630 | + 'size': 19, |
631 | + 'location': "file:///tmp/glance-tests/2", |
632 | + 'properties': {'install': 'Bindows Heaven'}, |
633 | + } |
634 | + new_image = self.client.add_image(fixture) |
635 | + new_image_id = new_image['id'] |
636 | + |
637 | + # Test ID auto-assigned properly |
638 | + self.assertEquals(self.next_image_id, new_image_id) |
639 | + |
640 | + # Test all other attributes set |
641 | + data = self.client.get_image_meta(self.next_image_id) |
642 | + |
643 | + for k, v in fixture.items(): |
644 | + self.assertEquals(v, data[k]) |
645 | + |
646 | + # Test status was updated properly |
647 | + self.assertTrue('status' in data) |
648 | + self.assertEquals('active', data['status']) |
649 | + |
650 | + def test_add_image_with_bad_iso_properties(self): |
651 | + """Tests that we can add image metadata with iso disk format""" |
652 | + fixture = {'name': 'fake public iso', |
653 | + 'is_public': True, |
654 | + 'disk_format': 'iso', |
655 | + 'container_format': 'vhd', |
656 | + 'size': 19, |
657 | + 'location': "file:///tmp/glance-tests/" |
658 | + + str(self.next_image_id), |
659 | + 'properties': {'install': 'Bindows Heaven'}, |
660 | + } |
661 | + |
662 | + self.assertRaises(exception.Invalid, |
663 | + self.client.add_image, |
664 | + fixture) |
665 | |
666 | def test_add_image_already_exists(self): |
667 | """Tests proper exception is raised if image with ID already exists""" |
668 | @@ -615,9 +674,9 @@ |
669 | |
670 | new_image = self.client.add_image(fixture, image_data_fixture) |
671 | new_image_id = new_image['id'] |
672 | - self.assertEquals(3, new_image_id) |
673 | + self.assertEquals(self.next_image_id, new_image_id) |
674 | |
675 | - new_meta, new_image_chunks = self.client.get_image(3) |
676 | + new_meta, new_image_chunks = self.client.get_image(self.next_image_id) |
677 | |
678 | new_image_data = "" |
679 | for image_chunk in new_image_chunks: |
680 | @@ -650,12 +709,12 @@ |
681 | |
682 | new_image = self.client.add_image(fixture, open(tmp_image_filepath)) |
683 | new_image_id = new_image['id'] |
684 | - self.assertEquals(3, new_image_id) |
685 | + self.assertEquals(self.next_image_id, new_image_id) |
686 | |
687 | if os.path.exists(tmp_image_filepath): |
688 | os.unlink(tmp_image_filepath) |
689 | |
690 | - new_meta, new_image_chunks = self.client.get_image(3) |
691 | + new_meta, new_image_chunks = self.client.get_image(self.next_image_id) |
692 | |
693 | new_image_data = "" |
694 | for image_chunk in new_image_chunks: |
695 | @@ -678,9 +737,9 @@ |
696 | |
697 | new_image = self.client.add_image(fixture, image_data_fixture) |
698 | new_image_id = new_image['id'] |
699 | - self.assertEquals(3, new_image_id) |
700 | + self.assertEquals(self.next_image_id, new_image_id) |
701 | |
702 | - new_meta, new_image_chunks = self.client.get_image(3) |
703 | + new_meta, new_image_chunks = self.client.get_image(self.next_image_id) |
704 | |
705 | new_image_data = "" |
706 | for image_chunk in new_image_chunks: |
707 | @@ -725,7 +784,7 @@ |
708 | |
709 | def test_update_image_not_existing(self): |
710 | """Tests non existing image update doesn't work""" |
711 | - fixture = {'id': 3, |
712 | + fixture = {'id': self.next_image_id, |
713 | 'name': 'fake public image', |
714 | 'is_public': True, |
715 | 'disk_format': 'vhd', |
716 | @@ -735,7 +794,7 @@ |
717 | |
718 | self.assertRaises(exception.NotFound, |
719 | self.client.update_image, |
720 | - 3, |
721 | + self.next_image_id, |
722 | fixture) |
723 | |
724 | def test_delete_image(self): |
725 | @@ -757,4 +816,4 @@ |
726 | |
727 | self.assertRaises(exception.NotFound, |
728 | self.client.delete_image, |
729 | - 3) |
730 | + self.next_image_id) |
Nice work, Donal! Thanks for your work in refactoring the unit tests to make them more flexible.
One tiny thing, though. Please update the documentation for disk_formats for both these places:
http:// glance. openstack. org/formats. html glance. openstack. org/glanceapi. html
http://
You can find these in the source tree under /doc/source/ formats. rst and /doc/source/ glanceapi. rst.
Thanks!
jay