Merge "Enable Translator with new TOSCA library (6)"

This commit is contained in:
Jenkins 2015-09-04 19:40:40 +00:00 committed by Gerrit Code Review
commit b80d846b13
28 changed files with 103 additions and 802 deletions

View File

@ -21,8 +21,9 @@ class ToscaTemplateOutputTest(TestCase):
def test_translate_output(self):
tosca_tpl = os.path.join(
os.path.dirname(os.path.abspath(toscaparser.__file__)),
"tests/data/", "tosca_nodejs_mongodb_two_instances.yaml")
os.path.dirname(os.path.abspath(__file__)),
"../../toscalib/tests/data/"
"tosca_nodejs_mongodb_two_instances.yaml")
tosca = ToscaTemplate(tosca_tpl)
translate = TOSCATranslator(tosca, [])
hot_translation = translate.translate()

View File

@ -11,7 +11,6 @@
# under the License.
import os
import toscaparser
from toscaparser.tosca_template import ToscaTemplate
from translator.tests.base import TestCase
@ -23,8 +22,8 @@ class ToscaMongoNodejsTest(TestCase):
'''TOSCA template with nodejs, app and mongodb on 2 servers.'''
tosca_tpl = os.path.join(
os.path.dirname(os.path.abspath(toscaparser.__file__)),
"tests/data/", "tosca_nodejs_mongodb_two_instances.yaml")
os.path.dirname(os.path.abspath(__file__)),
"../toscalib/tests/data/tosca_nodejs_mongodb_two_instances.yaml")
tosca = ToscaTemplate(tosca_tpl, parsed_params)
def test_relationship_def(self):

View File

