diff --git a/translator/hot/tests/test_translate_inputs.py b/translator/hot/tests/test_translate_inputs.py index 9487fb64..079876ac 100644 --- a/translator/hot/tests/test_translate_inputs.py +++ b/translator/hot/tests/test_translate_inputs.py @@ -63,7 +63,7 @@ class ToscaTemplateInputValidationTest(TestCase): ''' input_params = {'cpus': '0.3'} - expectedmessage = _("invalid literal for int() with base 10: '0.3'") + expectedmessage = _('"0.3" is not an integer.') self._translate_input_test(tpl_snippet, input_params, expectedmessage) @@ -148,8 +148,8 @@ class ToscaTemplateInputValidationTest(TestCase): ''' input_params = {'num_cpus': '3'} - expectedmessage = _('num_cpus: 3 is not an valid value' - ' "[1, 2, 4, 8]".') + expectedmessage = _('num_cpus: 3 is not a valid value. Expected a ' + 'value from "[1, 2, 4, 8]".') self._translate_input_test(tpl_snippet, input_params, expectedmessage) def test_invalid_input_constraints_for_in_range(self): diff --git a/translator/hot/translate_inputs.py b/translator/hot/translate_inputs.py index a68dd09f..ea9f990e 100644 --- a/translator/hot/translate_inputs.py +++ b/translator/hot/translate_inputs.py @@ -74,14 +74,11 @@ class TranslateInputs(object): hot_input_type = TOSCA_TO_HOT_INPUT_TYPES[input.type] if input.name in self.parsed_params: - input_type = hot_input_type - if input.type == "scalar-unit.size": - input_type = input.type - DataEntity.validate_datatype(input_type, - self.parsed_params[input.name]) - hot_default = self.parsed_params[input.name] + hot_default = DataEntity.validate_datatype( + input.type, self.parsed_params[input.name]) elif input.default is not None: - hot_default = input.default + hot_default = DataEntity.validate_datatype(input.type, + input.default) else: log.warning(_("Need to specify a value " "for input {0}").format(input.name)) @@ -111,9 +108,7 @@ class TranslateInputs(object): hot_constraints = [] if input.constraints: for constraint in input.constraints: - constraint.validate( - int(hot_default) if hot_input_type == "number" - else hot_default) + constraint.validate(hot_default) hc, hvalue = self._translate_constraints( constraint.constraint_key, constraint.constraint_value) hot_constraints.append({hc: hvalue}) diff --git a/translator/tests/data/hot_output/hot_elk.yaml b/translator/tests/data/hot_output/hot_elk.yaml index 414745cc..daa725c1 100644 --- a/translator/tests/data/hot_output/hot_elk.yaml +++ b/translator/tests/data/hot_output/hot_elk.yaml @@ -470,7 +470,7 @@ resources: app_server: type: OS::Nova::Server properties: - flavor: m1.medium + flavor: m1.large image: ubuntu-software-config-os-init key_name: userkey user_data_format: SOFTWARE_CONFIG @@ -478,7 +478,7 @@ resources: mongo_server: type: OS::Nova::Server properties: - flavor: m1.medium + flavor: m1.large image: ubuntu-software-config-os-init key_name: userkey user_data_format: SOFTWARE_CONFIG @@ -486,7 +486,7 @@ resources: logstash_server: type: OS::Nova::Server properties: - flavor: m1.medium + flavor: m1.large image: ubuntu-software-config-os-init key_name: userkey user_data_format: SOFTWARE_CONFIG @@ -494,7 +494,7 @@ resources: elasticsearch_server: type: OS::Nova::Server properties: - flavor: m1.medium + flavor: m1.large image: ubuntu-software-config-os-init key_name: userkey user_data_format: SOFTWARE_CONFIG @@ -502,7 +502,7 @@ resources: kibana_server: type: OS::Nova::Server properties: - flavor: m1.medium + flavor: m1.large image: ubuntu-software-config-os-init key_name: userkey user_data_format: SOFTWARE_CONFIG diff --git a/translator/tests/data/hot_output/hot_single_instance_wordpress.yaml b/translator/tests/data/hot_output/hot_single_instance_wordpress.yaml index 4aea2ddf..3fa1f62f 100644 --- a/translator/tests/data/hot_output/hot_single_instance_wordpress.yaml +++ b/translator/tests/data/hot_output/hot_single_instance_wordpress.yaml @@ -186,7 +186,7 @@ resources: server: type: OS::Nova::Server properties: - flavor: m1.medium + flavor: m1.xlarge image: ubuntu-software-config-os-init key_name: userkey user_data_format: SOFTWARE_CONFIG diff --git a/translator/tests/data/hot_output/hot_single_server_with_defaults_with_input.yaml b/translator/tests/data/hot_output/hot_single_server_with_defaults_with_input.yaml new file mode 100644 index 00000000..deb4fabb --- /dev/null +++ b/translator/tests/data/hot_output/hot_single_server_with_defaults_with_input.yaml @@ -0,0 +1,37 @@ +heat_template_version: 2013-05-23 + +description: > + TOSCA simple profile that just defines a single compute instance and selects a + (guest) host Operating System from the Compute node's properties. Note, this + example includes default values on inputs properties. + +parameters: + cpus: + type: number + description: Number of CPUs for the server. + default: 1 + constraints: + - allowed_values: + - 1 + - 2 + - 4 + - 8 + +resources: + my_server: + type: OS::Nova::Server + properties: + flavor: m1.small + image: ubuntu-12.04-software-config-os-init + key_name: userkey + user_data_format: SOFTWARE_CONFIG + +outputs: + private_ip: + description: The private IP address of the deployed server instance. + value: + get_attr: + - my_server + - networks + - private + - 0 diff --git a/translator/tests/data/hot_output/hot_single_server_with_defaults_without_input.yaml b/translator/tests/data/hot_output/hot_single_server_with_defaults_without_input.yaml new file mode 100644 index 00000000..4aa7d1f5 --- /dev/null +++ b/translator/tests/data/hot_output/hot_single_server_with_defaults_without_input.yaml @@ -0,0 +1,37 @@ +heat_template_version: 2013-05-23 + +description: > + TOSCA simple profile that just defines a single compute instance and selects a + (guest) host Operating System from the Compute node's properties. Note, this + example includes default values on inputs properties. + +parameters: + cpus: + type: number + description: Number of CPUs for the server. + default: 4 + constraints: + - allowed_values: + - 1 + - 2 + - 4 + - 8 + +resources: + my_server: + type: OS::Nova::Server + properties: + flavor: m1.large + image: ubuntu-12.04-software-config-os-init + key_name: userkey + user_data_format: SOFTWARE_CONFIG + +outputs: + private_ip: + description: The private IP address of the deployed server instance. + value: + get_attr: + - my_server + - networks + - private + - 0 diff --git a/translator/tests/data/hot_output/hot_web_application.yaml b/translator/tests/data/hot_output/hot_web_application.yaml index 2349eef9..9ab55461 100644 --- a/translator/tests/data/hot_output/hot_web_application.yaml +++ b/translator/tests/data/hot_output/hot_web_application.yaml @@ -24,7 +24,7 @@ resources: server: type: OS::Nova::Server properties: - flavor: m1.small + flavor: m1.medium image: ubuntu-software-config-os-init key_name: userkey user_data_format: SOFTWARE_CONFIG @@ -67,7 +67,7 @@ resources: config: get_resource: web_app_create_config input_values: - context_root: app + context_root: my_web_app server: get_resource: server depends_on: diff --git a/translator/tests/data/hot_output/storage/hot_blockstorage_with_custom_relationship_type.yaml b/translator/tests/data/hot_output/storage/hot_blockstorage_with_custom_relationship_type.yaml index bc1bcc16..e16731eb 100644 --- a/translator/tests/data/hot_output/storage/hot_blockstorage_with_custom_relationship_type.yaml +++ b/translator/tests/data/hot_output/storage/hot_blockstorage_with_custom_relationship_type.yaml @@ -54,6 +54,9 @@ resources: get_resource: my_server volume_id: get_resource: my_storage + mountpoint: + get_param: storage_location + outputs: private_ip: diff --git a/translator/tests/data/tosca_single_server_with_defaults.yaml b/translator/tests/data/tosca_single_server_with_defaults.yaml new file mode 100644 index 00000000..68933e2c --- /dev/null +++ b/translator/tests/data/tosca_single_server_with_defaults.yaml @@ -0,0 +1,35 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile that just defines a single compute instance and + selects a (guest) host Operating System from the Compute node's properties. + Note, this example includes default values on inputs properties. + +topology_template: + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + default: 4 + + node_templates: + my_server: + type: Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: ubuntu + version: 12.04 + outputs: + private_ip: + description: The private IP address of the deployed server instance. + value: { get_attribute: [my_server, private_address] } \ No newline at end of file diff --git a/translator/tests/test_tosca_hot_translation.py b/translator/tests/test_tosca_hot_translation.py index f3c995ff..b4622f72 100644 --- a/translator/tests/test_tosca_hot_translation.py +++ b/translator/tests/test_tosca_hot_translation.py @@ -28,6 +28,26 @@ class ToscaHotTranslationTest(TestCase): self.assertEqual({}, diff, ' : ' + json.dumps(diff, indent=4, separators=(', ', ': '))) + def test_hot_translate_single_server_with_defaults(self): + tosca_file = \ + '../tests/data/tosca_single_server_with_defaults.yaml' + hot_file_with_input = '../tests/data/hot_output/' \ + 'hot_single_server_with_defaults_with_input.yaml' + hot_file_without_input = '../tests/data/hot_output/' \ + 'hot_single_server_with_defaults_without_input.yaml' + + params1 = {'cpus': '1'} + diff1 = TranslationUtils.compare_tosca_translation_with_hot( + tosca_file, hot_file_with_input, params1) + self.assertEqual({}, diff1, ' : ' + + json.dumps(diff1, indent=4, separators=(', ', ': '))) + + params2 = {} + diff2 = TranslationUtils.compare_tosca_translation_with_hot( + tosca_file, hot_file_without_input, params2) + self.assertEqual({}, diff2, ' : ' + + json.dumps(diff2, indent=4, separators=(', ', ': '))) + def test_hot_translate_wordpress_single_instance(self): tosca_file = \ '../tests/data/tosca_single_instance_wordpress.yaml'