1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
13 from toscaparser.nodetemplate import NodeTemplate
14 from toscaparser.policy import Policy
15 from toscaparser.tests.base import TestCase
16 import toscaparser.utils.yamlparser
17 from translator.hot.tosca.tosca_compute import ToscaCompute
18 from translator.hot.tosca.tosca_policies import ToscaPolicies
21 class ToscaPoicyTest(TestCase):
23 def _tosca_policy_test(self, tpl_snippet, expectedprops):
24 nodetemplates = (toscaparser.utils.yamlparser.
25 simple_parse(tpl_snippet)['node_templates'])
26 policies = (toscaparser.utils.yamlparser.
27 simple_parse(tpl_snippet)['policies'])
28 name = list(nodetemplates.keys())[0]
29 policy_name = list(policies[0].keys())[0]
30 for policy in policies:
31 tpl = policy[policy_name]
32 targets = tpl["targets"]
34 nodetemplate = NodeTemplate(name, nodetemplates)
35 toscacompute = ToscaCompute(nodetemplate)
36 toscacompute.handle_properties()
38 policy = Policy(policy_name, tpl, targets,
40 toscapolicy = ToscaPolicies(policy)
41 nodetemplate = [toscacompute]
42 toscapolicy.handle_properties(nodetemplate)
44 self.assertEqual(toscacompute.properties, expectedprops)
48 def test_compute_with_policies(self):
52 type: tosca.nodes.Compute
66 - my_compute_placement_policy:
67 type: tosca.policies.Placement
68 description: Apply my placement policy to my application servers
71 expectedprops = {'flavor': 'm1.large',
72 'image': 'fedora-amd64-heat-config',
76 'my_compute_placement_policy'}},
77 'user_data_format': 'SOFTWARE_CONFIG',
78 'software_config_transport': 'POLL_SERVER_HEAT'}
79 self._tosca_policy_test(