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
15 from toscaparser.nodetemplate import NodeTemplate
16 from toscaparser.tests.base import TestCase
17 import toscaparser.utils.yamlparser
18 from translator.hot.tosca.tosca_compute import ToscaCompute
21 class ToscaComputeTest(TestCase):
23 def _tosca_compute_test(self, tpl_snippet, expectedprops):
24 nodetemplates = (toscaparser.utils.yamlparser.
25 simple_parse(tpl_snippet)['node_templates'])
26 name = list(nodetemplates.keys())[0]
27 nodetemplate = NodeTemplate(name, nodetemplates)
28 nodetemplate.validate()
29 toscacompute = ToscaCompute(nodetemplate)
30 toscacompute.handle_properties()
32 self.assertEqual(expectedprops, toscacompute.properties)
34 def test_node_compute_with_host_and_os_capabilities(self):
38 type: tosca.nodes.Compute
52 expectedprops = {'flavor': 'm1.large',
53 'image': 'fedora-amd64-heat-config',
54 'user_data_format': 'SOFTWARE_CONFIG',
55 'software_config_transport': 'POLL_SERVER_HEAT'}
56 self._tosca_compute_test(
60 def test_node_compute_without_os_capabilities(self):
64 type: tosca.nodes.Compute
73 expectedprops = {'flavor': 'm1.large',
74 'user_data_format': 'SOFTWARE_CONFIG',
75 'software_config_transport': 'POLL_SERVER_HEAT'}
76 self._tosca_compute_test(
80 def test_node_compute_without_host_capabilities(self):
84 type: tosca.nodes.Compute
93 expectedprops = {'flavor': None,
94 'image': 'fedora-amd64-heat-config',
95 'user_data_format': 'SOFTWARE_CONFIG',
96 'software_config_transport': 'POLL_SERVER_HEAT'}
97 self._tosca_compute_test(
101 def test_node_compute_without_properties_and_os_capabilities(self):
105 type: tosca.nodes.Compute
111 expectedprops = {'flavor': None,
112 'user_data_format': 'SOFTWARE_CONFIG',
113 'software_config_transport': 'POLL_SERVER_HEAT'}
114 self._tosca_compute_test(
118 def test_node_compute_with_only_type(self):
122 type: tosca.nodes.Compute
124 expectedprops = {'flavor': None,
125 'user_data_format': 'SOFTWARE_CONFIG',
126 'software_config_transport': 'POLL_SERVER_HEAT'}
127 self._tosca_compute_test(
131 def test_node_compute_host_capabilities_without_properties(self):
135 type: tosca.nodes.Compute
141 expectedprops = {'flavor': None,
142 'user_data_format': 'SOFTWARE_CONFIG',
143 'software_config_transport': 'POLL_SERVER_HEAT'}
144 self._tosca_compute_test(
148 def test_node_compute_host_capabilities_without_disk_size(self):
152 type: tosca.nodes.Compute
159 expectedprops = {'flavor': 'm1.large',
160 'user_data_format': 'SOFTWARE_CONFIG',
161 'software_config_transport': 'POLL_SERVER_HEAT'}
162 self._tosca_compute_test(
166 def test_node_compute_host_capabilities_without_mem_size(self):
170 type: tosca.nodes.Compute
177 expectedprops = {'flavor': 'm1.large',
178 'user_data_format': 'SOFTWARE_CONFIG',
179 'software_config_transport': 'POLL_SERVER_HEAT'}
180 self._tosca_compute_test(
184 def test_node_compute_host_capabilities_without_mem_size_disk_size(self):
188 type: tosca.nodes.Compute
194 expectedprops = {'flavor': 'm1.large',
195 'user_data_format': 'SOFTWARE_CONFIG',
196 'software_config_transport': 'POLL_SERVER_HEAT'}
197 self._tosca_compute_test(
201 @mock.patch('translator.common.flavors.get_flavors')
202 def test_node_compute_with_nova_flavor(self, mock_flavor):
206 type: tosca.nodes.Compute
214 mock_flavor.return_value = {
220 expectedprops = {'flavor': 'm1.mock_flavor',
221 'user_data_format': 'SOFTWARE_CONFIG',
222 'software_config_transport': 'POLL_SERVER_HEAT'}
223 self._tosca_compute_test(tpl_snippet, expectedprops)
225 @mock.patch('translator.common.images.get_images')
226 def test_node_compute_with_glance_image(self, mock_images):
230 type: tosca.nodes.Compute
241 distribution: Fake Distribution
244 mock_images.return_value = {
245 'fake-image-foobar': {'architecture': 'x86_64',
247 'distribution': 'Fake Distribution',
249 'fake-image-foobar-old': {'architecture': 'x86_64',
251 'distribution': 'Fake Distribution',
254 expectedprops = {'flavor': 'm1.small',
255 'image': 'fake-image-foobar',
256 'user_data_format': 'SOFTWARE_CONFIG',
257 'software_config_transport': 'POLL_SERVER_HEAT'}
258 self._tosca_compute_test(tpl_snippet, expectedprops)