Skip to content

testing

A backend in memory for tests of the service, advanced by the test.

FakeBackend

FakeBackend(nodes=None, finish_after=None, images=())

A backend whose workflows change only when the test says so.

A submitted workflow is Pending without nodes. start sets every node running, finish every node succeeded, fail and set_node one node, fail_attempt and oom_kill fail attempts of a pod; finish_after finishes a workflow that many seconds after its submission. The attempts of a pod are numbered from 0 in the order they fail. A coordinator which merges and succeeds writes the marker of a merge into the output of its task in store, as the harness does, unless merges is False (the harness of simrun 0.1.0). The calls which change the cluster are recorded in calls.

Attributes:

Name Type Description
manifests dict[str, dict[str, Any]]

The submitted manifests by name.

subscribed list[Callable[[], None]]

The callbacks registered with subscribe.

calls list[tuple[Any, ...]]

("submit", name), ("cancel", name), ("stop", name), ("logs", name, task_id), ("reserve", node, run_id), ("unreserve", node, run_id) and ("build_image", ref, files of the context).

images

The images of the registry.

pod_logs dict[tuple[str, str], list[PodLog]]

The logs of the pods by workflow name and task id, see add_log.

store Path | None

The store of the service, where a coordinator which merges writes the marker of its merge; None writes none.

merges

Whether a coordinator which merges writes the marker.

Create the backend.

Parameters:

Name Type Description Default
nodes list[Node] | None

The nodes of the cluster, TEST_NODES by default.

None
finish_after float | None

Seconds after which a submitted workflow succeeds.

None
images Iterable[str]

The images the registry has.

()

subscribe

subscribe(callback)

Remember the callback in subscribed; the fake never calls it.

submit

submit(record, plans, types, cluster)

Accept the workflow of a run, pending without nodes; one which exists is kept.

Raises:

Type Description
ValueError

The workflow cannot be built, e.g. a task has no image.

status

status(name)

The status of a workflow; KeyError for an unknown one.

start

start(name)

Set every node of a workflow running.

finish

finish(name)

Let every node of a workflow succeed.

set_node

set_node(name, node, phase)

Set the phase of one node.

fail

fail(name, node)

Fail a node, given by its name or by a task id (its coordinator -w0).

delete

delete(name)

Remove a workflow, as its time to live does.

fail_attempt

fail_attempt(
    name, worker, exit_code=None, oom_killed=False
)

Fail the next attempt of a pod of a worker, merge or unsplit task.

oom_kill

oom_kill(name, worker, count=1)

Let the next attempts of a pod be killed by the out of memory killer.

cancel

cancel(name)

Terminate a workflow.

stop

stop(name)

Stop a workflow.

add_log

add_log(name, task_id, node, text, done=True)

Add the log of a pod of a task, the pod named <workflow>-<node>.

logs

logs(name, task_id, tail_lines=None)

The logs added with add_log, the last tail_lines lines of each.

nodes

nodes()

The nodes, with their reservations.

place

place(placement)

Place a pod, listed by placements until its workflow has ended.

A placement of a pod placed before replaces it, e.g. once the pod is bound.

placements

placements()

The pods placed for the workflows which have not ended.

reserve

reserve(node, run_id)

Reserve a node; KeyError for an unknown one.

unreserve

unreserve(node, run_id)

Release a node reserved by the run; KeyError for an unknown node.

build_image

build_image(context, ref)

Record the build and add the image to the registry.

has_image

has_image(ref)

Whether the image was given or built.

dag_nodes

dag_nodes(manifest)

The names of the DAG nodes of a workflow manifest, as Argo names them.

A DAG task over a sequence is one node per item, <task>(<index>:<item>).