Synchronize upstream version of 0.9
[parser.git] / tosca2heat / heat-translator / translator / hot / tosca / tests / test_tosca_floatingip.py
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
4 #
5 #         http://www.apache.org/licenses/LICENSE-2.0
6 #
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
11 #    under the License.
12
13 from toscaparser.nodetemplate import NodeTemplate
14 from toscaparser.tests.base import TestCase
15 import toscaparser.utils.yamlparser
16 from translator.hot.tosca.tosca_floating import ToscaFloatingIP
17
18
19 class ToscaFloatingIPTest(TestCase):
20
21     def _tosca_floatingip_test(self, tpl_snippet, expectedprops, name=None):
22         nodetemplates = (toscaparser.utils.yamlparser.
23                          simple_parse(tpl_snippet)['node_templates'])
24         if not name:
25             name = list(nodetemplates.keys())[0]
26         nodetemplate = NodeTemplate(name, nodetemplates, custom_def=[])
27         nodetemplate.validate()
28         tosca_floatingip = ToscaFloatingIP(nodetemplate)
29         tosca_floatingip.handle_properties()
30         self.assertEqual(expectedprops, tosca_floatingip.properties)
31
32     def test_node_floatingip_with_properties(self):
33         tpl_snippet = '''
34         node_templates:
35           floating_ip:
36             type: tosca.nodes.network.FloatingIP
37             properties:
38               floating_network: public
39               floating_ip_address: 192.168.56.8
40               port_id: abcd
41         '''
42         expectedprops = {'floating_network': 'public',
43                          'floating_ip_address': '192.168.56.8',
44                          'port_id': 'abcd'}
45         self._tosca_floatingip_test(
46             tpl_snippet,
47             expectedprops)
48
49     def test_node_floatingip_with_properties_and_link_requirements(self):
50         tpl_snippet = '''
51         node_templates:
52           floating_ip:
53             type: tosca.nodes.network.FloatingIP
54             properties:
55               floating_network: public
56               floating_ip_address: 192.168.56.8
57             requirements:
58               - link:
59                   node: port1
60           port1:
61             type: tosca.nodes.network.Port
62             properties:
63               ip_address: 10.0.0.6
64         '''
65         expectedprops = {'floating_network': 'public',
66                          'floating_ip_address': '192.168.56.8',
67                          'port_id': '{ get_resource: port1 }'}
68         self._tosca_floatingip_test(
69             tpl_snippet,
70             expectedprops,
71             name='floating_ip')