@@ -722,3 +722,115 @@ def test_output_on_error(self):
722722 ac_ex_db = ex_db_access .ActionExecution .get_by_id (str (ac_ex_db .id ))
723723 self .assertEqual (ac_ex_db .status , ac_const .LIVEACTION_STATUS_FAILED )
724724 self .assertDictEqual (ac_ex_db .result , expected_result )
725+
726+ def test_fail_manually (self ):
727+ wf_meta = base .get_wf_fixture_meta_data (TEST_PACK_PATH , 'fail-manually.yaml' )
728+ lv_ac_db = lv_db_models .LiveActionDB (action = wf_meta ['name' ])
729+ lv_ac_db , ac_ex_db = ac_svc .request (lv_ac_db )
730+ wf_ex_db = wf_db_access .WorkflowExecution .query (action_execution = str (ac_ex_db .id ))[0 ]
731+
732+ # Assert task1 and workflow execution failed due to fail in the task transition.
733+ query_filters = {'workflow_execution' : str (wf_ex_db .id ), 'task_id' : 'task1' }
734+ tk1_ex_db = wf_db_access .TaskExecution .query (** query_filters )[0 ]
735+ tk1_ac_ex_db = ex_db_access .ActionExecution .query (task_execution = str (tk1_ex_db .id ))[0 ]
736+ tk1_lv_ac_db = lv_db_access .LiveAction .get_by_id (tk1_ac_ex_db .liveaction ['id' ])
737+ self .assertEqual (tk1_lv_ac_db .status , ac_const .LIVEACTION_STATUS_FAILED )
738+ wf_svc .handle_action_execution_completion (tk1_ac_ex_db )
739+ wf_ex_db = wf_db_access .WorkflowExecution .get_by_id (wf_ex_db .id )
740+ self .assertEqual (wf_ex_db .status , wf_statuses .FAILED )
741+
742+ # Assert log task is scheduled even though the workflow execution failed manually.
743+ query_filters = {'workflow_execution' : str (wf_ex_db .id ), 'task_id' : 'log' }
744+ tk2_ex_db = wf_db_access .TaskExecution .query (** query_filters )[0 ]
745+ tk2_ac_ex_db = ex_db_access .ActionExecution .query (task_execution = str (tk2_ex_db .id ))[0 ]
746+ tk2_lv_ac_db = lv_db_access .LiveAction .get_by_id (tk2_ac_ex_db .liveaction ['id' ])
747+ self .assertEqual (tk2_lv_ac_db .status , ac_const .LIVEACTION_STATUS_SUCCEEDED )
748+ wf_svc .handle_action_execution_completion (tk2_ac_ex_db )
749+ wf_ex_db = wf_db_access .WorkflowExecution .get_by_id (wf_ex_db .id )
750+ self .assertEqual (wf_ex_db .status , wf_statuses .FAILED )
751+
752+ # Check errors and output.
753+ expected_errors = [
754+ {
755+ 'task_id' : 'fail' ,
756+ 'type' : 'error' ,
757+ 'message' : 'Execution failed. See result for details.'
758+ },
759+ {
760+ 'task_id' : 'task1' ,
761+ 'type' : 'error' ,
762+ 'message' : 'Execution failed. See result for details.' ,
763+ 'result' : {
764+ 'failed' : True ,
765+ 'return_code' : 1 ,
766+ 'stderr' : '' ,
767+ 'stdout' : '' ,
768+ 'succeeded' : False
769+ }
770+ }
771+ ]
772+
773+ self .assertListEqual (self .sort_wf_runtime_errors (wf_ex_db .errors ), expected_errors )
774+
775+ def test_fail_manually_with_recovery_failure (self ):
776+ wf_file = 'fail-manually-with-recovery-failure.yaml'
777+ wf_meta = base .get_wf_fixture_meta_data (TEST_PACK_PATH , wf_file )
778+ lv_ac_db = lv_db_models .LiveActionDB (action = wf_meta ['name' ])
779+ lv_ac_db , ac_ex_db = ac_svc .request (lv_ac_db )
780+ wf_ex_db = wf_db_access .WorkflowExecution .query (action_execution = str (ac_ex_db .id ))[0 ]
781+
782+ # Assert task1 and workflow execution failed due to fail in the task transition.
783+ query_filters = {'workflow_execution' : str (wf_ex_db .id ), 'task_id' : 'task1' }
784+ tk1_ex_db = wf_db_access .TaskExecution .query (** query_filters )[0 ]
785+ tk1_ac_ex_db = ex_db_access .ActionExecution .query (task_execution = str (tk1_ex_db .id ))[0 ]
786+ tk1_lv_ac_db = lv_db_access .LiveAction .get_by_id (tk1_ac_ex_db .liveaction ['id' ])
787+ self .assertEqual (tk1_lv_ac_db .status , ac_const .LIVEACTION_STATUS_FAILED )
788+ wf_svc .handle_action_execution_completion (tk1_ac_ex_db )
789+ wf_ex_db = wf_db_access .WorkflowExecution .get_by_id (wf_ex_db .id )
790+ self .assertEqual (wf_ex_db .status , wf_statuses .FAILED )
791+
792+ # Assert recover task is scheduled even though the workflow execution failed manually.
793+ # The recover task in the workflow is setup to fail.
794+ query_filters = {'workflow_execution' : str (wf_ex_db .id ), 'task_id' : 'recover' }
795+ tk2_ex_db = wf_db_access .TaskExecution .query (** query_filters )[0 ]
796+ tk2_ac_ex_db = ex_db_access .ActionExecution .query (task_execution = str (tk2_ex_db .id ))[0 ]
797+ tk2_lv_ac_db = lv_db_access .LiveAction .get_by_id (tk2_ac_ex_db .liveaction ['id' ])
798+ self .assertEqual (tk2_lv_ac_db .status , ac_const .LIVEACTION_STATUS_FAILED )
799+ wf_svc .handle_action_execution_completion (tk2_ac_ex_db )
800+ wf_ex_db = wf_db_access .WorkflowExecution .get_by_id (wf_ex_db .id )
801+ self .assertEqual (wf_ex_db .status , wf_statuses .FAILED )
802+
803+ # Check errors and output.
804+ expected_errors = [
805+ {
806+ 'task_id' : 'fail' ,
807+ 'type' : 'error' ,
808+ 'message' : 'Execution failed. See result for details.'
809+ },
810+ {
811+ 'task_id' : 'recover' ,
812+ 'type' : 'error' ,
813+ 'message' : 'Execution failed. See result for details.' ,
814+ 'result' : {
815+ 'failed' : True ,
816+ 'return_code' : 1 ,
817+ 'stderr' : '' ,
818+ 'stdout' : '' ,
819+ 'succeeded' : False
820+ }
821+ },
822+ {
823+ 'task_id' : 'task1' ,
824+ 'type' : 'error' ,
825+ 'message' : 'Execution failed. See result for details.' ,
826+ 'result' : {
827+ 'failed' : True ,
828+ 'return_code' : 1 ,
829+ 'stderr' : '' ,
830+ 'stdout' : '' ,
831+ 'succeeded' : False
832+ }
833+ }
834+ ]
835+
836+ self .assertListEqual (self .sort_wf_runtime_errors (wf_ex_db .errors ), expected_errors )
0 commit comments