#NEWLINE# @ mock . patch ( 'random.shuffle' ) #NEWLINE# @ mock . patch ( 'time.sleep' ) #NEWLINE# @ mock . patch ( 'nova.image.glance._glanceclient_from_endpoint' ) #NEWLINE# def test_retry_works_with_generators( self , create_client_mock , sleep_mock , shuffle_mock ) : #NEWLINE# #INDENT# def some_generator( exception ) : #NEWLINE# #INDENT# if exception : #NEWLINE# #INDENT# raise glanceclient . exc . CommunicationError ( 'Boom!' ) #NEWLINE# #UNINDENT# ( yield 'something' ) #NEWLINE# #UNINDENT# api_servers = [ 'https://host2:9292' , 'https://host2:9293' , 'http://host3:9294' ] #NEWLINE# client_mock = mock . MagicMock ( ) #NEWLINE# images_mock = mock . MagicMock ( ) #NEWLINE# images_mock . list . side_effect = [ some_generator ( exception = True ) , some_generator ( exception = False ) ] #NEWLINE# type ( client_mock ) . images = mock . PropertyMock ( return_value = images_mock ) #NEWLINE# create_client_mock . return_value = client_mock #NEWLINE# self . flags ( num_retries = 1 , group = 'glance' ) #NEWLINE# self . flags ( api_servers = api_servers , group = 'glance' ) #NEWLINE# ctx = context . RequestContext ( 'fake' , 'fake' ) #NEWLINE# client = glance . GlanceClientWrapper ( ) #NEWLINE# client . call ( ctx , 1 , 'list' , 'meow' ) #NEWLINE# sleep_mock . assert_called_once_with ( 1 ) #NEWLINE# self . assertEqual ( str ( client . api_server ) , 'https://host2:9293' )