Exemplo n.º 1
0
 def __init__(self, graph_representation, conditions={}, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.connection_pool = DummyMockConnectionPool(*args, **kwargs)
     self.graph = TopologyGraph(graph_representation, conditions)
Exemplo n.º 2
0
def test_topology_graph_build_hanging_after_merge(
        graph_hanging_deployment_after_merge):
    graph = TopologyGraph(graph_hanging_deployment_after_merge)
    node_names_list = [node.name for node in graph.origin_nodes]
    assert set(node_names_list) == {
        'deployment0',
        'deployment4',
        'deployment6',
        'deployment8',
    }
    assert (len(graph.origin_nodes[node_names_list.index(
        'deployment0')].outgoing_nodes) == 2)
    assert set([
        node.name for node in graph.origin_nodes[node_names_list.index(
            'deployment0')].outgoing_nodes
    ]) == {'deployment1', 'deployment2'}

    node_deployment0 = graph.origin_nodes[node_names_list.index('deployment0')]
    assert node_deployment0.name == 'deployment0'
    assert node_deployment0.number_of_parts == 1
    assert not node_deployment0.hanging
    outgoing_deployment0_list = [
        node.name for node in node_deployment0.outgoing_nodes
    ]

    node_deployment1 = node_deployment0.outgoing_nodes[
        outgoing_deployment0_list.index('deployment1')]
    assert node_deployment1.name == 'deployment1'
    assert node_deployment1.number_of_parts == 1
    assert len(node_deployment1.outgoing_nodes) == 0
    assert node_deployment1.hanging

    node_deployment2 = node_deployment0.outgoing_nodes[
        outgoing_deployment0_list.index('deployment2')]
    assert node_deployment2.name == 'deployment2'
    assert node_deployment2.number_of_parts == 1
    assert len(node_deployment2.outgoing_nodes) == 1
    assert not node_deployment2.hanging

    node_deployment3 = node_deployment2.outgoing_nodes[0]
    assert node_deployment3.name == 'deployment3'
    assert node_deployment3.number_of_parts == 1
    assert len(node_deployment3.outgoing_nodes) == 0
    assert not node_deployment3.hanging

    node_deployment4 = graph.origin_nodes[node_names_list.index('deployment4')]
    assert node_deployment4.name == 'deployment4'
    assert node_deployment4.number_of_parts == 1
    assert len(node_deployment4.outgoing_nodes) == 1
    assert set([
        node.name for node in graph.origin_nodes[node_names_list.index(
            'deployment4')].outgoing_nodes
    ]) == {'deployment5'}
    assert not node_deployment4.hanging

    node_deployment5 = node_deployment4.outgoing_nodes[0]
    assert node_deployment5.name == 'deployment5'
    assert node_deployment5.number_of_parts == 1
    assert len(node_deployment5.outgoing_nodes) == 0
    assert not node_deployment5.hanging

    node_deployment6 = graph.origin_nodes[node_names_list.index('deployment6')]
    assert node_deployment6.name == 'deployment6'
    assert len(node_deployment6.outgoing_nodes) == 1
    assert node_deployment6.number_of_parts == 1
    assert node_deployment6.outgoing_nodes[0].name == 'deployment7'
    assert not node_deployment6.hanging

    node_deployment8 = graph.origin_nodes[node_names_list.index('deployment8')]
    assert node_deployment8.name == 'deployment8'
    assert len(node_deployment8.outgoing_nodes) == 1
    assert node_deployment8.number_of_parts == 1
    assert node_deployment8.outgoing_nodes[0].name == 'deployment7'
    assert not node_deployment8.hanging

    assert id(node_deployment6.outgoing_nodes[0]) == id(
        node_deployment8.outgoing_nodes[0])

    node_deployment7 = node_deployment6.outgoing_nodes[0]
    assert node_deployment7.name == 'deployment7'
    assert len(node_deployment7.outgoing_nodes) == 1
    assert node_deployment7.number_of_parts == 2
    assert node_deployment7.outgoing_nodes[0].name == 'deployment9'
    assert not node_deployment7.hanging

    node_deployment9 = node_deployment7.outgoing_nodes[0]
    assert node_deployment9.name == 'deployment9'
    assert len(node_deployment9.outgoing_nodes) == 0
    assert node_deployment9.number_of_parts == 1
    assert node_deployment9.hanging
Exemplo n.º 3
0
def test_topology_graph_build_bifurcation(bifurcation_graph_dict, conditions):
    graph = TopologyGraph(bifurcation_graph_dict, conditions)
    node_names_list = [node.name for node in graph.origin_nodes]
    assert set(node_names_list) == {
        'deployment0', 'deployment4', 'deployment6'
    }
    assert (len(graph.origin_nodes[node_names_list.index(
        'deployment0')].outgoing_nodes) == 2)
    assert set([
        node.name for node in graph.origin_nodes[node_names_list.index(
            'deployment0')].outgoing_nodes
    ]) == {'deployment1', 'deployment2'}

    node_deployment0 = graph.origin_nodes[node_names_list.index('deployment0')]
    assert not node_deployment0.hanging
    assert node_deployment0.name == 'deployment0'
    assert node_deployment0.number_of_parts == 1
    outgoing_deployment0_list = [
        node.name for node in node_deployment0.outgoing_nodes
    ]

    node_deployment1 = node_deployment0.outgoing_nodes[
        outgoing_deployment0_list.index('deployment1')]
    assert node_deployment1.name == 'deployment1'
    if conditions == {}:
        assert node_deployment1._filter_condition is None
    else:
        assert node_deployment1._filter_condition == {'tags__key': {'$eq': 5}}
    assert node_deployment1.number_of_parts == 1
    assert len(node_deployment1.outgoing_nodes) == 0
    assert node_deployment1.hanging

    node_deployment2 = node_deployment0.outgoing_nodes[
        outgoing_deployment0_list.index('deployment2')]
    assert node_deployment2.name == 'deployment2'
    if conditions == {}:
        assert node_deployment2._filter_condition is None
    else:
        assert node_deployment2._filter_condition == {'tags__key': {'$eq': 4}}
    assert node_deployment2.number_of_parts == 1
    assert len(node_deployment2.outgoing_nodes) == 1
    assert not node_deployment2.hanging

    node_deployment3 = node_deployment2.outgoing_nodes[0]
    assert node_deployment3.name == 'deployment3'
    assert node_deployment3.number_of_parts == 1
    assert len(node_deployment3.outgoing_nodes) == 0
    assert not node_deployment3.hanging

    node_deployment4 = graph.origin_nodes[node_names_list.index('deployment4')]
    assert node_deployment4.name == 'deployment4'
    assert node_deployment4.number_of_parts == 1
    assert len(node_deployment4.outgoing_nodes) == 1
    assert not node_deployment4.hanging
    assert set([
        node.name for node in graph.origin_nodes[node_names_list.index(
            'deployment4')].outgoing_nodes
    ]) == {'deployment5'}

    node_deployment5 = node_deployment4.outgoing_nodes[0]
    assert node_deployment5.name == 'deployment5'
    assert node_deployment5.number_of_parts == 1
    assert not node_deployment5.hanging
    assert len(node_deployment5.outgoing_nodes) == 0

    node_deployment6 = graph.origin_nodes[node_names_list.index('deployment6')]
    assert node_deployment6.name == 'deployment6'
    assert len(node_deployment6.outgoing_nodes) == 0
    assert node_deployment6.number_of_parts == 1
    assert node_deployment6.hanging
    assert set([node.name
                for node in node_deployment6.outgoing_nodes]) == set()
Exemplo n.º 4
0
def test_topology_graph_build_complete(complete_graph_dict):
    graph = TopologyGraph(complete_graph_dict)
    assert set([node.name for node in graph.origin_nodes]) == {
        'deployment0',
        'deployment4',
        'deployment6',
    }
    node_names_list = [node.name for node in graph.origin_nodes]

    node_deployment0 = graph.origin_nodes[node_names_list.index('deployment0')]
    assert node_deployment0.number_of_parts == 1
    assert not node_deployment0.hanging
    outgoing_deployment0_list = [
        node.name for node in node_deployment0.outgoing_nodes
    ]

    node_deployment1 = node_deployment0.outgoing_nodes[
        outgoing_deployment0_list.index('deployment1')]
    assert node_deployment1.number_of_parts == 1
    assert not node_deployment1.hanging
    assert len(node_deployment1.outgoing_nodes) == 0

    node_deployment2 = node_deployment0.outgoing_nodes[
        outgoing_deployment0_list.index('deployment2')]
    assert len(node_deployment2.outgoing_nodes) == 1
    assert node_deployment2.number_of_parts == 1
    assert not node_deployment2.hanging

    node_deployment3 = node_deployment2.outgoing_nodes[0]
    assert node_deployment3.name == 'deployment3'
    assert node_deployment3.number_of_parts == 1
    assert len(node_deployment3.outgoing_nodes) == 1
    assert node_deployment3.outgoing_nodes[0].name == 'merger'
    assert not node_deployment3.hanging

    node_deployment4 = graph.origin_nodes[node_names_list.index('deployment4')]
    assert node_deployment4.number_of_parts == 1
    assert len(node_deployment4.outgoing_nodes) == 1
    assert not node_deployment4.hanging

    node_deployment5 = node_deployment4.outgoing_nodes[0]
    assert node_deployment5.number_of_parts == 1
    assert node_deployment5.name == 'deployment5'
    assert len(node_deployment5.outgoing_nodes) == 1
    assert node_deployment5.outgoing_nodes[0].name == 'merger'
    assert not node_deployment5.hanging

    assert id(node_deployment3.outgoing_nodes[0]) == id(
        node_deployment5.outgoing_nodes[0])

    merger_deployment = node_deployment3.outgoing_nodes[0]
    assert merger_deployment.name == 'merger'
    assert len(merger_deployment.outgoing_nodes) == 1
    assert merger_deployment.number_of_parts == 2
    assert not merger_deployment.hanging

    deployment_last_deployment = merger_deployment.outgoing_nodes[0]
    assert deployment_last_deployment.name == 'deployment_last'
    assert len(deployment_last_deployment.outgoing_nodes) == 0
    assert deployment_last_deployment.number_of_parts == 1
    assert not deployment_last_deployment.hanging

    node_deployment6 = graph.origin_nodes[node_names_list.index('deployment6')]
    assert node_deployment6.name == 'deployment6'
    assert node_deployment6.number_of_parts == 1
    assert len(node_deployment6.outgoing_nodes) == 0
    assert node_deployment6.hanging
Exemplo n.º 5
0
def test_empty_graph():
    graph = TopologyGraph({})
    assert not graph.origin_nodes