vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / tests / orchestrator / workflows / builtin / test_heal.py
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements.  See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License.  You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import pytest
17
18 from aria.orchestrator.workflows.api import task
19 from aria.orchestrator.workflows.builtin.heal import heal
20
21 from tests import mock, storage
22
23 from . import (assert_node_install_operations, assert_node_uninstall_operations)
24
25
26 @pytest.fixture
27 def ctx(tmpdir):
28     context = mock.context.simple(str(tmpdir))
29     yield context
30     storage.release_sqlite_storage(context.model)
31
32
33 @pytest.mark.skip(reason='heal is not implemented for now')
34 def test_heal_dependent_node(ctx):
35     dependent_node = \
36         ctx.model.node.get_by_name(mock.models.DEPENDENT_NODE_NAME)
37     dependent_node.host_fk = dependent_node.id
38     ctx.model.node.update(dependent_node)
39     heal_graph = task.WorkflowTask(heal, ctx=ctx, node_id=dependent_node.id)
40
41     assert len(list(heal_graph.tasks)) == 2
42     uninstall_subgraph, install_subgraph = list(heal_graph.topological_order(reverse=True))
43
44     assert len(list(uninstall_subgraph.tasks)) == 2
45     dependent_node_subgraph_uninstall, dependency_node_subgraph_uninstall = \
46         list(uninstall_subgraph.topological_order(reverse=True))
47
48     assert len(list(install_subgraph.tasks)) == 2
49     dependency_node_subgraph_install, dependent_node_subgraph_install = \
50         list(install_subgraph.topological_order(reverse=True))
51
52     dependent_node_uninstall_tasks = \
53         list(dependent_node_subgraph_uninstall.topological_order(reverse=True))
54     assert isinstance(dependency_node_subgraph_uninstall, task.StubTask)
55     dependent_node_install_tasks = \
56         list(dependent_node_subgraph_install.topological_order(reverse=True))
57     assert isinstance(dependency_node_subgraph_install, task.StubTask)
58
59     assert_node_uninstall_operations(dependent_node_uninstall_tasks, relationships=1)
60     assert_node_install_operations(dependent_node_install_tasks, relationships=1)
61
62
63 @pytest.mark.skip(reason='heal is not implemented for now')
64 def test_heal_dependency_node(ctx):
65     dependency_node = \
66         ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_NAME)
67     dependency_node.host_fk = dependency_node.id
68     ctx.model.node.update(dependency_node)
69     heal_graph = task.WorkflowTask(heal, ctx=ctx, node_id=dependency_node.id)
70     # both subgraphs should contain un\install for both the dependent and the dependency
71     assert len(list(heal_graph.tasks)) == 2
72     uninstall_subgraph, install_subgraph = list(heal_graph.topological_order(reverse=True))
73
74     uninstall_tasks = list(uninstall_subgraph.topological_order(reverse=True))
75     assert len(uninstall_tasks) == 4
76     unlink_source, unlink_target = uninstall_tasks[:2]
77     dependent_node_subgraph_uninstall, dependency_node_subgraph_uninstall = uninstall_tasks[2:]
78
79     install_tasks = list(install_subgraph.topological_order(reverse=True))
80     assert len(install_tasks) == 4
81     dependency_node_subgraph_install, dependent_node_subgraph_install = install_tasks[:2]
82     establish_source, establish_target = install_tasks[2:]
83
84     assert isinstance(dependent_node_subgraph_uninstall, task.StubTask)
85     dependency_node_uninstall_tasks = \
86         list(dependency_node_subgraph_uninstall.topological_order(reverse=True))
87     assert isinstance(dependent_node_subgraph_install, task.StubTask)
88     dependency_node_install_tasks = \
89         list(dependency_node_subgraph_install.topological_order(reverse=True))
90
91     assert unlink_source.name.startswith('aria.interfaces.relationship_lifecycle.unlink')
92     assert unlink_target.name.startswith('aria.interfaces.relationship_lifecycle.unlink')
93     assert_node_uninstall_operations(dependency_node_uninstall_tasks)
94
95     assert_node_install_operations(dependency_node_install_tasks)
96     assert establish_source.name.startswith('aria.interfaces.relationship_lifecycle.establish')
97     assert establish_target.name.startswith('aria.interfaces.relationship_lifecycle.establish')
98
99
100 # TODO: add tests for contained in scenario