Beispiel #1
0
    def test_request_rerun_again_while_prev_rerun_is_still_running(self):
        # Create and return a failed workflow execution.
        wf_meta, lv_ac_db1, ac_ex_db1, wf_ex_db = self.prep_wf_ex_for_rerun()

        # Manually create the liveaction and action execution objects for the rerun.
        lv_ac_db2 = lv_db_models.LiveActionDB(action=wf_meta["name"])
        lv_ac_db2, ac_ex_db2 = action_service.create_request(lv_ac_db2)

        # Request workflow execution rerun.
        st2_ctx = self.mock_st2_context(ac_ex_db2, ac_ex_db1.context)
        st2_ctx["workflow_execution_id"] = str(wf_ex_db.id)
        rerun_options = {"ref": str(ac_ex_db1.id), "tasks": ["task1"]}
        wf_ex_db = workflow_service.request_rerun(ac_ex_db2, st2_ctx,
                                                  rerun_options)
        wf_ex_db = self.prep_wf_ex(wf_ex_db)

        # Check workflow status.
        conductor, wf_ex_db = workflow_service.refresh_conductor(
            str(wf_ex_db.id))
        self.assertEqual(conductor.get_workflow_status(), wf_statuses.RUNNING)
        self.assertEqual(wf_ex_db.status, wf_statuses.RUNNING)

        # Complete task1.
        self.run_workflow_step(wf_ex_db, "task1", 0)

        # Check workflow status and make sure it is still running.
        conductor, wf_ex_db = workflow_service.refresh_conductor(
            str(wf_ex_db.id))
        self.assertEqual(conductor.get_workflow_status(), wf_statuses.RUNNING)
        self.assertEqual(wf_ex_db.status, wf_statuses.RUNNING)
        lv_ac_db2 = lv_db_access.LiveAction.get_by_id(str(lv_ac_db2.id))
        self.assertEqual(lv_ac_db2.status,
                         action_constants.LIVEACTION_STATUS_RUNNING)
        ac_ex_db2 = ex_db_access.ActionExecution.get_by_id(str(ac_ex_db2.id))
        self.assertEqual(ac_ex_db2.status,
                         action_constants.LIVEACTION_STATUS_RUNNING)

        # Manually create the liveaction and action execution objects for the rerun.
        lv_ac_db3 = lv_db_models.LiveActionDB(action=wf_meta["name"])
        lv_ac_db3, ac_ex_db3 = action_service.create_request(lv_ac_db3)

        # Request workflow execution rerun again.
        st2_ctx = self.mock_st2_context(ac_ex_db3, ac_ex_db1.context)
        st2_ctx["workflow_execution_id"] = str(wf_ex_db.id)
        rerun_options = {"ref": str(ac_ex_db1.id), "tasks": ["task1"]}
        expected_error = ('^Unable to rerun workflow execution ".*" '
                          "because it is not in a completed state.$")

        self.assertRaisesRegexp(
            wf_exc.WorkflowExecutionRerunException,
            expected_error,
            workflow_service.request_rerun,
            ac_ex_db3,
            st2_ctx,
            rerun_options,
        )
Beispiel #2
0
    def rerun_workflow(self, ac_ex_ref, options=None):
        try:
            # Request rerun of workflow execution.
            wf_ex_id = ac_ex_ref.context.get('workflow_execution')
            st2_ctx = self._construct_st2_context()
            st2_ctx['workflow_execution_id'] = wf_ex_id
            wf_ex_db = wf_svc.request_rerun(self.execution, st2_ctx, options=options)
        except Exception as e:
            status = ac_const.LIVEACTION_STATUS_FAILED
            result = {'errors': [{'message': six.text_type(e)}], 'output': None}
            return (status, result, self.context)

        return self._handle_workflow_return_value(wf_ex_db)
Beispiel #3
0
    def test_request_rerun(self):
        # Create and return a failed workflow execution.
        wf_meta, lv_ac_db1, ac_ex_db1, wf_ex_db = self.prep_wf_ex_for_rerun()

        # Manually create the liveaction and action execution objects for the rerun.
        lv_ac_db2 = lv_db_models.LiveActionDB(action=wf_meta['name'])
        lv_ac_db2, ac_ex_db2 = action_service.create_request(lv_ac_db2)

        # Request workflow execution rerun.
        st2_ctx = self.mock_st2_context(ac_ex_db2, ac_ex_db1.context)
        st2_ctx['workflow_execution_id'] = str(wf_ex_db.id)
        rerun_options = {'ref': str(ac_ex_db1.id), 'tasks': ['task1']}
        wf_ex_db = workflow_service.request_rerun(ac_ex_db2, st2_ctx,
                                                  rerun_options)
        wf_ex_db = self.prep_wf_ex(wf_ex_db)

        # Check workflow status.
        conductor, wf_ex_db = workflow_service.refresh_conductor(
            str(wf_ex_db.id))
        self.assertEqual(conductor.get_workflow_status(), wf_statuses.RUNNING)
        self.assertEqual(wf_ex_db.status, wf_statuses.RUNNING)

        # Complete task1.
        self.run_workflow_step(wf_ex_db, 'task1', 0)

        # Check workflow status and make sure it is still running.
        conductor, wf_ex_db = workflow_service.refresh_conductor(
            str(wf_ex_db.id))
        self.assertEqual(conductor.get_workflow_status(), wf_statuses.RUNNING)
        self.assertEqual(wf_ex_db.status, wf_statuses.RUNNING)
        lv_ac_db2 = lv_db_access.LiveAction.get_by_id(str(lv_ac_db2.id))
        self.assertEqual(lv_ac_db2.status,
                         action_constants.LIVEACTION_STATUS_RUNNING)
        ac_ex_db2 = ex_db_access.ActionExecution.get_by_id(str(ac_ex_db2.id))
        self.assertEqual(ac_ex_db2.status,
                         action_constants.LIVEACTION_STATUS_RUNNING)