@ -11,8 +11,6 @@
# under the License.
import json
import os
import toscaparser
from translator.common.utils import TranslationUtils
from translator.tests.base import TestCase
@ -83,9 +81,8 @@ class ToscaHotTranslationTest(TestCase):
json.dumps(diff, indent=4, separators=(', ', ': ')))
def test_hot_translate_nodejs_mongodb_two_instances(self):
tosca_file = os.path.join(
os.path.dirname(os.path.abspath(toscaparser.__file__)),
"tests/data/", "tosca_nodejs_mongodb_two_instances.yaml")
tosca_file = \
'../toscalib/tests/data/tosca_nodejs_mongodb_two_instances.yaml'
hot_file = '../toscalib/tests/data/hot_output/' \
'hot_nodejs_mongodb_two_instances.yaml'
params = {'github_url':

View File

@ -1,48 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
Custom type and node definition used to test custom datatypes.
node_types:
tosca.nodes.my.SomeNode:
derived_from: tosca.nodes.Root
properties:
people:
type: tosca.my.datatypes.People
datatype_definitions:
tosca.my.datatypes.PeopleBase:
properties:
name:
type: string
required: true
constraints:
- min_length: 2
gender:
type: string
default: unknown
tosca.my.datatypes.People:
derived_from: tosca.my.datatypes.PeopleBase
properties:
addresses:
type: map
entry_schema:
type: string
contacts:
type: list
entry_schema:
type: tosca.my.datatypes.ContactInfo
tosca.my.datatypes.ContactInfo:
description: simple contact information
properties:
contact_name:
type: string
required: true
constraints:
- min_length: 2
contact_email:
type: string
contact_phone:
type: string

View File

@ -1,65 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA templates used to test custom datatypes.
node_types:
tosca.nodes.my.SomeNode:
derived_from: tosca.nodes.Root
properties:
people:
type: tosca.my.datatypes.People
datatype_definitions:
tosca.my.datatypes.PeopleBase:
properties:
name:
type: string
required: true
constraints:
- min_length: 2
gender:
type: string
default: unknown
tosca.my.datatypes.People:
derived_from: tosca.my.datatypes.PeopleBase
properties:
addresses:
type: map
entry_schema:
type: string
contacts:
type: list
entry_schema:
type: tosca.my.datatypes.ContactInfo
tosca.my.datatypes.ContactInfo:
description: simple contact information
properties:
contact_name:
type: string
required: true
constraints:
- min_length: 2
contact_email:
type: string
contact_phone:
type: string
topology_template:
node_templates:
positive:
type: tosca.nodes.my.SomeNode
properties:
people:
name: Mike
gender: male
addresses: {Home: 1 foo street, Office: 9 bar avenue}
contacts:
- {contact_name: Tom,
contact_email: tom@email.com,
contact_phone: '123456789'}
- {contact_name: Jerry,
contact_email: jerry@email.com,
contact_phone: '321654987'}

View File

@ -1,25 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA templates used to test custom datatypes.
imports:
- custom_datatype_def.yaml
topology_template:
node_templates:
# 123456789 is not a string
error in nested datatype:
type: tosca.nodes.my.SomeNode
properties:
people:
name: Mike
gender: male
addresses: {Home: 1 foo street, Office: 9 bar avenue}
contacts:
- {contact_name: Tom,
contact_email: tom@email.com,
contact_phone: 123456789}
- {contact_name: Jerry,
contact_email: jerry@email.com,
contact_phone: '321654987'}

View File

@ -1,24 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA templates used to test custom datatypes.
imports:
- custom_datatype_def.yaml
topology_template:
node_templates:
positive:
type: tosca.nodes.my.SomeNode
properties:
people:
name: Mike
gender: male
addresses: {Home: 1 foo street, Office: 9 bar avenue}
contacts:
- {contact_name: Tom,
contact_email: tom@email.com,
contact_phone: '123456789'}
- {contact_name: Jerry,
contact_email: jerry@email.com,
contact_phone: '321654987'}

View File

@ -1,18 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA templates used to test custom datatypes.
imports:
- custom_datatype_def.yaml
topology_template:
node_templates:
# addresses is not a map
error in field value:
type: tosca.nodes.my.SomeNode
properties:
people:
name: Mike
gender: male
addresses: [1 foo street, 9 bar avenue]

View File

@ -1,33 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA template for testing get_attribute with HOST keyword.
topology_template:
node_templates:
server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 2
dbms:
type: tosca.nodes.DBMS
requirements:
- host: server
interfaces:
Standard:
configure:
implementation: configure.sh
inputs:
ip_address: { get_attribute: [ HOST, private_address ] }
database:
type: tosca.nodes.Database
requirements:
- host: dbms
interfaces:
Standard:
configure:
implementation: configure.sh
inputs:
ip_address: { get_attribute: [ HOST, private_address ] }

View File

@ -1,20 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA template for testing get_attribute with HOST keyword.
topology_template:
node_templates:
server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 2
interfaces:
Standard:
configure:
implementation: configure.sh
inputs:
ip_address: { get_attribute: [ HOST, private_address ] }

View File

@ -1,17 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA template for testing get_attribute with HOST keyword.
topology_template:
node_templates:
server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 2
outputs:
ip_address:
value: { get_attribute: [ HOST, private_address ] }

View File

@ -1,28 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
Tosca template for testing unknown attribute name in get_attribute
function.
topology_template:
inputs:
image_id:
type: string
node_templates:
server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 2
interfaces:
Standard:
configure:
implementation: start_server.sh
inputs:
image_id: { get_input: image_id }
outputs:
ip_address:
value: { get_attribute: [ server, unknown_attribute ] }

View File

@ -1,28 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
Tosca template for testing unknown node template name in get_attribute
function.
topology_template:
inputs:
image_id:
type: string
node_templates:
server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 2
interfaces:
Standard:
configure:
implementation: start_server.sh
inputs:
image_id: { get_input: image_id }
outputs:
ip_address:
value: { get_attribute: [ unknown_node_template, private_address ] }

View File

@ -1,34 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA simple profile template to test invalid get_input function.
topology_template:
inputs:
cpus:
type: integer
description: Number of CPUs for the server.
constraints:
- valid_values: [ 1, 2, 4, 8 ]
node_templates:
server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
# compute properties (flavor)
disk_size: 10
num_cpus: { get_input: [cpus, cpus] }
mem_size: 4096
os:
properties:
architecture: x86_64
type: Linux
distribution: Fedora
version: 18.0
outputs:
server_address:
description: IP address of server instance.
value: { get_attribute: [server, private_address] }

View File

@ -1,36 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
Tosca template for testing an unknown capability property.
topology_template:
node_templates:
server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 2
dbms:
type: tosca.nodes.DBMS
properties:
root_password: 1234
port: 3672
database:
type: tosca.nodes.Database
properties:
name: my_db
user: abcd
password: 1234
capabilities:
database_endpoint:
properties:
port: { get_property: [ dbms, port ] }
requirements:
- host: dbms
interfaces:
Standard:
configure:
implementation: database_configure.sh
inputs:
db_port: { get_property: [ SELF, database_endpoint, unknown ] }

View File

@ -1,20 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
Tosca template for testing an unknown input.
topology_template:
node_templates:
server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 2
interfaces:
Standard:
configure:
implementation: start_server.sh
inputs:
image_id: { get_input: image_id }

View File

@ -1,13 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
Tosca template for testing an unknown input.
topology_template:
node_templates:
obj_store_server:
type: tosca.nodes.ObjectStorage
properties:
name: { get_input: objectstore_name }
size: 1024 MB
maxsize: 1 GB

View File

@ -1,14 +0,0 @@
tosca_definitions_version: tosca_xyz
description: >
Test template with an invalid template version.
topology_template:
node_templates:
server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 2

View File

@ -1,15 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
Tosca template for testing a template with no inputs.
topology_template:
node_templates:
server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 2
outputs:

View File

@ -1,15 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
Tosca template for testing a template with no outputs.
topology_template:
inputs:
node_templates:
server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 2

View File

@ -1,67 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
Test Requirements.
imports:
- custom_types/wordpress.yaml
topology_template:
node_templates:
my_app:
description: >
Specify multiple requirement via node and relationship keyword,
as an explicit relationship. Also demonstrates relationship with
type keyword and without it as an in-line reference.
type: tosca.nodes.WebApplication.WordPress
requirements:
- req1:
node: my_webserver
relationship: tosca.relationships.HostedOn
- req2:
node: mysql_database
relationship:
type: tosca.relationships.ConnectsTo
mysql_database:
description: Specify requirement via a capability as an implicit relationship.
type: tosca.nodes.Database
requirements:
- host:
node: my_dbms
relationship: tosca.relationships.HostedOn
my_dbms:
type: tosca.nodes.DBMS
my_webserver:
type: tosca.nodes.WebServer
my_server:
description: >
Specify requirement via a relationship template, as an explicit relationship.
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 2
disk_size: 10 GB
mem_size: 4 MB
os:
properties:
# host Operating System image properties
architecture: x86_64
type: linux
distribution: rhel
version: 6.5
requirements:
- req1:
node: my_storage
relationship: storage_attachment
my_storage:
type: tosca.nodes.BlockStorage
properties:
size: 1 GiB
snapshot_id: id
relationship_templates:
storage_attachment:
type: tosca.relationships.AttachesTo
properties:
location: /temp

View File

@ -1,33 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA simple profile with short type name for Compute.
topology_template:
inputs:
cpus:
type: integer
description: Number of CPUs for the server.
constraints:
- valid_values: [ 1, 2, 4, 8 ]
node_templates:
server:
type: Compute
capabilities:
host:
properties:
disk_size: 10 GB
num_cpus: { get_input: cpus }
mem_size: 4096 MB
os:
properties:
architecture: x86_64
type: Linux
distribution: Fedora
version: 18.0
outputs:
server_address:
description: IP address of server instance.
value: { get_attribute: [server, private_address] }

View File

@ -1,31 +0,0 @@
description: >
TOSCA simple profile missing version section.
topology_template:
inputs:
cpus:
type: integer
description: Number of CPUs for the server.
constraints:
- valid_values: [ 1, 2, 4, 8 ]
node_templates:
server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
disk_size: 10 GB
num_cpus: { get_input: cpus }
mem_size: 4096 MB
os:
properties:
architecture: x86_64
type: Linux
distribution: Fedora
version: 18.0
outputs:
server_address:
description: IP address of server instance.
value: { get_property: [server, private_address] }

View File

@ -1,33 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA simple profile with invalid top-level key: 'node_template'.
topology_template:
inputs:
cpus:
type: integer
description: Number of CPUs for the server.
constraints:
- valid_values: [ 1, 2, 4, 8 ]
node_template:
server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
disk_size: 10 GB
num_cpus: { get_input: cpus }
mem_size: 4096 MB
os:
properties:
architecture: x86_64
type: Linux
distribution: Fedora
version: 18.0
outputs:
server_address:
description: IP address of server instance.
value: { get_property: [server, private_address] }

View File

@ -1,44 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
node_types:
example.TransactionSubsystem:
properties:
mq_server_ip:
type: string
receiver_port:
type: integer
attributes:
receiver_ip:
type: string
receiver_port:
type: integer
capabilities:
message_receiver:
type: example.capabilities.Receiver
requirements:
- database_endpoint: tosca.capabilities.Endpoint.Database
example.QueuingSubsystem:
derived_from: tosca.nodes.SoftwareComponent
example.DatabaseSubsystem:
derived_from: tosca.nodes.Database
example.SomeApp:
derived_from: tosca.nodes.SoftwareComponent
properties:
admin_user:
type: string
pool_size:
type: integer
capabilities:
message_receiver:
type: example.capabilities.Receiver
capability_types:
example.capabilities.Receiver:
derived_from: tosca.capabilities.Endpoint
properties:
server_ip:
type: string

View File

@ -1,85 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
Service template with topology_template, act as a nested system inside another system.
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.
receiver_port:
type: string
description: Port to be used for receiving messages.
my_cpus:
type: integer
description: Number of CPUs for the server.
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 ]
policies:
- policy_name: none

