Commit 2db19479 authored by Spiros Koulouzis's avatar Spiros Koulouzis

fixed null attributes bug

parent 3ec949cd
...@@ -225,8 +225,8 @@ public class ToscaHelper { ...@@ -225,8 +225,8 @@ public class ToscaHelper {
List<Map<String, Object>> definitions = getProvisionInterfaceDefinitions(toscaInterfaceTypes); List<Map<String, Object>> definitions = getProvisionInterfaceDefinitions(toscaInterfaceTypes);
Map<String, Object> definition = getBestProvisionInterfaceDefinition(definitions); Map<String, Object> definition = getBestProvisionInterfaceDefinition(definitions);
Map<String, Object> provisionInterface = getProvisionInterfaceInstance(definition, operation); Map<String, Object> provisionInterface = getProvisionInterfaceInstance(definition, operation);
vmTopologyMap.getNodeTemplate().setInterfaces(provisionInterface);
return null; return vmTopologyMap;
} }
private Map<String, Object> getBestProvisionInterfaceDefinition(List<Map<String, Object>> definitions) { private Map<String, Object> getBestProvisionInterfaceDefinition(List<Map<String, Object>> definitions) {
...@@ -240,10 +240,9 @@ public class ToscaHelper { ...@@ -240,10 +240,9 @@ public class ToscaHelper {
private Map<String, Object> getProvisionInterfaceInstance(Map<String, Object> definition, String operation) throws ApiException { private Map<String, Object> getProvisionInterfaceInstance(Map<String, Object> definition, String operation) throws ApiException {
String type = definition.keySet().iterator().next(); String type = definition.keySet().iterator().next();
String[] typeArray = type.split("."); String[] typeArray = type.split("\\.");
Map<String, Object> provisionInterface = api.getDefaultInterface(String.valueOf(id), type, typeArray[typeArray.length - 1], operation); Map<String, Object> provisionInterface = api.getDefaultInterface(String.valueOf(id), type, typeArray[typeArray.length - 1].toLowerCase(), operation);
return null; return provisionInterface;
} }
} }
...@@ -28,10 +28,14 @@ import java.net.HttpURLConnection; ...@@ -28,10 +28,14 @@ import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import nl.uva.sne.drip.model.NodeTemplate;
import nl.uva.sne.drip.model.NodeTemplateMap; import nl.uva.sne.drip.model.NodeTemplateMap;
import nl.uva.sne.drip.model.Provisioner;
import nl.uva.sne.drip.model.tosca.Credential;
import nl.uva.sne.drip.model.tosca.ToscaTemplate; import nl.uva.sne.drip.model.tosca.ToscaTemplate;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
...@@ -52,6 +56,7 @@ public class ToscaHelperTest { ...@@ -52,6 +56,7 @@ public class ToscaHelperTest {
private static ToscaHelper instance; private static ToscaHelper instance;
private static ToscaTemplate toscaTemplate; private static ToscaTemplate toscaTemplate;
private static Boolean serviceUp; private static Boolean serviceUp;
private ToscaTemplate toscaTemplateWithCredentials;
public ToscaHelperTest() { public ToscaHelperTest() {
} }
...@@ -148,4 +153,109 @@ public class ToscaHelperTest { ...@@ -148,4 +153,109 @@ public class ToscaHelperTest {
} }
return true; return true;
} }
/**
* Test of getTemplateVMsForVMTopology method, of class ToscaHelper.
*/
@Test
public void testGetTemplateVMsForVMTopology() throws Exception {
if (serviceUp) {
System.out.println("getTemplateVMsForVMTopology");
List<NodeTemplateMap> vmTopologyTemplatesMap = instance.getVMTopologyTemplates();
for (NodeTemplateMap nodeTemplateMap : vmTopologyTemplatesMap) {
List<NodeTemplateMap> result = instance.getTemplateVMsForVMTopology(nodeTemplateMap);
for (NodeTemplateMap mvmTopology : result) {
assertEquals("tosca.nodes.ARTICONF.VM.Compute", mvmTopology.getNodeTemplate().getType());
}
}
}
}
/**
* Test of setCredentialsInVMTopology method, of class ToscaHelper.
*
* @throws java.lang.Exception
*/
@Test
public void testSetCredentialsInVMTopology() throws Exception {
if (serviceUp) {
toscaTemplateWithCredentials = null;
System.out.println("setCredentialsInVMTopology");
List<NodeTemplateMap> vmTopologies = instance.getVMTopologyTemplates();
for (NodeTemplateMap vmTopologyMap : vmTopologies) {
String provider = instance.getTopologyProvider(vmTopologyMap);
Credential credential = new Credential();
credential.setCloudProviderName(provider);
credential.setProtocol("protocol");
Map<String, String> keys = new HashMap<>();
keys.put("key1", "eeeeeeavovfouirveiuvbepuyb8rwqovd8boacbdbvwy8oqry7f08r3euadinanzxcjc078yn0183xoqedw");
credential.setKeys(keys);
credential.setToken("ijwbfciweubfriw");
credential.setTokenType("passwrd");
credential.setUser("user");
vmTopologyMap = instance.setCredentialsInVMTopology(vmTopologyMap, credential);
toscaTemplateWithCredentials = instance.setVMTopologyInToscaTemplate(toscaTemplate, vmTopologyMap);
}
System.err.println(instance.getId());
instance.uploadToscaTemplate(toscaTemplateWithCredentials);
System.err.println(instance.getId());
NodeTemplate topology_1 = toscaTemplateWithCredentials.getTopologyTemplate().getNodeTemplates().get("topology_1");
Map<String, Object> attributes = topology_1.getAttributes();
assertNotNull(attributes);
assertNotNull(attributes.get("credential"));
NodeTemplate topology = toscaTemplateWithCredentials.getTopologyTemplate().getNodeTemplates().get("topology_1");
attributes = topology.getAttributes();
assertNotNull(attributes);
assertNotNull(attributes.get("credential"));
List<NodeTemplateMap> vmTopologiesMaps = instance.getVMTopologyTemplates();
for (NodeTemplateMap vmTopologyMap : vmTopologiesMaps) {
Credential toscaCredentials = instance.getCredentialsFromVMTopology(vmTopologyMap);
assertNotNull(toscaCredentials);
}
instance.uploadToscaTemplate(toscaTemplate);
}
}
/**
* Test of setVMTopologyInToscaTemplate method, of class ToscaHelper.
*/
@Test
public void testSetVMTopologyInToscaTemplate() {
System.out.println("setVMTopologyInToscaTemplate");
ToscaTemplate toscaTemplate = null;
NodeTemplateMap vmTopologyMap = null;
ToscaHelper instance = null;
ToscaTemplate expResult = null;
ToscaTemplate result = instance.setVMTopologyInToscaTemplate(toscaTemplate, vmTopologyMap);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of setProvisionerInterfaceInVMTopology method, of class ToscaHelper.
*/
@Test
public void testSetProvisionerInterfaceInVMTopology() throws Exception {
System.out.println("setProvisionerInterfaceInVMTopology");
NodeTemplateMap vmTopologyMap = null;
Provisioner provisioner = null;
String operation = "";
ToscaHelper instance = null;
NodeTemplateMap expResult = null;
NodeTemplateMap result = instance.setProvisionerInterfaceInVMTopology(vmTopologyMap, provisioner, operation);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
} }
...@@ -78,7 +78,7 @@ def get_default_interface(id, interface_type, instance_name, operation_name): # ...@@ -78,7 +78,7 @@ def get_default_interface(id, interface_type, instance_name, operation_name): #
:rtype: Dict[str, object] :rtype: Dict[str, object]
""" """
res = tosca_template_service.get_default_interface(id, interface_type, instance_name,operation_name) res = tosca_template_service.get_default_interface(id, interface_type, instance_name, operation_name)
if res: if res:
return res return res
return 'Not Found', 404 return 'Not Found', 404
...@@ -101,7 +101,6 @@ def get_default_node_type(id, node_type, instance_name): # noqa: E501 ...@@ -101,7 +101,6 @@ def get_default_node_type(id, node_type, instance_name): # noqa: E501
return 'do some magic!' return 'do some magic!'
def get_dsl_definitions(id, anchors=None, derived_from=None): # noqa: E501 def get_dsl_definitions(id, anchors=None, derived_from=None): # noqa: E501
""" """
......
...@@ -76,11 +76,23 @@ def get_tosca_template_dict_by_id(id): ...@@ -76,11 +76,23 @@ def get_tosca_template_dict_by_id(id):
return tosca_template_dict return tosca_template_dict
def purge_all_tables():
node_template_db.purge_tables()
dsl_definitions_db.purge_tables()
relationship_template_db.purge_tables()
interface_types_db.purge_tables()
node_template_db.close()
dsl_definitions_db.close()
relationship_template_db.close()
interface_types_db.close()
def save(file): def save(file):
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)
purge_all_tables()
dictionary = yaml.safe_load(file.stream) dictionary = yaml.safe_load(file.stream)
print(yaml.dump(dictionary))
tosca_template = ToscaTemplate(yaml_dict_tpl=copy.deepcopy(dictionary)) tosca_template = ToscaTemplate(yaml_dict_tpl=copy.deepcopy(dictionary))
tosca_template_model = ToscaTemplateModel.from_dict(dictionary) tosca_template_model = ToscaTemplateModel.from_dict(dictionary)
doc_id = tosca_templates_db.insert(dictionary) doc_id = tosca_templates_db.insert(dictionary)
...@@ -409,7 +421,7 @@ def merge_interfaces(id, interface_type): ...@@ -409,7 +421,7 @@ def merge_interfaces(id, interface_type):
if all_interfaces is None: if all_interfaces is None:
return None return None
all_inputs= {} all_inputs = {}
all_operations = {} all_operations = {}
for interface in all_interfaces: for interface in all_interfaces:
interface = interface[next(iter(interface))] interface = interface[next(iter(interface))]
......
...@@ -126,7 +126,7 @@ paths: ...@@ -126,7 +126,7 @@ paths:
"405": "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/interface/{interface_type}/defaults: /tosca_template/{id}/interface/{interface_type}/default:
get: get:
summary: "" summary: ""
description: "returns an interface instance with the default required values." description: "returns an interface instance with the default required values."
...@@ -167,7 +167,7 @@ paths: ...@@ -167,7 +167,7 @@ paths:
"405": "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/node_types/{node_type}/defaults: /tosca_template/{id}/node_types/{node_type}/default:
get: get:
summary: "" summary: ""
description: "returns an node templaye instance with the default required values." description: "returns an node templaye instance with the default required values."
......
...@@ -316,21 +316,6 @@ class TestDefaultController(BaseTestCase): ...@@ -316,21 +316,6 @@ class TestDefaultController(BaseTestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertIsInstance(response.json, list) self.assertIsInstance(response.json, list)
# def test_upload_tosca_template(self):
# """Test case for upload_tosca_template
#
# upload a tosca template description file
# """
# data = dict(file=(BytesIO(b'some file data'), 'file.txt'))
# response = self.client.open(
# '/tosca-sure/1.0.0/tosca_template',
# method='POST',
# data=data,
# content_type='multipart/form-data')
# self.assert200(response,
# 'Response body is : ' + response.data.decode('utf-8'))
def upload_file(self): def upload_file(self):
tosca_path = "../../../TOSCA/" tosca_path = "../../../TOSCA/"
...@@ -354,6 +339,23 @@ class TestDefaultController(BaseTestCase): ...@@ -354,6 +339,23 @@ class TestDefaultController(BaseTestCase):
file_id = response.data.decode('utf-8').replace('\n', '') file_id = response.data.decode('utf-8').replace('\n', '')
return file_id return file_id
def test_get_default_interface(self):
"""Test case for get_default_interface
"""
id_example = self.upload_file()
query_string = [('instance_name', 'instance_name_example'),
('operation_name', 'provision')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/interface/{interface_type}/default'.format(id=id_example,
interface_type='tosca.interfaces.ARTICONF.CloudsStorm'),
method='GET',
query_string=query_string)
self.assertTrue(response.is_json)
self.assertEqual(response.status_code, 200)
self.assertIsInstance(response.json, dict)
if __name__ == '__main__': if __name__ == '__main__':
import unittest import unittest
......
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