selinon.failure_node module

Failure node handling representation.

A failure is basically a node in graph, that represents all permutations of possible cases of failures. Consider having two failure conditions:

failures:
  - nodes:
        - Task1
        - Task2
        - Task3
    fallback:
        - FallbackTask1
  - nodes:
        - Task1
        - Task2
    fallback:
        - FallbackTask2

What we do here, we construct a graph of all possible permutations connected using edges that represent a node that should be added to create a new permutation:

 |-------------------------------
 |                              |
T1           T2           T3    |
  \         /  \         / \    |
   \       /    \       /   \   |
    \     /      \     /     \  v
     T1,T2*       T2,T3      T1,T3
        \         /           /
         \       /           /
          T1,T2,T3*  <-------

For nodes T1,T2,T3 and T1,T2 we assign a fallback as configured. This graph is then serialized into the Python configuration code. This way the dispatcher has O(N) time complexity when dealing with failures.

Note we are creating sparse tree - only for nodes that are listed in failures.

Note that we link failure nodes as allocated - we get a one way linked list of all failure nodes that helps us with Python code generation.

class selinon.failure_node.FailureNode(flow, traversed, failure_link)[source]

Bases: object

A representation of a failure node permutation.

add_to(node_name, failure)[source]

Add failure for next permutation.

Parameters:
  • node_name – a node for next permutation
  • failure – FailureNode that should be added
classmethod construct(flow, system, failures)[source]

Construct failures from failures dictionary.

Parameters:
  • flow – flow to which failures conform to
  • system – system context to be used
  • failures – failures dictionary
Returns:

a link for linked list of failures and a dict of starting failures

static construct_condition_name(failure_node, idx)[source]

Construct condition name that will be used in case of conditional fallbacks.

Parameters:
  • failure_node – failure node for which the condition name should be constructed
  • idx – index of condition that should be printed (could be multiple fallbacks with same source and dst)
Returns:

string representation of constructed condition name as stated in the generated python code

has_to(node_name)[source]

Check whether there is a link to next permutation.

Parameters:node_name – name of the node to be added to create a new permutation
Returns:True if there is a link to next permutation for node of name node_name
to(node_name)[source]

Retrieve next permutation based on link in failure graph.

Parameters:node_name – a name of the node for next permutation
Return type:FailureNode