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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 from aria.orchestrator.workflows.api import task
19 from aria.orchestrator.workflows.builtin.heal import heal
21 from tests import mock, storage
23 from . import (assert_node_install_operations, assert_node_uninstall_operations)
28 context = mock.context.simple(str(tmpdir))
30 storage.release_sqlite_storage(context.model)
33 @pytest.mark.skip(reason='heal is not implemented for now')
34 def test_heal_dependent_node(ctx):
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)
41 assert len(list(heal_graph.tasks)) == 2
42 uninstall_subgraph, install_subgraph = list(heal_graph.topological_order(reverse=True))
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))
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))
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)
59 assert_node_uninstall_operations(dependent_node_uninstall_tasks, relationships=1)
60 assert_node_install_operations(dependent_node_install_tasks, relationships=1)
63 @pytest.mark.skip(reason='heal is not implemented for now')
64 def test_heal_dependency_node(ctx):
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))
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:]
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:]
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))
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)
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')
100 # TODO: add tests for contained in scenario