示例#1
0
def test_workflow_app_inherit_parent_error(request):
    workflow_app = tags.WorkflowApp(
        name='descriptive-name',
        job_tracker='job-tracker',
        name_node='name-node',
        entities=tags.Serial(
            tags.Parallel(
                tags.Action(name='build_a', action=tags.Shell(exec_command='echo', arguments=['build_a'])),
                tags.Action(name='build_b', action=tags.Shell(exec_command='echo', arguments=['build_b'])),
                name='builders'
            ),
            tags.Parallel(
                tags.Action(name='resolve_a', action=tags.Shell(exec_command='echo', arguments=['resolve_a'])),
                tags.Action(name='resolve_b', action=tags.Shell(exec_command='echo', arguments=['resolve_b'])),
                name='resolvers'
            ),
            on_error=tags.Serial(
                tags.Action(name='error', action=tags.Shell(exec_command='echo', arguments=['error'])),
                tags.Kill(name='error', message='A bad thing happened')
            )
        )
    )

    assert_workflow(request, workflow_app)

    app = tests.utils.ParsedXml(workflow_app.xml())
    app.assert_node("/action[@name='action-build_a']/error", to='action-error')
    app.assert_node("/action[@name='action-build_b']/error", to='action-error')
    app.assert_node("/action[@name='action-resolve_a']/error", to='action-error')
    app.assert_node("/action[@name='action-resolve_a']/error", to='action-error')
    app.assert_node("/action[@name='action-error']/error", to='end')
    app.assert_node("/action[@name='action-error']/ok", to='kill-error')
示例#2
0
def test_workflow_with_reused_identifier():
    with pytest.raises(AssertionError) as assertion_info:
        tags.WorkflowApp(
            name='descriptive-name',
            job_tracker='job-tracker',
            name_node='name-node',
            entities=tags.Action(
                name='build', action=tags.Shell(exec_command='echo', arguments=['build']),
                on_error=tags.Action(name='build', action=tags.Shell(exec_command='echo', arguments=['error']))
            )
        )
    assert str(assertion_info.value) == 'Name(s) reused: action-build'

    with pytest.raises(AssertionError) as assertion_info:
        tags.WorkflowApp(
            name='descriptive-name',
            job_tracker='job-tracker',
            name_node='name-node',
            entities=tags.Serial(
                tags.Action(name='build', action=tags.Shell(exec_command='echo', arguments=['build'])),
                tags.Action(name='resolve', action=tags.Shell(exec_command='echo', arguments=['resolve'])),
                on_error=tags.Serial(
                    tags.Action(name='build', action=tags.Shell(exec_command='echo', arguments=['error'])),
                    tags.Kill('A bad thing happened')
                )
            )
        )
    assert str(assertion_info.value) == 'Name(s) reused: action-build'
示例#3
0
def test_workflow_app_serial_entities(request):
    # Create a serial collection of entities with a serial collection as an error condition
    entities = tags.Serial(
        tags.Action(tags.Shell(exec_command='echo', arguments=['build'])),
        tags.Action(tags.Shell(exec_command='echo', arguments=['resolve'])),
        on_error=tags.Serial(
            tags.Action(tags.Shell(exec_command='echo', arguments=['error'])),
            tags.Kill('A bad thing happened')
        )
    )
    assert len(set(entities)) == 4
    assert bool(entities)

    workflow_app = tags.WorkflowApp(
        name='descriptive-name',
        job_tracker='job-tracker',
        name_node='name-node',
        entities=entities
    )
    assert_workflow(request, workflow_app, """
<workflow-app xmlns="uri:oozie:workflow:0.5" name="descriptive-name">
    <global>
        <job-tracker>job-tracker</job-tracker>
        <name-node>name-node</name-node>
    </global>
    <start to="action-00000000" />
    <action name="action-00000002">
        <shell xmlns="uri:oozie:shell-action:0.3">
            <exec>echo</exec>
            <argument>error</argument>
        </shell>
        <ok to="kill-00000003" />
        <error to="end" />
    </action>
    <kill name="kill-00000003">
        <message>A bad thing happened</message>
    </kill>
    <action name="action-00000000">
        <shell xmlns="uri:oozie:shell-action:0.3">
            <exec>echo</exec>
            <argument>build</argument>
        </shell>
        <ok to="action-00000001" />
        <error to="action-00000002" />
    </action>
    <action name="action-00000001">
        <shell xmlns="uri:oozie:shell-action:0.3">
            <exec>echo</exec>
            <argument>resolve</argument>
        </shell>
        <ok to="end" />
        <error to="action-00000002" />
    </action>
    <end name="end" />
</workflow-app>
""")
示例#4
0
def test_workflow_app_decision_entities(request):
    entities = tags.Decision(
        default=tags.Action(tags.Shell(exec_command='echo', arguments=['default'])),
        choices={
            '${wf:lastErrorNode() eq null}': tags.Action(
                tags.Shell(exec_command='echo', arguments=['"No last error node"'])),
        },
        on_error=tags.Serial(
            tags.Action(tags.Shell(exec_command='echo', arguments=['error'])),
            tags.Kill('A bad thing happened')
        )
    )
    assert len(set(entities)) == 5

    workflow_app = tags.WorkflowApp(
        name='descriptive-name',
        job_tracker='job-tracker',
        name_node='name-node',
        entities=entities
    )
    assert_workflow(request, workflow_app, """
<workflow-app xmlns="uri:oozie:workflow:0.5" name="descriptive-name">
    <global>
        <job-tracker>job-tracker</job-tracker>
        <name-node>name-node</name-node>
    </global>
    <start to="decision-00000005" />
    <action name="action-00000002">
        <shell xmlns="uri:oozie:shell-action:0.3">
            <exec>echo</exec>
            <argument>error</argument>
        </shell>
        <ok to="kill-00000003" />
        <error to="end" />
    </action>
    <kill name="kill-00000003">
        <message>A bad thing happened</message>
    </kill>
    <decision name="decision-00000005">
        <switch>
            <case to="action-00000001">${wf:lastErrorNode() eq null}</case>
            <default to="action-00000000" />
        </switch>
    </decision>
    <action name="action-00000000">
        <shell xmlns="uri:oozie:shell-action:0.3">
            <exec>echo</exec>
            <argument>default</argument>
        </shell>
        <ok to="end" />
        <error to="action-00000002" />
    </action>
    <action name="action-00000001">
        <shell xmlns="uri:oozie:shell-action:0.3">
            <exec>echo</exec>
            <argument>"No last error node"</argument>
        </shell>
        <ok to="end" />
        <error to="action-00000002" />
    </action>
    <end name="end" />
</workflow-app>
""")
示例#5
0
def test_workflow_app_empty_serial_entities():
    # Empty collections should act empty
    assert len(set(tags.Serial())) == 0
    assert not bool(tags.Serial())