Commit 163e531e authored by Spiros Koulouzis's avatar Spiros Koulouzis

added tests

parent 8650a4b3
...@@ -10,12 +10,12 @@ topology_template: ...@@ -10,12 +10,12 @@ topology_template:
Standard: Standard:
create: dumy.yaml create: dumy.yaml
properties: properties:
cpu_frequency: 0.5 GHz disk_size: 50000 MB
disk_size: 15000 MB
host_name: vm host_name: vm
mem_size: 500 MB mem_size: 6000 MB
num_cpus: 1 num_cores: 2
os: ubuntu 15 os: ubuntu 16
role: master
user_name: vm_user user_name: vm_user
type: tosca.nodes.ARTICONF.VM.Compute type: tosca.nodes.ARTICONF.VM.Compute
compute_1: compute_1:
...@@ -23,15 +23,24 @@ topology_template: ...@@ -23,15 +23,24 @@ topology_template:
Standard: Standard:
create: dumy.yaml create: dumy.yaml
properties: properties:
cpu_frequency: 0.5 GHz disk_size: 50000 MB
disk_size: 15000 MB
host_name: vm host_name: vm
mem_size: 500 MB mem_size: 6000 MB
num_cpus: 1 num_cores: 2
os: ubuntu 15 os: ubuntu 16
role: worker role: worker
user_name: vm_user user_name: vm_user
type: tosca.nodes.ARTICONF.VM.Compute type: tosca.nodes.ARTICONF.VM.Compute
kubernetes:
interfaces:
Standard:
create: interfaces/playbooks/kubernetes_install.yaml
requirements:
- host:
capability: tosca.capabilities.ARTICONF.VM.topology
node: topology
relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Orchestrator.Kubernetes
mysql: mysql:
artifacts: artifacts:
image: image:
...@@ -51,48 +60,24 @@ topology_template: ...@@ -51,48 +60,24 @@ topology_template:
requirements: requirements:
- host: - host:
capability: tosca.capabilities.ARTICONF.Orchestrator capability: tosca.capabilities.ARTICONF.Orchestrator
node: swarm node: kubernetes
relationship: tosca.relationships.HostedOn
- useless:
capability: tosca.capabilities.ARTICONF.Useless
node: swarm
relationship: tosca.relationships.HostedOn relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Container.Application.Docker type: tosca.nodes.ARTICONF.Container.Application.Docker
swarm:
interfaces:
Standard:
create: interfaces/playbooks/docker_swarm_install.yaml
properties:
masters_num: 1
workers_num: 1
requirements:
- host:
capability: tosca.capabilities.Scalable
node: topology
relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Orchestrator.Swarm
topology: topology:
interfaces: interfaces:
Standard: Standard:
create: dumy.yaml create: dumy.yaml
properties: properties:
domain: {} domain: UvA (Amsterdam, The Netherlands) XO Rack
name: {} provider: ExoGeni
provider: {}
requirements: requirements:
- vm: - vm:
capability: tosca.capabilities.ARTICONF.VM capability: tosca.capabilities.ARTICONF.VM
node: compute node: compute
occurrences:
- 1
- UNBOUNDED
relationship: tosca.relationships.DependsOn relationship: tosca.relationships.DependsOn
- vm: - vm:
capability: tosca.capabilities.ARTICONF.VM capability: tosca.capabilities.ARTICONF.VM
node: compute_1 node: compute_1
occurrences:
- 1
- UNBOUNDED
relationship: tosca.relationships.DependsOn relationship: tosca.relationships.DependsOn
type: tosca.nodes.ARTICONF.VM.topology type: tosca.nodes.ARTICONF.VM.topology
wordpress: wordpress:
...@@ -116,11 +101,7 @@ topology_template: ...@@ -116,11 +101,7 @@ topology_template:
type: tosca.relationships.DependsOn type: tosca.relationships.DependsOn
- host: - host:
capability: tosca.capabilities.ARTICONF.Orchestrator capability: tosca.capabilities.ARTICONF.Orchestrator
node: swarm node: kubernetes
relationship: tosca.relationships.HostedOn
- useless:
capability: tosca.capabilities.ARTICONF.Useless
node: swarm
relationship: tosca.relationships.HostedOn relationship: tosca.relationships.HostedOn
type: tosca.nodes.ARTICONF.Container.Application.Docker type: tosca.nodes.ARTICONF.Container.Application.Docker
policies: policies:
......
...@@ -2,8 +2,13 @@ ...@@ -2,8 +2,13 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment=""> <list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/../TOSCA/application_example_output.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../TOSCA/application_example_output.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/planner/planner.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/planner.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/planner/simple_spec_alayzer.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/simple_spec_alayzer.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/planner/simple_spec_alayzer.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/simple_spec_alayzer.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/rpc_server.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/rpc_server.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test_planner.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/tests/test_planner.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/utils/tosca.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils/tosca.py" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
...@@ -39,6 +44,9 @@ ...@@ -39,6 +44,9 @@
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" /> <property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
</component> </component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src/tests" />
</key>
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src/planner" /> <recent name="$PROJECT_DIR$/src/planner" />
</key> </key>
...@@ -90,7 +98,7 @@ ...@@ -90,7 +98,7 @@
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/rpc_server.py" /> <option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/rpc_server.py" />
<option name="PARAMETERS" value="test_local" /> <option name="PARAMETERS" value="localhost planner_queue" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" /> <option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" /> <option name="MODULE_MODE" value="false" />
...@@ -110,7 +118,7 @@ ...@@ -110,7 +118,7 @@
<option name="IS_MODULE_SDK" value="true" /> <option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/test_planner.py" /> <option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/tests/test_planner.py" />
<option name="PARAMETERS" value="" /> <option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" /> <option name="EMULATE_TERMINAL" value="false" />
...@@ -119,9 +127,24 @@ ...@@ -119,9 +127,24 @@
<option name="INPUT_FILE" value="" /> <option name="INPUT_FILE" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="Unittests in tests" type="tests" factoryName="Unittests" temporary="true" nameIsGenerated="true">
<module name="drip_planner2" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/src/tests" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="_new_additionalArguments" value="&quot;&quot;" />
<option name="_new_target" value="&quot;$PROJECT_DIR$/src/tests&quot;" />
<option name="_new_targetType" value="&quot;PATH&quot;" />
<method v="2" />
</configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Python.rpc_server" /> <item itemvalue="Python.rpc_server" />
<item itemvalue="Python tests.Unittests in tests" />
<item itemvalue="Python.test_planner" /> <item itemvalue="Python.test_planner" />
<item itemvalue="Python.basic_planner" /> <item itemvalue="Python.basic_planner" />
</list> </list>
...@@ -257,7 +280,14 @@ ...@@ -257,7 +280,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1571757387680</updated> <updated>1571757387680</updated>
</task> </task>
<option name="localTasksCounter" value="18" /> <task id="LOCAL-00018" summary="check if topology node has properties">
<created>1571760668434</created>
<option name="number" value="00018" />
<option name="presentableId" value="LOCAL-00018" />
<option name="project" value="LOCAL" />
<updated>1571760668434</updated>
</task>
<option name="localTasksCounter" value="19" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
...@@ -290,7 +320,8 @@ ...@@ -290,7 +320,8 @@
<MESSAGE value="set min number of VMs based on the swarm default workers and masters" /> <MESSAGE value="set min number of VMs based on the swarm default workers and masters" />
<MESSAGE value="fixed policies error" /> <MESSAGE value="fixed policies error" />
<MESSAGE value="added test" /> <MESSAGE value="added test" />
<option name="LAST_COMMIT_MESSAGE" value="added test" /> <MESSAGE value="check if topology node has properties" />
<option name="LAST_COMMIT_MESSAGE" value="check if topology node has properties" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>
...@@ -305,11 +336,6 @@ ...@@ -305,11 +336,6 @@
<line>22</line> <line>22</line>
<option name="timeStamp" value="128" /> <option name="timeStamp" value="128" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/rpc_server.py</url>
<line>136</line>
<option name="timeStamp" value="295" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line"> <line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/rpc_server.py</url> <url>file://$PROJECT_DIR$/src/rpc_server.py</url>
<line>106</line> <line>106</line>
...@@ -317,13 +343,8 @@ ...@@ -317,13 +343,8 @@
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line"> <line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/rpc_server.py</url> <url>file://$PROJECT_DIR$/src/rpc_server.py</url>
<line>99</line> <line>138</line>
<option name="timeStamp" value="303" /> <option name="timeStamp" value="305" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/planner/simple_spec_alayzer.py</url>
<line>24</line>
<option name="timeStamp" value="304" />
</line-breakpoint> </line-breakpoint>
</breakpoints> </breakpoints>
<default-breakpoints> <default-breakpoints>
......
...@@ -5,11 +5,11 @@ from toscaparser.topology_template import TopologyTemplate ...@@ -5,11 +5,11 @@ from toscaparser.topology_template import TopologyTemplate
import operator import operator
from planner.simple_spec_alayzer import SimpleAnalyzer from src.planner.simple_spec_alayzer import SimpleAnalyzer
from planner.spec_service import * from src.planner.spec_service import *
from utils.tosca import * from src.utils.tosca import *
from planner.specification_analyzer import * from src.planner.specification_analyzer import *
from utils import tosca as tosca_util from src.utils import tosca as tosca_util
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
......
...@@ -31,7 +31,6 @@ class SimpleAnalyzer(SpecificationAnalyzer): ...@@ -31,7 +31,6 @@ class SimpleAnalyzer(SpecificationAnalyzer):
masters_num = orchestrator_nodes[0].get_property_value('masters_num') masters_num = orchestrator_nodes[0].get_property_value('masters_num')
workers_num = orchestrator_nodes[0].get_property_value('workers_num') workers_num = orchestrator_nodes[0].get_property_value('workers_num')
topology_nodes = tosca_util.get_nodes_by_type('tosca.nodes.ARTICONF.VM.topology', topology_nodes = tosca_util.get_nodes_by_type('tosca.nodes.ARTICONF.VM.topology',
self.tosca_template.nodetemplates, self.all_node_types, self.tosca_template.nodetemplates, self.all_node_types,
self.all_custom_def) self.all_custom_def)
......
...@@ -98,7 +98,7 @@ def handle_delivery(message): ...@@ -98,7 +98,7 @@ def handle_delivery(message):
logger.info("template ----: \n" + yaml.dump(template_dict)) logger.info("template ----: \n" + yaml.dump(template_dict))
response = {'toscaTemplate': template_dict} response = {'toscaTemplate': template_dict}
output_current_milli_time = lambda: int(round(time.time() * 1000)) output_current_milli_time = int(round(time.time() * 1000))
response["creationDate"] = output_current_milli_time response["creationDate"] = output_current_milli_time
response["parameters"] = [] response["parameters"] = []
if queue_name == "planner_queue": if queue_name == "planner_queue":
...@@ -118,7 +118,7 @@ if __name__ == "__main__": ...@@ -118,7 +118,7 @@ if __name__ == "__main__":
test_planner = Planner(input_tosca_file_path, spec_service) test_planner = Planner(input_tosca_file_path, spec_service)
test_tosca_template = test_planner.resolve_requirements() test_tosca_template = test_planner.resolve_requirements()
test_tosca_template = test_planner.set_infrastructure_specifications() test_tosca_template = test_planner.set_infrastructure_specifications()
template = tosca_util.get_tosca_template_2_topology_template_dictionary(test_tosca_template) template_dict = tosca_util.get_tosca_template_2_topology_template_dictionary(test_tosca_template)
logger.info("template ----: \n" + yaml.dump(template)) logger.info("template ----: \n" + yaml.dump(template))
try: try:
...@@ -132,9 +132,12 @@ if __name__ == "__main__": ...@@ -132,9 +132,12 @@ if __name__ == "__main__":
input_tosca_file_path = tosca_path + '/application_example_output.yaml' input_tosca_file_path = tosca_path + '/application_example_output.yaml'
with open(input_tosca_file_path, 'w') as outfile: with open(input_tosca_file_path, 'w') as outfile:
outfile.write(yaml.dump(template)) outfile.write(yaml.dump(template_dict))
ToscaTemplate(input_tosca_file_path) ToscaTemplate(input_tosca_file_path)
test_response = {'toscaTemplate': template_dict}
logger.info("Output message:" + json.dumps(test_response))
else: else:
logger.info("Input args: " + sys.argv[0] + ' ' + sys.argv[1] + ' ' + sys.argv[2]) logger.info("Input args: " + sys.argv[0] + ' ' + sys.argv[1] + ' ' + sys.argv[2])
channel = init_chanel(sys.argv) channel = init_chanel(sys.argv)
......
import json
import logging
import os import os
import os.path import os.path
import tempfile import tempfile
import time
import unittest import unittest
from planner.planner import * from src.planner.planner import *
from planner.spec_service import SpecService from src.planner.spec_service import SpecService
from utils import tosca as tosca_util from src.utils import tosca as tosca_util
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
def test_something(self): def test_something(self):
tosca_path = "../../TOSCA/" logger = logging.getLogger(__name__)
tosca_file_path = tosca_path+'/application_example_updated.yaml' tosca_path = "../../../TOSCA/"
input_tosca_file_path = tosca_path + '/application_example.yaml'
dir_path = os.path.dirname(os.path.realpath(__file__))
print(dir_path)
self.assertEqual(True, os.path.exists(input_tosca_file_path),
"Input TOSCA file: " + input_tosca_file_path + " not found")
conf = {'url': "http://host"} conf = {'url': "http://host"}
spec_service = SpecService(conf) spec_service = SpecService(conf)
test_planner = Planner(tosca_file_path, spec_service) test_planner = Planner(input_tosca_file_path, spec_service)
tosca_template = test_planner.resolve_requirements() test_tosca_template = test_planner.resolve_requirements()
tosca_template = test_planner.set_infrastructure_specifications() test_tosca_template = test_planner.set_infrastructure_specifications()
template = tosca_util.get_tosca_template_2_topology_template_dictionary(tosca_template) template_dict = tosca_util.get_tosca_template_2_topology_template_dictionary(test_tosca_template)
# logger.info("template ----: \n" + yaml.dump(template)) logger.info("template ----: \n" + yaml.dump(template_dict))
try: try:
tosca_folder_path = os.path.join(tempfile.gettempdir(), tosca_path) tosca_folder_path = os.path.join(tempfile.gettempdir(), tosca_path)
...@@ -28,10 +39,18 @@ class MyTestCase(unittest.TestCase): ...@@ -28,10 +39,18 @@ class MyTestCase(unittest.TestCase):
tosca_folder_path = os.path.dirname(os.path.abspath(sys.argv[0])) + os.path.join(tempfile.gettempdir(), tosca_folder_path = os.path.dirname(os.path.abspath(sys.argv[0])) + os.path.join(tempfile.gettempdir(),
tosca_path) tosca_path)
tosca_file_name = 'tosca_template' tosca_file_name = 'tosca_template'
input_tosca_file_path = tosca_path+'/application_example_output.yaml' input_tosca_file_path = tosca_path + '/application_example_output.yaml'
with open(input_tosca_file_path, 'w') as outfile: with open(input_tosca_file_path, 'w') as outfile:
outfile.write(yaml.dump(template)) outfile.write(yaml.dump(template_dict))
ToscaTemplate(input_tosca_file_path) ToscaTemplate(input_tosca_file_path)
test_response = {'toscaTemplate': template_dict}
response = {'toscaTemplate': template_dict}
output_current_milli_time = int(round(time.time() * 1000))
response["creationDate"] = output_current_milli_time
response["parameters"] = []
print("Output message:" + json.dumps(response))
self.assertEqual(True, True) self.assertEqual(True, True)
...@@ -5,7 +5,7 @@ from toscaparser import tosca_template ...@@ -5,7 +5,7 @@ from toscaparser import tosca_template
from toscaparser.elements.nodetype import NodeType from toscaparser.elements.nodetype import NodeType
from toscaparser.nodetemplate import NodeTemplate from toscaparser.nodetemplate import NodeTemplate
from utils.TOSCA_parser import TOSCAParser from src.utils.TOSCA_parser import TOSCAParser
import yaml import yaml
import logging import logging
......
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