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.tests.base import TestCase
15 import toscaparser.utils.yamlparser
16 from translator.hot.tosca.tosca_floating import ToscaFloatingIP
19 class ToscaFloatingIPTest(TestCase):
21 def _tosca_floatingip_test(self, tpl_snippet, expectedprops, name=None):
22 nodetemplates = (toscaparser.utils.yamlparser.
23 simple_parse(tpl_snippet)['node_templates'])
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)
32 def test_node_floatingip_with_properties(self):
36 type: tosca.nodes.network.FloatingIP
38 floating_network: public
39 floating_ip_address: 192.168.56.8
42 expectedprops = {'floating_network': 'public',
43 'floating_ip_address': '192.168.56.8',
45 self._tosca_floatingip_test(
49 def test_node_floatingip_with_properties_and_link_requirements(self):
53 type: tosca.nodes.network.FloatingIP
55 floating_network: public
56 floating_ip_address: 192.168.56.8
61 type: tosca.nodes.network.Port
65 expectedprops = {'floating_network': 'public',
66 'floating_ip_address': '192.168.56.8',
67 'port_id': '{ get_resource: port1 }'}
68 self._tosca_floatingip_test(