vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / tests / orchestrator / workflows / builtin / __init__.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 from aria.orchestrator.workflows.builtin import workflows
17
18
19 def _assert_relationships(operations, expected_op_full_name, relationships=0):
20     """
21
22     :param operations: and iterable of operations
23     :param expected_op_full_name: Note that source/target doesn't really matter since they are
24     dropped
25     :param relationships: the number of relationships
26     :return:
27     """
28     expected_op_name = expected_op_full_name.rsplit('_', 1)[0]
29     for _ in xrange(relationships):
30         # Since the target and source operations start of the same way, we only need to retrieve the
31         # suffix once
32         operation = next(operations)
33         relationship_id_1 = operation.actor.id
34         _assert_cfg_interface_op(operation, expected_op_name)
35
36         operation = next(operations)
37         relationship_id_2 = operation.actor.id
38         _assert_cfg_interface_op(operation, expected_op_name)
39
40         assert relationship_id_1 == relationship_id_2
41
42
43 def assert_node_install_operations(operations, relationships=0):
44     operations = iter(operations)
45
46     _assert_std_interface_op(next(operations), workflows.NORMATIVE_CREATE)
47     _assert_relationships(operations, workflows.NORMATIVE_PRE_CONFIGURE_SOURCE, relationships)
48     _assert_std_interface_op(next(operations), workflows.NORMATIVE_CONFIGURE)
49     _assert_relationships(operations, workflows.NORMATIVE_POST_CONFIGURE_SOURCE, relationships)
50     _assert_std_interface_op(next(operations), workflows.NORMATIVE_START)
51     _assert_relationships(operations, workflows.NORMATIVE_ADD_SOURCE, relationships)
52
53
54 def assert_node_uninstall_operations(operations, relationships=0):
55     operations = iter(operations)
56
57     _assert_std_interface_op(next(operations), workflows.NORMATIVE_STOP)
58     _assert_relationships(operations, workflows.NORMATIVE_REMOVE_SOURCE, relationships)
59     _assert_std_interface_op(next(operations), workflows.NORMATIVE_DELETE)
60
61
62 def _assert_cfg_interface_op(op, operation_name):
63     # We need to remove the source/target
64     assert op.operation_name.rsplit('_', 1)[0] == operation_name
65     assert op.interface_name == workflows.NORMATIVE_CONFIGURE_INTERFACE
66
67
68 def _assert_std_interface_op(op, operation_name):
69     assert op.operation_name == operation_name
70     assert op.interface_name == workflows.NORMATIVE_STANDARD_INTERFACE