summaryrefslogtreecommitdiffstats
path: root/tosca2heat/tosca-parser/toscaparser/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tosca2heat/tosca-parser/toscaparser/tests')
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/custom_types/compute_with_nested_atributes.yaml22
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/custom_types/node_with_cap.yaml5
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/datatypes/test_datatype_portspec_add_req.yaml41
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_get_attribute_with_index_error.yaml2
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_get_attribute_with_nested_params.yaml23
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_token.yaml15
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_token_invalid.yaml17
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/test_containers.yaml44
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/test_credential_datatype.yaml77
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/test_invalid_input_defaults.yaml12
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/test_repositories_definition.yaml6
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/subsystem.yaml3
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/system.yaml3
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/data/tosca_repositories_test_definition.yaml26
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_datatypes.py135
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_functions.py46
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py5
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py23
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py79
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py145
20 files changed, 680 insertions, 49 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/custom_types/compute_with_nested_atributes.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/custom_types/compute_with_nested_atributes.yaml
new file mode 100644
index 0000000..f23a8a1
--- /dev/null
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/custom_types/compute_with_nested_atributes.yaml
@@ -0,0 +1,22 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Compute node type with capability with an atribute of type list
+
+capability_types:
+
+ tosca.capabilities.indigo.Endpoint:
+ derived_from: tosca.capabilities.Endpoint
+ attributes:
+ credential:
+ type: list
+ entry_schema:
+ type: tosca.datatypes.Credential
+
+node_types:
+
+ tosca.nodes.ComputeWithCapWithAttr:
+ derived_from: tosca.nodes.Compute
+ capabilities:
+ endpoint:
+ type: tosca.capabilities.indigo.Endpoint
+
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/custom_types/node_with_cap.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/custom_types/node_with_cap.yaml
index 11e1b51..b17513f 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/data/custom_types/node_with_cap.yaml
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/custom_types/node_with_cap.yaml
@@ -3,7 +3,8 @@ tosca_definitions_version: tosca_simple_yaml_1_0
description: >
Node type that has a requirement of a capability with a defined value
-node_types:
+capability_types:
+
tosca.capabilities.SomeCap:
derived_from: tosca.capabilities.Root
properties:
@@ -14,6 +15,8 @@ node_types:
constraints:
- equal: someval
+node_types:
+
tosca.nodes.SomeNode:
derived_from: tosca.nodes.Root
requirements:
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/datatypes/test_datatype_portspec_add_req.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/datatypes/test_datatype_portspec_add_req.yaml
new file mode 100644
index 0000000..f944927
--- /dev/null
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/datatypes/test_datatype_portspec_add_req.yaml
@@ -0,0 +1,41 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: TOSCA test PortSpec Additional Requirement clauses
+
+node_types:
+
+ MyNodeType:
+ derived_from: Root
+ properties:
+ test_port:
+ type: PortSpec
+
+topology_template:
+
+ node_templates:
+
+ # Test invalid source value below (default) specified range constraint
+ test_node2:
+ type: MyNodeType
+ properties:
+ test_port:
+ protocol: tcp
+ source: 0
+
+ # Test invalid source value over specified range
+ test_node3:
+ type: MyNodeType
+ properties:
+ test_port:
+ protocol: tcp
+ source: 65535
+ source_range: [ 2, 65534 ]
+
+ # Test invalid source value under specified range
+ test_node4:
+ type: MyNodeType
+ properties:
+ test_port:
+ protocol: tcp
+ source: 1
+ source_range: [ 2, 65534 ]
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_get_attribute_with_index_error.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_get_attribute_with_index_error.yaml
index 88a2721..7511999 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_get_attribute_with_index_error.yaml
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_get_attribute_with_index_error.yaml
@@ -1,7 +1,7 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
- TOSCA template for testing get_attribute with a list attribute and an index
+ TOSCA template for testing get_attribute with an incorrect index
imports:
- ../custom_types/compute_with_attribute_list.yaml
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_get_attribute_with_nested_params.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_get_attribute_with_nested_params.yaml
new file mode 100644
index 0000000..79e632c
--- /dev/null
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_get_attribute_with_nested_params.yaml
@@ -0,0 +1,23 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >
+ TOSCA template for testing get_attribute with nested attributes
+
+imports:
+ - ../custom_types/compute_with_nested_atributes.yaml
+
+topology_template:
+ node_templates:
+ server:
+ type: tosca.nodes.ComputeWithCapWithAttr
+ capabilities:
+ endpoint:
+ properties:
+ port: 80
+ interfaces:
+ Standard:
+ configure:
+ implementation: configure.sh
+ inputs:
+ ip_address: { get_attribute: [ SELF, endpoint, credential, 0, token ] }
+
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_token.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_token.yaml
new file mode 100644
index 0000000..495a930
--- /dev/null
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_token.yaml
@@ -0,0 +1,15 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Template for deploying a single server with token function.
+
+topology_template:
+ node_templates:
+ server:
+ type: tosca.nodes.Compute
+
+ outputs:
+ url:
+ description: Get the first part of the ip
+ value: { token: [ get_attribute: [ server, public_address ],
+ '.' ,
+ 0 ] }
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_token_invalid.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_token_invalid.yaml
new file mode 100644
index 0000000..35ae2ff
--- /dev/null
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/functions/test_token_invalid.yaml
@@ -0,0 +1,17 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Template for deploying a single server with invalid token function.
+
+topology_template:
+ outputs:
+ invalid_token_syntax_1:
+ description: test token with only two paremeters.
+ value: { token: ["some_string", "_"]}
+
+ invalid_token_syntax_2:
+ description: test token with invalid string as third argument.
+ value: { token: ["some_string", "_", "1"]}
+
+ invalid_token_syntax_3:
+ description: test token with invalid string as second argument.
+ value: { token: ["some_string", "aa", "1"]}
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/test_containers.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/test_containers.yaml
new file mode 100644
index 0000000..ba1cc16
--- /dev/null
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/test_containers.yaml
@@ -0,0 +1,44 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >
+ TOSCA simple profile with mysql docker container.
+
+# Repositories to retrieve code artifacts from
+repositories:
+ docker_hub: https://registry.hub.docker.com/
+
+topology_template:
+
+ inputs:
+ mysql_root_pwd:
+ type: string
+ description: Root password for MySQL.
+
+ node_templates:
+ # The MYSQL container based on official MySQL image in Docker hub
+ mysql_container:
+ type: tosca.nodes.Container.Application
+ requirements:
+ - host: mysql_runtime
+ artifacts:
+ my_image:
+ file: mysql
+ type: tosca.artifacts.Deployment.Image.Container.Docker
+ repository: docker_hub
+ interfaces:
+ Standard:
+ create:
+ implementation: my_image
+ inputs:
+ MYSQL_ROOT_PASSWORD: { get_input: mysql_root_pwd }
+
+ # The properties of the runtime to host the container
+ mysql_runtime:
+ type: tosca.nodes.Container.Runtime
+ capabilities:
+ host:
+ properties:
+ num_cpus: 1
+ disk_size: 10 GB
+ mem_size: 2 MB
+
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/test_credential_datatype.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/test_credential_datatype.yaml
new file mode 100644
index 0000000..583ec82
--- /dev/null
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/test_credential_datatype.yaml
@@ -0,0 +1,77 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >
+ TOSCA simple profile with to demonstrate the usage of the
+ TOSCA Credential Data Type.
+
+imports:
+ - custom_types/wordpress.yaml
+
+relationship_types:
+ my.types.WordpressDbConnection:
+ derived_from: tosca.relationships.ConnectsTo
+ properties:
+ credential:
+ user: db_user
+ token: db_pwd
+
+topology_template:
+ node_templates:
+ wordpress:
+ type: tosca.nodes.WebApplication.WordPress
+ requirements:
+ - host: webserver
+ - database_endpoint:
+ node: mysql_database
+ relationship: my.types.WordpressDbConnection
+
+ mysql_database:
+ type: tosca.nodes.Database
+ properties:
+ name: db_name
+ user: db_user
+ password: db_pwd
+ capabilities:
+ database_endpoint:
+ properties:
+ port: 3306
+ requirements:
+ - host:
+ node: mysql_dbms
+
+ mysql_dbms:
+ type: tosca.nodes.DBMS
+ properties:
+ root_password: db_root_pwd
+ port: 3306
+ requirements:
+ - host: server
+
+ webserver:
+ type: tosca.nodes.WebServer
+ properties:
+ admin_credential:
+ user: username
+ token: some_pass
+ requirements:
+ - host: server
+
+ server:
+ type: tosca.nodes.Compute
+ capabilities:
+ host:
+ properties:
+ disk_size: 10 GB
+ num_cpus: 1
+ mem_size: 4096 MB
+ os:
+ properties:
+ architecture: x86_64
+ type: Linux
+ distribution: Ubuntu
+ version: 14.04
+
+ outputs:
+ website_url:
+ description: URL for Wordpress wiki.
+ value: { get_attribute: [server, private_address] }
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/test_invalid_input_defaults.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/test_invalid_input_defaults.yaml
new file mode 100644
index 0000000..f8f4ae7
--- /dev/null
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/test_invalid_input_defaults.yaml
@@ -0,0 +1,12 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Test template with default not matching required type.
+
+topology_template:
+ inputs:
+ invalid_default:
+ type: integer
+ default: two
+ valid_default:
+ type: integer
+ default: 2
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/test_repositories_definition.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/test_repositories_definition.yaml
index 2145d8f..c2856c8 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/data/test_repositories_definition.yaml
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/test_repositories_definition.yaml
@@ -4,9 +4,9 @@ repositories:
some_repository:
description: Some repo
url: https://raw.githubusercontent.com/openstack/tosca-parser/master/toscaparser/tests/data/custom_types/
- namespace_uri: http://docs.oasis-open.org/tosca/ns/simple/yaml/1.0a
- namespace_prefix: oasis_tosca
-
+ credential: #type: Credential
+ token_type: basic_auth
+ token: myusername:mypassword
imports:
- some_import:
file: compute_with_prop.yaml
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/subsystem.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/subsystem.yaml
index 99d645b..b27e698 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/subsystem.yaml
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/subsystem.yaml
@@ -12,15 +12,12 @@ topology_template:
inputs:
mq_server_ip:
type: string
- required: true
description: IP address of the message queuing server to receive messages from.
receiver_port:
type: string
- required: true
description: Port to be used for receiving messages.
my_cpus:
type: integer
- default: 2
description: Number of CPUs for the server.
constraints:
- valid_values: [ 1, 2, 4, 8 ]
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/system.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/system.yaml
index 2d459aa..9996e4f 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/system.yaml
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/system.yaml
@@ -2,6 +2,7 @@ tosca_definitions_version: tosca_simple_yaml_1_0
imports:
- definitions.yaml
+ - subsystem.yaml
topology_template:
description: Template of online transaction processing service.
@@ -54,4 +55,4 @@ topology_template:
# to be updated when substitution_mapping is implemented
# capabilities:
# database_endpoint:
- # to be updated when substitution_mapping is implemented \ No newline at end of file
+ # to be updated when substitution_mapping is implemented
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/tosca_repositories_test_definition.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/tosca_repositories_test_definition.yaml
new file mode 100644
index 0000000..0001d06
--- /dev/null
+++ b/tosca2heat/tosca-parser/toscaparser/tests/data/tosca_repositories_test_definition.yaml
@@ -0,0 +1,26 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: TOSCA simple profile with repositories validation and imports.
+
+repositories:
+ repo_code0: https://raw.githubusercontent.com/nandinivemula/intern
+ repo_code1:
+ description: My project's code Repository in github usercontent.
+ url: https://raw.githubusercontent.com/nandinivemula/intern/master
+ credential: #type: Credential
+ token_type: basic_auth
+ token: myusername:mypassword
+
+ repo_code2:
+ description: My Project's code Repository in github.
+ url: https://github.com/nandinivemula/intern/master
+ credential: #type: Credential
+ token_type: basic_auth
+ token: myusername:mypassword
+
+imports:
+ - sample_import:
+ file: tosca_repository_import.yaml
+ repository: repo_code1
+ namespace_uri: https://github.com/nandinivemula/intern
+ namespace_prefix: intern
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_datatypes.py b/tosca2heat/tosca-parser/toscaparser/tests/test_datatypes.py
index 0e613b2..0a6cfe0 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_datatypes.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_datatypes.py
@@ -66,16 +66,21 @@ class DataTypeTest(TestCase):
tosca.my.datatypes.TestLab:
properties:
- temperature:
+ humidity:
+ type: range
+ required: false
+ constraints:
+ - in_range: [-256, INFINITY]
+ temperature1:
type: range
required: false
constraints:
- in_range: [-256, UNBOUNDED]
- humidity:
+ temperature2:
type: range
required: false
constraints:
- - in_range: [-256, INFINITY]
+ - in_range: [UNBOUNDED, 256]
'''
custom_type_def = yamlparser.simple_parse(custom_type_schema)
@@ -84,15 +89,6 @@ class DataTypeTest(TestCase):
value = yamlparser.simple_parse(value_snippet)
self.assertEqual(value, {})
- # TODO(Matt) - opened as bug 1555300
- # Need a test for PortSpec normative data type
- # that tests the spec. requirement: "A valid PortSpec
- # must have at least one of the following properties:
- # target, target_range, source or source_range."
- # TODO(Matt) - opened as bug 1555310
- # test PortSpec value for source and target
- # against the source_range and target_range
- # when specified.
def test_built_in_datatype(self):
value_snippet = '''
private_network:
@@ -140,6 +136,31 @@ class DataTypeTest(TestCase):
data = DataEntity('PortInfo', value.get('ethernet_port'))
self.assertIsNotNone(data.validate())
+ # Test normative PortSpec datatype's additional requirements
+ # TODO(Matt) - opened as bug 1555300
+ # Need a test for PortSpec normative data type
+ # that tests the spec. requirement: "A valid PortSpec
+ # must have at least one of the following properties:
+ # target, target_range, source or source_range."
+ # TODO(Matt) - opened as bug 1555310
+ # test PortSpec value for source and target
+ # against the source_range and target_range
+ # when specified.
+ def test_port_spec_addl_reqs(self):
+ value_snippet = '''
+ test_port:
+ protocol: tcp
+ target: 65535
+ target_range: [ 1, 65535 ]
+ source: 1
+ source_range: [ 1, 65535 ]
+
+ '''
+ value = yamlparser.simple_parse(value_snippet)
+ data = DataEntity('tosca.datatypes.network.PortSpec',
+ value.get('test_port'))
+ self.assertIsNotNone(data.validate())
+
def test_built_in_datatype_without_properties(self):
value_snippet = '''
2
@@ -365,6 +386,7 @@ class DataTypeTest(TestCase):
value_snippet = '''
user_port:
protocol: tcp
+ target: 1
target_range: [20000]
'''
value = yamlparser.simple_parse(value_snippet)
@@ -377,6 +399,7 @@ class DataTypeTest(TestCase):
value_snippet = '''
user_port:
protocol: tcp
+ target: 1
target_range: [20000, 3000]
'''
value = yamlparser.simple_parse(value_snippet)
@@ -400,9 +423,95 @@ class DataTypeTest(TestCase):
def test_range_unbounded(self):
value_snippet = '''
- temperature: [-100, 999999]
+ humidity: [-100, 100]
+ '''
+ value = yamlparser.simple_parse(value_snippet)
+ data = DataEntity('tosca.my.datatypes.TestLab',
+ value, DataTypeTest.custom_type_def)
+ err = self.assertRaises(exception.InvalidSchemaError,
+ lambda: data.validate())
+ self.assertEqual(_('The property "in_range" expects comparable values.'
+ ),
+ err.__str__())
+
+ def test_invalid_ranges_against_constraints(self):
+ # The TestLab range type has min=-256, max=UNBOUNDED
+ value_snippet = '''
+ temperature1: [-257, 999999]
+ '''
+ value = yamlparser.simple_parse(value_snippet)
+ data = DataEntity('tosca.my.datatypes.TestLab', value,
+ DataTypeTest.custom_type_def)
+ err = self.assertRaises(exception.ValidationError, data.validate)
+ self.assertEqual(_('The value "-257" of property "temperature1" is '
+ 'out of range "(min:-256, max:UNBOUNDED)".'),
+ err.__str__())
+
+ value_snippet = '''
+ temperature2: [-999999, 257]
+ '''
+ value = yamlparser.simple_parse(value_snippet)
+ data = DataEntity('tosca.my.datatypes.TestLab', value,
+ DataTypeTest.custom_type_def)
+ err = self.assertRaises(exception.ValidationError, data.validate)
+ self.assertEqual(_('The value "257" of property "temperature2" is '
+ 'out of range "(min:UNBOUNDED, max:256)".'),
+ err.__str__())
+
+ def test_valid_ranges_against_constraints(self):
+
+ # The TestLab range type has max=UNBOUNDED
+ value_snippet = '''
+ temperature1: [-255, 999999]
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('tosca.my.datatypes.TestLab', value,
DataTypeTest.custom_type_def)
self.assertIsNotNone(data.validate())
+
+ # The TestLab range type has min=UNBOUNDED
+ value_snippet = '''
+ temperature2: [-999999, 255]
+ '''
+ value = yamlparser.simple_parse(value_snippet)
+ data = DataEntity('tosca.my.datatypes.TestLab', value,
+ DataTypeTest.custom_type_def)
+ self.assertIsNotNone(data.validate())
+
+ def test_incorrect_field_in_datatype(self):
+ tpl_snippet = '''
+ tosca_definitions_version: tosca_simple_yaml_1_0
+ topology_template:
+ node_templates:
+ server:
+ type: tosca.nodes.Compute
+
+ webserver:
+ type: tosca.nodes.WebServer
+ properties:
+ admin_credential:
+ user: username
+ token: some_pass
+ some_field: value
+ requirements:
+ - host: server
+ '''
+ tpl = yamlparser.simple_parse(tpl_snippet)
+ err = self.assertRaises(exception.ValidationError, ToscaTemplate,
+ None, None, None, tpl)
+ self.assertIn(_('The pre-parsed input failed validation with the '
+ 'following error(s): \n\n\tUnknownFieldError: Data '
+ 'value of type "tosca.datatypes.Credential" contains'
+ ' unknown field "some_field". Refer to the definition'
+ ' to verify valid values'), err.__str__())
+
+ def test_functions_datatype(self):
+ value_snippet = '''
+ admin_credential:
+ user: username
+ token: { get_input: password }
+ '''
+ value = yamlparser.simple_parse(value_snippet)
+ data = DataEntity('tosca.datatypes.Credential',
+ value.get('admin_credential'))
+ self.assertIsNotNone(data.validate())
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_functions.py b/tosca2heat/tosca-parser/toscaparser/tests/test_functions.py
index 2a6225d..4d063e5 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_functions.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_functions.py
@@ -201,8 +201,9 @@ class GetAttributeTest(TestCase):
website_url_output.value.attribute_name)
def test_get_attribute_invalid_args(self):
- expected_msg = _('Expected arguments: "node-template-name", '
- '"attribute-name"')
+ expected_msg = _('Illegal arguments for function "get_attribute".'
+ ' Expected arguments: "node-template-name", '
+ '"req-or-cap"(optional), "property name"')
err = self.assertRaises(ValueError,
functions.get_function, None, None,
{'get_attribute': []})
@@ -211,10 +212,6 @@ class GetAttributeTest(TestCase):
functions.get_function, None, None,
{'get_attribute': ['x']})
self.assertIn(expected_msg, six.text_type(err))
- err = self.assertRaises(ValueError,
- functions.get_function, None, None,
- {'get_attribute': ['x', 'y', 'z', 'k']})
- self.assertIn(expected_msg, six.text_type(err))
def test_get_attribute_unknown_node_template_name(self):
self.assertRaises(
@@ -280,7 +277,7 @@ class GetAttributeTest(TestCase):
exception.ExceptionCollector.assertExceptionMessage(
ValueError,
_('Illegal arguments for function "get_attribute". '
- 'Expected arguments: "node-template-name", "attribute-name"'))
+ 'Unexpected attribute/index value "0"'))
def test_get_attribute_source_target_keywords(self):
tosca_tpl = os.path.join(
@@ -300,6 +297,10 @@ class GetAttributeTest(TestCase):
source_port = operation.inputs['source_port']
self.assertTrue(isinstance(source_port, functions.GetAttribute))
+ def test_get_attribute_with_nested_params(self):
+ self._load_template(
+ 'functions/test_get_attribute_with_nested_params.yaml')
+
class ConcatTest(TestCase):
@@ -322,3 +323,34 @@ class ConcatTest(TestCase):
ValueError,
_('Invalid arguments for function "concat". Expected at least '
'one arguments.'))
+
+
+class TokenTest(TestCase):
+
+ def _load_template(self, filename):
+ return ToscaTemplate(os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ filename))
+
+ def test_validate_token(self):
+ tosca = self._load_template("data/functions/test_token.yaml")
+ server_url_output = [
+ output for output in tosca.outputs if output.name == 'url'][0]
+ func = functions.get_function(self, tosca.outputs,
+ server_url_output.value)
+ self.assertIsInstance(func, functions.Token)
+
+ self.assertRaises(exception.ValidationError, self._load_template,
+ 'data/functions/test_token_invalid.yaml')
+ exception.ExceptionCollector.assertExceptionMessage(
+ ValueError,
+ _('Invalid arguments for function "token". Expected at least '
+ 'three arguments.'))
+ exception.ExceptionCollector.assertExceptionMessage(
+ ValueError,
+ _('Invalid arguments for function "token". Expected '
+ 'integer value as third argument.'))
+ exception.ExceptionCollector.assertExceptionMessage(
+ ValueError,
+ _('Invalid arguments for function "token". Expected '
+ 'single char value as second argument.'))
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py b/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py
index cbd4e3b..0f1a33e 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py
@@ -34,11 +34,6 @@ class TopologyTemplateTest(TestCase):
self.topo = TopologyTemplate(self.topo_tpl,
self._get_all_custom_def())
- self.tosca_system_tpl_path = os.path.join(
- os.path.dirname(os.path.abspath(__file__)),
- "data/topology_template/system.yaml")
- self.system_template = ToscaTemplate(self.tosca_system_tpl_path)
-
def _get_custom_def(self, type_definition):
custom_defs = {}
for definition in self.imports:
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py b/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py
index f0a87ac..358bf28 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_toscadef.py
@@ -60,6 +60,7 @@ class ToscaDefTest(TestCase):
def test_group(self):
self.assertEqual(group_type.type, "tosca.groups.Root")
+ self.assertEqual(group_type.parent_type, None)
self.assertIn(ifaces.LIFECYCLE_SHORTNAME, group_type.interfaces)
def test_capabilities(self):
@@ -188,8 +189,9 @@ class ToscaDefTest(TestCase):
self.assertIn(ifaces.LIFECYCLE_SHORTNAME, root_node.interfaces)
def test_artifacts(self):
+ self.assertEqual(artif_root_type.parent_type, None)
self.assertEqual('tosca.artifacts.Root',
- artif_file_type.parent_type)
+ artif_file_type.parent_type.type)
self.assertEqual({}, artif_file_type.parent_artifacts)
self.assertEqual(sorted(['tosca.artifacts.Root'],
key=lambda x: str(x)),
@@ -198,7 +200,7 @@ class ToscaDefTest(TestCase):
key=lambda x: str(x)))
self.assertEqual('tosca.artifacts.Implementation',
- artif_bash_type.parent_type)
+ artif_bash_type.parent_type.type)
self.assertEqual({'tosca.artifacts.Implementation':
{'derived_from': 'tosca.artifacts.Root',
'description':
@@ -212,7 +214,7 @@ class ToscaDefTest(TestCase):
key=lambda x: str(x)))
self.assertEqual('tosca.artifacts.Implementation',
- artif_python_type.parent_type)
+ artif_python_type.parent_type.type)
self.assertEqual({'tosca.artifacts.Implementation':
{'derived_from': 'tosca.artifacts.Root',
'description':
@@ -227,7 +229,7 @@ class ToscaDefTest(TestCase):
key=lambda x: str(x)))
self.assertEqual('tosca.artifacts.Deployment.Image',
- artif_container_docker_type.parent_type)
+ artif_container_docker_type.parent_type.type)
self.assertEqual({'tosca.artifacts.Deployment':
{'derived_from': 'tosca.artifacts.Root',
'description':
@@ -244,7 +246,7 @@ class ToscaDefTest(TestCase):
key=lambda x: str(x)))
self.assertEqual('tosca.artifacts.Deployment.Image',
- artif_vm_iso_type.parent_type)
+ artif_vm_iso_type.parent_type.type)
self.assertEqual({'tosca.artifacts.Deployment':
{'derived_from': 'tosca.artifacts.Root',
'description':
@@ -263,7 +265,7 @@ class ToscaDefTest(TestCase):
key=lambda x: str(x)))
self.assertEqual('tosca.artifacts.Deployment.Image',
- artif_vm_qcow2_type.parent_type)
+ artif_vm_qcow2_type.parent_type.type)
self.assertEqual({'tosca.artifacts.Deployment':
{'derived_from': 'tosca.artifacts.Root',
'description':
@@ -282,8 +284,9 @@ class ToscaDefTest(TestCase):
key=lambda x: str(x)))
def test_policies(self):
+ self.assertEqual(policy_root_type.parent_type, None)
self.assertEqual('tosca.policies.Root',
- policy_placement_type.parent_type)
+ policy_placement_type.parent_type.type)
self.assertEqual({}, policy_placement_type.parent_policies)
self.assertEqual(sorted(['tosca.policies.Root',
'The TOSCA Policy Type definition that is '
@@ -295,7 +298,7 @@ class ToscaDefTest(TestCase):
key=lambda x: str(x)))
self.assertEqual('tosca.policies.Root',
- policy_scaling_type.parent_type)
+ policy_scaling_type.parent_type.type)
self.assertEqual({}, policy_scaling_type.parent_policies)
self.assertEqual(sorted(['tosca.policies.Root',
'The TOSCA Policy Type definition that is '
@@ -307,7 +310,7 @@ class ToscaDefTest(TestCase):
key=lambda x: str(x)))
self.assertEqual('tosca.policies.Root',
- policy_update_type.parent_type)
+ policy_update_type.parent_type.type)
self.assertEqual({}, policy_update_type.parent_policies)
self.assertEqual(sorted(['tosca.policies.Root',
'The TOSCA Policy Type definition that is '
@@ -319,7 +322,7 @@ class ToscaDefTest(TestCase):
key=lambda x: str(x)))
self.assertEqual('tosca.policies.Root',
- policy_performance_type.parent_type)
+ policy_performance_type.parent_type.type)
self.assertEqual({}, policy_performance_type.parent_policies)
self.assertEqual(sorted(['tosca.policies.Root',
'The TOSCA Policy Type definition that is '
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py
index 3fd49bf..2488b65 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py
@@ -12,10 +12,10 @@
import os
import six
-
from toscaparser.common import exception
import toscaparser.elements.interfaces as ifaces
from toscaparser.elements.nodetype import NodeType
+from toscaparser.elements.portspectype import PortSpec
from toscaparser.functions import GetInput
from toscaparser.functions import GetProperty
from toscaparser.nodetemplate import NodeTemplate
@@ -26,16 +26,17 @@ import toscaparser.utils.yamlparser
class ToscaTemplateTest(TestCase):
-
'''TOSCA template.'''
tosca_tpl = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"data/tosca_single_instance_wordpress.yaml")
tosca = ToscaTemplate(tosca_tpl)
-
tosca_elk_tpl = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"data/tosca_elk.yaml")
+ tosca_repo_tpl = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "data/tosca_repositories_test_definition.yaml")
def test_version(self):
self.assertEqual(self.tosca.version, "tosca_simple_yaml_1_0")
@@ -134,6 +135,19 @@ class ToscaTemplateTest(TestCase):
self.assertEqual('Linux', os_props['type'].value)
self.assertEqual('Linux', os_type_prop)
+ def test_node_inheritance_type(self):
+ wordpress_node = [
+ node for node in self.tosca.nodetemplates
+ if node.name == 'wordpress'][0]
+ self.assertTrue(
+ wordpress_node.is_derived_from("tosca.nodes.WebApplication"))
+ self.assertTrue(
+ wordpress_node.is_derived_from("tosca.nodes.Root"))
+ self.assertFalse(
+ wordpress_node.is_derived_from("tosca.policies.Root"))
+ self.assertFalse(
+ wordpress_node.is_derived_from("tosca.groups.Root"))
+
def test_outputs(self):
self.assertEqual(
['website_url'],
@@ -211,6 +225,8 @@ class ToscaTemplateTest(TestCase):
for key in relation.keys():
rel_tpl = relation.get(key).get_relationship_template()
if rel_tpl:
+ self.assertTrue(rel_tpl[0].is_derived_from(
+ "tosca.relationships.Root"))
interfaces = rel_tpl[0].interfaces
for interface in interfaces:
self.assertEqual(config_interface,
@@ -236,6 +252,18 @@ class ToscaTemplateTest(TestCase):
expected_hosts,
sorted([v.type for v in node_tpl.relationships.values()]))
+ def test_repositories(self):
+ template = ToscaTemplate(self.tosca_repo_tpl)
+ self.assertEqual(
+ ['repo_code0', 'repo_code1', 'repo_code2'],
+ sorted([input.name for input in template.repositories]))
+
+ input_name = "repo_code2"
+ expected_url = "https://github.com/nandinivemula/intern/master"
+ for input in template.repositories:
+ if input.name == input_name:
+ self.assertEqual(input.url, expected_url)
+
def test_template_macro(self):
template = ToscaTemplate(self.tosca_elk_tpl)
for node_tpl in template.nodetemplates:
@@ -728,5 +756,50 @@ class ToscaTemplateTest(TestCase):
"data/test_tosca_custom_rel_with_script.yaml")
tosca = ToscaTemplate(tosca_tpl)
rel = tosca.relationship_templates[0]
+ self.assertEqual(rel.type, "tosca.relationships.HostedOn")
+ self.assertTrue(rel.is_derived_from("tosca.relationships.Root"))
self.assertEqual(len(rel.interfaces), 1)
self.assertEqual(rel.interfaces[0].type, "Configure")
+
+ def test_various_portspec_errors(self):
+ tosca_tpl = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "data/datatypes/test_datatype_portspec_add_req.yaml")
+ self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl,
+ None)
+
+ # TODO(TBD) find way to reuse error messages from constraints.py
+ msg = (_('The value "%(pvalue)s" of property "%(pname)s" is out of '
+ 'range "(min:%(vmin)s, max:%(vmax)s)".') %
+ dict(pname=PortSpec.SOURCE,
+ pvalue='0',
+ vmin='1',
+ vmax='65535'))
+ exception.ExceptionCollector.assertExceptionMessage(
+ exception.ValidationError, msg)
+
+ # Test value below range min.
+ msg = (_('The value "%(pvalue)s" of property "%(pname)s" is out of '
+ 'range "(min:%(vmin)s, max:%(vmax)s)".') %
+ dict(pname=PortSpec.SOURCE,
+ pvalue='1',
+ vmin='2',
+ vmax='65534'))
+ exception.ExceptionCollector.assertExceptionMessage(
+ exception.RangeValueError, msg)
+
+ # Test value above range max.
+ msg = (_('The value "%(pvalue)s" of property "%(pname)s" is out of '
+ 'range "(min:%(vmin)s, max:%(vmax)s)".') %
+ dict(pname=PortSpec.SOURCE,
+ pvalue='65535',
+ vmin='2',
+ vmax='65534'))
+ exception.ExceptionCollector.assertExceptionMessage(
+ exception.RangeValueError, msg)
+
+ def test_containers(self):
+ tosca_tpl = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "data/test_containers.yaml")
+ ToscaTemplate(tosca_tpl)
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py
index 81a1a6c..986d9e4 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py
@@ -20,12 +20,12 @@ from toscaparser.parameters import Input
from toscaparser.parameters import Output
from toscaparser.policy import Policy
from toscaparser.relationship_template import RelationshipTemplate
+from toscaparser.repositories import Repository
from toscaparser.tests.base import TestCase
from toscaparser.topology_template import TopologyTemplate
from toscaparser.tosca_template import ToscaTemplate
from toscaparser.triggers import Triggers
from toscaparser.utils.gettextutils import _
-
import toscaparser.utils.yamlparser
@@ -105,7 +105,9 @@ class ToscaTemplateValidationTest(TestCase):
type: integer
description: Number of CPUs for the server.
constraint:
- - valid_values: [ 1, 2, 4, 8 ]
+ - valid_values: [ 1, 2, 4 ]
+ required: yes
+ status: supported
'''
inputs = (toscaparser.utils.yamlparser.
simple_parse(tpl_snippet)['inputs'])
@@ -335,6 +337,113 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml
'to verify valid values.'),
err.__str__())
+ def _repo_content(self, path):
+ repositories = path['repositories']
+ reposit = []
+ for name, val in repositories.items():
+ reposits = Repository(name, val)
+ reposit.append(reposits)
+ return reposit
+
+ def test_repositories(self):
+ tpl_snippet = '''
+ repositories:
+ repo_code0: https://raw.githubusercontent.com/nandinivemula/intern
+ repo_code1:
+ description: My project's code Repository in github usercontent.
+ url: https://github.com/nandinivemula/intern
+ credential:
+ user: nandini
+ password: tcs@12345
+ repo_code2:
+ description: My Project's code Repository in github.
+ url: https://github.com/nandinivemula/intern
+ credential:
+ user: xyzw
+ password: xyz@123
+ '''
+ tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
+ repoobject = self._repo_content(tpl)
+ actualrepo_names = []
+ for repo in repoobject:
+ repos = repo.name
+ actualrepo_names.append(repos)
+ reposname = list(tpl.values())
+ reposnames = reposname[0]
+ expected_reponames = list(reposnames.keys())
+ self.assertEqual(expected_reponames, actualrepo_names)
+
+ def test_repositories_with_missing_required_field(self):
+ tpl_snippet = '''
+ repositories:
+ repo_code0: https://raw.githubusercontent.com/nandinivemula/intern
+ repo_code1:
+ description: My project's code Repository in github usercontent.
+ credential:
+ user: nandini
+ password: tcs@12345
+ repo_code2:
+ description: My Project's code Repository in github.
+ url: https://github.com/nandinivemula/intern
+ credential:
+ user: xyzw
+ password: xyz@123
+ '''
+ tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
+ err = self.assertRaises(exception.MissingRequiredFieldError,
+ self._repo_content, tpl)
+ expectedmessage = _('Repository "repo_code1" is missing '
+ 'required field "url".')
+ self.assertEqual(expectedmessage, err.__str__())
+
+ def test_repositories_with_unknown_field(self):
+ tpl_snippet = '''
+ repositories:
+ repo_code0: https://raw.githubusercontent.com/nandinivemula/intern
+ repo_code1:
+ description: My project's code Repository in github usercontent.
+ url: https://github.com/nandinivemula/intern
+ credential:
+ user: nandini
+ password: tcs@12345
+ repo_code2:
+ descripton: My Project's code Repository in github.
+ url: https://github.com/nandinivemula/intern
+ credential:
+ user: xyzw
+ password: xyz@123
+ '''
+ tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
+ err = self.assertRaises(exception.UnknownFieldError,
+ self._repo_content, tpl)
+ expectedmessage = _('repositories "repo_code2" contains unknown field'
+ ' "descripton". Refer to the definition to verify'
+ ' valid values.')
+ self.assertEqual(expectedmessage, err.__str__())
+
+ def test_repositories_with_invalid_url(self):
+ tpl_snippet = '''
+ repositories:
+ repo_code0: https://raw.githubusercontent.com/nandinivemula/intern
+ repo_code1:
+ description: My project's code Repository in github usercontent.
+ url: h
+ credential:
+ user: nandini
+ password: tcs@12345
+ repo_code2:
+ description: My Project's code Repository in github.
+ url: https://github.com/nandinivemula/intern
+ credential:
+ user: xyzw
+ password: xyz@123
+ '''
+ tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
+ err = self.assertRaises(exception.URLException,
+ self._repo_content, tpl)
+ expectedmessage = _('repsositories "repo_code1" Invalid Url')
+ self.assertEqual(expectedmessage, err.__str__())
+
def test_groups(self):
tpl_snippet = '''
node_templates:
@@ -1379,3 +1488,35 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml
exception.MissingRequiredFieldError,
lambda: Policy(name, policies[name], None, None))
self.assertEqual(expectedmessage, err.__str__())
+
+ def test_credential_datatype(self):
+ tosca_tpl = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "data/test_credential_datatype.yaml")
+ self.assertIsNotNone(ToscaTemplate(tosca_tpl))
+
+ def test_invalid_default_value(self):
+ tpl_path = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "data/test_invalid_input_defaults.yaml")
+ self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path)
+ exception.ExceptionCollector.assertExceptionMessage(
+ ValueError, _('"two" is not an integer.'))
+
+ def test_invalid_capability(self):
+ tpl_snippet = '''
+ node_templates:
+ server:
+ type: tosca.nodes.Compute
+ capabilities:
+ oss:
+ properties:
+ architecture: x86_64
+ '''
+ tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
+ err = self.assertRaises(exception.UnknownFieldError,
+ TopologyTemplate, tpl, None)
+ expectedmessage = _('"capabilities" of template "server" contains '
+ 'unknown field "oss". Refer to the definition '
+ 'to verify valid values.')
+ self.assertEqual(expectedmessage, err.__str__())