Example #1
0
    def test_mark_workflow_instance_complete(self):
        workflow_instance = WorkflowInstance()
        InstanceWorkflowEngine._mark_workflow_instance_complete(
            workflow_instance, StatusConstants.FAILED)

        eq_(StatusConstants.FAILED, workflow_instance.status_id)
        ok_(workflow_instance.end_date is not None)
Example #2
0
    def _pipeline_helper(self):
        action_instance = ActionInstance(id=1, order=0)
        workflow_instance = WorkflowInstance(id=1, actions=[action_instance])
        stage_instance = StageInstance(id=1, workflows=[workflow_instance])
        pipeline_instance = PipelineInstance(
            id=1, stages=[stage_instance, stage_instance])

        return action_instance, workflow_instance, stage_instance, pipeline_instance
Example #3
0
    def test_create_action_instance_with_no_slicing(self):
        workflow_engine = InstanceWorkflowEngine(Mock(), Mock())

        workflow_instance = WorkflowInstance(id=1)
        workflow = Workflow(actions=[
            Action(slices=0, id=1, cmd="test1"),
            Action(slices=0, id=2, cmd="test2")
        ])
        workflow_engine._create_action_instances(Mock(id=1), workflow_instance,
                                                 workflow)

        eq_(2, len(workflow_instance.action_instances))
        eq_('test1', workflow_instance.action_instances[0].cmd)
        eq_(StatusConstants.READY,
            workflow_instance.action_instances[0].status_id)
        eq_('test2', workflow_instance.action_instances[1].cmd)
        eq_(StatusConstants.NEW,
            workflow_instance.action_instances[1].status_id)
Example #4
0
    def test_create_action_instance_with_slicing_before(self):
        workflow_engine = InstanceWorkflowEngine(Mock(), Mock())

        workflow_instance = WorkflowInstance(id=1)
        workflow = Workflow(actions=[
            Action(slices=4, id=1, cmd="test1"),
            Action(slices=0, id=2, cmd="test2")
        ])
        workflow_engine._create_action_instances(Mock(id=1), workflow_instance,
                                                 workflow)

        eq_(5, len(workflow_instance.action_instances))
        for i in range(0, 4):
            eq_('test1', workflow_instance.action_instances[i].cmd)
            eq_(StatusConstants.READY,
                workflow_instance.action_instances[i].status_id)

        eq_('test2', workflow_instance.action_instances[4].cmd)
        eq_(StatusConstants.NEW,
            workflow_instance.action_instances[4].status_id)
Example #5
0
    def _build_pipeline_instance(self, actions, completed=False):
        pipeline_instance = PipelineInstance()
        status_id = StatusConstants.NEW if not completed else StatusConstants.SUCCESS

        if completed:
            pipeline_instance.created_date = datetime.datetime.utcnow()
            pipeline_instance.start_date = datetime.datetime.utcnow()
            pipeline_instance.end_date = datetime.datetime.utcnow()
            pipeline_instance.status_id = status_id

        stage_instances = {}

        s_idcount = w_idcount = a_idcount = 1
        pipeline_instance.pipeline = Mock(stages=[])

        for action in actions:
            sp = action.split(':')

            stage_instance = StageInstance(id=s_idcount, status_id=status_id)
            stage_instances[s_idcount] = stage_instance

            if completed:
                stage_instance.created_date = datetime.datetime.utcnow()
                stage_instance.start_date = datetime.datetime.utcnow()
                stage_instance.end_date = datetime.datetime.utcnow()

            w_number = int(sp[0])
            a_sp = sp[1].split('-')
            for workflow_id in range(0, w_number):
                workflow_instance = WorkflowInstance(
                    id=w_idcount,
                    stage_instance_id=stage_instance.id,
                    status_id=status_id)

                if completed:
                    workflow_instance.created_date = datetime.datetime.utcnow()
                    workflow_instance.start_date = datetime.datetime.utcnow()
                    workflow_instance.end_date = datetime.datetime.utcnow()

                try:
                    order = 0
                    for action_count in a_sp[workflow_id].split(','):
                        a_count = int(action_count)
                        for num in range(0, a_count):
                            action_instance = ActionInstance(
                                id=a_idcount,
                                order=order,
                                slice="{}/{}".format(num + 1, a_count),
                                workflow_instance_id=workflow_instance.id,
                                status_id=status_id)
                            if completed:
                                action_instance.created_date = datetime.datetime.utcnow(
                                )
                                action_instance.start_date = datetime.datetime.utcnow(
                                )
                                action_instance.end_date = datetime.datetime.utcnow(
                                )

                            workflow_instance.action_instances.append(
                                action_instance)
                            a_idcount += 1
                        order += 1
                except:
                    action_instance = ActionInstance(
                        id=a_idcount,
                        order=0,
                        workflow_instance_id=workflow_instance.id,
                        status_id=status_id)
                    if completed:
                        action_instance.created_date = datetime.datetime.utcnow(
                        )
                        action_instance.start_date = datetime.datetime.utcnow()
                        action_instance.end_date = datetime.datetime.utcnow()

                    workflow_instance.action_instances.append()
                w_idcount += 1
                stage_instance.workflow_instances.append(workflow_instance)
            pipeline_instance.stage_instances.append(stage_instance)
            pipeline_instance.pipeline.stages.append(stage_instance)

            s_idcount += 1
        return pipeline_instance
Example #6
0
 def test_get_actions(self):
     workflow_engine = InstanceWorkflowEngine(Mock(), Mock())
     action_instance = ActionInstance()
     workflow_instance = WorkflowInstance(
         action_instances=[action_instance])
     eq_([action_instance], workflow_engine._get_actions(workflow_instance))
Example #7
0
 def test_get_workflows(self):
     workflow_engine = InstanceWorkflowEngine(Mock(), Mock())
     workflow_instance = WorkflowInstance()
     stage_instance = StageInstance(workflow_instances=[workflow_instance])
     eq_([workflow_instance],
         workflow_engine._get_workflows(stage_instance))