Exemple #1
0
    def test_mark_pipeline_instance_complete(self):
        pipeline_instance = PipelineInstance()
        InstanceWorkflowEngine._mark_pipeline_instance_complete(
            pipeline_instance, StatusConstants.FAILED)

        eq_(StatusConstants.FAILED, pipeline_instance.status_id)
        ok_(pipeline_instance.end_date is not None)
Exemple #2
0
    def test_mark_stage_instance_complete(self):
        stage_instance = StageInstance()
        InstanceWorkflowEngine._mark_stage_instance_complete(
            stage_instance, StatusConstants.SUCCESS)

        eq_(StatusConstants.SUCCESS, stage_instance.status_id)
        ok_(stage_instance.end_date is not None)
Exemple #3
0
    def _save_status(self,
                     action_instance,
                     session,
                     post_data,
                     allow_save=False):
        if 'status' in post_data:
            status = self.get_status_by_name(post_data['status'], session)

            if action_instance.callback_required and status.type == StatusTypes.SUCCESS and not allow_save:
                # Allow_save comes from callback_method.
                return

            self._wait_for_parallel_calculations(action_instance)

            pipeline_instance = session.query(PipelineInstance).options(
                joinedload(PipelineInstance.stage_instances).joinedload(
                    StageInstance.workflow_instances).joinedload(
                        WorkflowInstance.action_instances)).options(
                            joinedload(PipelineInstance.parameters)).get(
                                action_instance.pipeline_instance_id)
            workflow_engine = InstanceWorkflowEngine(StatusDal(session),
                                                     pipeline_instance)
            workflow_engine.complete_an_action(action_instance.id, status.id)
            for instance in workflow_engine.instances_to_add:
                session.add(instance)
            session.commit()

            self.event_service.trigger_possible_event(pipeline_instance,
                                                      action_instance, session)
Exemple #4
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)
Exemple #5
0
    def _testing_check_verify(self, objects, expected):
        workflow_engine = InstanceWorkflowEngine(Mock(), Mock())
        workflow_engine.status_cache[StatusConstants.NEW] = Status(
            id=StatusConstants.NEW, name="Test NEW", type=StatusTypes.SUCCESS)
        workflow_engine.status_cache[StatusConstants.SUCCESS] = Status(
            id=StatusConstants.SUCCESS,
            name="Test SUCCESS",
            type=StatusTypes.SUCCESS)
        workflow_engine.status_cache[StatusConstants.FAILED] = Status(
            id=StatusConstants.FAILED,
            name="Test FAILED",
            type=StatusTypes.FAILED)
        workflow_engine.status_cache[StatusConstants.CANCELED] = Status(
            id=StatusConstants.NEW,
            name="Test CANCELED",
            type=StatusTypes.CANCELED)

        if expected[2]:
            workflow_engine.status_cache[expected[2].id] = expected[2]

        all_complete, all_passed, failed_type = workflow_engine._check_and_verify_statuses(
            objects)

        eq_(expected[0], all_complete, "All Complete did not match")
        eq_(expected[1], all_passed, "All passed did not match.")
        eq_(expected[2], failed_type, "Failed Type did not match.")
Exemple #6
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)
Exemple #7
0
    def test_check_verify_statuses_simple(self):
        workflow_engine = InstanceWorkflowEngine(Mock(), Mock())

        all_complete, all_passed, failed_type = workflow_engine._check_and_verify_statuses(
            [StageInstance(status_id=StatusConstants.NEW)])
        eq_(False, all_complete)
        eq_(True, all_passed)
        eq_(None, failed_type)
Exemple #8
0
    def test_get_status(self):
        status_dal = Mock()
        status = Status(id=1, name="Something")
        status_dal.get_status_by_id.return_value = status

        workflow_engine = InstanceWorkflowEngine(status_dal, Mock())

        eq_(status, workflow_engine._get_status(1))
        eq_({1: status}, workflow_engine.status_cache)
Exemple #9
0
    def test_reset_pipeline_instance_status_set_to_inprogress(self):
        pipeline_instance = self._build_pipeline_instance(
            ['1:1', '7:1-1-1-1,1,4,1-1-1-1'])

        workflow_engine = InstanceWorkflowEngine(self._get_mocked_dal(),
                                                 pipeline_instance)
        workflow_engine.reset_pipeline()
        self.assertEqual(StatusConstants.INPROGRESS,
                         pipeline_instance.status_id)
Exemple #10
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)
Exemple #11
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)
        ]))
Exemple #12
0
    def test_reset_pipeline_instance_sets_appropriate_dates(self):
        pipeline_instance = self._build_pipeline_instance(['1:1', '1:1'])
        pipeline_instance.end_date = datetime.datetime.utcnow()

        workflow_engine = InstanceWorkflowEngine(self._get_mocked_dal(),
                                                 pipeline_instance)
        workflow_engine.reset_pipeline()
        self.assertTrue(pipeline_instance.start_date is not None,
                        "Start date was not set.")
        self.assertTrue(pipeline_instance.end_date is None,
                        'End date was not reset.')
Exemple #13
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)
            ]))
Exemple #14
0
    def reset_pipeline_instance(self, pipeline_instance_id):
        for session in get_db_session():
            pipeline_instance = session.query(PipelineInstance)\
                                              .options(
                                                  joinedload(PipelineInstance.stage_instances)
                                                  .joinedload(StageInstance.workflow_instances)
                                                  .joinedload(WorkflowInstance.action_instances)).filter(PipelineInstance.id == pipeline_instance_id).first()

            instance_workflow_engine = InstanceWorkflowEngine(
                self.status_dal, pipeline_instance)
            instance_workflow_engine.reset_pipeline()
            session.commit()
        return True
Exemple #15
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)
            ]))
Exemple #16
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)
Exemple #17
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)
Exemple #18
0
    def test_reset_action_instance(self):
        pipeline_instance = self._build_pipeline_instance(['1:1', '2:1-2,1'],
                                                          True)

        workflow_engine = InstanceWorkflowEngine(self._get_mocked_dal(),
                                                 pipeline_instance)
        action_instance = workflow_engine.get_action_instance_by_id(3)
        workflow_engine.reset_action(action_instance)

        self.assertEquals(None, pipeline_instance.end_date)
        self.assertEquals(None, pipeline_instance.stage_instances[1].end_date)
        self.assertEquals(
            None, pipeline_instance.stage_instances[1].workflow_instances[1].
            end_date)
        self.assertEquals(None, action_instance.end_date)
        self.assertEquals(StatusConstants.READY, action_instance.status_id)
Exemple #19
0
    def test_complete_an_action_instance_sets_dates_and_status(self):
        pipeline_instance = self._build_pipeline_instance(['1:1'])

        workflow_engine = InstanceWorkflowEngine(self._get_mocked_dal(),
                                                 pipeline_instance)
        action_instance = workflow_engine.get_action_instance_by_id(1)
        workflow_engine.complete_an_action(action_instance.id,
                                           StatusConstants.CANCELED)

        self.assertEqual(StatusConstants.CANCELED, action_instance.status_id)
        self.assertEqual(StatusConstants.CANCELED, pipeline_instance.status_id)
        self.assertEqual(StatusConstants.CANCELED,
                         pipeline_instance.stage_instances[0].status_id)
        self.assertEqual(
            StatusConstants.CANCELED, pipeline_instance.stage_instances[0].
            workflow_instances[0].status_id)
Exemple #20
0
    def cancel_action_instance(self, action_instance_id):
        for session in get_db_session():
            action_instance = self.get_action_instance_by_id(
                action_instance_id, session)

            if action_instance:
                serialized = action_instance.serialize()
                instance_workflow_engine = InstanceWorkflowEngine(
                    StatusDal(session), action_instance.pipeline_instance)
                instance_workflow_engine.complete_an_action(
                    action_instance_id, StatusConstants.CANCELED)
                self.queue_constants.cancel_worker(serialized)
                session.commit()
            else:
                raise InvalidObjectException("Action Instance not found", 404)
        return {"message": "Action Instance has been canceled."}
Exemple #21
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)
Exemple #22
0
    def reset_action_instance(self,
                              _id,
                              complete_reset=False,
                              check_status=False):  # pylint: disable=unused-argument
        for session in get_db_session():
            action_instance = session.query(ActionInstance).get(_id)
            if check_status and action_instance.status_id != StatusConstants.INPROGRESS:
                return False

            instance_workflow_engine = InstanceWorkflowEngine(
                self.status_dal, action_instance.pipeline_instance)
            instance_workflow_engine.reset_action(action_instance)

            if self.qa_module is not None:
                self.qa_module.reset_results(action_instance.id, session)

            session.commit()
        return True
Exemple #23
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)
Exemple #24
0
    def test_reset_pipeline_instance_first_action_instance_and_orders_are_set_to_inprogress(
            self):
        pipeline_instance = self._build_pipeline_instance(['2:1-2,1'])

        workflow_engine = InstanceWorkflowEngine(self._get_mocked_dal(),
                                                 pipeline_instance)
        workflow_engine.reset_pipeline()
        self.assertEqual(
            StatusConstants.READY, pipeline_instance.stage_instances[0].
            workflow_instances[0].action_instances[0].status_id)
        self.assertEqual(
            StatusConstants.READY, pipeline_instance.stage_instances[0].
            workflow_instances[1].action_instances[0].status_id)
        self.assertEqual(
            StatusConstants.READY, pipeline_instance.stage_instances[0].
            workflow_instances[1].action_instances[1].status_id)
        self.assertEqual(
            StatusConstants.NEW, pipeline_instance.stage_instances[0].
            workflow_instances[1].action_instances[2].status_id)
Exemple #25
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)
Exemple #26
0
    def test_init(self):
        status_dal = Mock()
        pipeline_instance = PipelineInstance(id=1)
        workflow_engine = InstanceWorkflowEngine(status_dal, pipeline_instance)

        eq_(workflow_engine.pipeline, pipeline_instance)
        eq_(status_dal, workflow_engine.status_dal)
        eq_(PipelineInstance, workflow_engine.pipeline_class)
        eq_(StageInstance, workflow_engine.stage_class)
        eq_(WorkflowInstance, workflow_engine.workflow_class)
        eq_(ActionInstance, workflow_engine.action_class)
Exemple #27
0
    def test_complete_an_action_instance_starts_next(self):
        pipeline_instance = self._build_pipeline_instance(['1:2'])
        pipeline_instance.status_id = StatusConstants.INPROGRESS

        workflow_engine = InstanceWorkflowEngine(self._get_mocked_dal(),
                                                 pipeline_instance)
        action_instance = workflow_engine.get_action_instance_by_id(2)
        workflow_engine.complete_an_action(1, StatusConstants.SUCCESS)

        self._print_pipeline_instance(pipeline_instance)

        self.assertEqual(StatusConstants.READY, action_instance.status_id)
        self.assertEqual(StatusConstants.INPROGRESS,
                         pipeline_instance.status_id)
        self.assertEqual(
            StatusConstants.SUCCESS, pipeline_instance.stage_instances[0].
            workflow_instances[0].action_instances[0].status_id)
        self.assertEqual(
            StatusConstants.READY, pipeline_instance.stage_instances[0].
            workflow_instances[0].action_instances[1].status_id)
Exemple #28
0
    def test_complex_reset_action_complete_stage_should_activate_proper_actions(
            self):
        pipeline_instance = self._build_pipeline_instance(
            ['1:1', '7:1-1-1-1,1,4,1-1-1-1'])

        workflow_engine = InstanceWorkflowEngine(self._get_mocked_dal(),
                                                 pipeline_instance)
        workflow_engine.reset_pipeline()
        first_stage = pipeline_instance.stage_instances[0]
        second_stage = pipeline_instance.stage_instances[1]
        workflow_engine.complete_an_action(1, StatusConstants.SUCCESS)

        self.assertEquals(StatusConstants.SUCCESS, first_stage.status_id)
        self.assertEquals(StatusConstants.SUCCESS,
                          first_stage.workflow_instances[0].status_id)
        self.assertEquals(
            StatusConstants.SUCCESS,
            first_stage.workflow_instances[0].action_instances[0].status_id)

        self.assertEquals(StatusConstants.INPROGRESS, second_stage.status_id)
        for workflow_instance in second_stage.workflow_instances:
            self.assertEquals(StatusConstants.INPROGRESS,
                              workflow_instance.status_id)
            for action_instance in workflow_instance.action_instances:
                if action_instance.order == 0:
                    self.assertEquals(StatusConstants.READY,
                                      action_instance.status_id)
                else:
                    self.assertEquals(StatusConstants.NEW,
                                      action_instance.status_id)
Exemple #29
0
    def test_complex_reset_action_instance_first_stage_should_be_ready(self):
        pipeline_instance = self._build_pipeline_instance(
            ['1:1', '7:1-1-1-1,1,4,1-1-1-1'], True)

        workflow_engine = InstanceWorkflowEngine(self._get_mocked_dal(),
                                                 pipeline_instance)
        workflow_engine.reset_pipeline()
        first_stage = pipeline_instance.stage_instances[0]
        second_stage = pipeline_instance.stage_instances[1]

        self.assertEquals(StatusConstants.READY, first_stage.status_id)
        self.assertEquals(StatusConstants.INPROGRESS,
                          first_stage.workflow_instances[0].status_id)
        self.assertEquals(
            StatusConstants.READY,
            first_stage.workflow_instances[0].action_instances[0].status_id)

        self.assertEquals(StatusConstants.NEW, second_stage.status_id)
        for workflow_instance in second_stage.workflow_instances:
            self.assertEquals(StatusConstants.NEW, workflow_instance.status_id)
            for action_instance in workflow_instance.action_instances:
                self.assertEquals(StatusConstants.NEW,
                                  action_instance.status_id)
Exemple #30
0
    def test_reconciled_stages(self):
        stage_instance = StageInstance(id=2,
                                       status_id=StatusConstants.SUCCESS,
                                       stage_id=2)
        pipeline_instance = PipelineInstance(
            stage_instances=[
                StageInstance(id=1, status_id=StatusConstants.SUCCESS),
                stage_instance
            ],
            pipeline=Pipeline(stages=[Stage(id=1), Stage(id=2)]))
        instance_workflow_engine = InstanceWorkflowEngine(
            Mock(), pipeline_instance)
        instance_workflow_engine._load_pipeline()
        instance_workflow_engine.complete_a_stage(2, StatusConstants.SUCCESS)

        eq_(StatusConstants.SUCCESS, pipeline_instance.status_id)
        ok_(pipeline_instance.end_date is not None)