Esempio n. 1
0
 def test_check_verify_status_complex_all_pass(self):
     self._testing_check_verify([
         ActionInstance(status_id=StatusConstants.SUCCESS),
         ActionInstance(status_id=StatusConstants.SUCCESS),
         ActionInstance(status_id=StatusConstants.INPROGRESS),
         ActionInstance(status_id=StatusConstants.NEW)
     ], [False, True, None])
Esempio n. 2
0
 def test_check_verify_status_complex_one_canceled(self):
     self._testing_check_verify([
         ActionInstance(status_id=StatusConstants.SUCCESS),
         ActionInstance(status_id=StatusConstants.CANCELED)
     ], [
         True, False,
         Status(id=StatusConstants.CANCELED,
                type=StatusTypes.CANCELED,
                name="Testing CANCELED")
     ])
Esempio n. 3
0
    def test_can_continue_workflow_should_fail(self):
        workflow_engine = InstanceWorkflowEngine(Mock(), Mock())
        workflow_engine.status_cache[StatusConstants.SUCCESS] = Status(
            id=StatusConstants.SUCCESS, type=StatusTypes.SUCCESS)
        workflow_engine.status_cache[100] = Status(id=100,
                                                   type=StatusTypes.FAILED)

        ok_(not workflow_engine._can_continue_workflow([
            ActionInstance(status_id=100),
            ActionInstance(status_id=StatusConstants.SUCCESS)
        ]))
Esempio n. 4
0
    def test_can_continue_workflow_status_not_in_severity(self):
        workflow_engine = InstanceWorkflowEngine(Mock(), Mock())
        workflow_engine.status_cache[StatusConstants.SUCCESS] = Status(
            id=StatusConstants.SUCCESS, type=StatusTypes.SUCCESS)
        workflow_engine.status_cache[100] = Status(id=100, type="semiborked")

        ok_(
            workflow_engine._can_continue_workflow([
                ActionInstance(status_id=100),
                ActionInstance(status_id=StatusConstants.SUCCESS)
            ]))
Esempio n. 5
0
    def test_activate_next_action_all_complete_with_inprogress(self):
        workflow_engine = InstanceWorkflowEngine(Mock(), Mock())
        action_instances = [
            ActionInstance(status_id=StatusConstants.SUCCESS, order=0),
            ActionInstance(status_id=StatusConstants.INPROGRESS, order=1),
            ActionInstance(status_id=StatusConstants.NEW, order=2)
        ]
        workflow_engine._activate_next_action_all_complete(action_instances)

        eq_(StatusConstants.INPROGRESS, action_instances[1].status_id)
        eq_(StatusConstants.NEW, action_instances[2].status_id)
Esempio n. 6
0
 def test_check_verify_status_complex_one_failed(self):
     self._testing_check_verify([
         ActionInstance(status_id=StatusConstants.SUCCESS),
         ActionInstance(status_id=StatusConstants.FAILED),
         ActionInstance(status_id=StatusConstants.NEW)
     ], [
         False, False,
         Status(id=StatusConstants.FAILED,
                type=StatusTypes.FAILED,
                name="Testing FAILED")
     ])
Esempio n. 7
0
    def test_can_continue_workflow_should_continue_with_sliced_actions(self):
        workflow_engine = InstanceWorkflowEngine(Mock(), Mock())
        workflow_engine.status_cache[StatusConstants.SUCCESS] = Status(
            id=StatusConstants.READY, type=StatusTypes.SUCCESS)
        workflow_engine.status_cache[100] = Status(id=100,
                                                   type=StatusTypes.FAILED)

        ok_(
            workflow_engine._can_continue_workflow([
                ActionInstance(status_id=100, slice='1/2', action_id=1),
                ActionInstance(status_id=StatusConstants.READY,
                               slice='1/1',
                               action_id=1)
            ]))
Esempio n. 8
0
    def test_activate_next_action_all_complete_with_unknown(self):
        workflow_engine = InstanceWorkflowEngine(Mock(), Mock())
        workflow_engine.status_cache[StatusConstants.UNKNOWN] = Status(
            type=StatusTypes.WARNING)

        action_instances = [
            ActionInstance(status_id=StatusConstants.SUCCESS, order=0),
            ActionInstance(status_id=StatusConstants.UNKNOWN, order=1),
            ActionInstance(status_id=StatusConstants.NEW, order=2)
        ]
        workflow_engine._activate_next_action_all_complete(action_instances)

        eq_(StatusConstants.UNKNOWN, action_instances[1].status_id)
        eq_(StatusConstants.NEW, action_instances[2].status_id)
Esempio n. 9
0
    def test_activate_next_action_all_complete_with_canceled(self):
        workflow_engine = InstanceWorkflowEngine(Mock(), Mock())
        workflow_engine.status_cache[StatusConstants.CANCELED] = Status(
            type=StatusTypes.CANCELED)

        action_instances = [
            ActionInstance(status_id=StatusConstants.SUCCESS, order=0),
            ActionInstance(status_id=StatusConstants.CANCELED, order=1),
            ActionInstance(status_id=StatusConstants.NEW, order=2)
        ]
        workflow_engine._activate_next_action_all_complete(action_instances)

        eq_(StatusConstants.CANCELED, action_instances[1].status_id)
        eq_(StatusConstants.NEW, action_instances[2].status_id)
