Workflows

Factory

class libpermian.workflows.factory.WorkflowFactory
classmethod assign(TestRuns)

Aggregate CaseRunConfiguration objects based on their workflows and call Workflows factory function which then takes care of creating desired Worklflow instances. The Workflow instances are responsible for assigning themselves (as they see fit) to the CaseRunConfiguration objects. Note that one Workflow can be assigned to multiple CaseRunConfiguration objects.

Parameters:

TestRuns

classmethod clear_workflow_classes()

Saves currently registered workflow_classes and replaces it with only builtin classes This method should be used only for testing

original_workflow_classes = {}
classmethod register(name, workflow_class=None)

Class decorator used for registering workflows. Use this to assign name to the workflow. The workflow name is used in caseRunConfigurations and corresponding workflows are created for those caseRunConfigurations for their execution. See assign method.

Use this decorator following way:

@WorkflowFactory.register('my-super-workflow')
class SuperWorkflow(libpermian.workflows.grouped.IsolatedWorkflow):
    ...

Another possible use is:

class SuperWorkflow(libpermian.workflows.grouped.IsolatedWorkflow):
    ...
WorkflowFactory.register('my-super-workflow', SuperWorkflow)
Parameters:
  • name (str) – Name under which the workflow will be recorded

  • workflow_class (GroupedWorkflow, optional) – When not used as decorator, provide the workflow class in this argument.

classmethod restore_workflow_classes()

Restores workflow_classes saved by clear_workflow_classes, must be used after clear_workflow_classes This method should be used only for testing

workflow_classes = {None: <class 'libpermian.workflows.builtin.UnknownWorkflow'>, 'manual': <class 'libpermian.workflows.builtin.ManualWorkflow'>}

Built-in

class libpermian.workflows.builtin.ManualWorkflow(testRuns, crcList)

This workflow is used for manual testcases, it doesn’t do anything

displayStatus()

Provides displayStatus string of this workflow.

Returns:

Markdown formatted string to be displayed for user

Return type:

str

dry_execute()

This method is invoked instead of the execute when the caseRunConfiguration should be executed in dry_run mode.

execute()

Steps performed during the execution of the workflow. Here’s the place where the core code of the workflow should be happening.

This method should NEVER EVER perform any computation intensive tasks as it’s executed in python thread. If needed, use separate processes using subprocess, multiprocessing modules or fork function.

Returns:

None

Return type:

None

terminate()

Process termination of this workflow.

Returns:

True if the workflow was terminated False otherwise

Return type:

bool

class libpermian.workflows.builtin.UnknownWorkflow(testRuns, crcList)

This workflow is used when the workflow name in caseRunConfiguration has no corresponding workflow.

The purpose of this workflow is to report error during execution.

displayStatus()

Provides displayStatus string of this workflow.

Returns:

Markdown formatted string to be displayed for user

Return type:

str

execute()

Steps performed during the execution of the workflow. Here’s the place where the core code of the workflow should be happening.

This method should NEVER EVER perform any computation intensive tasks as it’s executed in python thread. If needed, use separate processes using subprocess, multiprocessing modules or fork function.

Returns:

None

Return type:

None

run()

This is the main body of the workflow execution. This method calls setup, execute (or dry_execute) and teardown methods in sequence.

This method is not meant to be called directly as it’s started in separate thread once the workflow.start method is invoked. For more information see Threading.Thread.start.

Returns:

None

Return type:

None

terminate()

Process termination of this workflow.

Returns:

True if the workflow was terminated False otherwise

Return type:

bool

Grouped

class libpermian.workflows.grouped.GroupedWorkflow(testRuns, crcList)

Abstract class for all workflows. Use this class as parent for you workflow if you want to handle multiple caseRunConfigurations by one workflow instance. If you’re not seeking this functionality, look for IsolatedWorkflow class.

Workflow instances should not be directly created, use the factory method which should handle creation of the workflow instances.

dry_execute()

This method is invoked instead of the execute when the caseRunConfiguration should be executed in dry_run mode.

abstract execute()

Steps performed during the execution of the workflow. Here’s the place where the core code of the workflow should be happening.

This method should NEVER EVER perform any computation intensive tasks as it’s executed in python thread. If needed, use separate processes using subprocess, multiprocessing modules or fork function.

Returns:

None

Return type:

None

abstract classmethod factory(testRuns, crcList)

