Ejemplo n.º 1
0
def test_pending_state():
    """Test creating instances of the pending state class."""
    created_at = dt.datetime.now()
    state = StatePending(created_at)
    assert state.is_pending()
    assert state.is_active()
    assert not state.is_canceled()
    assert not state.is_error()
    assert not state.is_running()
    assert not state.is_success()
    assert state.created_at == created_at
    running = state.start()
    assert state.created_at == running.created_at
    assert running.started_at is not None
    # Cancel pending run
    canceled = state.cancel()
    assert canceled.is_canceled()
    assert len(canceled.messages) == 1
    canceled = state.cancel(messages=['by', 'user'])
    assert canceled.is_canceled()
    assert len(canceled.messages) == 2
    # Set pending run into error state
    state = StatePending(created_at)
    error = state.error(messages=['there', 'was', 'a', 'error'])
    assert error.is_error()
    assert len(error.messages) == 4
Ejemplo n.º 2
0
    def create_workflow(self, run, template, arguments):
        """Create a new instance of a workflow from the given workflow
        template and user-provided arguments.

        Parameters
        ----------
        run: flowserv.model.base.RunObject
            Handle for the run that is being executed.
        template: flowserv.model.template.base.WorkflowTemplate
            Workflow template containing the parameterized specification and
            the parameter declarations.
        arguments: dict
            Dictionary of argument values for parameters in the template.

        Returns
        -------
        flowserv.model.workflow.remote.RemoteWorkflowObject
        """
        # Create a serial workfow to have a workflow handle.
        _, _, output_file = parser.parse_template(template=template,
                                                  arguments=arguments)
        self.state = StatePending()
        self._pollcount = 0
        return RemoteWorkflowObject(workflow_id=run.run_id,
                                    state=self.state,
                                    output_files=output_file)
Ejemplo n.º 3
0
def get_workflow_state(workflow):
    """Get workflow state."""
    try:
        state = REANAClient().get_workflow_state(workflow, StatePending())
        click.echo('in state {}'.format(state))
    except Exception as ex:
        click.echo('Error: {}'.format(ex))
def test_run_workflow_error(tmpdir):
    """Test error edge case for the run_workflow function."""
    _, _, result = run_workflow(run_id='0',
                                rundir=tmpdir,
                                state=StatePending(),
                                output_files=[],
                                steps=None,
                                arguments=dict(),
                                workers=None)
    assert result['type'] == STATE_ERROR
def test_run_workflow_error(tmpdir):
    """Test error edge case for the run_workflow function."""
    # This will cause a NonType exception when trying to access the steps in
    # the exec_workflow method.
    _, _, result = run_workflow(run_id='0',
                                state=StatePending(),
                                output_files=[],
                                steps=None,
                                arguments=dict(),
                                volumes=DefaultVolume(basedir=tmpdir),
                                workers=None)
    assert result['type'] == STATE_ERROR
Ejemplo n.º 6
0
def test_remote_run_success(tmpdir):
    """Test monitoring a successful workflow run."""
    client = RemoteTestClient()
    workflow = RemoteWorkflowHandle(
        run_id='R0',
        workflow_id='W0',
        state=StatePending(),
        output_files=list(),
        runstore=FileSystemStorage(basedir=tmpdir),
        client=client
    )
    state = monitor_workflow(workflow=workflow, poll_interval=0.1)
    assert state.is_success()
Ejemplo n.º 7
0
def test_remote_run_error(tmpdir):
    """Test monitoring an erroneous workflow run."""
    # Create client that will raise an error after the default rounds of polling.
    client = RemoteTestClient(error='some error')
    workflow = RemoteWorkflowHandle(
        run_id='R0',
        workflow_id='W0',
        state=StatePending(),
        output_files=list(),
        runstore=FileSystemStorage(basedir=tmpdir),
        client=client
    )
    state = monitor_workflow(workflow=workflow, poll_interval=0.1)
    assert state.is_error()
Ejemplo n.º 8
0
def run_workflow(spec):
    """Create a new workflow run for the given specification."""
    doc = util.read_object(filename=spec)
    rundir = os.path.dirname(spec)
    if not rundir:
        rundir = '.'
    run = RunHandle(
        identifier='0000',
        workflow_id='0000',
        group_id='0000',
        state=StatePending(),
        arguments=dict(),
        rundir=rundir
    )
    template = WorkflowTemplate(workflow_spec=doc, sourcedir=rundir)
    wf = REANAClient().create_workflow(run, template, dict())
    click.echo('created workflow {} ({})'.format(wf.identifier, wf.state))
Ejemplo n.º 9
0
    def __init__(self, runcount=5, error=None):
        """Initialize the internal state that maintains the created workflow.
        The client only supports execution for a single workflow at a time.

        Parameters
        ----------
        runcount: int, default=5
            Number of poll counts before the workflow state changes. This is
            used to simulate asynchronous workflow excution.
        error: string
            Error message. If given the resulting workflow run will be in
            error state and this string will be the only error message.
        data: list or dict, default=['no data']
            Result file content for successful workflow runs. Writes this data
            item to the result file when the poll counter reaches the run count
            and the error message is None.
        """
        self.runcount = runcount
        self.error = error
        self.state = None
        # Count the number of times that the get_workflow_state() method has
        # been called.
        self.state = StatePending()
        self._pollcount = 0