summaryrefslogtreecommitdiffstats
path: root/azure/aria/aria-extension-cloudify/src/aria/tests/orchestrator/workflows/builtin/test_heal.py
blob: 0a422bd6e0bf0b2a4ff7c05715d3112d256df4f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

from aria.orchestrator.workflows.api import task
from aria.orchestrator.workflows.builtin.heal import heal

from tests import mock, storage

from . import (assert_node_install_operations, assert_node_uninstall_operations)


@pytest.fixture
def ctx(tmpdir):
    context = mock.context.simple(str(tmpdir))
    yield context
    storage.release_sqlite_storage(context.model)


@pytest.mark.skip(reason='heal is not implemented for now')
def test_heal_dependent_node(ctx):
    dependent_node = \
        ctx.model.node.get_by_name(mock.models.DEPENDENT_NODE_NAME)
    dependent_node.host_fk = dependent_node.id
    ctx.model.node.update(dependent_node)
    heal_graph = task.WorkflowTask(heal, ctx=ctx, node_id=dependent_node.id)

    assert len(list(heal_graph.tasks)) == 2
    uninstall_subgraph, install_subgraph = list(heal_graph.topological_order(reverse=True))

    assert len(list(uninstall_subgraph.tasks)) == 2
    dependent_node_subgraph_uninstall, dependency_node_subgraph_uninstall = \
        list(uninstall_subgraph.topological_order(reverse=True))

    assert len(list(install_subgraph.tasks)) == 2
    dependency_node_subgraph_install, dependent_node_subgraph_install = \
        list(install_subgraph.topological_order(reverse=True))

    dependent_node_uninstall_tasks = \
        list(dependent_node_subgraph_uninstall.topological_order(reverse=True))
    assert isinstance(dependency_node_subgraph_uninstall, task.StubTask)
    dependent_node_install_tasks = \
        list(dependent_node_subgraph_install.topological_order(reverse=True))
    assert isinstance(dependency_node_subgraph_install, task.StubTask)

    assert_node_uninstall_operations(dependent_node_uninstall_tasks, relationships=1)
    assert_node_install_operations(dependent_node_install_tasks, relationships=1)


@pytest.mark.skip(reason='heal is not implemented for now')
def test_heal_dependency_node(ctx):
    dependency_node = \
        ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_NAME)
    dependency_node.host_fk = dependency_node.id
    ctx.model.node.update(dependency_node)
    heal_graph = task.WorkflowTask(heal, ctx=ctx, node_id=dependency_node.id)
    # both subgraphs should contain un\install for both the dependent and the dependency
    assert len(list(heal_graph.tasks)) == 2
    uninstall_subgraph, install_subgraph = list(heal_graph.topological_order(reverse=True))

    uninstall_tasks = list(uninstall_subgraph.topological_order(reverse=True))
    assert len(uninstall_tasks) == 4
    unlink_source, unlink_target = uninstall_tasks[:2]
    dependent_node_subgraph_uninstall, dependency_node_subgraph_uninstall = uninstall_tasks[2:]

    install_tasks = list(install_subgraph.topological_order(reverse=True))
    assert len(install_tasks) == 4
    dependency_node_subgraph_install, dependent_node_subgraph_install = install_tasks[:2]
    establish_source, establish_target = install_tasks[2:]

    assert isinstance(dependent_node_subgraph_uninstall, task.StubTask)
    dependency_node_uninstall_tasks = \
        list(dependency_node_subgraph_uninstall.topological_order(reverse=True))
    assert isinstance(dependent_node_subgraph_install, task.StubTask)
    dependency_node_install_tasks = \
        list(dependency_node_subgraph_install.topological_order(reverse=True))

    assert unlink_source.name.startswith('aria.interfaces.relationship_lifecycle.unlink')
    assert unlink_target.name.startswith('aria.interfaces.relationship_lifecycle.unlink')
    assert_node_uninstall_operations(dependency_node_uninstall_tasks)

    assert_node_install_operations(dependency_node_install_tasks)
    assert establish_source.name.startswith('aria.interfaces.relationship_lifecycle.establish')
    assert establish_target.name.startswith('aria.interfaces.relationship_lifecycle.establish')


# TODO: add tests for contained in scenario