Make instances of this workflow for given caseRunConfigurations and assign them accordingly.

Note: Once same instance may be assigned to multiple items of caseRunConfigurations. The way how the instances are assigned to individual caseRunConfiguration objects is up to the workflow.

Parameters:

crcIds (list) – List of CaseRunConfiguration which belong to this workflow.

Returns:

None

Return type:

None

formatLogMessage(message)
groupAddLog(name, log_path, crcList=None)

Add arbitrary log_path to a log under specific name related to provided crcIds. If crcIds is not provided, all crcIds related to the workflow are used.

The log_path can either be path to local file (relative or absolute) or URL.

This method just registers the log_path but doesn’t create files.

abstract groupDisplayStatus(crcId)

Provides more comprehensive (and possibly graphically formatted) status of the workflow for the end user. This is meant as channel where more advanced information such as hyperlink to external system with some brief description of current workflow state is provided.

Note: Output of this method should never be parsed.

Parameters:

crcIds

Returns:

Markdown formatted text provided for human processing

Return type:

str

groupLog(message, name='workflow', crcList=None)

Add a message to a logfile with provided name related to provided crcIds. If the provided crcIds don’t have such log yet, it’s automatically created and assigned.

When trying to log message to a log which is not a local file, exception RemoteLogError is raised.

groupLogData(data, name, crcList=None, filename=None)

Write bytes from data to file named name under crc’s log directory.

name and filename have the same meaning as in the method CaseRunConfiguration.openLogfile(). data is the bytes to write.

If crcList is not provided, all related crcIds are affected.

File is overwritten if it exists.

groupReportResult(crcList, result)

Provide partial or final result for the crcId. For more information see TODO:Result.

Parameters:
  • crcIds (list) – TODO

  • result (TODO) – TODO

Returns:

None

Return type:

None

abstract groupTerminate(crcIds)

Terminate execution of specific crcIds handled by the workflow.

Parameters:

crcIds (list) – Configurations to be terminated

Returns:

TODO

Return type:

TODO

run()

This is the main body of the workflow execution. This method calls setup, execute (or dry_execute) and teardown methods in sequence.

This method is not meant to be called directly as it’s started in separate thread once the workflow.start method is invoked. For more information see Threading.Thread.start.

Returns:

None

Return type:

None

setup()

Steps performed before actual execution started.

Returns:

None

Return type:

None

silent_exceptions = ()
teardown()

Steps performed after the execution ended.

Returns:

None

Return type:

None

Isolated

class libpermian.workflows.isolated.IsolatedWorkflow(testRuns, crcList)

Abstract class for workflows which goal is to execute caseRunConfiguration instances separately and no grouping of execution is desired.

This class provides additional methods related to the only one caseRunConfiguration it’s handling. See methods which name doesn’t start with ‘group’.

Workflow instances should not be directly created, use the factory method which should handle creation of the workflow instances.

addLog(name, log_path)
abstract displayStatus()

Provides displayStatus string of this workflow.

Returns:

Markdown formatted string to be displayed for user

Return type:

str

classmethod factory(testRuns, crcList)

Make instances of this workflow for given crcIds and assign them accordingly.

The IsolatedWorkflow implementation of this factory makes separate instance for each caseRunConfiguration object where each of the instances is handling exactly one caseRunConfiguration object.

Parameters:

crcIds (list) – List of CaseRunConfiguration which belong to this workflow.

Returns:

None

Return type:

None

groupDisplayStatus(crcId)

Provide displayStatus of the given crcId which in case of Isolated workflow is the only one it’s handling. If the crcId doesn’t match the one valid for this workflow, throw exception.

Raises:

ValueError – If invalid crcId is provided

Returns:

Markdown formatted string to be displayed for user

Return type:

str

groupTerminate(crcIds)

Terminate all matching crcIds which in case of Isolated workflow is the only one it’s handling. If the crcIds doesn’t contain just the one valid for this workflow, throw exception.

Raises:

ValueError – If invalid crcIds is provided

Returns:

True if the workflow was terminated False otherwise

Return type:

bool

log(message, name='workflow')
logData(data, name, filename=None)
reportResult(result)

Shortcut method for groupReportResult. The crcIds is not needed when this method is used.

abstract terminate()

Process termination of this workflow.

Returns:

True if the workflow was terminated False otherwise

Return type:

bool