#NEWLINE# def _state_wait( self , f , f_args = None , f_kwargs = None , final_set = set ( ) , error_set = 'error' ) : #NEWLINE# #INDENT# if ( not isinstance ( final_set , set ) ) : #NEWLINE# #INDENT# final_set = set ( ( final_set , ) ) #NEWLINE# #UNINDENT# if ( not isinstance ( error_set , set ) ) : #NEWLINE# #INDENT# error_set = set ( ( error_set , ) ) #NEWLINE# #UNINDENT# interval = self . default_check_interval #NEWLINE# start_time = time . time ( ) #NEWLINE# args = ( f_args if ( f_args is not None ) else [ ] ) #NEWLINE# kwargs = ( f_kwargs if ( f_kwargs is not None ) else { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# try : #NEWLINE# #INDENT# old_status = status = f ( * args , ** kwargs ) #NEWLINE# #UNINDENT# except exceptions . NotFound : #NEWLINE# #INDENT# old_status = status = 'NotFound' #NEWLINE# #UNINDENT# while True : #NEWLINE# #INDENT# if ( status != old_status ) : #NEWLINE# #INDENT# LOG . info ( 'State transition "%s" ==> "%s" %d second' , old_status , status , ( time . time ( ) - start_time ) ) #NEWLINE# #UNINDENT# if ( status in final_set ) : #NEWLINE# #INDENT# return status #NEWLINE# #UNINDENT# if ( ( error_set is not None ) and ( status in error_set ) ) : #NEWLINE# #INDENT# raise testtools . TestCase . failureException ( ( 'State changes to error state! While waiting for %s at "%s"' % ( final_set , status ) ) ) #NEWLINE# #UNINDENT# dtime = ( time . time ( ) - start_time ) #NEWLINE# if ( dtime > self . default_timeout ) : #NEWLINE# #INDENT# raise testtools . TestCase . failureException ( ( 'State change timeout exceeded! (%ds) While waiting for %s at "%s"' % ( dtime , final_set , status ) ) ) #NEWLINE# #UNINDENT# time . sleep ( interval ) #NEWLINE# interval += self . default_check_interval #NEWLINE# old_status = status #NEWLINE# try : #NEWLINE# #INDENT# status = f ( * args , ** kwargs ) #NEWLINE# #UNINDENT# except exceptions . NotFound : #NEWLINE# #INDENT# status = 'NotFound'