Commit aa0d2e03 authored by Spiros Koulouzis's avatar Spiros Koulouzis

fixed bug on returning list instead of model

parent 534906e7
......@@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.6 (deployer)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.8 (deployer)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (deployer)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (deployer)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
......@@ -50,11 +50,17 @@ class TestDeployer(unittest.TestCase):
tosca_client = self.init_sure_tosca_client('http://localhost:8081/tosca-sure/1.0.0/')
tosca_client = self.init_sure_tosca_client('http://localhost:8081/tosca-sure/1.0.0')
doc_id = self.upload_tosca_template(tosca_template_path,tosca_client)
self.assertIsNotNone(doc_id)
tosca_interfaces = tosca_client.get_tosca_template(doc_id).get
nodes_to_deploy = tosca_client.get_node_templates(doc_id,type_name='tosca.nodes.ARTICONF.Application')
self.assertIsNotNone(nodes_to_deploy)
nodes_to_deploy_ordered = []
for node in nodes_to_deploy:
related_nodes = tosca_client.get_related_nodes(doc_id,node.name)
for related_node in related_nodes:
print(related_node)
# tmp_path = tempfile.mkdtemp()
# vms = tosca.get_vms(tosca_template_dict)
# inventory_path = ansible_service.write_inventory_file(tmp_path, vms)
......
......@@ -2,11 +2,12 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="3f84153d-6ed1-4691-94d6-53105266f15e" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/../commons/src/main/java/nl/uva/sne/drip/sure/tosca/client/ApiClient.java" beforeDir="false" afterPath="$PROJECT_DIR$/../commons/src/main/java/nl/uva/sne/drip/sure/tosca/client/ApiClient.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../commons/src/test/java/nl/uva/sne/drip/sure_tosca/client/DefaultApiTest.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../deployer/test/test_deployer.py" beforeDir="false" afterPath="$PROJECT_DIR$/../deployer/test/test_deployer.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/sure_tosca_client/api_client.py" beforeDir="false" afterPath="$PROJECT_DIR$/sure_tosca_client/api_client.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test/test_default_api.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/test_default_api.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/service/tosca_template_service.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/service/tosca_template_service.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/test/test_default_controller.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/test/test_default_controller.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -67,38 +68,38 @@
<screen x="67" y="34" width="1853" height="1046" />
</state>
<state x="723" y="257" width="530" height="598" key="FileChooserDialogImpl/67.34.1853.1046@67.34.1853.1046" timestamp="1584814061190" />
<state width="1825" height="307" key="GridCell.Tab.0.bottom" timestamp="1585229908006">
<state width="1825" height="257" key="GridCell.Tab.0.bottom" timestamp="1585306552985">
<screen x="67" y="34" width="1853" height="1046" />
</state>
<state width="1825" height="307" key="GridCell.Tab.0.bottom/67.34.1853.1046@67.34.1853.1046" timestamp="1585229908006" />
<state width="1825" height="307" key="GridCell.Tab.0.center" timestamp="1585229908006">
<state width="1825" height="257" key="GridCell.Tab.0.bottom/67.34.1853.1046@67.34.1853.1046" timestamp="1585306552985" />
<state width="1825" height="257" key="GridCell.Tab.0.center" timestamp="1585306552983">
<screen x="67" y="34" width="1853" height="1046" />
</state>
<state width="1825" height="307" key="GridCell.Tab.0.center/67.34.1853.1046@67.34.1853.1046" timestamp="1585229908006" />
<state width="1825" height="307" key="GridCell.Tab.0.left" timestamp="1585229908006">
<state width="1825" height="257" key="GridCell.Tab.0.center/67.34.1853.1046@67.34.1853.1046" timestamp="1585306552983" />
<state width="1825" height="257" key="GridCell.Tab.0.left" timestamp="1585306552983">
<screen x="67" y="34" width="1853" height="1046" />
</state>
<state width="1825" height="307" key="GridCell.Tab.0.left/67.34.1853.1046@67.34.1853.1046" timestamp="1585229908006" />
<state width="1825" height="307" key="GridCell.Tab.0.right" timestamp="1585229908006">
<state width="1825" height="257" key="GridCell.Tab.0.left/67.34.1853.1046@67.34.1853.1046" timestamp="1585306552983" />
<state width="1825" height="257" key="GridCell.Tab.0.right" timestamp="1585306552984">
<screen x="67" y="34" width="1853" height="1046" />
</state>
<state width="1825" height="307" key="GridCell.Tab.0.right/67.34.1853.1046@67.34.1853.1046" timestamp="1585229908006" />
<state width="1825" height="166" key="GridCell.Tab.1.bottom" timestamp="1585229893964">
<state width="1825" height="257" key="GridCell.Tab.0.right/67.34.1853.1046@67.34.1853.1046" timestamp="1585306552984" />
<state width="1825" height="383" key="GridCell.Tab.1.bottom" timestamp="1585306552969">
<screen x="67" y="34" width="1853" height="1046" />
</state>
<state width="1825" height="166" key="GridCell.Tab.1.bottom/67.34.1853.1046@67.34.1853.1046" timestamp="1585229893964" />
<state width="1825" height="166" key="GridCell.Tab.1.center" timestamp="1585229893964">
<state width="1825" height="383" key="GridCell.Tab.1.bottom/67.34.1853.1046@67.34.1853.1046" timestamp="1585306552969" />
<state width="1825" height="383" key="GridCell.Tab.1.center" timestamp="1585306552966">
<screen x="67" y="34" width="1853" height="1046" />
</state>
<state width="1825" height="166" key="GridCell.Tab.1.center/67.34.1853.1046@67.34.1853.1046" timestamp="1585229893964" />
<state width="1825" height="166" key="GridCell.Tab.1.left" timestamp="1585229893964">
<state width="1825" height="383" key="GridCell.Tab.1.center/67.34.1853.1046@67.34.1853.1046" timestamp="1585306552966" />
<state width="1825" height="383" key="GridCell.Tab.1.left" timestamp="1585306552965">
<screen x="67" y="34" width="1853" height="1046" />
</state>
<state width="1825" height="166" key="GridCell.Tab.1.left/67.34.1853.1046@67.34.1853.1046" timestamp="1585229893964" />
<state width="1825" height="166" key="GridCell.Tab.1.right" timestamp="1585229893964">
<state width="1825" height="383" key="GridCell.Tab.1.left/67.34.1853.1046@67.34.1853.1046" timestamp="1585306552965" />
<state width="1825" height="383" key="GridCell.Tab.1.right" timestamp="1585306552968">
<screen x="67" y="34" width="1853" height="1046" />
</state>
<state width="1825" height="166" key="GridCell.Tab.1.right/67.34.1853.1046@67.34.1853.1046" timestamp="1585229893964" />
<state width="1825" height="383" key="GridCell.Tab.1.right/67.34.1853.1046@67.34.1853.1046" timestamp="1585306552968" />
<state x="359" y="103" key="SettingsEditor" timestamp="1584813615342">
<screen x="67" y="34" width="1853" height="1046" />
</state>
......@@ -108,20 +109,4 @@
</state>
<state x="563" y="235" width="1053" height="732" key="find.popup/67.34.1853.1046@67.34.1853.1046" timestamp="1584900160970" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/test/test_default_api.py</url>
<line>158</line>
<option name="timeStamp" value="3" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/sure_tosca_client/api_client.py</url>
<line>367</line>
<option name="timeStamp" value="5" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>
\ No newline at end of file
......@@ -26,7 +26,7 @@ from six.moves.urllib.parse import quote
from sure_tosca_client.configuration import Configuration
import sure_tosca_client.models
from sure_tosca_client import rest
from sure_tosca_client import rest, models
class ApiClient(object):
......@@ -267,7 +267,7 @@ class ApiClient(object):
if klass in self.NATIVE_TYPES_MAPPING:
klass = self.NATIVE_TYPES_MAPPING[klass]
else:
klass = getattr(swagger_client.models, klass)
klass = getattr(models, klass)
if klass in self.PRIMITIVE_TYPES:
return self.__deserialize_primitive(data, klass)
......
......@@ -94,7 +94,13 @@ class TestDefaultApi(unittest.TestCase):
"""Test case for get_node_templates
"""
pass
file_id = self.upload_tosca_template('application_example_provisioned.yaml')
node_templates = self.api.get_node_templates(file_id)
self.assertIsNotNone(node_templates)
nodes_to_deploy = self.api.get_node_templates(file_id,type_name = 'tosca.nodes.ARTICONF.Application')
def test_get_node_type_name(self):
"""Test case for get_node_type_name
......@@ -156,8 +162,7 @@ class TestDefaultApi(unittest.TestCase):
upload a tosca template description file # noqa: E501
"""
file_id = self.upload_tosca_template("application_example_provisioned.yaml")
file_id = self.upload_tosca_template('application_example_provisioned.yaml')
self.assertIsNotNone(file_id)
def get_tosca_file(self, file_name):
......@@ -173,7 +178,7 @@ class TestDefaultApi(unittest.TestCase):
return input_tosca_file_path
def upload_tosca_template(self, file_name):
file = self.get_tosca_file("application_example_provisioned.yaml")
file = self.get_tosca_file(file_name)
file_id = self.api.upload_tosca_template(file)
return file_id
......
......@@ -164,17 +164,25 @@ def change_to_node_template_model(query_results):
return res
def get_node_templates_with_ancestor_types(id, type_name):
query_results = []
node_templates = get_node_templates(id)
if node_templates:
for node_template in node_templates:
ancestor_types = get_all_ancestor_types(id, node_template.name)
for ancestor_type in ancestor_types:
if ancestor_type == type_name and node_template not in query_results:
query_results.append(node_template)
break
return query_results
def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None, has_properties=None,
has_attributes=None,
has_requirements=None, has_capabilities=None, has_artifacts=None):
if len(node_template_db) <= 1:
tosca_template_model = get_tosca_template_model_by_id(id)
object_list = tosca_template_model.topology_template.node_templates
# tosca_template = get_tosca_template(tosca_template_model.to_dict())
# tosca_node_types = tosca_template.nodetemplates[0].type_definition.TOSCA_DEF
# all_custom_def = tosca_template.nodetemplates[0].custom_def
# object_list.update(tosca_node_types)
# object_list.update(all_custom_def)
if object_list:
for key in object_list:
node = {root_key: key}
......@@ -222,6 +230,10 @@ def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None,
queries.append(query.artifacts != prop)
query_results = query_db(queries, db=node_template_db)
if type_name and not query_results:
query_results = get_node_templates_with_ancestor_types(id,type_name)
return query_results
if query_results:
return change_to_node_template_model(query_results)
else:
......@@ -381,8 +393,8 @@ def get_related_nodes(id, node_name):
related_nodes = []
for name in related_node_names:
related_node = get_node_templates(id, node_name=name)
related_nodes.append(related_node)
related_nodes = related_nodes + related_node
logger.info('Node: '+node_name +' has related nodes: '+str(related_nodes))
return related_nodes
......
......@@ -178,6 +178,22 @@ class TestDefaultController(BaseTestCase):
self.assertEqual(response.status_code, 200)
self.assertIsInstance(response.json, list)
query_string = [('type_name', 'tosca.nodes.ARTICONF.Application'),
('node_name', None),
('has_interfaces', True),
('has_properties', None),
('has_attributes', None),
('has_requirements', None),
('has_capabilities', None),
('has_artifacts', None)]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates'.format(id=id_example),
method='GET',
query_string=query_string)
self.assertTrue(response.is_json)
self.assertEqual(response.status_code, 200)
self.assertIsInstance(response.json, list)
def test_get_node_type_name(self):
"""Test case for get_node_type_name
......
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