Esempio n. 10
0
    def test_get_workable_work_requests_work_request_validation(
            self, get_db_session):
        action_dal = ActionDal()

        session = WrapperHelper()
        get_db_session.return_value = [session]

        action_instance = ActionInstance(id=1,
                                         pipeline_instance_id=1,
                                         workflow_instance_id=1)
        pipeline_parameters = PipelineParameters(parameter="foo", value="bar")
        action_instance_config = ActionInstanceConfig()
        pipeline_parameters_2 = PipelineParameters(parameter="foo2",
                                                   value="bar2")
        action_instance_config2 = ActionInstanceConfig()
        session.results.append(
            (action_instance, pipeline_parameters, action_instance_config))
        session.results.append(
            (action_instance, pipeline_parameters_2, action_instance_config2))

        work_requests = action_dal.get_workable_work_requests()
        work_request = work_requests[0]
        eq_(1, len(work_requests))
        eq_(1, work_request.action_instance_id)
        eq_(1, work_request.pipeline_instance_id)
        eq_(1, work_request.workflow_instance_id)

        eq_({"foo": "bar", "foo2": "bar2"}, work_request.environment)
Esempio n. 11
0
    def test_mark_action_instance_complete(self):
        action_instance = ActionInstance()
        InstanceWorkflowEngine._mark_action_instance_complete(
            action_instance, StatusConstants.SUCCESS)

        eq_(StatusConstants.SUCCESS, action_instance.status_id)
        ok_(action_instance.end_date is not None)
Esempio n. 12
0
    def test_activate_next_action_all_complete_with_same_order_multiple_new(
            self):
        workflow_engine = InstanceWorkflowEngine(Mock(), Mock())
        action_instances = [
            ActionInstance(status_id=StatusConstants.SUCCESS, order=0),
            ActionInstance(status_id=StatusConstants.NEW, order=1),
            ActionInstance(status_id=StatusConstants.NEW, order=1),
            ActionInstance(status_id=StatusConstants.NEW, order=2)
        ]
        return_value = workflow_engine._activate_next_action_all_complete(
            action_instances)

        eq_(StatusConstants.READY, action_instances[1].status_id)
        eq_(StatusConstants.READY, action_instances[2].status_id)
        eq_(StatusConstants.NEW, action_instances[3].status_id)
        ok_(not return_value)
Esempio n. 13
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
Esempio n. 14
0
    def test_get_workable_work_requests_verify_outerjoin(self, get_db_session):
        action_dal = ActionDal()

        session = WrapperHelper()
        get_db_session.return_value = [session]

        action_instance = ActionInstance()
        pipeline_parameters = PipelineParameters()
        action_instance_config = ActionInstanceConfig()
        session.results.append(
            (action_instance, pipeline_parameters, action_instance_config))

        action_dal.get_workable_work_requests()

        ok_(PipelineParameters in session.outerjoin_args)
        eq_(PipelineParameters.__table__.columns['pipeline_instance_id'],
            session.outerjoin_args[1].left)
        eq_(ActionInstance.__table__.columns['pipeline_instance_id'],
            session.outerjoin_args[1].right)
Esempio n. 15
0
    def test_get_workable_work_requests_verify_queryables(
            self, get_db_session):
        action_dal = ActionDal()

        session = WrapperHelper()
        get_db_session.return_value = [session]

        action_instance = ActionInstance()
        pipeline_parameters = PipelineParameters()
        action_instance_config = ActionInstanceConfig()
        session.results.append(
            (action_instance, pipeline_parameters, action_instance_config))

        action_dal.get_workable_work_requests()

        eq_([
            ActionInstance, PipelineParameters, ActionInstanceConfig,
            ActionInstance, PipelineParameters, ActionInstanceConfig
        ], session.query_args)
Esempio n. 16
0
    def test_get_workable_work_requests_verify_order_by(self, get_db_session):
        action_dal = ActionDal()

        session = WrapperHelper()
        get_db_session.return_value = [session]

        action_instance = ActionInstance()
        pipeline_parameters = PipelineParameters()
        action_instance_config = ActionInstanceConfig()
        session.results.append(
            (action_instance, pipeline_parameters, action_instance_config))

        action_dal.get_workable_work_requests()

        eq_(PipelineInstance.__table__.columns['priority'],
            session.order_by_args[0].element)
        eq_(PipelineInstance.__table__.columns['created_date'],
            session.order_by_args[1].element)
        eq_(PipelineInstance.__table__.columns['id'],
            session.order_by_args[2].element)
        eq_(ActionInstance.__table__.columns['order'],
            session.order_by_args[3].element)
        eq_(ActionInstance.__table__.columns['slice'],
            session.order_by_args[4].element)
Esempio n. 17
0
    def test_mark_action_instance_complete_canceled(self):
        action_instance = ActionInstance(start_date=datetime.datetime.utcnow())
        InstanceWorkflowEngine._mark_action_instance_complete(
            action_instance, StatusConstants.CANCELED)

        eq_(action_instance.start_date, action_instance.end_date)
Esempio n. 18
0
    def test_activate_next_action_all_complete_simple(self):
        workflow_engine = InstanceWorkflowEngine(Mock(), Mock())
        action_instances = [ActionInstance(status_id=StatusConstants.NEW)]
        workflow_engine._activate_next_action_all_complete(action_instances)

        eq_(StatusConstants.READY, action_instances[0].status_id)
Esempio n. 19
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
Esempio n. 20
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))