Exemplo n.º 1
0
def _test(context, executor, lock_files, func, dataholder, expected_failure):
    def _node(ctx):
        return ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_NAME)

    interface_name, operation_name = mock.operations.NODE_OPERATIONS_INSTALL[0]

    key = 'key'
    first_value = 'value1'
    second_value = 'value2'
    arguments = {
        'lock_files': lock_files,
        'key': key,
        'first_value': first_value,
        'second_value': second_value,
        'holder_path': dataholder.path
    }

    node = _node(context)
    interface = mock.models.create_interface(
        node.service,
        interface_name,
        operation_name,
        operation_kwargs=dict(function='{0}.{1}'.format(__name__, func.__name__),
                              arguments=arguments)
    )
    node.interfaces[interface.name] = interface
    context.model.node.update(node)

    @workflow
    def mock_workflow(graph, **_):
        graph.add_tasks(
            api.task.OperationTask(
                node,
                interface_name=interface_name,
                operation_name=operation_name,
                arguments=arguments),
            api.task.OperationTask(
                node,
                interface_name=interface_name,
                operation_name=operation_name,
                arguments=arguments)
        )

    signal = events.on_failure_task_signal
    with events_collector(signal) as collected:
        try:
            execute_workflow(mock_workflow, context, executor)
        except ExecutorException:
            pass

    props = _node(context).attributes
    assert dataholder['invocations'] == 2
    assert props[key].value == dataholder[key]

    exceptions = [event['kwargs']['exception'] for event in collected.get(signal, [])]
    if expected_failure:
        assert exceptions
Exemplo n.º 2
0
 def _execute_and_get_task_exception(self, *args, **kwargs):
     signal = events.on_failure_task_signal
     with events_collector(signal) as collected:
         with pytest.raises(ExecutorException):
             self._execute(*args, **kwargs)
     return collected[signal][0]['kwargs']['exception']
 def _run_and_get_task_exceptions(self, *args, **kwargs):
     signal = events.on_failure_task_signal
     with events_collector(signal) as collected:
         with pytest.raises(ExecutorException):
             self._run(*args, **kwargs)
     return [event['kwargs']['exception'] for event in collected[signal]]