From db33fd6014c3d746d08002c7cfd061fcdad9868f Mon Sep 17 00:00:00 2001 From: shangxdy Date: Thu, 21 Jul 2016 19:50:29 +0800 Subject: Add transaction subsystem definition in the use case of substitution_mappings As a developer; I want to implement the function of substitution_mapping; So that will complete the test file about transaction subsystem definitions for example. Change-Id: I5e44c2b4933afadf96743641279016af5afc39e0 JIRA: PARSER-68 Signed-off-by: shangxdy --- .../tests/data/topology_template/definitions.yaml | 34 ++++++--- .../tests/data/topology_template/system.yaml | 13 ++++ .../topology_template/transactionsubsystem.yaml | 88 ++++++++++++++++++++++ .../toscaparser/tests/test_topology_template.py | 6 +- .../tosca-parser/toscaparser/tosca_template.py | 2 +- 5 files changed, 129 insertions(+), 14 deletions(-) create mode 100644 tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/transactionsubsystem.yaml (limited to 'tosca2heat') diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/definitions.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/definitions.yaml index cfa0614..e8e8c8a 100644 --- a/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/definitions.yaml +++ b/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/definitions.yaml @@ -1,6 +1,23 @@ tosca_definitions_version: tosca_simple_yaml_1_0 node_types: + example.QueuingSubsystem: + derived_from: tosca.nodes.SoftwareComponent + properties: + server_ip: + type: string + server_port: + type: integer + requirements: + - receiver1: + node: example.TransactionSubsystem + capability: example.capabilities.Receiver + relationship: tosca.relationships.ConnectsTo + - receiver2: + node: example.TransactionSubsystem + capability: example.capabilities.Receiver + relationship: tosca.relationships.ConnectsTo + example.TransactionSubsystem: properties: mq_server_ip: @@ -17,18 +34,8 @@ node_types: type: example.capabilities.Receiver requirements: - database_endpoint: - capability: tosca.capabilities.Endpoint.Database node: tosca.nodes.Database - relationship: tosca.relationships.ConnectsTo - - example.QueuingSubsystem: - derived_from: tosca.nodes.SoftwareComponent - requirements: - - receiver1: - node: example.TransactionSubsystem - relationship: tosca.relationships.ConnectsTo - - receiver2: - node: example.TransactionSubsystem + capability: tosca.capabilities.Endpoint.Database relationship: tosca.relationships.ConnectsTo example.DatabaseSubsystem: @@ -44,6 +51,11 @@ node_types: capabilities: message_receiver: type: example.capabilities.Receiver + requirements: + - database: + node: tosca.nodes.Database + capability: tosca.capabilities.Endpoint.Database + relationship: tosca.relationships.ConnectsTo capability_types: example.capabilities.Receiver: 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 9996e4f..84d625d 100644 --- a/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/system.yaml +++ b/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/system.yaml @@ -7,11 +7,24 @@ imports: topology_template: description: Template of online transaction processing service. + inputs: + mq_server_ip: + type: string + default: 127.0.0.1 + description: IP address of the message queuing server to receive messages from. + mq_server_port: + type: integer + default1: 8080 + description: Port to be used for receiving messages. + node_templates: mq: type: example.QueuingSubsystem # properties: # to be updated when substitution_mapping is implemented + properties: + server_ip: { get_input: mq_server_ip } + server_port: { get_input: mq_server_port } # capabilities: # message_queue_endpoint: # to be updated when substitution_mapping is implemented diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/transactionsubsystem.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/transactionsubsystem.yaml new file mode 100644 index 0000000..0f145a3 --- /dev/null +++ b/tosca2heat/tosca-parser/toscaparser/tests/data/topology_template/transactionsubsystem.yaml @@ -0,0 +1,88 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Transaction subsystem, which is service template with topology_template, + act as a nested system inside another system and also act as stand + alone service template. + +imports: + - definitions.yaml + +topology_template: + description: Template of a database including its hosting stack. + + inputs: + mq_server_ip: + type: string + description: IP address of the message queuing server to receive messages from. + default: 127.0.0.1 + receiver_port: + type: integer + description: Port to be used for receiving messages. + default: 8080 + my_cpus: + type: integer + description: Number of CPUs for the server. + default: 2 + constraints: + - valid_values: [ 1, 2, 4, 8 ] + + substitution_mappings: + node_type: example.TransactionSubsystem + capabilities: + message_receiver: [ app, message_receiver ] + requirements: + database_endpoint: [ app, database ] + + node_templates: + app: + type: example.SomeApp + properties: + admin_user: foo + pool_size: 10 + capabilities: + message_receiver: + properties: + server_ip: { get_input: mq_server_ip } + requirements: + - host: + node: websrv + + websrv: + type: tosca.nodes.WebServer + capabilities: + data_endpoint: + properties: + port_name: { get_input: receiver_port } + requirements: + - host: + node: server + + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: my_cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + + outputs: + receiver_ip: + description: private IP address of the message receiver application + value: { get_attribute: [ server, private_address ] } +# It seems current _process_intrisic_function can not handle more than 2 arguments, save it for later +# receiver_port: +# description: Port of the message receiver endpoint +# value: { get_attribute: [ app, data_endpoint, port_name ] } + + groups: + webserver_group: + members: [ websrv, server ] + type: tosca.groups.Root diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py b/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py index 0f1a33e..14f2496 100644 --- a/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py +++ b/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py @@ -27,7 +27,7 @@ class TopologyTemplateTest(TestCase): '''TOSCA template.''' self.tosca_tpl_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), - "data/topology_template/subsystem.yaml") + "data/topology_template/transactionsubsystem.yaml") self.tpl = YAML_LOADER(self.tosca_tpl_path) self.topo_tpl = self.tpl.get('topology_template') self.imports = self.tpl.get('imports') @@ -157,4 +157,6 @@ class TopologyTemplateTest(TestCase): tpl_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), "data/topology_template/system.yaml") - self.assertIsNotNone(ToscaTemplate(tpl_path)) + system_tosca_template = ToscaTemplate(tpl_path) + self.assertIsNotNone(system_tosca_template) + self.assertEqual(len(system_tosca_template.nested_tosca_template), 0) diff --git a/tosca2heat/tosca-parser/toscaparser/tosca_template.py b/tosca2heat/tosca-parser/toscaparser/tosca_template.py index 8753a2c..5da34d6 100644 --- a/tosca2heat/tosca-parser/toscaparser/tosca_template.py +++ b/tosca2heat/tosca-parser/toscaparser/tosca_template.py @@ -216,7 +216,7 @@ class ToscaTemplate(object): path=filename, parsed_params=self.parsed_params, yaml_dict_tpl=tosca_tpl) if nested_template.topology_template.substitution_mappings: - self.nested_tosca_template.apend(nested_template) + self.nested_tosca_template.append(nested_template) def _validate_field(self): version = self._tpl_version() -- cgit 1.2.3-korg