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
16 from toscaparser.common.exception import ExceptionCollector
17 from toscaparser.common.exception import URLException
18 from toscaparser.common.exception import ValidationError
19 from toscaparser.utils.gettextutils import _
20 from translator.common.utils import TranslationUtils
21 from translator.tests.base import TestCase
24 class ToscaHotTranslationTest(TestCase):
26 def _test_successful_translation(self, tosca_file, hot_file, params=None):
29 diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file,
32 self.assertEqual({}, diff, '<difference> : ' +
33 json.dumps(diff, indent=4, separators=(', ', ': ')))
35 def _test_failed_translation(self, tosca_file, hot_file, params, msg,
36 msg_path, error_raise, error_collect):
38 path = os.path.normpath(os.path.join(
39 os.path.dirname(os.path.realpath(__file__)), tosca_file))
43 TranslationUtils.compare_tosca_translation_with_hot,
44 tosca_file, hot_file, params)
45 ExceptionCollector.assertExceptionMessage(error_collect, msg)
47 def test_hot_translate_single_server(self):
48 tosca_file = '../tests/data/tosca_single_server.yaml'
49 hot_file = '../tests/data/hot_output/hot_single_server.yaml'
51 self._test_successful_translation(tosca_file, hot_file, params)
53 def test_hot_translate_single_server_with_defaults(self):
55 '../tests/data/tosca_single_server_with_defaults.yaml'
57 hot_file_with_input = '../tests/data/hot_output/' \
58 'hot_single_server_with_defaults_with_input.yaml'
59 params1 = {'cpus': '1'}
60 self._test_successful_translation(tosca_file, hot_file_with_input,
63 hot_file_without_input = '../tests/data/hot_output/' \
64 'hot_single_server_with_defaults_without_input.yaml'
66 self._test_successful_translation(tosca_file, hot_file_without_input,
69 def test_hot_translate_wordpress_single_instance(self):
70 tosca_file = '../tests/data/tosca_single_instance_wordpress.yaml'
71 hot_file = '../tests/data/hot_output/' \
72 'hot_single_instance_wordpress.yaml'
73 params = {'db_name': 'wordpress',
76 'db_root_pwd': 'passw0rd',
79 self._test_successful_translation(tosca_file, hot_file, params)
81 def test_hot_translate_helloworld(self):
82 tosca_file = '../tests/data/tosca_helloworld.yaml'
83 hot_file = '../tests/data/hot_output/hot_hello_world.yaml'
84 self._test_successful_translation(tosca_file, hot_file)
86 def test_hot_translate_host_assignment(self):
87 tosca_file = '../tests/data/test_host_assignment.yaml'
88 hot_file = '../tests/data/hot_output/hot_host_assignment.yaml'
89 self._test_successful_translation(tosca_file, hot_file)
91 def test_hot_translate_elk(self):
92 tosca_file = '../tests/data/tosca_elk.yaml'
93 hot_file = '../tests/data/hot_output/hot_elk.yaml'
94 params = {'github_url':
95 'http://github.com/paypal/rest-api-sample-app-nodejs.git',
97 self._test_successful_translation(tosca_file, hot_file, params)
99 def test_hot_translate_nodejs_mongodb_two_instances(self):
100 tosca_file = '../tests/data/tosca_nodejs_mongodb_two_instances.yaml'
101 hot_file = '../tests/data/hot_output/' \
102 'hot_nodejs_mongodb_two_instances.yaml'
103 params = {'github_url':
104 'http://github.com/paypal/rest-api-sample-app-nodejs.git',
106 self._test_successful_translation(tosca_file, hot_file, params)
108 def test_hot_translate_blockstorage_with_attachment(self):
109 tosca_file = '../tests/data/storage/' \
110 'tosca_blockstorage_with_attachment.yaml'
111 hot_file = '../tests/data/hot_output/storage/' \
112 'hot_blockstorage_with_attachment.yaml'
114 'storage_location': '/dev/vdc',
115 'storage_size': '2000 MB',
116 'storage_snapshot_id': 'ssid'}
117 self._test_successful_translation(tosca_file, hot_file, params)
119 def test_hot_translate_blockstorage_with_custom_relationship_type(self):
120 tosca_file = '../tests/data/storage/' \
121 'tosca_blockstorage_with_custom_relationship_type.yaml'
122 hot_file = '../tests/data/hot_output/storage/' \
123 'hot_blockstorage_with_custom_relationship_type.yaml'
125 'storage_location': '/dev/vdc',
126 'storage_size': '1 GB',
127 'storage_snapshot_id': 'ssid'}
128 self._test_successful_translation(tosca_file, hot_file, params)
130 def test_hot_translate_blockstorage_with_relationship_template(self):
131 tosca_file = '../tests/data/storage/' \
132 'tosca_blockstorage_with_relationship_template.yaml'
133 hot_file = '../tests/data/hot_output/storage/' \
134 'hot_blockstorage_with_relationship_template.yaml'
136 'storage_location': '/dev/vdc',
137 'storage_size': '1 GB'}
138 self._test_successful_translation(tosca_file, hot_file, params)
140 def test_hot_translate_blockstorage_with_attachment_notation1(self):
141 tosca_file = '../tests/data/storage/' \
142 'tosca_blockstorage_with_attachment_notation1.yaml'
143 hot_file1 = '../tests/data/hot_output/storage/' \
144 'hot_blockstorage_with_attachment_notation1_alt1.yaml'
145 hot_file2 = '../tests/data/hot_output/storage/' \
146 'hot_blockstorage_with_attachment_notation1_alt2.yaml'
148 'storage_location': 'some_folder',
149 'storage_size': '1 GB',
150 'storage_snapshot_id': 'ssid'}
153 self._test_successful_translation(tosca_file, hot_file1, params)
155 self._test_successful_translation(tosca_file, hot_file2, params)
157 def test_hot_translate_blockstorage_with_attachment_notation2(self):
158 tosca_file = '../tests/data/storage/' \
159 'tosca_blockstorage_with_attachment_notation2.yaml'
160 hot_file1 = '../tests/data/hot_output/storage/' \
161 'hot_blockstorage_with_attachment_notation2_alt1.yaml'
162 hot_file2 = '../tests/data/hot_output/storage/' \
163 'hot_blockstorage_with_attachment_notation2_alt2.yaml'
165 'storage_location': '/dev/vdc',
166 'storage_size': '1 GB',
167 'storage_snapshot_id': 'ssid'}
169 self._test_successful_translation(tosca_file, hot_file1, params)
171 self._test_successful_translation(tosca_file, hot_file2, params)
173 def test_hot_translate_multiple_blockstorage_with_attachment(self):
174 tosca_file = '../tests/data/storage/' \
175 'tosca_multiple_blockstorage_with_attachment.yaml'
176 hot_file1 = '../tests/data/hot_output/storage/' \
177 'hot_multiple_blockstorage_with_attachment_alt1.yaml'
178 hot_file2 = '../tests/data/hot_output/storage/' \
179 'hot_multiple_blockstorage_with_attachment_alt2.yaml'
181 'storage_location': '/dev/vdc',
182 'storage_size': '1 GB',
183 'storage_snapshot_id': 'ssid'}
185 self._test_successful_translation(tosca_file, hot_file1, params)
187 self._test_successful_translation(tosca_file, hot_file2, params)
189 def test_hot_translate_single_object_store(self):
190 tosca_file = '../tests/data/storage/tosca_single_object_store.yaml'
191 hot_file = '../tests/data/hot_output/hot_single_object_store.yaml'
192 params = {'objectstore_name': 'myobjstore'}
193 self._test_successful_translation(tosca_file, hot_file, params)
195 def test_hot_translate_one_server_one_network(self):
196 tosca_file = '../tests/data/network/tosca_one_server_one_network.yaml'
197 hot_file = '../tests/data/hot_output/network/' \
198 'hot_one_server_one_network.yaml'
199 params = {'network_name': 'private_net'}
200 self._test_successful_translation(tosca_file, hot_file, params)
202 def test_hot_translate_server_on_existing_network(self):
203 tosca_file = '../tests/data/network/' \
204 'tosca_server_on_existing_network.yaml'
205 hot_file = '../tests/data/hot_output/network/' \
206 'hot_server_on_existing_network.yaml'
207 params = {'network_name': 'private_net'}
208 self._test_successful_translation(tosca_file, hot_file, params)
210 def test_hot_translate_two_servers_one_network(self):
211 tosca_file = '../tests/data/network/tosca_two_servers_one_network.yaml'
212 hot_file = '../tests/data/hot_output/network/' \
213 'hot_two_servers_one_network.yaml'
214 params = {'network_name': 'my_private_net',
215 'network_cidr': '10.0.0.0/24',
216 'network_start_ip': '10.0.0.100',
217 'network_end_ip': '10.0.0.150'}
218 self._test_successful_translation(tosca_file, hot_file, params)
220 def test_hot_translate_one_server_three_networks(self):
221 tosca_file = '../tests/data/network/' \
222 'tosca_one_server_three_networks.yaml'
223 hot_file = '../tests/data/hot_output/network/' \
224 'hot_one_server_three_networks.yaml'
226 self._test_successful_translation(tosca_file, hot_file, params)
228 def test_hot_translate_software_component(self):
229 tosca_file = '../tests/data/tosca_software_component.yaml'
230 hot_file = '../tests/data/hot_output/hot_software_component.yaml'
231 params = {'cpus': '1',
232 'download_url': 'http://www.software.com/download'}
233 self._test_successful_translation(tosca_file, hot_file, params)
235 def test_hot_translate_web_application(self):
236 tosca_file = '../tests/data/tosca_web_application.yaml'
237 hot_file = '../tests/data/hot_output/hot_web_application.yaml'
238 params = {'cpus': '2', 'context_root': 'my_web_app'}
239 self._test_successful_translation(tosca_file, hot_file, params)
241 def test_hot_translate_template_with_url_import(self):
242 tosca_file = '../tests/data/' \
243 'tosca_single_instance_wordpress_with_url_import.yaml'
244 hot_file = '../tests/data/hot_output/' \
245 'hot_single_instance_wordpress.yaml'
246 params = {'db_name': 'wordpress',
247 'db_user': 'wp_user',
249 'db_root_pwd': 'passw0rd',
252 self._test_successful_translation(tosca_file, hot_file, params)
254 def test_hot_translate_template_by_url_with_local_import(self):
255 tosca_file = 'https://raw.githubusercontent.com/openstack/' \
256 'heat-translator/master/translator/tests/data/' \
257 'tosca_single_instance_wordpress.yaml'
258 hot_file = '../tests/data/hot_output/' \
259 'hot_single_instance_wordpress.yaml'
260 params = {'db_name': 'wordpress',
261 'db_user': 'wp_user',
263 'db_root_pwd': 'passw0rd',
266 self._test_successful_translation(tosca_file, hot_file, params)
268 def test_hot_translate_template_by_url_with_local_abspath_import(self):
269 tosca_file = 'https://raw.githubusercontent.com/openstack/' \
270 'heat-translator/master/translator/tests/data/' \
271 'tosca_single_instance_wordpress_with_local_abspath' \
273 hot_file = '../tests/data/hot_output/' \
274 'hot_single_instance_wordpress.yaml'
275 params = {'db_name': 'wordpress',
276 'db_user': 'wp_user',
278 'db_root_pwd': 'passw0rd',
281 expected_msg = _('Absolute file name "/tmp/wordpress.yaml" cannot be '
282 'used in a URL-based input template "https://raw.'
283 'githubusercontent.com/openstack/heat-translator/'
284 'master/translator/tests/data/tosca_single_instance_'
285 'wordpress_with_local_abspath_import.yaml".')
287 self._test_failed_translation(tosca_file, hot_file, params,
288 expected_msg, msg_path, ValidationError,
291 def test_hot_translate_template_by_url_with_url_import(self):
292 tosca_url = 'https://raw.githubusercontent.com/openstack/' \
293 'heat-translator/master/translator/tests/data/' \
294 'tosca_single_instance_wordpress_with_url_import.yaml'
295 hot_file = '../tests/data/hot_output/' \
296 'hot_single_instance_wordpress.yaml'
297 params = {'db_name': 'wordpress',
298 'db_user': 'wp_user',
300 'db_root_pwd': 'passw0rd',
303 self._test_successful_translation(tosca_url, hot_file, params)
305 def test_translate_hello_world_csar(self):
306 tosca_file = '../tests/data/csar_hello_world.zip'
307 hot_file = '../tests/data/hot_output/hot_hello_world.yaml'
308 self._test_successful_translation(tosca_file, hot_file)
310 def test_translate_single_instance_wordpress_csar(self):
311 tosca_file = '../tests/data/csar_single_instance_wordpress.zip'
312 hot_file = '../tests/data/hot_output/' \
313 'hot_single_instance_wordpress_from_csar.yaml'
314 params = {'db_name': 'wordpress',
315 'db_user': 'wp_user',
317 'db_root_pwd': 'passw0rd',
320 self._test_successful_translation(tosca_file, hot_file, params)
322 def test_translate_elk_csar_from_url(self):
323 tosca_file = 'https://github.com/openstack/heat-translator/raw/' \
324 'master/translator/tests/data/csar_elk.zip'
325 hot_file = '../tests/data/hot_output/hot_elk_from_csar.yaml'
326 params = {'github_url':
327 'http://github.com/paypal/rest-api-sample-app-nodejs.git',
329 self._test_successful_translation(tosca_file, hot_file, params)
331 def test_translate_csar_not_zip(self):
332 tosca_file = '../tests/data/csar_not_zip.zip'
335 expected_msg = _('"%s" is not a valid zip file.')
337 self._test_failed_translation(tosca_file, hot_file, params,
338 expected_msg, msg_path, ValidationError,
341 def test_translate_csar_metadata_not_yaml(self):
342 tosca_file = '../tests/data/csar_metadata_not_yaml.zip'
345 expected_msg = _('The file "TOSCA-Metadata/TOSCA.meta" in the CSAR '
346 '"%s" does not contain valid YAML content.')
348 self._test_failed_translation(tosca_file, hot_file, params,
349 expected_msg, msg_path, ValidationError,
352 def test_translate_csar_wrong_metadata_file(self):
353 tosca_file = '../tests/data/csar_wrong_metadata_file.zip'
356 expected_msg = _('"%s" is not a valid CSAR as it does not contain the '
357 'required file "TOSCA.meta" in the folder '
360 self._test_failed_translation(tosca_file, hot_file, params,
361 expected_msg, msg_path, ValidationError,
364 def test_translate_csar_wordpress_invalid_import_path(self):
365 tosca_file = '../tests/data/csar_wordpress_invalid_import_path.zip'
368 expected_msg = _('Import '
369 '"Invalid_import_path/wordpress.yaml" is not valid.')
371 self._test_failed_translation(tosca_file, hot_file, params,
372 expected_msg, msg_path, ValidationError,
375 def test_translate_csar_wordpress_invalid_script_url(self):
376 tosca_file = '../tests/data/csar_wordpress_invalid_script_url.zip'
379 expected_msg = _('The resource at '
380 '"https://raw.githubusercontent.com/openstack/'
381 'heat-translator/master/translator/tests/data/'
382 'custom_types/wordpress1.yaml" cannot be accessed.')
384 self._test_failed_translation(tosca_file, hot_file, params,
385 expected_msg, msg_path, ValidationError,
388 def test_hot_translate_flavor_image(self):
389 tosca_file = '../tests/data/test_tosca_flavor_and_image.yaml'
390 hot_file = '../tests/data/hot_output/hot_flavor_and_image.yaml'
391 self._test_successful_translation(tosca_file, hot_file)
393 def test_hot_translate_flavor_image_params(self):
394 tosca_file = '../tests/data/test_tosca_flavor_and_image.yaml'
395 hot_file = '../tests/data/hot_output/hot_flavor_and_image_params.yaml'
396 params = {'key_name': 'paramkey'}
397 self._test_successful_translation(tosca_file, hot_file, params)
399 def test_hot_translate_custom_type(self):
400 tosca_file = '../tests/data/test_tosca_custom_type.yaml'
401 hot_file = '../tests/data/hot_output/' \
402 'hot_custom_type.yaml'
404 self._test_successful_translation(tosca_file, hot_file, params)
406 def test_hot_translate_custom_type_with_override(self):
407 tosca_file = '../tests/data/test_tosca_custom_type_with_override.yaml'
408 hot_file = '../tests/data/hot_output/' \
409 'hot_custom_type_with_override.yaml'
411 self._test_successful_translation(tosca_file, hot_file, params)
413 def test_hot_translate_custom_type_with_param_override(self):
414 tosca_file = '../tests/data/test_tosca_custom_type_with_override.yaml'
415 hot_file = '../tests/data/hot_output/' \
416 'hot_custom_type_with_param_override.yaml'
417 params = {'install_path': '/home/custom/from/cli'}
418 self._test_successful_translation(tosca_file, hot_file, params)
420 def test_hot_translate_artifact(self):
421 tosca_file = '../tests/data/test_tosca_artifact.yaml'
422 hot_file = '../tests/data/hot_output/' \
425 self._test_successful_translation(tosca_file, hot_file, params)
427 def test_hot_translate_without_tosca_os_version(self):
428 tosca_file = '../tests/data/' \
429 'test_single_server_without_optional_version_prop.yaml'
430 hot_file = '../tests/data/hot_output/' \
431 'hot_single_server_without_tosca_os_version.yaml'
433 self._test_successful_translation(tosca_file, hot_file, params)
435 def test_hot_translate_helloworld_with_userkey(self):
436 tosca_file = '../tests/data/tosca_helloworld.yaml'
437 hot_file = '../tests/data/hot_output/hot_hello_world_userkey.yaml'
438 params = {'key_name': 'userkey'}
439 self._test_successful_translation(tosca_file, hot_file, params)
441 def test_hot_translate_custom_networks_nodes_inline(self):
442 tosca_file = '../tests/data/network/' \
443 'test_tosca_custom_network_nodes_inline.yaml'
444 hot_file = '../tests/data/hot_output/network/' \
445 'hot_custom_network_nodes.yaml'
447 self._test_successful_translation(tosca_file, hot_file, params)
449 def test_hot_translate_custom_networks_nodes_imports(self):
450 tosca_file = '../tests/data/network/' \
451 'test_tosca_custom_network_nodes_imports.yaml'
452 hot_file = '../tests/data/hot_output/network/' \
453 'hot_custom_network_nodes.yaml'
455 self._test_successful_translation(tosca_file, hot_file, params)
457 def test_hot_translate_nfv_sample(self):
458 tosca_file = '../tests/data/test_tosca_nfv_sample.yaml'
459 hot_file = '../tests/data/hot_output/hot_nfv_sample.yaml'
461 self._test_successful_translation(tosca_file, hot_file, params)
463 def test_hot_translate_policy(self):
464 tosca_file = '../tests/data/tosca_policies.yaml'
465 hot_file = '../tests/data/hot_output/hot_policies.yaml'
467 self._test_successful_translation(tosca_file, hot_file, params)
469 def test_hot_script_types(self):
470 tosca_file = '../tests/data/test_tosca_script_types.yaml'
471 hot_file = '../tests/data/hot_output/hot_script_types.yaml'
473 self._test_successful_translation(tosca_file, hot_file, params)
475 def test_hot_interface_on_compute(self):
476 tosca_file = '../tests/data/test_tosca_interface_on_compute.yaml'
477 hot_file = '../tests/data/hot_output/hot_interface_on_compute.yaml'
479 self._test_successful_translation(tosca_file, hot_file, params)
481 def test_hot_get_functions_semantic(self):
482 tosca_file = '../tests/data/test_tosca_get_functions_semantic.yaml'
483 hot_file = '../tests/data/hot_output/hot_get_functions_semantic.yaml'
485 self._test_successful_translation(tosca_file, hot_file, params)
487 def test_hot_exchange_public_ssh_key(self):
488 tosca_file = '../tests/data/tosca_exchange_public_ssh_key.yaml'
489 hot_file = '../tests/data/hot_output/hot_exchange_public_ssh_key.yaml'
491 self._test_successful_translation(tosca_file, hot_file, params)