Commit e33cdc35 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added test to validate all tosca examples

parent f2de48e1
tosca_definitions_version: "tosca_simple_yaml_1_0" tosca_definitions_version: "tosca_simple_yaml_1_0"
topology_template: topology_template:
node_templates: node_templates:
compute: compute:
properties: properties:
...@@ -154,6 +155,8 @@ topology_template: ...@@ -154,6 +155,8 @@ topology_template:
playbooks: playbooks:
- get_info_service.yml - get_info_service.yml
description: "TOSCA example" description: "TOSCA example"
imports: imports:
- nodes: "https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/nodes.yaml" - nodes: "https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/nodes.yaml"
......
tosca_definitions_version: "tosca_simple_yaml_1_0"
topology_template:
node_templates:
compute:
properties:
disk_size: "10000 MB"
mem_size: "1000 MB"
num_cores: 1
os: "Ubuntu 18.04"
user_name: "vm_user"
interfaces:
Standard:
create: "dumy.yaml"
type: "tosca.nodes.ARTICONF.VM.Compute"
compute_1:
properties:
disk_size: "10000 MB"
mem_size: "1000 MB"
num_cores: 1
os: "Ubuntu 18.04"
user_name: "vm_user"
interfaces:
Standard:
create: "dumy.yaml"
type: "tosca.nodes.ARTICONF.VM.Compute"
kubernetes:
requirements:
- host:
capability: "tosca.capabilities.ARTICONF.VM.topology"
node: "topology"
relationship: "tosca.relationships.HostedOn"
interfaces:
Standard:
configure:
inputs:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/k8s_dashboard.yaml"
create:
inputs:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/install_k8s.yaml"
delete:
inputs:
playbook: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/ansible_playbooks/k8s_delete.yaml"
type: "tosca.nodes.ARTICONF.docker.Orchestrator.Kubernetes"
topology:
properties:
domain: "Frankfurt"
provider: "EC2"
requirements:
- vm:
capability: "tosca.capabilities.ARTICONF.VM"
node: "compute_1"
relationship: "tosca.relationships.DependsOn"
interfaces:
CloudsStorm:
delete:
inputs:
code_type: "SEQ"
object_type: "SubTopology"
hscale:
inputs:
code_type: "SEQ"
object_type: "SubTopology"
provision:
inputs:
code_type: "SEQ"
object_type: "SubTopology"
start:
inputs:
code_type: "SEQ"
object_type: "SubTopology"
stop:
inputs:
code_type: "SEQ"
object_type: "SubTopology"
type: "tosca.nodes.ARTICONF.VM.topology"
topology_1:
properties:
domain: "Frankfurt"
provider: "EC2"
requirements:
- vm:
capability: "tosca.capabilities.ARTICONF.VM"
node: "compute_1"
relationship: "tosca.relationships.DependsOn"
interfaces:
CloudsStorm:
delete:
inputs:
code_type: "SEQ"
object_type: "SubTopology"
hscale:
inputs:
code_type: "SEQ"
object_type: "SubTopology"
provision:
inputs:
code_type: "SEQ"
object_type: "SubTopology"
start:
inputs:
code_type: "SEQ"
object_type: "SubTopology"
stop:
inputs:
code_type: "SEQ"
object_type: "SubTopology"
type: "tosca.nodes.ARTICONF.VM.topology"
artifacts:
provisioned_files:
required: false
type: "string"
ws-pema:
properties:
ports:
- "30001:8080"
requirements:
- host:
capability: "tosca.capabilities.ARTICONF.docker.Orchestrator"
node: "kubernetes"
relationship: "tosca.relationships.HostedOn"
type: "tosca.nodes.ARTICONF.Container.Application.Docker"
artifacts:
image:
file: "alogo53/ws-pema-lifewatch"
repository: "docker_hub"
type: "tosca.artifacts.Deployment.Image.Container.Docker"
interfaces:
Kubernetes:
delete:
inputs:
repository: https://github.com/skoulouzis/playbooks.git
playbooks:
- delete_service.yml
create:
inputs:
repository: https://github.com/skoulouzis/playbooks.git
playbooks:
- create_service.yml
scale:
inputs:
repository: https://github.com/skoulouzis/playbooks.git
playbooks:
- scale_service.yml
replicas: 1
autoscale:
inputs:
repository: https://github.com/skoulouzis/playbooks.git
playbooks:
- autoscale_service.yml
horizontal_pod_autoscaler: horizontal_pod_autoscaler.yml
info:
inputs:
repository: https://github.com/skoulouzis/playbooks.git
playbooks:
- get_info_service.yml
outputs:
private_ip_compute:
description: The private IP address of the application’s first tier.
value: { get_attribute: [compute, private_ip] }
private_ip_compute_1:
description: The private IP address of the application’s second tier.
value: { get_attribute: [compute_1, private_ip] }
description: "TOSCA example"
imports:
- nodes: "https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/nodes.yaml"
- data: "https://raw.githubusercontent.com/skoulouzis/CONF/develop/TOSCA/types/data.yml"
- capabilities: "https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/capabilities.yaml"
- policies: "https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/policies.yaml"
- interfaces: "https://raw.githubusercontent.com/skoulouzis/DRIP/develop/TOSCA/types/interfaces.yml"
...@@ -8,7 +8,7 @@ COPY send_to_sonarqube.sh send_to_sonarqube.sh ...@@ -8,7 +8,7 @@ COPY send_to_sonarqube.sh send_to_sonarqube.sh
CMD ./clone_git.sh $BRANCH $GIT_URL $FOLDER_NAME && \ CMD ./clone_git.sh $BRANCH $GIT_URL $FOLDER_NAME && \
./build.sh $FOLDER_NAME && \ ./build.sh $FOLDER_NAME && \
./send_to_sonarqube.sh $SONAR_HOST $SONAR_LOGIN ./send_to_sonarqube.sh $FOLDER_NAME $SONAR_HOST $SONAR_LOGIN
......
#!/bin/bash #!/bin/bash
SONAR_HOST=$1 SRC=$1
SONAR_LOGIN=$2 SONAR_HOST=$2
SONAR_LOGIN=$3
for i in $(find -name target); do # Not recommended, will break on whitespace cd $SRC
for i in $(find . -name target); do # Not recommended, will break on whitespace
echo "Sending $i" echo "Sending $i"
done done
...@@ -106,7 +106,7 @@ def save(file: FileStorage): ...@@ -106,7 +106,7 @@ def save(file: FileStorage):
# try: # try:
# tosca_template_file_path = os.path.join(db_dir_path, file.filename) # tosca_template_file_path = os.path.join(db_dir_path, file.filename)
start = time.time() start = time.time()
logger.info("Got request for tosca template") logger.info("Got request for tosca template. File name: "+str(file.filename))
purge_all_tables() purge_all_tables()
dictionary = yaml.safe_load(file.stream) dictionary = yaml.safe_load(file.stream)
# dictionary = yaml.load(file.stream) # dictionary = yaml.load(file.stream)
......
...@@ -21,7 +21,7 @@ class TestDefaultController(BaseTestCase): ...@@ -21,7 +21,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_properties'.format( '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_properties'.format(
id=id_example, node_name='compute'), id=id_example, node_name='compute'),
...@@ -36,6 +36,7 @@ class TestDefaultController(BaseTestCase): ...@@ -36,6 +36,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_types'.format( '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_types'.format(
id=id_example, node_name='compute'), id=id_example, node_name='compute'),
...@@ -50,7 +51,7 @@ class TestDefaultController(BaseTestCase): ...@@ -50,7 +51,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_requirements'.format( '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_requirements'.format(
id=id_example, node_name='kubernetes'), id=id_example, node_name='kubernetes'),
...@@ -66,6 +67,7 @@ class TestDefaultController(BaseTestCase): ...@@ -66,6 +67,7 @@ class TestDefaultController(BaseTestCase):
""" """
# query_string = [('anchors', 'anchors_example'), ('derived_from', 'derived_from_example')] # query_string = [('anchors', 'anchors_example'), ('derived_from', 'derived_from_example')]
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/dsl_definitions'.format(id=id_example), '/tosca-sure/1.0.0/tosca_template/{id}/dsl_definitions'.format(id=id_example),
method='GET') method='GET')
...@@ -77,6 +79,7 @@ class TestDefaultController(BaseTestCase): ...@@ -77,6 +79,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/imports'.format(id=id_example), '/tosca-sure/1.0.0/tosca_template/{id}/imports'.format(id=id_example),
method='GET') method='GET')
...@@ -87,7 +90,8 @@ class TestDefaultController(BaseTestCase): ...@@ -87,7 +90,8 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_outputs.yaml')
self.assertTrue (id_example >= 0)
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/outputs'.format( '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/outputs'.format(
id=id_example, node_name='compute'), id=id_example, node_name='compute'),
...@@ -102,6 +106,7 @@ class TestDefaultController(BaseTestCase): ...@@ -102,6 +106,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/properties'.format( '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/properties'.format(
id=id_example, node_name='compute'), id=id_example, node_name='compute'),
...@@ -116,6 +121,7 @@ class TestDefaultController(BaseTestCase): ...@@ -116,6 +121,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/requirements'.format( '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/requirements'.format(
id=id_example, node_name='kubernetes'), id=id_example, node_name='kubernetes'),
...@@ -130,6 +136,7 @@ class TestDefaultController(BaseTestCase): ...@@ -130,6 +136,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
query_string = [('type_name', None), query_string = [('type_name', None),
('node_name', 'compute'), ('node_name', 'compute'),
('has_interfaces', True), ('has_interfaces', True),
...@@ -200,6 +207,7 @@ class TestDefaultController(BaseTestCase): ...@@ -200,6 +207,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/type_name'.format( '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/type_name'.format(
id=id_example, node_name='compute'), id=id_example, node_name='compute'),
...@@ -214,6 +222,7 @@ class TestDefaultController(BaseTestCase): ...@@ -214,6 +222,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/derived_from'.format( '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/derived_from'.format(
id=id_example, node_name='kubernetes'), id=id_example, node_name='kubernetes'),
...@@ -228,6 +237,7 @@ class TestDefaultController(BaseTestCase): ...@@ -228,6 +237,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/related'.format( '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/related'.format(
id=id_example, node_name='mysql'), id=id_example, node_name='mysql'),
...@@ -242,6 +252,7 @@ class TestDefaultController(BaseTestCase): ...@@ -242,6 +252,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
query_string = [('type_name', None), query_string = [('type_name', None),
('derived_from', None)] ('derived_from', None)]
response = self.client.open( response = self.client.open(
...@@ -256,6 +267,7 @@ class TestDefaultController(BaseTestCase): ...@@ -256,6 +267,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template'.format(id=id_example), '/tosca-sure/1.0.0/tosca_template/{id}/topology_template'.format(id=id_example),
method='GET') method='GET')
...@@ -269,6 +281,7 @@ class TestDefaultController(BaseTestCase): ...@@ -269,6 +281,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}'.format(id=id_example), '/tosca-sure/1.0.0/tosca_template/{id}'.format(id=id_example),
method='GET') method='GET')
...@@ -282,6 +295,7 @@ class TestDefaultController(BaseTestCase): ...@@ -282,6 +295,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
query_string = [('kind_of_type', 'interface_types'), query_string = [('kind_of_type', 'interface_types'),
('has_interfaces', None), ('has_interfaces', None),
('type_name', 'tosca.interfaces.ARTICONF.CloudsStorm'), ('type_name', 'tosca.interfaces.ARTICONF.CloudsStorm'),
...@@ -321,6 +335,7 @@ class TestDefaultController(BaseTestCase): ...@@ -321,6 +335,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
properties = {'properties': {'cpu_frequency': '2 GHz'}} properties = {'properties': {'cpu_frequency': '2 GHz'}}
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/properties'.format( '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/properties'.format(
...@@ -340,7 +355,7 @@ class TestDefaultController(BaseTestCase): ...@@ -340,7 +355,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates'.format(id=id_example), '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates'.format(id=id_example),
method='GET', method='GET',
...@@ -356,6 +371,7 @@ class TestDefaultController(BaseTestCase): ...@@ -356,6 +371,7 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file('application_example_2_topologies.yaml') id_example = self.upload_file('application_example_2_topologies.yaml')
self.assertTrue (id_example >= 0)
query_string = [('instance_name', 'instance_name_example'), query_string = [('instance_name', 'instance_name_example'),
('operation_name', 'provision')] ('operation_name', 'provision')]
response = self.client.open( response = self.client.open(
......
...@@ -2,12 +2,41 @@ import os ...@@ -2,12 +2,41 @@ import os
from unittest import TestCase from unittest import TestCase
from six import BytesIO from six import BytesIO
from werkzeug.datastructures import FileStorage from werkzeug.datastructures import FileStorage
import logging
from sure_tosca.models import ToscaTemplateModel from sure_tosca.models import ToscaTemplateModel
from sure_tosca.service import tosca_template_service from sure_tosca.service import tosca_template_service
logger = logging.getLogger(__name__)
if not getattr(logger, 'handler_set', None):
logger.setLevel(logging.INFO)
h = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
h.setFormatter(formatter)
logger.addHandler(h)
logger.handler_set = True
class Test(TestCase): class Test(TestCase):
def test_upload(self):
file_names = ['application_example_outputs.yaml','application_example_2_topologies.yaml','lifeWatch_vre1.yaml',
'application_example_updated.yaml','compute.yaml','application_example_provisioned.yaml','topology.yaml',
'kubernetes.yaml','application_example_planed.yaml']
for file_name in file_names:
logger.info("Testing : " + str(file_name))
doc_id = tosca_template_service.save(self.upload_file(file_name))
logger.info("doc_id : " + str(doc_id))
self.assertTrue (doc_id >= 0)
def test_get_tosca_template_model_by_id(self):
doc_id = tosca_template_service.save(self.upload_file('application_example_updated.yaml'))
tosca_template_dict = tosca_template_service.get_tosca_template_dict_by_id(doc_id)
tosca_template_model = ToscaTemplateModel.from_dict(tosca_template_dict)
self.assertIsNotNone(tosca_template_model)
self.assertIsNotNone(tosca_template_model.topology_template)
self.assertIsNotNone(tosca_template_model.topology_template.node_templates)
def test_get_tosca_template_model_by_id(self): def test_get_tosca_template_model_by_id(self):
doc_id = tosca_template_service.save(self.upload_file('application_example_updated.yaml')) doc_id = tosca_template_service.save(self.upload_file('application_example_updated.yaml'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment