예제 #1
0
def waiting_process():

    state = {"foo": "bar"}

    success_step = ProcessStepTable(pid=PID,
                                    name="generic-step",
                                    status="success",
                                    state=state,
                                    created_by="Fredje")
    waiting_step = ProcessStepTable(pid=PID,
                                    name="waiting-step",
                                    status="waiting",
                                    state="Uberly cool error message",
                                    created_by="Fredje")

    process = ProcessTable(
        pid=PID,
        workflow=WORKFLOW_ID,
        last_status=ProcessStatus.WAITING,
        assignee=Assignee.SYSTEM,
        last_step="waiting-step",
        created_by="Fredje",
    )

    waiting_workflow = WorkflowTable(name="Waiting workflow",
                                     target=Target.SYSTEM,
                                     description="Description")

    db.session.add(waiting_workflow)
    db.session.add(process)
    db.session.add(success_step)
    db.session.add(waiting_step)
    db.session.commit()
def task():
    three_weeks_ago = nowtz() - timedelta(weeks=3)
    two_weeks_ago = nowtz() - timedelta(weeks=2)
    state = {"foo": "bar"}

    generic_step = ProcessStepTable(name="generic-step",
                                    status="success",
                                    state=state)

    task_old = ProcessTable(
        workflow="nice and old task",
        last_status=ProcessStatus.COMPLETED,
        last_step="Awesome last step",
        started_at=three_weeks_ago,
        last_modified_at=two_weeks_ago,
        steps=[generic_step],
        is_task=True,
    )

    task_new = ProcessTable(
        workflow="nice and new task",
        last_status=ProcessStatus.COMPLETED,
        last_step="Awesome last step",
        started_at=three_weeks_ago,
        last_modified_at=nowtz(),
        steps=[generic_step],
        is_task=True,
    )

    process = ProcessTable(
        workflow="nice process",
        last_status=ProcessStatus.COMPLETED,
        last_step="Awesome last step",
        started_at=three_weeks_ago,
        last_modified_at=two_weeks_ago,
        steps=[generic_step],
        is_task=False,
    )
    db.session.add(generic_step)
    db.session.add(task_old)
    db.session.add(task_new)
    db.session.add(process)
    db.session.commit()
예제 #3
0
def _db_create_process(stat: ProcessStat) -> None:
    p = ProcessTable(
        pid=stat.pid,
        workflow=stat.workflow.name,
        last_status=ProcessStatus.CREATED,
        created_by=stat.current_user,
        is_task=stat.workflow.target == Target.SYSTEM,
    )
    db.session.add(p)
    db.session.commit()
예제 #4
0
    def mock_process(subscription_id,
                     status,
                     started,
                     assignee=Assignee.SYSTEM,
                     is_task=False):
        pid = uuid4()
        process = ProcessTable(
            pid=pid,
            workflow=test_workflow,
            last_status=status,
            last_step="Modify",
            started_at=started,
            last_modified_at=started + timedelta(minutes=10),
            assignee=assignee,
            is_task=is_task,
        )

        init_step = ProcessStepTable(pid=pid,
                                     name="Start",
                                     status="success",
                                     state={})
        db.session.add(process)

        if subscription_id:
            insert_step = ProcessStepTable(
                pid=pid,
                name="Insert UUID in state",
                status="success",
                state={"subscription_id": subscription_id})
            check_step = ProcessStepTable(
                pid=pid,
                name="Test that it is a string now",
                status="success",
                state={"subscription_id": subscription_id},
            )
            step = ProcessStepTable(pid=pid,
                                    name="Modify",
                                    status="suspend",
                                    state={"subscription_id": subscription_id})

            process_subscription = ProcessSubscriptionTable(
                pid=pid, subscription_id=subscription_id)

            db.session.add(init_step)
            db.session.add(insert_step)
            db.session.add(check_step)
            db.session.add(step)
            db.session.add(process_subscription)
        db.session.commit()

        return pid
예제 #5
0
def resume_process(
    process: ProcessTable,
    *,
    user_inputs: Optional[List[State]] = None,
    user: Optional[str] = None,
    broadcast_func: Optional[BroadcastFunc] = None,
) -> Tuple[UUID, Future]:
    """Resume a failed or suspended process.

    Args:
        process: Process from database
        user_inputs: Optional user input from forms
        user: user who resumed this process
        broadcast_func: Optional function to broadcast process data

    Returns:
        process id

    """
    # ATTENTION!! When modifying this function make sure you make similar changes to `resume_workflow` in the test code

    if user_inputs is None:
        user_inputs = [{}]

    pstat = load_process(process)

    if pstat.workflow == removed_workflow:
        raise ValueError("This workflow cannot be resumed")

    form = pstat.log[0].form

    user_input = post_process(form, pstat.state.unwrap(), user_inputs)

    if user:
        pstat.update(current_user=user)

    if user_input:
        pstat.update(state=pstat.state.map(
            lambda state: StateMerger.merge(state, user_input)))

    # enforce an update to the process status to properly show the process
    process.last_status = ProcessStatus.RUNNING
    db.session.add(process)
    db.session.commit()

    _safe_logstep_prep = partial(_safe_logstep, broadcast_func=broadcast_func)
    return _run_process_async(pstat.pid,
                              lambda: runwf(pstat, _safe_logstep_prep))
예제 #6
0
def test_delete_subscription(responses, seed, test_client):
    pid = str(uuid4())
    db.session.add(
        ProcessTable(pid=pid,
                     workflow="statisch_lichtpad_aanvragen",
                     last_status=ProcessStatus.CREATED))
    db.session.add(
        ProcessSubscriptionTable(pid=pid,
                                 subscription_id=PORT_A_SUBSCRIPTION_ID))
    db.session.commit()

    response = test_client.delete(
        f"/api/subscriptions/{PORT_A_SUBSCRIPTION_ID}")
    assert response.status_code == HTTPStatus.OK

    response = test_client.get("/api/processes")
    assert len(response.json()) == 0
예제 #7
0
def _create_failed_process(subscription_id):
    pid = uuid4()

    process = ProcessTable(
        pid=pid,
        workflow="validate_ip_prefix",
        last_status=ProcessStatus.FAILED,
        last_step="Verify references in NSO",
        assignee="NOC",
        is_task=False,
    )
    process_subscription = ProcessSubscriptionTable(
        pid=pid, subscription_id=subscription_id)

    db.session.add(process)
    db.session.add(process_subscription)

    db.session.commit()
예제 #8
0
def completed_process(test_workflow, generic_subscription_1):
    pid = uuid4()
    process = ProcessTable(pid=pid,
                           workflow=test_workflow,
                           last_status=ProcessStatus.COMPLETED)
    init_step = ProcessStepTable(pid=pid,
                                 name="Start",
                                 status=StepStatus.SUCCESS,
                                 state={})
    insert_step = ProcessStepTable(
        pid=pid,
        name="Insert UUID in state",
        status=StepStatus.SUCCESS,
        state={"subscription_id": generic_subscription_1},
    )
    check_step = ProcessStepTable(
        pid=pid,
        name="Test that it is a string now",
        status=StepStatus.SUCCESS,
        state={"subscription_id": generic_subscription_1},
    )
    step = ProcessStepTable(pid=pid,
                            name="Modify",
                            status=StepStatus.SUCCESS,
                            state={"subscription_id": generic_subscription_1})

    process_subscription = ProcessSubscriptionTable(
        pid=pid, subscription_id=generic_subscription_1)

    db.session.add(process)
    db.session.add(init_step)
    db.session.add(insert_step)
    db.session.add(check_step)
    db.session.add(step)
    db.session.add(process_subscription)
    db.session.commit()

    return pid