#NEWLINE# @ mock . patch ( 'sahara.utils.openstack.heat.get_stack' ) #NEWLINE# @ mock . patch ( 'sahara.context.sleep' , return_value = None ) #NEWLINE# def test_wait_completion( self , sleep , client ) : #NEWLINE# #INDENT# cl = mock . Mock ( stack_name = 'cluster' ) #NEWLINE# client . side_effect = [ stack ( 'CREATE_IN_PROGRESS' ) , stack ( 'CREATE_COMPLETE' ) ] #NEWLINE# h . wait_stack_completion ( cl ) #NEWLINE# self . assertEqual ( 2 , client . call_count ) #NEWLINE# client . side_effect = [ stack ( 'UPDATE_IN_PROGRESS' ) , stack ( 'UPDATE_COMPLETE' ) ] #NEWLINE# h . wait_stack_completion ( client ) #NEWLINE# self . assertEqual ( 4 , client . call_count ) #NEWLINE# client . side_effect = [ stack ( 'DELETE_IN_PROGRESS' ) , stack ( 'DELETE_COMPLETE' ) ] #NEWLINE# h . wait_stack_completion ( cl ) #NEWLINE# self . assertEqual ( 6 , client . call_count ) #NEWLINE# client . side_effect = [ stack ( 'CREATE_COMPLETE' ) , stack ( 'CREATE_COMPLETE' ) , stack ( 'UPDATE_IN_PROGRESS' ) , stack ( 'UPDATE_COMPLETE' , 1 ) ] #NEWLINE# h . wait_stack_completion ( cl , is_update = True ) #NEWLINE# self . assertEqual ( 10 , client . call_count ) #NEWLINE# client . side_effect = [ stack ( 'UPDATE_COMPLETE' ) , stack ( 'UPDATE_IN_PROGRESS' ) , stack ( 'UPDATE_COMPLETE' , 1 ) ] #NEWLINE# h . wait_stack_completion ( cl , is_update = True ) #NEWLINE# self . assertEqual ( 13 , client . call_count ) #NEWLINE# client . side_effect = [ stack ( 'CREATE_IN_PROGRESS' ) , stack ( 'CREATE_FAILED' ) ] #NEWLINE# with testtools . ExpectedException ( ex . HeatStackException , value_re = 'Heat stack failed with status CREATE_FAILED\nError ID: .*' ) : #NEWLINE# #INDENT# h . wait_stack_completion ( cl )