#NEWLINE# @ mock . patch . object ( six . moves . builtins , 'open' ) #NEWLINE# @ mock . patch ( 'nova.image.glance.GlanceImageService._get_transfer_module' ) #NEWLINE# @ mock . patch ( 'nova.image.glance.GlanceImageService.show' ) #NEWLINE# def test_download_direct_exception_fallback( self , show_mock , get_tran_mock , open_mock ) : #NEWLINE# #INDENT# self . flags ( allowed_direct_url_schemes = [ 'file' ] , group = 'glance' ) #NEWLINE# show_mock . return_value = { #NEWLINE# #INDENT# 'locations' : [ { #NEWLINE# #INDENT# 'url' : 'file:///files/image' , #NEWLINE# 'metadata' : mock . sentinel . loc_meta , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } #NEWLINE# tran_mod = mock . MagicMock ( ) #NEWLINE# tran_mod . download . side_effect = Exception #NEWLINE# get_tran_mock . return_value = tran_mod #NEWLINE# client = mock . MagicMock ( ) #NEWLINE# client . call . return_value = [ 1 , 2 , 3 ] #NEWLINE# ctx = mock . sentinel . ctx #NEWLINE# writer = mock . MagicMock ( ) #NEWLINE# open_mock . return_value = writer #NEWLINE# service = glance . GlanceImageService ( client ) #NEWLINE# res = service . download ( ctx , mock . sentinel . image_id , dst_path = mock . sentinel . dst_path ) #NEWLINE# self . assertIsNone ( res ) #NEWLINE# show_mock . assert_called_once_with ( ctx , mock . sentinel . image_id , include_locations = True ) #NEWLINE# get_tran_mock . assert_called_once_with ( 'file' ) #NEWLINE# tran_mod . download . assert_called_once_with ( ctx , mock . ANY , mock . sentinel . dst_path , mock . sentinel . loc_meta ) #NEWLINE# client . call . assert_called_once_with ( ctx , 1 , 'data' , mock . sentinel . image_id ) #NEWLINE# open_mock . assert_called_with ( mock . sentinel . dst_path , 'wb' ) #NEWLINE# self . assertIsNone ( res ) #NEWLINE# writer . write . assert_has_calls ( [ mock . call ( 1 ) , mock . call ( 2 ) , mock . call ( 3 ) ] )