diff --git a/translator/hot/tests/test_translate_outputs.py b/translator/hot/tests/test_translate_outputs.py new file mode 100644 index 00000000..6fb2d54c --- /dev/null +++ b/translator/hot/tests/test_translate_outputs.py @@ -0,0 +1,49 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os +from translator.hot.tosca_translator import TOSCATranslator +from translator.toscalib.tests.base import TestCase +from translator.toscalib.tosca_template import ToscaTemplate +import translator.toscalib.utils.yamlparser + + +class ToscaTemplateOutputTest(TestCase): + + def test_translate_output(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "../../tests/data/tosca_elk.yaml") + tosca = ToscaTemplate(tosca_tpl) + translate = TOSCATranslator(tosca, []) + hot_translation = translate.translate() + + expected_output = {'nodejs_url': + {'description': 'URL for the nodejs ' + 'server, http://:3000', + 'value': + {'get_attr': + ['app_server', 'networks', 'private', 0]}}, + 'mongodb_url': + {'description': 'URL for the mongodb server.', + 'value': + {'get_attr': + ['mongo_server', 'networks', 'private', 0]}}} + + hot_translation_dict = \ + translator.toscalib.utils.yamlparser.simple_parse(hot_translation) + + outputs = hot_translation_dict.get('outputs') + for resource_name in outputs: + translated_value = outputs.get(resource_name) + expected_value = expected_output.get(resource_name) + self.assertEqual(translated_value, expected_value) diff --git a/translator/hot/tosca/tosca_compute.py b/translator/hot/tosca/tosca_compute.py index 773cfb36..769ceb21 100755 --- a/translator/hot/tosca/tosca_compute.py +++ b/translator/hot/tosca/tosca_compute.py @@ -169,6 +169,12 @@ class ToscaCompute(HotResource): # Convert from a TOSCA attribute for a nodetemplate to a HOT # attribute for the matching resource. Unless there is additional # runtime support, this should be a one to one mapping. - if attribute == 'ip_address': - attr['get_attr'] = [self.name, 'networks', '"private"', 0] + + # Note: We treat private and public IP addresses equally, but + # this will change in the future when TOSCA starts to support + # multiple private/public IP addresses. + if attribute == 'private_address' or \ + attribute == 'public_address': + attr['get_attr'] = [self.name, 'networks', 'private', 0] + return attr diff --git a/translator/hot/translate_outputs.py b/translator/hot/translate_outputs.py index c2e11f68..d31480ae 100644 --- a/translator/hot/translate_outputs.py +++ b/translator/hot/translate_outputs.py @@ -13,8 +13,6 @@ from translator.hot.syntax.hot_output import HotOutput -TOSCA_TO_HOT_GET_ATTRS = {'ip_address': 'first_address'} - class TranslateOutputs(): '''Translate TOSCA Outputs to Heat Outputs.''' diff --git a/translator/tests/data/tosca_blockstorage_with_attachment.yaml b/translator/tests/data/tosca_blockstorage_with_attachment.yaml index c5d834a3..a02ae62f 100644 --- a/translator/tests/data/tosca_blockstorage_with_attachment.yaml +++ b/translator/tests/data/tosca_blockstorage_with_attachment.yaml @@ -49,9 +49,9 @@ node_templates: snapshot_id: { get_input: storage_snapshot_id } outputs: - public_ip: - description: Public IP address of the newly created compute instance. - value: { get_attribute: [my_server, ip_address] } + private_ip: + description: Private IP address of the newly created compute instance. + value: { get_attribute: [my_server, private_address] } volume_id: description: The volume id of the block storage instance. value: { get_attribute: [my_storage, volume_id] } diff --git a/translator/tests/data/tosca_elk.yaml b/translator/tests/data/tosca_elk.yaml index e705d83f..40e6ed92 100644 --- a/translator/tests/data/tosca_elk.yaml +++ b/translator/tests/data/tosca_elk.yaml @@ -44,7 +44,7 @@ node_templates: implementation: nodejs/config.sh inputs: github_url: { get_property: [ SELF, github_url ] } - mongodb_ip: { get_attribute: [mongo_server, ip_address] } + mongodb_ip: { get_attribute: [mongo_server, private_address] } start: nodejs/start.sh mongo_dbms: @@ -59,7 +59,7 @@ node_templates: configure: implementation: mongodb/config.sh inputs: - mongodb_ip: { get_attribute: [mongo_server, ip_address] } + mongodb_ip: { get_attribute: [mongo_server, private_address] } start: mongodb/start.sh mongo_server: @@ -78,8 +78,8 @@ node_templates: outputs: nodejs_url: description: URL for the nodejs server, http://:3000 - value: { get_attribute: [app_server, ip_address] } + value: { get_attribute: [app_server, private_address] } mongodb_url: description: URL for the mongodb server. - value: { get_attribute: [mongo_server, ip_address] } + value: { get_attribute: [mongo_server, private_address] } diff --git a/translator/tests/data/tosca_multiple_blockstorage_with_attachment.yaml b/translator/tests/data/tosca_multiple_blockstorage_with_attachment.yaml index 69fd5b1f..d6df1812 100644 --- a/translator/tests/data/tosca_multiple_blockstorage_with_attachment.yaml +++ b/translator/tests/data/tosca_multiple_blockstorage_with_attachment.yaml @@ -72,6 +72,6 @@ node_templates: snapshot_id: { get_input: storage_snapshot_id } outputs: - public_ip: - description: Public IP address of the newly created compute instance. - value: { get_attribute: [my_server, ip_address] } + private_ip: + description: Private IP address of the newly created compute instance. + value: { get_attribute: [my_server, private_address] } diff --git a/translator/tests/test_blockstorage.py b/translator/tests/test_blockstorage.py index fa7ca82e..67873318 100644 --- a/translator/tests/test_blockstorage.py +++ b/translator/tests/test_blockstorage.py @@ -47,12 +47,12 @@ class ToscaBlockStorageTest(TestCase): self.assertEqual(translated_value, expected_value) outputs = output_dict['outputs'] - self.assertIn('public_ip', outputs) + self.assertIn('private_ip', outputs) self.assertEqual( - 'Public IP address of the newly created compute instance.', - outputs['public_ip']['description']) + 'Private IP address of the newly created compute instance.', + outputs['private_ip']['description']) self.assertEqual({'get_attr': ['my_server', 'networks', 'private', 0]}, - outputs['public_ip']['value']) + outputs['private_ip']['value']) self.assertIn('volume_id', outputs) self.assertEqual('The volume id of the block storage instance.', outputs['volume_id']['description']) diff --git a/translator/toscalib/elements/TOSCA_definition.yaml b/translator/toscalib/elements/TOSCA_definition.yaml index dadfe488..94f50a03 100644 --- a/translator/toscalib/elements/TOSCA_definition.yaml +++ b/translator/toscalib/elements/TOSCA_definition.yaml @@ -51,14 +51,10 @@ tosca.nodes.Compute: - greater_or_equal: 0 MB description: > Size of memory, available to applications running on the Compute node. - ip_address: - required: no - type: string - description: > - The primary IP address assigned by the cloud provider that applications - may use to access the Compute node. attributes: - ip_address: + private_address: + type: string + public_address: type: string capabilities: host: diff --git a/translator/toscalib/functions.py b/translator/toscalib/functions.py index 94631ba1..28bc8764 100644 --- a/translator/toscalib/functions.py +++ b/translator/toscalib/functions.py @@ -106,8 +106,8 @@ class GetAttribute(Function): Examples: - * { get_attribute: [ server, ip_address ] } - * { get_attribute: [ HOST, ip_address ] } + * { get_attribute: [ server, private_address ] } + * { get_attribute: [ HOST, private_address ] } """ def validate(self): diff --git a/translator/toscalib/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/tosca_single_instance_wordpress.yaml b/translator/toscalib/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/tosca_single_instance_wordpress.yaml index 9bbfe642..a72fd078 100644 --- a/translator/toscalib/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/tosca_single_instance_wordpress.yaml +++ b/translator/toscalib/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/tosca_single_instance_wordpress.yaml @@ -105,4 +105,4 @@ node_templates: outputs: website_url: description: IP address for Wordpress wiki. - value: { get_attribute: [server, ip_address] } + value: { get_attribute: [server, private_address] } diff --git a/translator/toscalib/tests/data/functions/test_get_attribute_host_keyword.yaml b/translator/toscalib/tests/data/functions/test_get_attribute_host_keyword.yaml index c3ceac02..a02e71c7 100644 --- a/translator/toscalib/tests/data/functions/test_get_attribute_host_keyword.yaml +++ b/translator/toscalib/tests/data/functions/test_get_attribute_host_keyword.yaml @@ -18,7 +18,7 @@ node_templates: configure: implementation: configure.sh inputs: - ip_address: { get_attribute: [ HOST, ip_address ] } + ip_address: { get_attribute: [ HOST, private_address ] } database: type: tosca.nodes.Database @@ -29,4 +29,4 @@ node_templates: configure: implementation: configure.sh inputs: - ip_address: { get_attribute: [ HOST, ip_address ] } + ip_address: { get_attribute: [ HOST, private_address ] } diff --git a/translator/toscalib/tests/data/functions/test_get_attribute_host_not_found.yaml b/translator/toscalib/tests/data/functions/test_get_attribute_host_not_found.yaml index bacd6e1a..0f0d9695 100644 --- a/translator/toscalib/tests/data/functions/test_get_attribute_host_not_found.yaml +++ b/translator/toscalib/tests/data/functions/test_get_attribute_host_not_found.yaml @@ -13,4 +13,4 @@ node_templates: configure: implementation: configure.sh inputs: - ip_address: { get_attribute: [ HOST, ip_address ] } + ip_address: { get_attribute: [ HOST, private_address ] } diff --git a/translator/toscalib/tests/data/functions/test_get_attribute_illegal_host_in_outputs.yaml b/translator/toscalib/tests/data/functions/test_get_attribute_illegal_host_in_outputs.yaml index 2b621541..fdb4a660 100644 --- a/translator/toscalib/tests/data/functions/test_get_attribute_illegal_host_in_outputs.yaml +++ b/translator/toscalib/tests/data/functions/test_get_attribute_illegal_host_in_outputs.yaml @@ -11,4 +11,4 @@ node_templates: outputs: ip_address: - value: { get_attribute: [ HOST, ip_address ] } + value: { get_attribute: [ HOST, private_address ] } diff --git a/translator/toscalib/tests/data/functions/test_get_attribute_unknown_node_template_name.yaml b/translator/toscalib/tests/data/functions/test_get_attribute_unknown_node_template_name.yaml index 5f609d7d..edc2e4a3 100644 --- a/translator/toscalib/tests/data/functions/test_get_attribute_unknown_node_template_name.yaml +++ b/translator/toscalib/tests/data/functions/test_get_attribute_unknown_node_template_name.yaml @@ -22,4 +22,4 @@ node_templates: outputs: ip_address: - value: { get_attribute: [ unknown_node_template, ip_address ] } + value: { get_attribute: [ unknown_node_template, private_address ] } diff --git a/translator/toscalib/tests/data/test_tosca_normative_type_by_shortname.yaml b/translator/toscalib/tests/data/test_tosca_normative_type_by_shortname.yaml index fa932394..aee9bd9b 100644 --- a/translator/toscalib/tests/data/test_tosca_normative_type_by_shortname.yaml +++ b/translator/toscalib/tests/data/test_tosca_normative_type_by_shortname.yaml @@ -29,4 +29,4 @@ node_templates: outputs: server_address: description: IP address of server instance. - value: { get_attribute: [server, ip_address] } + value: { get_attribute: [server, private_address] } diff --git a/translator/toscalib/tests/data/test_tosca_top_level_error1.yaml b/translator/toscalib/tests/data/test_tosca_top_level_error1.yaml index 482b7c1e..e7f98b63 100644 --- a/translator/toscalib/tests/data/test_tosca_top_level_error1.yaml +++ b/translator/toscalib/tests/data/test_tosca_top_level_error1.yaml @@ -27,4 +27,4 @@ node_templates: outputs: server_address: description: IP address of server instance. - value: { get_property: [server, ip_address] } + value: { get_property: [server, private_address] } diff --git a/translator/toscalib/tests/data/test_tosca_top_level_error2.yaml b/translator/toscalib/tests/data/test_tosca_top_level_error2.yaml index fe3dbbf5..ad72b5c7 100644 --- a/translator/toscalib/tests/data/test_tosca_top_level_error2.yaml +++ b/translator/toscalib/tests/data/test_tosca_top_level_error2.yaml @@ -29,4 +29,4 @@ node_template: outputs: server_address: description: IP address of server instance. - value: { get_property: [server, ip_address] } + value: { get_property: [server, private_address] } diff --git a/translator/toscalib/tests/data/tosca_elk.yaml b/translator/toscalib/tests/data/tosca_elk.yaml index 40f8d178..f2650a5b 100644 --- a/translator/toscalib/tests/data/tosca_elk.yaml +++ b/translator/toscalib/tests/data/tosca_elk.yaml @@ -27,7 +27,7 @@ dsl_definitions: pre_configure_source: implementation: collectd/pre_configure_source.py inputs: - host: { get_attribute: [ TARGET, ip_address ]} + host: { get_attribute: [ TARGET, private_address ]} tosca.interfaces.relationship.Configure: pre_configure_target: implementation: collectd/pre_configure_target.py @@ -36,7 +36,7 @@ dsl_definitions: pre_configure_source: implementation: rsyslog/pre_configure_source.py inputs: - host: { get_attribute: [ TARGET, ip_address ]} + host: { get_attribute: [ TARGET, private_address ]} inputs: my_cpus: type: integer @@ -109,7 +109,7 @@ node_templates: pre_configure_source: implementation: pre_configure_source.py inputs: - host: { get_attribute: [ TARGET, ip_address ] } + host: { get_attribute: [ TARGET, private_address ] } port: { get_attribute: [ TARGET, port ] } interfaces: tosca.interfaces.node.lifecycle.Standard: @@ -199,19 +199,19 @@ node_templates: outputs: nodejs_url: description: URL for the nodejs server. - value: { get_attribute: [ app_server, ip_address ] } + value: { get_attribute: [ app_server, private_address ] } mongodb_url: description: URL for the mongodb server. - value: { get_attribute: [ mongo_server, ip_address ] } + value: { get_attribute: [ mongo_server, private_address ] } mongodb_port: description: Port for the mongodb server. value: { get_property: [ mongo_dbms, dbms_port ] } elasticsearch_url: description: URL for the elasticsearch server. - value: { get_attribute: [ elasticsearch_server, ip_address ] } + value: { get_attribute: [ elasticsearch_server, private_address ] } logstash_url: description: URL for the logstash server. - value: { get_attribute: [ logstash_server, ip_address ] } + value: { get_attribute: [ logstash_server, private_address ] } kibana_url: description: URL for the kibana server. - value: { get_attribute: [ kibana_server, ip_address ] } + value: { get_attribute: [ kibana_server, private_address ] } diff --git a/translator/toscalib/tests/data/tosca_single_instance_wordpress.yaml b/translator/toscalib/tests/data/tosca_single_instance_wordpress.yaml index b882b27f..de0148a8 100644 --- a/translator/toscalib/tests/data/tosca_single_instance_wordpress.yaml +++ b/translator/toscalib/tests/data/tosca_single_instance_wordpress.yaml @@ -111,4 +111,4 @@ node_templates: outputs: website_url: description: URL for Wordpress wiki. - value: { get_attribute: [server, ip_address] } + value: { get_attribute: [server, private_address] } diff --git a/translator/toscalib/tests/test_functions.py b/translator/toscalib/tests/test_functions.py index 93ec6a40..745e9dd1 100644 --- a/translator/toscalib/tests/test_functions.py +++ b/translator/toscalib/tests/test_functions.py @@ -112,7 +112,8 @@ class GetAttributeTest(TestCase): x for x in tpl.outputs if x.name == 'website_url'][0] self.assertIsInstance(website_url_output.value, functions.GetAttribute) self.assertEqual('server', website_url_output.value.node_template_name) - self.assertEqual('ip_address', website_url_output.value.attribute_name) + self.assertEqual('private_address', + website_url_output.value.attribute_name) def test_get_attribute_invalid_args(self): expected_msg = 'Expected arguments: node-template-name, attribute-name' diff --git a/translator/toscalib/tests/test_toscadef.py b/translator/toscalib/tests/test_toscadef.py index 6614636a..d535446f 100644 --- a/translator/toscalib/tests/test_toscadef.py +++ b/translator/toscalib/tests/test_toscadef.py @@ -99,13 +99,12 @@ class ToscaDefTest(TestCase): def test_properties_def(self): self.assertEqual( - ['disk_size', 'ip_address', 'mem_size', - 'num_cpus'], + ['disk_size', 'mem_size', 'num_cpus'], sorted(compute_type.get_properties_def().keys())) def test_attributes_def(self): self.assertEqual( - ['ip_address'], + ['private_address', 'public_address'], sorted([p.name for p in compute_type.attributes_def])) def test_requirements(self): diff --git a/translator/toscalib/tests/test_toscatplvalidation.py b/translator/toscalib/tests/test_toscatplvalidation.py index 94c785e2..38a24e36 100644 --- a/translator/toscalib/tests/test_toscatplvalidation.py +++ b/translator/toscalib/tests/test_toscatplvalidation.py @@ -74,7 +74,7 @@ class ToscaTemplateValidationTest(TestCase): outputs: server_address: description: IP address of server instance. - values: { get_property: [server, ip_address] } + values: { get_property: [server, private_address] } ''' outputs = (translator.toscalib.utils.yamlparser. simple_parse(tpl_snippet)['outputs']) @@ -92,7 +92,7 @@ class ToscaTemplateValidationTest(TestCase): outputs: server_address: descriptions: IP address of server instance. - value: { get_property: [server, ip_address] } + value: { get_property: [server, private_address] } ''' outputs = (translator.toscalib.utils.yamlparser. simple_parse(tpl_snippet)['outputs'])