#NEWLINE# def execute( self , * cmd , **kwargs ) : #NEWLINE# #INDENT# cmd = [ str ( c ) for c in cmd ] #NEWLINE# loglevel = kwargs . pop ( 'loglevel' , std_logging . DEBUG ) #NEWLINE# log_errors = kwargs . pop ( 'log_errors' , None ) #NEWLINE# process_input = kwargs . pop ( 'process_input' , None ) #NEWLINE# delay_on_retry = kwargs . pop ( 'delay_on_retry' , True ) #NEWLINE# attempts = kwargs . pop ( 'attempts' , 1 ) #NEWLINE# check_exit_code = kwargs . pop ( 'check_exit_code' , [ 0 ] ) #NEWLINE# ignore_exit_code = False #NEWLINE# if isinstance ( check_exit_code , bool ) : #NEWLINE# #INDENT# ignore_exit_code = ( not check_exit_code ) #NEWLINE# check_exit_code = [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( check_exit_code , int ) : #NEWLINE# #INDENT# check_exit_code = [ check_exit_code ] #NEWLINE# #UNINDENT# #UNINDENT# sanitized_cmd = strutils . mask_password ( ' ' . join ( cmd ) ) #NEWLINE# LOG . info ( _LI ( 'Executing RootwrapDaemonHelper.execute cmd=[%(cmd)r] kwargs=[%(kwargs)r]' ) , { #NEWLINE# #INDENT# 'cmd' : sanitized_cmd , #NEWLINE# 'kwargs' : kwargs , #NEWLINE# #UNINDENT# } ) #NEWLINE# while ( attempts > 0 ) : #NEWLINE# #INDENT# attempts -= 1 #NEWLINE# try : #NEWLINE# #INDENT# start_time = time . time ( ) #NEWLINE# LOG . log ( loglevel , _ ( 'Running cmd (subprocess): %s' ) , sanitized_cmd ) #NEWLINE# ( returncode , out , err ) = self . client . execute ( cmd , process_input ) #NEWLINE# end_time = ( time . time ( ) - start_time ) #NEWLINE# LOG . log ( loglevel , 'CMD "%(sanitized_cmd)s" returned: %(return_code)s in %(end_time)0.3fs' , { #NEWLINE# #INDENT# 'sanitized_cmd' : sanitized_cmd , #NEWLINE# 'return_code' : returncode , #NEWLINE# 'end_time' : end_time , #NEWLINE# #UNINDENT# } ) #NEWLINE# if ( ( not ignore_exit_code ) and ( returncode not in check_exit_code ) ) : #NEWLINE# #INDENT# out = strutils . mask_password ( out ) #NEWLINE# err = strutils . mask_password ( err ) #NEWLINE# raise processutils . ProcessExecutionError ( exit_code = returncode , stdout = out , stderr = err , cmd = sanitized_cmd ) #NEWLINE# #UNINDENT# return ( c , err ) #NEWLINE# #UNINDENT# except processutils . ProcessExecutionError as err : #NEWLINE# #INDENT# if ( ( log_errors == processutils . LOG_ALL_ERRORS ) or ( ( log_errors == processutils . LOG_FINAL_ERROR ) and ( not attempts ) ) ) : #NEWLINE# #INDENT# format = _ ( '%(desc)r\ncommand: %(cmd)r\nexit code: %(code)r\nstdout: %(stdout)r\nstderr: %(stderr)r' ) #NEWLINE# LOG . log ( loglevel , format , { #NEWLINE# #INDENT# 'desc' : err . description , #NEWLINE# 'cmd' : err . cmd , #NEWLINE# 'code' : err . exit_code , #NEWLINE# 'stdout' : err . stdout , #NEWLINE# 'stderr' : err . stderr , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if ( not attempts ) : #NEWLINE# #INDENT# LOG . log ( loglevel , _ ( '%r failed. Not Retrying.' ) , sanitized_cmd ) #NEWLINE# raise #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# LOG . log ( loglevel , _ ( '%r failed. Retrying.' ) , sanitized_cmd ) #NEWLINE# if delay_on_retry : #NEWLINE# #INDENT# time . sleep ( ( random . randint ( 20 , 200 ) / 100.0 ) )