Fix translation issue with interface inputs and functions

Fix the issue with interface inputs described using intrinsic
functions, that produces an invalid HOT output. Also, include
necessary unit tests, and revert templates that were simplified
due to this issue..

This patch includes changes required in heat-translator for
resolving the issue.

Change-Id: I0aa01a05a7e9bf695c10b193023958ec11e4a422
Closes-Bug: #1440247
This commit is contained in:
Vahid Hashemian 2015-09-30 22:17:13 -07:00
parent 3f98139a7e
commit 34f2e51e0d
10 changed files with 148 additions and 21 deletions

View File

@ -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):

View File

@ -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})

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -54,6 +54,9 @@ resources:
get_resource: my_server
volume_id:
get_resource: my_storage
mountpoint:
get_param: storage_location
outputs:
private_ip:

View File

@ -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] }

View File

@ -28,6 +28,26 @@ class ToscaHotTranslationTest(TestCase):
self.assertEqual({}, diff, '<difference> : ' +
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, '<difference> : ' +
json.dumps(diff1, indent=4, separators=(', ', ': ')))
params2 = {}
diff2 = TranslationUtils.compare_tosca_translation_with_hot(
tosca_file, hot_file_without_input, params2)
self.assertEqual({}, diff2, '<difference> : ' +
json.dumps(diff2, indent=4, separators=(', ', ': ')))
def test_hot_translate_wordpress_single_instance(self):
tosca_file = \
'../tests/data/tosca_single_instance_wordpress.yaml'