View File

@ -1,46 +0,0 @@
tosca_definitions_version: tosca_simple_yaml_1_0
topology_template:
description: Template of online transaction processing service.
node_templates:
mq:
type: example.QueuingSubsystem
# properties:
# to be updated when substitution_mapping is implemented
# capabilities:
# message_queue_endpoint:
# to be updated when substitution_mapping is implemented
requirements:
- receiver: trans1
- receiver: trans2
trans1:
type: example.TransactionSubsystem
properties:
mq_server_ip: { get_attribute: [ mq, server_ip ] }
receiver_port: 8080
# capabilities:
# message_receiver:
# to be updated when substitution_mapping is implemented
requirements:
- database_endpoint: dbsys
trans2:
type: example.TransactionSubsystem
properties:
mq_server_ip: { get_attribute: [ mq, server_ip ] }
receiver_port: 8080
# capabilities:
# message_receiver:
# to be updated when substitution_mapping is implemented
requirements:
- database_endpoint: dbsys
dbsys:
type: example.DatabaseSubsystem
# properties:
# to be updated when substitution_mapping is implemented
# capabilities:
# database_endpoint:
# to be updated when substitution_mapping is implemented

View File

@ -0,0 +1,96 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA simple profile with nodejs and mongodb.
imports:
- custom_types/paypalpizzastore_nodejs_app.yaml
dsl_definitions:
host_capabilities: &host_capabilities
disk_size: 10 GB
num_cpus: 1
mem_size: 4096 MB
os_capabilities: &os_capabilities
architecture: x86_64
type: Linux
distribution: Ubuntu
version: 14.04
topology_template:
inputs:
my_cpus:
type: integer
description: Number of CPUs for the server.
constraints:
- valid_values: [ 1, 2, 4, 8 ]
default: 1
github_url:
type: string
description: The URL to download nodejs.
default: http://github.com/paypal/rest-api-sample-app-nodejs.git
node_templates:
paypal_pizzastore:
type: tosca.nodes.WebApplication.PayPalPizzaStore
properties:
github_url: { get_input: github_url }
requirements:
- host: nodejs
- database_connection: mongo_db
interfaces:
Standard:
configure:
implementation: nodejs/config.sh
inputs:
github_url: http://github.com/paypal/rest-api-sample-app-nodejs.git
mongodb_ip: { get_attribute: [mongo_server, private_address] }
start: nodejs/start.sh
nodejs:
type: tosca.nodes.WebServer
requirements:
- host: app_server
interfaces:
Standard:
create: nodejs/create.sh
mongo_db:
type: tosca.nodes.Database
requirements:
- host: mongo_dbms
interfaces:
Standard:
create: mongodb/create_database.sh
mongo_dbms:
type: tosca.nodes.DBMS
requirements:
- host: mongo_server
interfaces:
Standard:
create: mongodb/create.sh
configure:
implementation: mongodb/config.sh
inputs:
mongodb_ip: { get_attribute: [mongo_server, private_address] }
start: mongodb/start.sh
mongo_server:
type: tosca.nodes.Compute
capabilities:
host:
properties: *host_capabilities
os:
properties: *os_capabilities
app_server:
type: tosca.nodes.Compute
capabilities:
host:
properties: *host_capabilities
os:
properties: *os_capabilities
outputs:
nodejs_url:
description: URL for the nodejs server, http://<IP>:3000
value: { get_attribute: [app_server, private_address] }
mongodb_url:
description: URL for the mongodb server.
value: { get_attribute: [mongo_server, private_address] }