#NEWLINE# def RunPhase( self , phase , node_uuids = None , is_global = False , post_status = None ) : #NEWLINE# #INDENT# 'Run all the scripts for a phase.\n\n    This is the main function of the HookMaster.\n    It executes self.hooks_execution_fn, and after running\n    self.hooks_results_adapt_fn on its results it expects them to be in the\n    form {node_name: (fail_msg, [(script, result, output), ...]}).\n\n    @param phase: one of L{constants.HOOKS_PHASE_POST} or\n        L{constants.HOOKS_PHASE_PRE}; it denotes the hooks phase\n    @param node_uuids: overrides the predefined list of nodes for the given\n        phase\n    @param is_global: whether global or per-opcode hooks should be executed\n    @param post_status: the job execution status for the global post hooks\n    @return: the processed results of the hooks multi-node rpc call\n    @raise errors.HooksFailure: on communication failure to the nodes\n    @raise errors.HooksAbort: on failure of one of the hooks\n\n    ' #NEWLINE# if ( phase == constants . HOOKS_PHASE_PRE ) : #NEWLINE# #INDENT# if ( node_uuids is None ) : #NEWLINE# #INDENT# node_uuids = self . pre_nodes #NEWLINE# #UNINDENT# env = self . pre_env #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( phase == constants . HOOKS_PHASE_POST ) : #NEWLINE# #INDENT# if ( node_uuids is None ) : #NEWLINE# #INDENT# node_uuids = self . post_nodes #NEWLINE# if ( ( node_uuids is not None ) and ( self . prepare_post_nodes_fn is not None ) ) : #NEWLINE# #INDENT# node_uuids = frozenset ( self . prepare_post_nodes_fn ( list ( node_uuids ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# env = self . _BuildEnv ( phase ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise AssertionError ( ( "Unknown phase '%s'" % phase ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( not node_uuids ) and ( not is_global ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# hooks_path = ( constants . GLOBAL_HOOKS_DIR if is_global else self . hooks_path ) #NEWLINE# results = self . _RunWrapper ( node_uuids , hooks_path , phase , env , is_global , post_status ) #NEWLINE# if ( not results ) : #NEWLINE# #INDENT# msg = 'Communication Failure' #NEWLINE# if ( phase == constants . HOOKS_PHASE_PRE ) : #NEWLINE# #INDENT# raise errors . HooksFailure ( msg ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . log_fn ( msg ) #NEWLINE# return results #NEWLINE# #UNINDENT# #UNINDENT# converted_res = results #NEWLINE# if self . hooks_results_adapt_fn : #NEWLINE# #INDENT# converted_res = self . hooks_results_adapt_fn ( results ) #NEWLINE# #UNINDENT# errs = [ ] #NEWLINE# for ( node_name , ( fail_msg , offline , hooks_results ) ) in converted_res . items ( ) : #NEWLINE# #INDENT# if offline : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if fail_msg : #NEWLINE# #INDENT# self . log_fn ( 'Communication failure to node %s: %s' , node_name , fail_msg ) #NEWLINE# continue #NEWLINE# #UNINDENT# for ( script , hkr , output ) in hooks_results : #NEWLINE# #INDENT# if ( hkr == constants . HKR_FAIL ) : #NEWLINE# #INDENT# if ( phase == constants . HOOKS_PHASE_PRE ) : #NEWLINE# #INDENT# errs . append ( ( node_name , script , output ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not output ) : #NEWLINE# #INDENT# output = '(no output)' #NEWLINE# #UNINDENT# self . log_fn ( ( 'On %s script %s failed, output: %s' % ( node_name , script , output ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( errs and ( phase == constants . HOOKS_PHASE_PRE ) ) : #NEWLINE# #INDENT# raise errors . HooksAbort ( errs ) #NEWLINE# #UNINDENT# return results