@@ -283,6 +283,37 @@ def test_image_set_data_inspector_no_match(self):
283
283
self .assertEqual ('active' , image .status )
284
284
self .assertEqual (0 , image .virtual_size )
285
285
286
+ @mock .patch ('glance.common.format_inspector.QcowInspector.virtual_size' ,
287
+ new_callable = mock .PropertyMock )
288
+ @mock .patch ('glance.common.format_inspector.QcowInspector.format_match' ,
289
+ new_callable = mock .PropertyMock )
290
+ def test_image_set_data_inspector_virtual_size_failure (self , mock_fm ,
291
+ mock_vs ):
292
+ # Force our format to match
293
+ mock_fm .return_value = True
294
+
295
+ # Make virtual_size fail in some unexpected way
296
+ mock_vs .side_effect = ValueError ('some error' )
297
+
298
+ context = glance .context .RequestContext (user = USER1 )
299
+ image_stub = ImageStub (UUID2 , status = 'queued' , locations = [])
300
+ image_stub .disk_format = 'qcow2'
301
+ # We are going to pass an iterable data source, so use the
302
+ # FakeStoreAPIReader that actually reads from that data
303
+ store_api = unit_test_utils .FakeStoreAPIReader ()
304
+ image = glance .location .ImageProxy (image_stub , context ,
305
+ store_api , self .store_utils )
306
+
307
+ # Make sure set_data proceeds even though the format clearly
308
+ # does not match
309
+ image .set_data (iter (['YYYY' ]), 4 )
310
+ self .assertEqual (4 , image .size )
311
+ # NOTE(markwash): FakeStore returns image_id for location
312
+ self .assertEqual (UUID2 , image .locations [0 ]['url' ])
313
+ self .assertEqual ('Z' , image .checksum )
314
+ self .assertEqual ('active' , image .status )
315
+ self .assertEqual (0 , image .virtual_size )
316
+
286
317
@mock .patch ('glance.common.format_inspector.get_inspector' )
287
318
def test_image_set_data_inspector_not_needed (self , mock_gi ):
288
319
context = glance .context .RequestContext (user = USER1 )
0 commit comments