diff options
author | Michael Lando <ml636r@att.com> | 2017-02-19 12:35:04 +0200 |
---|---|---|
committer | Michael Lando <ml636r@att.com> | 2017-02-19 12:35:04 +0200 |
commit | f5f13c4f6b6fe3b4d98e349dfd7db59339803436 (patch) | |
tree | 72caffc93fab394ffa3b761505775331f1c559b9 /openecomp-be/lib/openecomp-tosca-lib/src/test | |
parent | 451a3400b76511393c62a444f588a4ed15f4a549 (diff) |
push addional code
Change-Id: Ia427bb3460cda3a896f8faced2de69eaf3807b74
Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/test')
25 files changed, 3464 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/TestUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/TestUtil.java new file mode 100644 index 0000000000..da3ae76f27 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/TestUtil.java @@ -0,0 +1,71 @@ +package org.openecomp.sdc.tosca; + +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.services.yamlutil.ToscaExtensionYamlUtil; + +import java.io.*; +import java.net.URL; +import java.nio.file.NotDirectoryException; +import java.util.HashMap; +import java.util.Map; + +public class TestUtil { + + public static ToscaServiceModel loadToscaServiceModel(String serviceTemplatesPath, + String globalServiceTemplatesPath, + String entryDefinitionServiceTemplate) + throws IOException { + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + Map<String, ServiceTemplate> serviceTemplates = new HashMap<>(); + if (entryDefinitionServiceTemplate == null) { + entryDefinitionServiceTemplate = "MainServiceTemplate.yaml"; + } + + loadServiceTemplates(serviceTemplatesPath, toscaExtensionYamlUtil, serviceTemplates); + if (globalServiceTemplatesPath != null) { + loadServiceTemplates(globalServiceTemplatesPath, toscaExtensionYamlUtil, serviceTemplates); + } + + return new ToscaServiceModel(null, serviceTemplates, entryDefinitionServiceTemplate); + } + + private static void loadServiceTemplates(String serviceTemplatesPath, + ToscaExtensionYamlUtil toscaExtensionYamlUtil, + Map<String, ServiceTemplate> serviceTemplates) + throws IOException { + URL urlFile = TestUtil.class.getResource(serviceTemplatesPath); + if (urlFile != null) { + File pathFile = new File(urlFile.getFile()); + File[] files = pathFile.listFiles(); + if (files != null) { + addServiceTemplateFiles(serviceTemplates, files, toscaExtensionYamlUtil); + } else { + throw new NotDirectoryException(serviceTemplatesPath); + } + } else { + throw new NotDirectoryException(serviceTemplatesPath); + } + } + + private static void addServiceTemplateFiles(Map<String, ServiceTemplate> serviceTemplates, + File[] files, + ToscaExtensionYamlUtil toscaExtensionYamlUtil) + throws IOException { + for (File file : files) { + try (InputStream yamlFile = new FileInputStream(file)) { + ServiceTemplate serviceTemplateFromYaml = + toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); + serviceTemplates.put(file.getName(), serviceTemplateFromYaml); + try { + yamlFile.close(); + } catch (IOException ignore) { + } + } catch (FileNotFoundException e) { + throw e; + } catch (IOException e) { + throw e; + } + } + } +} diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/PropertyTypeTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/PropertyTypeTest.java new file mode 100644 index 0000000000..470dd9784a --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/PropertyTypeTest.java @@ -0,0 +1,20 @@ +package org.openecomp.sdc.tosca.datatypes; + +import org.openecomp.sdc.tosca.datatypes.model.PropertyType; +import org.junit.Assert; +import org.junit.Test; + +public class PropertyTypeTest { + @Test + public void shouldReturnNullWhenDisplayNameDoesNotExistForAnyProperty() { + String s = "blabla"; + Assert.assertEquals(PropertyType.getPropertyTypeByDisplayName(s), null); + } + + @Test + public void shouldReturnApproppriatePropertyTypeWhenDisplayNameExist() { + String s = "scalar-unit.size"; + Assert + .assertEquals(PropertyType.getPropertyTypeByDisplayName(s), PropertyType.SCALAR_UNIT_SIZE); + } +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java new file mode 100644 index 0000000000..13b05543fb --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java @@ -0,0 +1,282 @@ +package org.openecomp.sdc.tosca.datatypes; + +import org.openecomp.sdc.tosca.datatypes.model.ArtifactType; +import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition; +import org.openecomp.sdc.tosca.datatypes.model.CapabilityAssignment; +import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; +import org.openecomp.sdc.tosca.datatypes.model.Constraint; +import org.openecomp.sdc.tosca.datatypes.model.Directive; +import org.openecomp.sdc.tosca.datatypes.model.Import; +import org.openecomp.sdc.tosca.datatypes.model.Metadata; +import org.openecomp.sdc.tosca.datatypes.model.NodeFilter; +import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.datatypes.model.NodeType; +import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition; +import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition; +import org.openecomp.sdc.tosca.datatypes.model.PropertyType; +import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; +import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.datatypes.model.SubstitutionMapping; +import org.openecomp.sdc.tosca.datatypes.model.TopologyTemplate; +import org.openecomp.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt; +import org.openecomp.sdc.tosca.services.DataModelUtil; +import org.openecomp.sdc.tosca.services.ToscaConstants; +import org.openecomp.sdc.tosca.services.yamlutil.ToscaExtensionYamlUtil; +import org.openecomp.core.utilities.yaml.YamlUtil; +import org.junit.Assert; +import org.junit.Test; + + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +public class ToscaModelTest { + + @Test + public void testServiceTemplateJavaToYaml() { + + ServiceTemplate serviceTemplate = new ServiceTemplate(); + Metadata metadata = new Metadata(); + metadata.setTemplate_author("OPENECOMP"); + metadata.setTemplate_name("Test"); + metadata.setTemplate_version("1.0.0"); + serviceTemplate.setTosca_definitions_version("tosca_simple_yaml_1_0_0"); + serviceTemplate.setDescription("testing desc tosca service template"); + serviceTemplate.setMetadata(metadata); + + Import fileImport1 = new Import(); + fileImport1.setFile("path1/path2/file1.yaml"); + Import fileImport2 = new Import(); + fileImport2.setFile("path1/path2/file2.yaml"); + Map<String, Import> imports = new HashMap<>(); + imports.put("myfile1", fileImport1); + imports.put("myfile2", fileImport2); + serviceTemplate.setImports(imports); + + ArtifactType artifact = new ArtifactType(); + artifact.setMime_type("application/java-archive"); + ArrayList<String> ext = new ArrayList<>(); + ext.add("yaml"); + ext.add("xml"); + artifact.setFile_ext(ext); + Map<String, ArtifactType> artifactTypes = new HashMap<>(); + artifactTypes.put("one_artifact", artifact); + serviceTemplate.setArtifact_types(artifactTypes); + + NodeType nodeType = new NodeType(); + nodeType.setDerived_from("tosca.nodes.Root"); + nodeType.setVersion("1.0.0"); + nodeType.setDescription("tosca compute test"); + + PropertyDefinition propDef1 = new PropertyDefinition(); + propDef1.setType("integer"); + propDef1.setDescription("Number of CPUs requested for a software node instance"); + propDef1.setRequired(true); + propDef1.set_default(1); + + Constraint graterOrEqual = new Constraint(); + graterOrEqual.setGreater_or_equal((float) 5.0); + Constraint constraintEqual = new Constraint(); + constraintEqual.setEqual(5); + Constraint greater_than = new Constraint(); + greater_than.setGreater_than(6.02); + Constraint inRange = new Constraint(); + inRange.setIn_range(new Object[2]); + inRange.getIn_range()[0] = 0; + inRange.getIn_range()[1] = ToscaConstants.UNBOUNDED; + + List<Constraint> constraints = new ArrayList<>(); + constraints.add(graterOrEqual); + constraints.add(constraintEqual); + constraints.add(greater_than); + constraints.add(inRange); + propDef1.setConstraints(constraints); + + Map<String, PropertyDefinition> properties = new HashMap<>(); + properties.put("cpu_num", propDef1); + nodeType.setProperties(properties); + + Map<String, AttributeDefinition> attributesDef = new HashMap<>(); + AttributeDefinition attDef = new AttributeDefinition(); + attDef.setType(PropertyType.STRING.getDisplayName()); + attDef.set_default("hi"); + attributesDef.put("attDef1", attDef); + nodeType.setAttributes(attributesDef); + + Map<String, RequirementDefinition> reqsDef = new HashMap<>(); + RequirementDefinition reqDef = new RequirementDefinition(); + reqDef.setCapability("tosca.cap1"); + reqDef.getOccurrences()[0] = 5; + reqsDef.put("re1", reqDef); + List<Map<String, RequirementDefinition>> reqList = new ArrayList<>(); + reqList.add(reqsDef); + nodeType.setRequirements(reqList); + + + Map<String, CapabilityDefinition> capsDef = new HashMap<>(); + CapabilityDefinition capdef = new CapabilityDefinition(); + capdef.setType("tosca.cap"); + List<String> vvSource = new ArrayList<>(); + vvSource.add("node1"); + vvSource.add("node2"); + capdef.setValid_source_types(vvSource); + capsDef.put("cap1", capdef); + nodeType.setCapabilities(capsDef); + + Map<String, NodeType> nodeTypes = new HashMap<>(); + nodeTypes.put("compute_node_type", nodeType); + serviceTemplate.setNode_types(nodeTypes); + + TopologyTemplate topologyTemplate = new TopologyTemplate(); + topologyTemplate.setDescription("topologi template descroption"); + Map<String, ParameterDefinition> inputs = new HashMap<>(); + ParameterDefinition paramDef = new ParameterDefinition(); + paramDef.setType(PropertyType.STRING.getDisplayName()); + paramDef.setDescription("desc"); + paramDef.set_default("my default val"); + paramDef.setRequired(false); + paramDef.setEntry_schema(DataModelUtil.createEntrySchema("tosca.myType", null, null)); + List<Constraint> paramConstraint = new ArrayList<>(); + Constraint paramConst1 = new Constraint(); + paramConst1.setGreater_than(6); + Constraint paramConst2 = new Constraint(); + paramConst2.setGreater_or_equal(9); + paramConstraint.add(paramConst1); + paramConstraint.add(paramConst2); + paramDef.setConstraints(paramConstraint); + inputs.put("inParam1", paramDef); + topologyTemplate.setInputs(inputs); + + Map<String, NodeTemplate> nodeTemplates = new HashMap<>(); + NodeTemplate nodeTemplate = new NodeTemplate(); + nodeTemplate.setType("nodeTypeRef"); + List<String> directives = new ArrayList<>(); + directives.add(Directive.SELECTABLE.getDisplayName()); + directives.add(Directive.SUBSTITUTABLE.getDisplayName()); + nodeTemplate.setDirectives(directives); + Map<String, Object> nodeTemplateProperties = new HashMap<>(); + nodeTemplateProperties.put("prop1", "abcd"); + nodeTemplateProperties.put("prop2", "{ get_input: my_mysql_rootpw }"); + nodeTemplate.setProperties(nodeTemplateProperties); + Map<String, Object> nodeTemplateAtts = new HashMap<>(); + nodeTemplateAtts.put("att1", "att1Val"); + nodeTemplateAtts.put("att2", "{ get_input: my_mysql_rootpw }"); + nodeTemplate.setAttributes(nodeTemplateAtts); + + + RequirementAssignment reqAssignment1 = new RequirementAssignment(); + reqAssignment1.setNode("nodeA"); + reqAssignment1.setCapability("capA"); + reqAssignment1.setRelationship("relationB"); + Object[] reqAssOccurrences = new Object[2]; + reqAssOccurrences[0] = 1; + reqAssOccurrences[1] = 2; + reqAssignment1.setOccurrences(reqAssOccurrences); + NodeFilter reqNodeFilter = new NodeFilter(); + List<Constraint> propConstrain1 = new ArrayList<>(); + Constraint propConst1 = new Constraint(); + propConst1.setGreater_or_equal(9); + propConstrain1.add(propConst1); + List<Constraint> propConstrain2 = new ArrayList<>(); + Constraint propConst2 = new Constraint(); + propConst2.setMin_length(1); + propConstrain2.add(propConst2); + Constraint propConst3 = new Constraint(); + propConst3.setMax_length(2); + propConstrain2.add(propConst3); + Map<String, List<Constraint>> nodeFilterProp = new HashMap<>(); + nodeFilterProp.put("propName1", propConstrain1); + nodeFilterProp.put("propName2", propConstrain2); + reqNodeFilter.setProperties(nodeFilterProp); + reqAssignment1.setNode_filter(reqNodeFilter); + + RequirementAssignment reqAssignment2 = new RequirementAssignment(); + reqAssignment2.setNode("nodeA"); + reqAssignment2.setCapability("capA"); + reqAssignment2.setRelationship("relationB"); + Map<String, RequirementAssignment> nodeTemplateRequirement1 = new HashMap<>(); + Map<String, RequirementAssignment> nodeTemplateRequirement2 = new HashMap<>(); + nodeTemplateRequirement1.put("req1", reqAssignment1); + nodeTemplateRequirement2.put("req2", reqAssignment2); + nodeTemplate.setRequirements(new ArrayList<>()); + nodeTemplate.getRequirements().add(nodeTemplateRequirement1); + nodeTemplate.getRequirements().add(nodeTemplateRequirement2); + + Map<String, CapabilityAssignment> nodeTemplateCapability = new HashMap<>(); + CapabilityAssignment capAss = new CapabilityAssignment(); + Map<String, Object> capProps = new HashMap<>(); + capProps.put("num_cpus", "{ get_input: cpus }"); + capAss.setProperties(capProps); + Map<String, Object> capAtts = new HashMap<>(); + capAtts.put("num_cpus", "66"); + capAss.setAttributes(capAtts); + nodeTemplateCapability.put("cap1", capAss); + nodeTemplate.setCapabilities(new ArrayList<>()); + nodeTemplate.getCapabilities().add(nodeTemplateCapability); + + NodeFilter nodeTemplateNodeFilter = new NodeFilter(); + Map<String, List<Constraint>> ntProp = new HashMap<>(); + Constraint c1 = new Constraint(); + c1.setEqual("1 MB"); + List<Constraint> consList = new ArrayList<>(); + consList.add(c1); + ntProp.put("test1", consList); + nodeTemplateNodeFilter.setProperties(ntProp); + nodeTemplate.setNode_filter(nodeTemplateNodeFilter); + nodeTemplates.put("firatNodeTemplate", nodeTemplate); + topologyTemplate.setNode_templates(nodeTemplates); + + SubstitutionMapping subMap = new SubstitutionMapping(); + subMap.setNode_type("myNodeType.node"); + Map<String, List<String>> mapCapabilities = new HashMap<>(); + List<String> NodeCap = new ArrayList<>(); + NodeCap.add("database"); + NodeCap.add("database_endpoint"); + mapCapabilities.put("database_endpoint", NodeCap); + subMap.setCapabilities(mapCapabilities); + topologyTemplate.setSubstitution_mappings(subMap); + serviceTemplate.setTopology_template(topologyTemplate); + + String yaml = new YamlUtil().objectToYaml(serviceTemplate); + ServiceTemplate serviceTemplateFromYaml = + new YamlUtil().yamlToObject(yaml, ServiceTemplate.class); + Assert.assertNotNull(serviceTemplateFromYaml); + } + + + @Test + public void testYamlToServiceTemplateObj() { + InputStream yamlFile = new YamlUtil().loadYamlFileIs("/mock/model/serviceTemplate.yaml"); + ServiceTemplate serviceTemplateFromYaml = + new YamlUtil().yamlToObject(yamlFile, ServiceTemplate.class); + Assert.assertNotNull(serviceTemplateFromYaml); + } + + + @Test + public void testYamlToServiceTemplateIncludingHeatExtend() { + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + InputStream yamlFile = + toscaExtensionYamlUtil.loadYamlFileIs("/mock/model/serviceTemplateHeatExtend.yaml"); + ServiceTemplate serviceTemplateFromYaml = + toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); + ParameterDefinitionExt parameterDefinitionExt = + (ParameterDefinitionExt) serviceTemplateFromYaml.getTopology_template().getInputs() + .get("inParam1"); + Assert.assertNotNull(parameterDefinitionExt.getLabel()); + String backToYamlString = toscaExtensionYamlUtil.objectToYaml(serviceTemplateFromYaml); + Assert.assertNotNull(backToYamlString); + } + +} + + + + + + diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/model/CapabilityDefinitionTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/model/CapabilityDefinitionTest.java new file mode 100644 index 0000000000..2b0f88fdea --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/model/CapabilityDefinitionTest.java @@ -0,0 +1,101 @@ +package org.openecomp.sdc.tosca.datatypes.model; + +import org.openecomp.sdc.tosca.services.ToscaConstants; +import org.openecomp.core.utilities.yaml.YamlUtil; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CapabilityDefinitionTest { + + @Test + public void cloneTest() { + CapabilityDefinition capDef1 = new CapabilityDefinition(); + Map<String, AttributeDefinition> attributes = new HashMap<>(); + attributes.put("key1", getAttributeDefinition()); + capDef1.setAttributes(attributes); + + capDef1.setDescription("This is my desc"); + capDef1.setOccurrences(getMockOccurrences()); + + Map<String, PropertyDefinition> properties = new HashMap<>(); + PropertyDefinition propertyDefinition = getMockPropertyDefinition(); + properties.put("key1", propertyDefinition); + capDef1.setProperties(properties); + capDef1.setType("My Type"); + List<String> valid_source_types = new ArrayList<>(); + valid_source_types.add("nonono"); + capDef1.setValid_source_types(valid_source_types); + + CapabilityDefinition capDef2 = capDef1.clone(); + NodeType nodeType = new NodeType(); + nodeType.setCapabilities(new HashMap<>()); + nodeType.getCapabilities().put("cap1", capDef1); + nodeType.getCapabilities().put("cap2", capDef2); + + String yamlString = new YamlUtil().objectToYaml(nodeType); + Boolean passResult = !yamlString.contains("&") && !yamlString.contains("*"); + Assert.assertEquals(true, passResult); + } + + private PropertyDefinition getMockPropertyDefinition() { + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setConstraints(getMockConstraints()); + propertyDefinition.setDescription("desc"); + propertyDefinition.setType("typeProp"); + propertyDefinition.set_default(5); + propertyDefinition.setEntry_schema(getMockEntrySchema()); + propertyDefinition.setRequired(false); + propertyDefinition.setStatus(Status.UNSUPPORTED); + return propertyDefinition; + } + + private Object[] getMockOccurrences() { + Object[] occurrences = new Object[2]; + occurrences[0] = 2; + occurrences[1] = ToscaConstants.UNBOUNDED; + return occurrences; + } + + private ArtifactDefinition getMockArtifactDefinition() { + ArtifactDefinition artifactDefinition = new ArtifactDefinition(); + artifactDefinition.setType("type1"); + artifactDefinition.setDescription("description of OPENECOMP def"); + artifactDefinition.setDeploy_path("my deployment path"); + artifactDefinition.setFile("my file"); + artifactDefinition.setRepository("my repository"); + return artifactDefinition; + } + + private AttributeDefinition getAttributeDefinition() { + AttributeDefinition attributeDefinition = new AttributeDefinition(); + attributeDefinition.setDescription("desc1"); + attributeDefinition.setType("type1"); + attributeDefinition.set_default("none"); + attributeDefinition.setEntry_schema(getMockEntrySchema()); + attributeDefinition.setStatus(Status.UNSUPPORTED); + return attributeDefinition; + } + + private EntrySchema getMockEntrySchema() { + EntrySchema entrySchema = new EntrySchema(); + entrySchema.setType("string"); + entrySchema.setDescription("string for string"); + List<Constraint> constraints = getMockConstraints(); + entrySchema.setConstraints(constraints); + return entrySchema; + } + + private List<Constraint> getMockConstraints() { + List<Constraint> constraints = new ArrayList<>(); + Constraint constraint = new Constraint(); + constraint.setEqual("5"); + constraints.add(constraint); + return constraints; + } + +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/model/RequirementDefinitionTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/model/RequirementDefinitionTest.java new file mode 100644 index 0000000000..3109a8abff --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/model/RequirementDefinitionTest.java @@ -0,0 +1,40 @@ +package org.openecomp.sdc.tosca.datatypes.model; + +import org.openecomp.core.utilities.yaml.YamlUtil; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class RequirementDefinitionTest { + + @Test + public void cloneTest() { + RequirementDefinition reqDef1 = new RequirementDefinition(); + reqDef1.setNode("node1"); + reqDef1.setRelationship("my Relationship"); + reqDef1.setCapability("capabilities"); + reqDef1.setOccurrences(new Object[]{1, 1}); + + RequirementDefinition reqDef2 = reqDef1.clone(); + NodeType nodeType = new NodeType(); + + List<Map<String, RequirementDefinition>> requirements = new ArrayList<>(); + Map<String, RequirementDefinition> reqMap1 = new HashMap<>(); + reqMap1.put("req1", reqDef1); + requirements.add(reqMap1); + Map<String, RequirementDefinition> reqMap2 = new HashMap<>(); + reqMap2.put("req2", reqDef2); + requirements.add(reqMap2); + nodeType.setRequirements(requirements); + + String yamlString = new YamlUtil().objectToYaml(nodeType); + Boolean passResult = !yamlString.contains("&") && !yamlString.contains("*"); + Assert.assertEquals(true, passResult); + } + + +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/DataModelUtilTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/DataModelUtilTest.java new file mode 100644 index 0000000000..893f7a1a5e --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/DataModelUtilTest.java @@ -0,0 +1,104 @@ +package org.openecomp.sdc.tosca.services; + +import org.openecomp.sdc.common.errors.CoreException; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; +import org.openecomp.sdc.tosca.datatypes.model.GroupDefinition; +import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.datatypes.model.NodeType; +import org.openecomp.sdc.tosca.datatypes.model.PolicyDefinition; +import org.openecomp.sdc.tosca.datatypes.model.RelationshipTemplate; +import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; +import org.openecomp.sdc.tosca.datatypes.model.SubstitutionMapping; + +import java.util.ArrayList; + +@RunWith(MockitoJUnitRunner.class) +public class DataModelUtilTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testAddSubstitutionMapping() throws Exception { + thrown.expect(CoreException.class); + thrown.expectMessage( + "Invalid action, can't add 'Substitution Mapping' to 'Service Template', 'Service Template' entity is NULL."); + DataModelUtil.addSubstitutionMapping(null, new SubstitutionMapping()); + } + + @Test + public void testAddSubstitutionMappingReq() throws Exception { + thrown.expect(CoreException.class); + thrown.expectMessage( + "Invalid action, can't add 'Substitution Mapping Requirements' to 'Service Template', 'Service Template' entity is NULL."); + DataModelUtil.addSubstitutionMappingReq(null, "123", new ArrayList<>()); + } + + @Test + public void testAddNodeTemplate() throws Exception { + thrown.expect(CoreException.class); + thrown.expectMessage( + "Invalid action, can't add 'Node Template' to 'Service Template', 'Service Template' entity is NULL."); + DataModelUtil.addNodeTemplate(null, "123", new NodeTemplate()); + } + + @Test + public void testAddPolicyDefinition() throws Exception { + thrown.expect(CoreException.class); + thrown.expectMessage( + "Invalid action, can't add 'Policy Definition' to 'Service Template', 'Service Template' entity is NULL."); + DataModelUtil.addPolicyDefinition(null, "123", new PolicyDefinition()); + } + + @Test + public void testAddNodeType() throws Exception { + thrown.expect(CoreException.class); + thrown.expectMessage( + "Invalid action, can't add 'Node Type' to 'Service Template', 'Service Template' entity is NULL."); + DataModelUtil.addNodeType(null, "123", new NodeType()); + } + + @Test + public void testAddRelationshipTemplate() throws Exception { + thrown.expect(CoreException.class); + thrown.expectMessage( + "Invalid action, can't add 'Relationship Template' to 'Service Template', 'Service Template' entity is NULL."); + DataModelUtil.addRelationshipTemplate(null, "123", new RelationshipTemplate()); + } + + @Test + public void testAddRequirementAssignment() throws Exception { + thrown.expect(CoreException.class); + thrown.expectMessage( + "Invalid action, can't add 'Requirement Assignment' to 'Node Template', 'Node Template' entity is NULL."); + DataModelUtil.addRequirementAssignment(null, "123", new RequirementAssignment()); + } + + @Test + public void testGetNodeTemplate() throws Exception { + thrown.expect(CoreException.class); + thrown.expectMessage( + "Invalid action, can't add 'Node Template' to 'Service Template', 'Service Template' entity is NULL."); + DataModelUtil.addNodeTemplate(null, "123", new NodeTemplate()); + } + + @Test + public void testGetNodeType() throws Exception { + thrown.expect(CoreException.class); + thrown.expectMessage( + "Invalid action, can't add 'Node Type' to 'Service Template', 'Service Template' entity is NULL."); + DataModelUtil.addNodeType(null, "123", new NodeType()); + } + + @Test + public void testAddGroupToTopologyTemplate() throws Exception { + thrown.expect(CoreException.class); + thrown.expectMessage( + "Invalid action, can't add 'Group Definition' to 'Service Template', 'Service Template' entity is NULL."); + DataModelUtil.addGroupDefinitionToTopologyTemplate(null, "123", new GroupDefinition()); + } +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java new file mode 100644 index 0000000000..47f0bd9aef --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java @@ -0,0 +1,472 @@ +package org.openecomp.sdc.tosca.services.impl; + +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.tosca.TestUtil; +import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.services.ToscaAnalyzerService; +import org.openecomp.sdc.tosca.services.ToscaConstants; +import org.openecomp.sdc.tosca.services.yamlutil.ToscaExtensionYamlUtil; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; +import org.openecomp.sdc.tosca.datatypes.model.Import; +import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.datatypes.model.NodeType; +import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.datatypes.model.SubstitutionMapping; +import org.openecomp.sdc.tosca.datatypes.model.TopologyTemplate; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class ToscaAnalyzerServiceImplTest { + /* + Dictionary: + SrvTmp: ServiceTemplate + NdTmp: NodeTemplate + NdTy: NodeType + */ + + private static ToscaAnalyzerService toscaAnalyzerService; + private static ToscaServiceModel toscaServiceModel; + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Mock + NodeTemplate nodeTemplateMock; + @Mock + ToscaServiceModel toscaServiceModelMock; + + @BeforeClass + public static void onlyOnceSetUp() throws IOException { + toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); + toscaServiceModel = TestUtil.loadToscaServiceModel("/mock/analyzerService/toscasubstitution/", + "/mock/globalServiceTemplates/", null); + } + + @Before + public void init() throws IOException { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testGetRequirements() throws Exception { + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + InputStream yamlFile = toscaExtensionYamlUtil + .loadYamlFileIs("/mock/analyzerService/NestedServiceTemplateReqTest.yaml"); + ServiceTemplate serviceTemplateFromYaml = + toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); + + NodeTemplate port_0 = + serviceTemplateFromYaml.getTopology_template().getNode_templates().get("cmaui_port_0"); + List<RequirementAssignment> reqList = + toscaAnalyzerService.getRequirements(port_0, ToscaConstants.BINDING_REQUIREMENT_ID); + assertEquals(1, reqList.size()); + + reqList.clear(); + NodeTemplate port_1 = + serviceTemplateFromYaml.getTopology_template().getNode_templates().get("cmaui1_port_1"); + reqList = toscaAnalyzerService.getRequirements(port_1, ToscaConstants.LINK_REQUIREMENT_ID); + assertEquals(2, reqList.size()); + + reqList.clear(); + reqList = toscaAnalyzerService.getRequirements(port_0, ToscaConstants.LINK_REQUIREMENT_ID); + assertEquals(0, reqList.size()); + } + + @Test + public void testGetNodeTemplateById() throws Exception { + ServiceTemplate emptyServiceTemplate = new ServiceTemplate(); + Optional<NodeTemplate> nodeTemplate = + toscaAnalyzerService.getNodeTemplateById(emptyServiceTemplate, "test_net222"); + assertEquals(false, nodeTemplate.isPresent()); + + ServiceTemplate mainServiceTemplate = toscaServiceModel.getServiceTemplates() + .get(toscaServiceModel.getEntryDefinitionServiceTemplate()); + nodeTemplate = toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_net"); + assertEquals(true, nodeTemplate.isPresent()); + + nodeTemplate = toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_net222"); + assertEquals(false, nodeTemplate.isPresent()); + } + + @Test + public void testGetSubstituteServiceTemplateName() throws Exception { + thrown.expect(CoreException.class); + thrown.expectMessage( + "Invalid Substitute Node Template invalid2, mandatory map property service_template_filter with mandatory key substitute_service_template must be defined."); + + ServiceTemplate mainServiceTemplate = toscaServiceModel.getServiceTemplates() + .get(toscaServiceModel.getEntryDefinitionServiceTemplate()); + Optional<NodeTemplate> notSubstitutableNodeTemplate = + toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_net"); + Optional<String> substituteServiceTemplateName = toscaAnalyzerService + .getSubstituteServiceTemplateName("test_net", notSubstitutableNodeTemplate.get()); + assertEquals(false, substituteServiceTemplateName.isPresent()); + + Optional<NodeTemplate> substitutableNodeTemplate = + toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_nested"); + substituteServiceTemplateName = toscaAnalyzerService + .getSubstituteServiceTemplateName("test_nested", substitutableNodeTemplate.get()); + assertEquals(true, substituteServiceTemplateName.isPresent()); + assertEquals("nestedServiceTemplate.yaml", substituteServiceTemplateName.get()); + + NodeTemplate invalidSubstitutableNodeTemplate1 = new NodeTemplate(); + substituteServiceTemplateName = toscaAnalyzerService + .getSubstituteServiceTemplateName("invalid1", invalidSubstitutableNodeTemplate1); + assertEquals(false, substituteServiceTemplateName.isPresent()); + + + NodeTemplate invalidSubstitutableNodeTemplate2 = substitutableNodeTemplate.get(); + Object serviceTemplateFilter = invalidSubstitutableNodeTemplate2.getProperties() + .get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME); + ((Map) serviceTemplateFilter).clear(); + toscaAnalyzerService + .getSubstituteServiceTemplateName("invalid2", invalidSubstitutableNodeTemplate2); + + + } + + + @Test + public void testGetSubstitutableNodeTemplates() throws Exception { + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + InputStream yamlFile = toscaExtensionYamlUtil + .loadYamlFileIs("/mock/analyzerService/ServiceTemplateSubstituteTest.yaml"); + ServiceTemplate serviceTemplateFromYaml = + toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); + + Map<String, NodeTemplate> substitutableNodeTemplates = + toscaAnalyzerService.getSubstitutableNodeTemplates(serviceTemplateFromYaml); + assertEquals(2, substitutableNodeTemplates.size()); + assertNotNull(substitutableNodeTemplates.get("test_nested1")); + assertNotNull(substitutableNodeTemplates.get("test_nested2")); + + ServiceTemplate emptyServiceTemplate = new ServiceTemplate(); + emptyServiceTemplate.setTopology_template(new TopologyTemplate()); + substitutableNodeTemplates = + toscaAnalyzerService.getSubstitutableNodeTemplates(emptyServiceTemplate); + assertEquals(0, substitutableNodeTemplates.size()); + + yamlFile = toscaExtensionYamlUtil + .loadYamlFileIs("/mock/analyzerService/NestedServiceTemplateReqTest.yaml"); + serviceTemplateFromYaml = toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); + substitutableNodeTemplates = + toscaAnalyzerService.getSubstitutableNodeTemplates(serviceTemplateFromYaml); + assertEquals(0, substitutableNodeTemplates.size()); + } + + @Test + public void testGetSubstitutionMappedNodeTemplateByExposedReq() throws Exception { + thrown.expect(CoreException.class); + thrown.expectMessage( + "Invalid Tosca model data, missing 'Node Template' entry for 'Node Template' id cmaui_port_9"); + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + InputStream yamlFile = toscaExtensionYamlUtil + .loadYamlFileIs("/mock/analyzerService/NestedServiceTemplateReqTest.yaml"); + ServiceTemplate nestedServiceTemplateFromYaml = + toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); + + Optional<Map.Entry<String, NodeTemplate>> mappedNodeTemplate = toscaAnalyzerService + .getSubstitutionMappedNodeTemplateByExposedReq("NestedServiceTemplateSubstituteTest.yaml", + nestedServiceTemplateFromYaml, "local_storage_server_cmaui"); + assertEquals("server_cmaui", mappedNodeTemplate.get().getKey()); + assertNotNull(mappedNodeTemplate.get().getValue()); + + mappedNodeTemplate = toscaAnalyzerService + .getSubstitutionMappedNodeTemplateByExposedReq("NestedServiceTemplateSubstituteTest.yaml", + nestedServiceTemplateFromYaml, "link_cmaui_port_invalid"); + assertEquals("server_cmaui", mappedNodeTemplate.get().getKey()); + assertNotNull(mappedNodeTemplate.get().getValue()); + + ServiceTemplate mainServiceTemplate = toscaServiceModel.getServiceTemplates() + .get(toscaServiceModel.getEntryDefinitionServiceTemplate()); + mappedNodeTemplate = toscaAnalyzerService.getSubstitutionMappedNodeTemplateByExposedReq( + toscaServiceModel.getEntryDefinitionServiceTemplate(), mainServiceTemplate, + "local_storage_server_cmaui"); + assertEquals(false, mappedNodeTemplate.isPresent()); + } + + @Test + public void invalidSubstitutableMapping() throws Exception { + thrown.expect(CoreException.class); + thrown.expectMessage( + "Invalid Substitution Service Template invalidMappingServiceTemplate.yaml, missing mandatory file 'Node type' in substitution mapping."); + ServiceTemplate invalidMappingServiceTemplate = new ServiceTemplate(); + invalidMappingServiceTemplate.setTopology_template(new TopologyTemplate()); + invalidMappingServiceTemplate.getTopology_template() + .setSubstitution_mappings(new SubstitutionMapping()); + toscaAnalyzerService + .getSubstitutionMappedNodeTemplateByExposedReq("invalidMappingServiceTemplate.yaml", + invalidMappingServiceTemplate, "local_storage_server_cmaui"); + } + + @Test + public void substitutableMappingWithNoReqMap() throws Exception { + ServiceTemplate mainServiceTemplate = toscaServiceModel.getServiceTemplates() + .get(toscaServiceModel.getEntryDefinitionServiceTemplate()); + ServiceTemplate emptyReqMapping = new ServiceTemplate(); + emptyReqMapping.setTopology_template(new TopologyTemplate()); + emptyReqMapping.getTopology_template().setSubstitution_mappings(new SubstitutionMapping()); + emptyReqMapping.getTopology_template().getSubstitution_mappings().setNode_type("temp"); + Optional<Map.Entry<String, NodeTemplate>> mappedNodeTemplate = toscaAnalyzerService + .getSubstitutionMappedNodeTemplateByExposedReq( + toscaServiceModel.getEntryDefinitionServiceTemplate(), mainServiceTemplate, + "local_storage_server_cmaui"); + assertEquals(false, mappedNodeTemplate.isPresent()); + } + + @Test + public void testGetSubstitutionMappedNodeTemplateByExposedReqInvalid() throws Exception { + thrown.expect(CoreException.class); + thrown.expectMessage( + "Invalid Tosca model data, missing 'Node Template' entry for 'Node Template' id cmaui_port_9"); + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + InputStream yamlFile = toscaExtensionYamlUtil + .loadYamlFileIs("/mock/analyzerService/NestedServiceTemplateReqTest.yaml"); + ServiceTemplate nestedServiceTemplateFromYaml = + toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); + + toscaAnalyzerService + .getSubstitutionMappedNodeTemplateByExposedReq("NestedServiceTemplateSubstituteTest.yaml", + nestedServiceTemplateFromYaml, "link_cmaui_port_invalid"); + } + + @Test + public void testIsDesiredRequirementAssignmentMatch() throws Exception { + + RequirementAssignment requirementAssignment = new RequirementAssignment(); + String capability = "Test.Capability"; + String node = "Test.node"; + String relationship = "Test.relationship"; + requirementAssignment.setCapability(capability); + requirementAssignment.setNode(node); + requirementAssignment.setRelationship(relationship); + + assertEquals(true, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, capability, node, relationship)); + assertEquals(true, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, null, node, relationship)); + assertEquals(true, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, capability, null, relationship)); + assertEquals(true, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, capability, node, null)); + assertEquals(true, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, null, null, relationship)); + assertEquals(true, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, capability, null, null)); + assertEquals(true, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, null, node, null)); + + } + + @Test + public void testIsDesiredRequirementAssignmentNoMatch() throws Exception { + + RequirementAssignment requirementAssignment = new RequirementAssignment(); + String capability = "Test.Capability"; + String node = "Test.node"; + String relationship = "Test.relationship"; + requirementAssignment.setCapability(capability); + requirementAssignment.setNode(node); + requirementAssignment.setRelationship(relationship); + + assertEquals(false, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, "no", node, relationship)); + assertEquals(false, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, "no", "no", relationship)); + assertEquals(false, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, "no", "no", "no")); + assertEquals(false, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, capability, "no", relationship)); + assertEquals(false, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, capability, node, "no")); + assertEquals(false, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, capability, "no", "no")); + assertEquals(false, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, "no", null, null)); + assertEquals(false, toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, null, null, null)); + + + } + + @Test + public void shouldReturnFalseIfNdTmpIsNull() { + assertFalse(toscaAnalyzerService + .isTypeOf(null, ToscaNodeType.NETWORK.getDisplayName(), new ServiceTemplate(), + toscaServiceModelMock)); + } + + @Test + public void shouldReturnTrueIfNdTmpTypeIsOfRequestedType() { + NodeTemplate nodeTemplate = new NodeTemplate(); + ToscaNodeType nodeTypeToSearch = ToscaNodeType.BLOCK_STORAGE; + nodeTemplate.setType(nodeTypeToSearch.getDisplayName()); + assertTrue(toscaAnalyzerService + .isTypeOf(nodeTemplate, nodeTypeToSearch.getDisplayName(), new ServiceTemplate(), + toscaServiceModelMock)); + } + + @Test + public void shouldReturnTrueIfNdTmpTypeIsFoundInSrvTmpNdTyAndNdTyDerivedFromRequestedType() { + String typeToMatch = ToscaNodeType.CINDER_VOLUME.getDisplayName(); + when(nodeTemplateMock.getType()).thenReturn(typeToMatch); + Map<String, NodeType> stNodeTypes = new HashMap<>(); + addNodeType(stNodeTypes, ToscaNodeType.COMPUTE.getDisplayName(), new NodeType()); + NodeType nodeType = createNodeType(ToscaNodeType.BLOCK_STORAGE.getDisplayName()); + addNodeType(stNodeTypes, typeToMatch, nodeType); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + serviceTemplate.setNode_types(stNodeTypes); + assertTrue(toscaAnalyzerService + .isTypeOf(nodeTemplateMock, ToscaNodeType.BLOCK_STORAGE.getDisplayName(), serviceTemplate, + toscaServiceModelMock)); + + } + + @Test + public void shouldThrowCoreExceptionForInvalidNodeType() { + thrown.expect(CoreException.class); + thrown.expectMessage( + "NodeType 'AAA' or one of its derivedFrom node type hierarchy, is not defined in tosca service model"); + when(nodeTemplateMock.getType()).thenReturn("AAA"); + Map<String, NodeType> stNodeTypes = new HashMap<>(); + addNodeType(stNodeTypes, "notImportant", new NodeType()); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + serviceTemplate.setNode_types(stNodeTypes); + toscaAnalyzerService + .isTypeOf(nodeTemplateMock, ToscaNodeType.COMPUTE.getDisplayName(), serviceTemplate, + toscaServiceModelMock); + } + + @Test + public void shouldThrowCoreExceptionForInvalidNodeType2Level() { + thrown.expect(CoreException.class); + thrown.expectMessage( + "NodeType 'A' or one of its derivedFrom node type hierarchy, is not defined in tosca service model"); + String typeToMatch = "A"; + when(nodeTemplateMock.getType()).thenReturn(typeToMatch); + Map<String, NodeType> stNodeTypes = new HashMap<>(); + addNodeType(stNodeTypes, "notImportant", new NodeType()); + addNodeType(stNodeTypes, "A", createNodeType("ADerivedFromB")); + addNodeType(stNodeTypes, "ADerivedFromB'", createNodeType("BDerivedFromC")); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + serviceTemplate.setNode_types(stNodeTypes); + assertTrue(toscaAnalyzerService + .isTypeOf(nodeTemplateMock, "BDerivedFromC", serviceTemplate, toscaServiceModelMock)); + } + + @Test + public void shouldReturnTrueIfNdTmpTypeIsFoundInSrvTmpNdTyAndNotDerivedFromRequestedTypeBut2ndLevelDerivedFromMatch() { + String typeToMatch = "A"; + when(nodeTemplateMock.getType()).thenReturn(typeToMatch); + Map<String, NodeType> stNodeTypes = new HashMap<>(); + addNodeType(stNodeTypes, "notImportant", new NodeType()); + addNodeType(stNodeTypes, "A", createNodeType("ADerivedFromB")); + addNodeType(stNodeTypes, "ADerivedFromB", createNodeType("BDerivedFromC")); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + serviceTemplate.setNode_types(stNodeTypes); + assertTrue(toscaAnalyzerService + .isTypeOf(nodeTemplateMock, "BDerivedFromC", serviceTemplate, toscaServiceModelMock)); + } + + private NodeType createNodeType(String derivedFrom) { + NodeType nodeType = new NodeType(); + nodeType.setDerived_from(derivedFrom); + return nodeType; + } + + private void addNodeType(Map<String, NodeType> stNodeTypes, String key, NodeType nodeType) { + stNodeTypes.put(key, nodeType); + } + + @Test + public void shouldReturnTrueIfNdTmpTypeIsFoundInSrvTmpNdTyButRequestedTypeNotMatchButFoundIn1stLevelImports() { + String typeToMatch = ToscaNodeType.CINDER_VOLUME.getDisplayName(); + when(nodeTemplateMock.getType()).thenReturn(typeToMatch); + ServiceTemplate mainST = new ServiceTemplate(); + Map<String, Import> imports = new HashMap<>(); + Import anImport = new Import(); + anImport.setFile("mainImport"); + imports.put("bla bla", anImport); + mainST.setImports(imports); + + //create searchable service template + Map<String, NodeType> stNodeTypes = new HashMap<>(); + addNodeType(stNodeTypes, ToscaNodeType.COMPUTE.getDisplayName(), new NodeType()); + NodeType nodeType = createNodeType(ToscaNodeType.BLOCK_STORAGE.getDisplayName()); + addNodeType(stNodeTypes, typeToMatch, nodeType); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + serviceTemplate.setNode_types(stNodeTypes); + + // add service templates to tosca service model + Map<String, ServiceTemplate> serviceTemplates = toscaServiceModelMock.getServiceTemplates(); + serviceTemplates.put("testMainServiceTemplate", mainST); + serviceTemplates.put("mainImport", serviceTemplate); + when(toscaServiceModelMock.getServiceTemplates()).thenReturn(serviceTemplates); + + assertTrue(toscaAnalyzerService + .isTypeOf(nodeTemplateMock, ToscaNodeType.BLOCK_STORAGE.getDisplayName(), mainST, + toscaServiceModelMock)); + } + + @Test + public void shouldReturnTrueIfNdTmpTypeIsFoundInSrvTmpNdTyButRequestedTypeNotMatchButFoundIn2ndLevelImports() { + String typeToMatch = ToscaNodeType.CINDER_VOLUME.getDisplayName(); + when(nodeTemplateMock.getType()).thenReturn(typeToMatch); + ServiceTemplate mainST = new ServiceTemplate(); + Map<String, Import> imports = new HashMap<>(); + Import anImport = new Import(); + anImport.setFile("refToMainImport"); + imports.put("bla bla", anImport); + mainST.setImports(imports); + + //create searchable service template + Map<String, NodeType> stNodeTypes = new HashMap<>(); + addNodeType(stNodeTypes, ToscaNodeType.COMPUTE.getDisplayName(), new NodeType()); + NodeType nodeType = createNodeType(ToscaNodeType.BLOCK_STORAGE.getDisplayName()); + addNodeType(stNodeTypes, typeToMatch, nodeType); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + serviceTemplate.setNode_types(stNodeTypes); + + // create 1st level service template with import only + ServiceTemplate firstLevelST = new ServiceTemplate(); + Map<String, Import> firstLevelImports = new HashMap<>(); + Import firstLevelImport = new Import(); + firstLevelImport.setFile("mainImport"); + firstLevelImports.put("bla bla 2", firstLevelImport); + + firstLevelST.setImports(firstLevelImports); + + // add service templates to tosca service model + Map<String, ServiceTemplate> serviceTemplates = toscaServiceModelMock.getServiceTemplates(); + serviceTemplates.put("testMainServiceTemplate", mainST); + serviceTemplates.put("refToMainImport", firstLevelST); + serviceTemplates.put("mainImport", serviceTemplate); + when(toscaServiceModelMock.getServiceTemplates()).thenReturn(serviceTemplates); + + assertTrue(toscaAnalyzerService + .isTypeOf(nodeTemplateMock, ToscaNodeType.BLOCK_STORAGE.getDisplayName(), mainST, + toscaServiceModelMock)); + } + + // not found at all should throw core exception + + +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImplTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImplTest.java new file mode 100644 index 0000000000..963b8a6f57 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImplTest.java @@ -0,0 +1,150 @@ +package org.openecomp.sdc.tosca.services.impl; + +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.Metadata; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.services.ToscaUtil; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +public class ToscaFileOutputServiceCsarImplTest { + + private ToscaFileOutputServiceCsarImpl toscaFileOutputServiceCsarImpl = + new ToscaFileOutputServiceCsarImpl(); + + @Test + public void testCreationMetaFile() { + String createdMeta = toscaFileOutputServiceCsarImpl.createMetaFile("entryFile.yaml"); + String expectedMeta = + "TOSCA-Meta-File-Version: 1.0\n" + + "CSAR-Version: 1.1\n" + + "Created-By: ASDC Onboarding portal\n" + + "Entry-Definitions: Definitions" + File.separator + "entryFile.yaml"; + Assert.assertEquals(createdMeta.replaceAll("\\s+", ""), expectedMeta.replaceAll("\\s+", "")); + } + + @Test + public void testCSARFileCreationWithExternalArtifacts() throws IOException { + ServiceTemplate mainServiceTemplate = new ServiceTemplate(); + Metadata metadata1 = new Metadata(); + metadata1.setTemplate_author("OPENECOMP"); + metadata1.setTemplate_name("ST1"); + metadata1.setTemplate_version("1.0.0"); + mainServiceTemplate.setTosca_definitions_version("tosca_simple_yaml_1_0_0"); + mainServiceTemplate.setDescription("testing desc tosca service template"); + mainServiceTemplate.setMetadata(metadata1); + + ServiceTemplate additionalServiceTemplate = new ServiceTemplate(); + Metadata metadata2 = new Metadata(); + metadata2.setTemplate_author("OPENECOMP"); + metadata2.setTemplate_name("ST2"); + metadata2.setTemplate_version("1.0.0"); + additionalServiceTemplate.setTosca_definitions_version("tosca_simple_yaml_1_0_0"); + additionalServiceTemplate.setDescription("testing desc tosca service template"); + additionalServiceTemplate.setMetadata(metadata2); + + Map<String, ServiceTemplate> definitionsInput = new HashMap<>(); + definitionsInput + .put(ToscaUtil.getServiceTemplateFileName(mainServiceTemplate), mainServiceTemplate); + definitionsInput.put(ToscaUtil.getServiceTemplateFileName(additionalServiceTemplate), + additionalServiceTemplate); + + + Map<String, byte[]> dummyHeatArtifacts = new HashMap<>(); + String file1Content = "this is file number 1"; + String file2Content = "this is file number 2"; + String file1 = "file1.xml"; + dummyHeatArtifacts.put(file1, file1Content.getBytes()); + String file2 = "file2.yml"; + dummyHeatArtifacts.put(file2, file2Content.getBytes()); + + + FileContentHandler heatFiles = new FileContentHandler(); + heatFiles.putAll(dummyHeatArtifacts); + Map<String, byte[]> licenseArtifacts = new HashMap<>(); + + FileContentHandler licenseArtifactsFiles = new FileContentHandler(); + + licenseArtifacts.put( + ToscaFileOutputServiceCsarImpl.EXTERNAL_ARTIFACTS_FOLDER_NAME + File.separator + + "license-file-1.xml", file1Content.getBytes()); + licenseArtifacts.put( + ToscaFileOutputServiceCsarImpl.EXTERNAL_ARTIFACTS_FOLDER_NAME + File.separator + + "license-file-2.xml", file1Content.getBytes()); + + licenseArtifactsFiles.putAll(licenseArtifacts); + + byte[] csarFile = toscaFileOutputServiceCsarImpl.createOutputFile( + new ToscaServiceModel(heatFiles, definitionsInput, + ToscaUtil.getServiceTemplateFileName(mainServiceTemplate)), licenseArtifactsFiles); + + String resultFileName = "resultFile.zip"; + File file = new File(resultFileName); + FileOutputStream fos = new FileOutputStream(file); + fos.write(csarFile); + fos.close(); + + ZipFile zipFile = new ZipFile(resultFileName); + + Enumeration<? extends ZipEntry> entries = zipFile.entries(); + + int count = 0; + while (entries.hasMoreElements()) { + count++; + entries.nextElement(); + } + Assert.assertEquals(7, count); + zipFile.close(); + Files.delete(Paths.get(file.getPath())); + } + + @Test + public void testCSARFileCreation_noArtifacts() throws IOException { + ServiceTemplate serviceTemplate = new ServiceTemplate(); + Metadata metadata = new Metadata(); + metadata.setTemplate_author("OPENECOMP"); + metadata.setTemplate_name("Test"); + metadata.setTemplate_version("1.0.0"); + serviceTemplate.setTosca_definitions_version("tosca_simple_yaml_1_0_0"); + serviceTemplate.setDescription("testing desc tosca service template"); + serviceTemplate.setMetadata(metadata); + Map<String, ServiceTemplate> definitionsInput = new HashMap<>(); + String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate); + definitionsInput.put(serviceTemplateFileName, serviceTemplate); + byte[] csarFile = toscaFileOutputServiceCsarImpl + .createOutputFile(new ToscaServiceModel(null, definitionsInput, serviceTemplateFileName), + null); + + + String resultFileName = "resultFile.zip"; + File file = new File(resultFileName); + FileOutputStream fos = new FileOutputStream(file); + fos.write(csarFile); + fos.close(); + + ZipFile zipFile = new ZipFile(resultFileName); + + Enumeration<? extends ZipEntry> entries = zipFile.entries(); + + int count = 0; + while (entries.hasMoreElements()) { + count++; + entries.nextElement(); + } + Assert.assertEquals(2, count); + zipFile.close(); + Files.delete(Paths.get(file.getPath())); + } +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/NestedServiceTemplateReqTest.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/NestedServiceTemplateReqTest.yaml new file mode 100644 index 0000000000..f64cb709f0 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/NestedServiceTemplateReqTest.yaml @@ -0,0 +1,176 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: nested +imports: + NeutronPortGlobalTypes: + file: NeutronPortGlobalTypesServiceTemplate.yaml + NeutronNetGlobalTypes: + file: NeutronNetGlobalTypesServiceTemplate.yaml + CommonGlobalTypes: + file: CommonGlobalTypesServiceTemplate.yaml + CinderVolumeGlobalTypes: + file: CinderVolumeGlobalTypesServiceTemplate.yaml + ContrailNetworkRuleGlobalType: + file: ContrailNetworkRuleGlobalTypeServiceTemplate.yaml + NeutronSecurityRulesGlobalTypes: + file: NeutronSecurityRulesGlobalTypesServiceTemplate.yaml + NovaServerGlobalTypes: + file: NovaServerGlobalTypesServiceTemplate.yaml + ContrailVirtualNetworkGlobalType: + file: ContrailVirtualNetworkGlobalTypeServiceTemplate.yaml + AbstractSubstituteGlobalTypes: + file: AbstractSubstituteGlobalTypesServiceTemplate.yaml + nested: + file: GlobalSubstitutionTypesServiceTemplate.yaml +node_types: + org.openecomp.resource.vfc.nodes.heat.cmaui_image: + derived_from: org.openecomp.resource.vfc.nodes.heat.nova.Server +topology_template: + inputs: + cmaui_names: + hidden: false + immutable: false + type: list + description: CMAUI1, CMAUI2 server names + entry_schema: + type: String + p1: + hidden: false + immutable: false + type: string + description: UID of OAM network + cmaui_image: + hidden: false + immutable: false + type: string + description: Image for CMAUI server + cmaui_flavor: + hidden: false + immutable: false + type: string + description: Flavor for CMAUI server + security_group_name: + hidden: false + immutable: false + description: not impotrtant + availability_zone_0: + label: availabilityzone name + hidden: false + immutable: false + type: string + description: availabilityzone name + node_templates: + server_cmaui: + type: org.openecomp.resource.vfc.nodes.heat.cmaui_image + properties: + flavor: + get_input: cmaui_flavor + availability_zone: + get_input: availability_zone_0 + image: + get_input: cmaui_image + name: + get_input: + - cmaui_names + - 0 + cmaui_port_0: + type: org.openecomp.resource.cp.nodes.heat.network.neutron.Port + properties: + replacement_policy: AUTO + security_groups: + - get_input: security_group_name + fixed_ips: + - ip_address: + get_input: + - cmaui_oam_ips + - 0 + network: + get_input: p1 + requirements: + - binding: + capability: tosca.capabilities.network.Bindable + node: server_cmaui + relationship: tosca.relationships.network.BindsTo + cmaui1_port_1: + type: org.openecomp.resource.cp.nodes.heat.network.neutron.Port + properties: + replacement_policy: AUTO + security_groups: + - get_input: security_group_name + fixed_ips: + - subnet: subnetNameVal + ip_address: + get_input: + - cmaui_oam_ips + - 1 + - subnet: subnetNameVal2 + ip_address: + get_input: + - cmaui_oam_ips + - 1 + network: jsa_net + requirements: + - link: + capability: tosca.capabilities.network.Linkable + node: jsa_net1 + relationship: tosca.relationships.network.LinksTo + - link: + capability: tosca.capabilities.network.Linkable + node: jsa_net2 + relationship: tosca.relationships.network.LinksTo + - binding: + capability: tosca.capabilities.network.Bindable + node: server_cmaui + relationship: tosca.relationships.network.BindsTo + jsa_net1: + type: org.openecomp.resource.vl.nodes.heat.network.neutron.Net + properties: + shared: true + network_name: + get_input: jsa_net_name + jsa_net2: + type: org.openecomp.resource.vl.nodes.heat.network.neutron.Net + properties: + shared: true + network_name: + get_input: jsa_net_name + groups: + nested: + type: org.openecomp.groups.heat.HeatStack + properties: + heat_file: ../Artifacts/nested.yml + description: cmaui server template for vMMSC + members: + - server_cmaui + - cmaui_port_0 + substitution_mappings: + node_type: org.openecomp.resource.abstract.nodes.heat.nested + capabilities: + host_server_cmaui: + - server_cmaui + - host + os_server_cmaui: + - server_cmaui + - os + endpoint_server_cmaui: + - server_cmaui + - endpoint + binding_server_cmaui: + - server_cmaui + - binding + scalable_server_cmaui: + - server_cmaui + - scalable + attachment_cmaui_port_0: + - cmaui_port_0 + - attachment + requirements: + local_storage_server_cmaui: + - server_cmaui + - local_storage + link_cmaui_port_0: + - cmaui_port_0 + - link + link_cmaui_port_invalid: + - cmaui_port_9 + - link diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/ServiceTemplateSubstituteTest.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/ServiceTemplateSubstituteTest.yaml new file mode 100644 index 0000000000..c4df76a1aa --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/ServiceTemplateSubstituteTest.yaml @@ -0,0 +1,89 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: Main +imports: + NeutronPortGlobalTypes: + file: NeutronPortGlobalTypesServiceTemplate.yaml + NeutronNetGlobalTypes: + file: NeutronNetGlobalTypesServiceTemplate.yaml + CommonGlobalTypes: + file: CommonGlobalTypesServiceTemplate.yaml + CinderVolumeGlobalTypes: + file: CinderVolumeGlobalTypesServiceTemplate.yaml + ContrailNetworkRuleGlobalType: + file: ContrailNetworkRuleGlobalTypeServiceTemplate.yaml + NeutronSecurityRulesGlobalTypes: + file: NeutronSecurityRulesGlobalTypesServiceTemplate.yaml + NovaServerGlobalTypes: + file: NovaServerGlobalTypesServiceTemplate.yaml + ContrailVirtualNetworkGlobalType: + file: ContrailVirtualNetworkGlobalTypeServiceTemplate.yaml + AbstractSubstituteGlobalTypes: + file: AbstractSubstituteGlobalTypesServiceTemplate.yaml +topology_template: + inputs: + shared_network_id: + hidden: false + immutable: false + type: string + description: network name of jsa log network + jsa_net_name: + hidden: false + immutable: false + type: string + description: network name of jsa log network + node_templates: + test_net: + type: org.openecomp.resource.vl.nodes.heat.network.neutron.Net + properties: + shared: true + network_name: + get_input: jsa_net_name + test_nested1: + type: org.openecomp.resource.abstract.nodes.heat.nested + directives: + - substitutable + properties: + p1: + get_input: shared_network_id + service_template_filter: + substitute_service_template: nestedServiceTemplate.yaml + requirements: + - link_cmaui_port_0: + capability: tosca.capabilities.network.Linkable + node: test_net + relationship: tosca.relationships.network.LinksTo + test_nested2: + type: org.openecomp.resource.abstract.nodes.heat.nested + directives: + - substitutable + properties: + p1: + get_input: shared_network_id + service_template_filter: + substitute_service_template: nestedServiceTemplate.yaml + requirements: + - link_cmaui_port_0: + capability: tosca.capabilities.network.Linkable + node: test_net + relationship: tosca.relationships.network.LinksTo + groups: + addOn: + type: org.openecomp.groups.heat.HeatStack + properties: + heat_file: ../Artifacts/addOn.yml + description: | + Version 2.0 02-09-2016 (Authors: John Doe, user PROD) + members: + - test_nested + main: + type: org.openecomp.groups.heat.HeatStack + properties: + heat_file: ../Artifacts/main.yml + description: | + Version 2.0 02-09-2016 (Authors: John Doe, user PROD) + members: + - test_net + outputs: + shared_network_id: + value: test_net
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscasubstitution/MainServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscasubstitution/MainServiceTemplate.yaml new file mode 100644 index 0000000000..65b90ef5b1 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscasubstitution/MainServiceTemplate.yaml @@ -0,0 +1,75 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: Main +imports: + NeutronPortGlobalTypes: + file: NeutronPortGlobalTypesServiceTemplate.yaml + NeutronNetGlobalTypes: + file: NeutronNetGlobalTypesServiceTemplate.yaml + CommonGlobalTypes: + file: CommonGlobalTypesServiceTemplate.yaml + CinderVolumeGlobalTypes: + file: CinderVolumeGlobalTypesServiceTemplate.yaml + ContrailNetworkRuleGlobalType: + file: ContrailNetworkRuleGlobalTypeServiceTemplate.yaml + NeutronSecurityRulesGlobalTypes: + file: NeutronSecurityRulesGlobalTypesServiceTemplate.yaml + NovaServerGlobalTypes: + file: NovaServerGlobalTypesServiceTemplate.yaml + ContrailVirtualNetworkGlobalType: + file: ContrailVirtualNetworkGlobalTypeServiceTemplate.yaml + AbstractSubstituteGlobalTypes: + file: AbstractSubstituteGlobalTypesServiceTemplate.yaml +topology_template: + inputs: + shared_network_id: + hidden: false + immutable: false + type: string + description: network name of jsa log network + jsa_net_name: + hidden: false + immutable: false + type: string + description: network name of jsa log network + node_templates: + test_net: + type: org.openecomp.resource.vl.nodes.heat.network.neutron.Net + properties: + shared: true + network_name: + get_input: jsa_net_name + test_nested: + type: org.openecomp.resource.abstract.nodes.heat.nested + directives: + - substitutable + properties: + p1: + get_input: shared_network_id + service_template_filter: + substitute_service_template: nestedServiceTemplate.yaml + requirements: + - link_cmaui_port_0: + capability: tosca.capabilities.network.Linkable + node: test_net + relationship: tosca.relationships.network.LinksTo + groups: + addOn: + type: org.openecomp.groups.heat.HeatStack + properties: + heat_file: ../Artifacts/addOn.yml + description: | + Version 2.0 02-09-2016 (Authors: John Doe, user PROD) + members: + - test_nested + main: + type: org.openecomp.groups.heat.HeatStack + properties: + heat_file: ../Artifacts/main.yml + description: | + Version 2.0 02-09-2016 (Authors: John Doe, user PROD) + members: + - test_net + outputs: + shared_network_id: + value: test_net
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscasubstitution/nestedServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscasubstitution/nestedServiceTemplate.yaml new file mode 100644 index 0000000000..cd27e7ba1a --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscasubstitution/nestedServiceTemplate.yaml @@ -0,0 +1,130 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: nested +imports: + NeutronPortGlobalTypes: + file: NeutronPortGlobalTypesServiceTemplate.yaml + NeutronNetGlobalTypes: + file: NeutronNetGlobalTypesServiceTemplate.yaml + CommonGlobalTypes: + file: CommonGlobalTypesServiceTemplate.yaml + CinderVolumeGlobalTypes: + file: CinderVolumeGlobalTypesServiceTemplate.yaml + ContrailNetworkRuleGlobalType: + file: ContrailNetworkRuleGlobalTypeServiceTemplate.yaml + NeutronSecurityRulesGlobalTypes: + file: NeutronSecurityRulesGlobalTypesServiceTemplate.yaml + NovaServerGlobalTypes: + file: NovaServerGlobalTypesServiceTemplate.yaml + ContrailVirtualNetworkGlobalType: + file: ContrailVirtualNetworkGlobalTypeServiceTemplate.yaml + AbstractSubstituteGlobalTypes: + file: AbstractSubstituteGlobalTypesServiceTemplate.yaml + nested: + file: GlobalSubstitutionTypesServiceTemplate.yaml +node_types: + org.openecomp.resource.vfc.nodes.heat.cmaui_image: + derived_from: org.openecomp.resource.vfc.nodes.heat.nova.Server +topology_template: + inputs: + cmaui_names: + hidden: false + immutable: false + type: list + description: CMAUI1, CMAUI2 server names + entry_schema: + type: String + p1: + hidden: false + immutable: false + type: string + description: UID of OAM network + cmaui_image: + hidden: false + immutable: false + type: string + description: Image for CMAUI server + cmaui_flavor: + hidden: false + immutable: false + type: string + description: Flavor for CMAUI server + security_group_name: + hidden: false + immutable: false + description: not impotrtant + availability_zone_0: + label: availabilityzone name + hidden: false + immutable: false + type: string + description: availabilityzone name + node_templates: + server_cmaui: + type: org.openecomp.resource.vfc.nodes.heat.cmaui_image + properties: + flavor: + get_input: cmaui_flavor + availability_zone: + get_input: availability_zone_0 + image: + get_input: cmaui_image + name: + get_input: + - cmaui_names + - 0 + cmaui_port_0: + type: org.openecomp.resource.cp.nodes.heat.network.neutron.Port + properties: + replacement_policy: AUTO + security_groups: + - get_input: security_group_name + fixed_ips: + - ip_address: + get_input: + - cmaui_oam_ips + - 0 + network: + get_input: p1 + requirements: + - binding: + capability: tosca.capabilities.network.Bindable + node: server_cmaui + relationship: tosca.relationships.network.BindsTo + groups: + nested: + type: org.openecomp.groups.heat.HeatStack + properties: + heat_file: ../Artifacts/nested.yml + description: cmaui server template for vMMSC + members: + - server_cmaui + - cmaui_port_0 + substitution_mappings: + node_type: org.openecomp.resource.abstract.nodes.heat.nested + capabilities: + host_server_cmaui: + - server_cmaui + - host + os_server_cmaui: + - server_cmaui + - os + endpoint_server_cmaui: + - server_cmaui + - endpoint + binding_server_cmaui: + - server_cmaui + - binding + scalable_server_cmaui: + - server_cmaui + - scalable + attachment_cmaui_port_0: + - cmaui_port_0 + - attachment + requirements: + local_storage_server_cmaui: + - server_cmaui + - local_storage + link_cmaui_port_0: + - cmaui_port_0 + - link
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/AbstractSubstituteGlobalTypesServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/AbstractSubstituteGlobalTypesServiceTemplate.yaml new file mode 100644 index 0000000000..8813b0abf6 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/AbstractSubstituteGlobalTypesServiceTemplate.yaml @@ -0,0 +1,47 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: AbstractSubstituteGlobalTypes + template_version: 1.0.0 +description: Abstract Substitute Global Types +imports: + common_definitions: + file: CommonGlobalTypesServiceTemplate.yaml +data_types: + org.openecomp.datatypes.heat.substitution.SubstitutionFilter: + derived_from: tosca.datatypes.Root + description: Substitution Filter + properties: + substitute_service_template: + type: string + description: Substitute Service Template + required: true + status: SUPPORTED + index_variable: + type: string + description: Index variable + required: false + default: '%index%' + status: SUPPORTED + constraints: + - min_length: 3 + count: + type: string + description: Count + required: false + default: 1 + status: SUPPORTED + mandatory: + type: boolean + description: Mandatory + required: false + default: true + status: SUPPORTED +node_types: + org.openecomp.resource.abstract.nodes.AbstractSubstitute: + derived_from: tosca.nodes.Root + properties: + service_template_filter: + type: org.openecomp.datatypes.heat.substitution.SubstitutionFilter + description: Substitution Filter + required: true + status: SUPPORTED
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/CinderVolumeGlobalTypesServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/CinderVolumeGlobalTypesServiceTemplate.yaml new file mode 100644 index 0000000000..3ef94f22e7 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/CinderVolumeGlobalTypesServiceTemplate.yaml @@ -0,0 +1,176 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: CinderVolumeGlobalTypes + template_version: 1.0.0 +description: Cinder Volume TOSCA Global Types +relationship_types: + org.openecomp.relationships.heat.cinder.VolumeAttachesTo: + derived_from: tosca.relationships.AttachesTo + description: This type represents an attachment relationship for associating volume + properties: + volume_id: + type: string + description: The ID of the volume to be attached + required: true + status: SUPPORTED + location: + type: string + description: The location where the volume is exposed on the instance, mountpoint + required: false + status: SUPPORTED + instance_uuid: + type: string + description: The ID of the server to which the volume attaches + required: true + status: SUPPORTED + attributes: + show: + type: string + description: Detailed information about resource + status: SUPPORTED +node_types: + org.openecomp.resource.vfc.nodes.heat.cinder.Volume: + derived_from: tosca.nodes.BlockStorage + properties: + availability_zone: + type: string + description: The availability zone in which the volume will be created + required: false + status: SUPPORTED + image: + type: string + description: If specified, the name or ID of the image to create the volume from + required: false + status: SUPPORTED + metadata: + type: map + description: Key/value pairs to associate with the volume + required: false + status: SUPPORTED + entry_schema: + type: string + volume_type: + type: string + description: If specified, the type of volume to use, mapping to a specific backend + required: false + status: SUPPORTED + description: + type: string + description: A description of the volume + required: false + status: SUPPORTED + device_type: + type: string + description: Device type + required: false + status: SUPPORTED + constraints: + - valid_values: + - cdrom + - disk + disk_bus: + type: string + description: 'Bus of the device: hypervisor driver chooses a suitable default + if omitted' + required: false + status: SUPPORTED + constraints: + - valid_values: + - ide + - lame_bus + - scsi + - usb + - virtio + backup_id: + type: string + description: If specified, the backup to create the volume from + required: false + status: SUPPORTED + source_volid: + type: string + description: If specified, the volume to use as source + required: false + status: SUPPORTED + boot_index: + type: integer + description: Integer used for ordering the boot disks + required: false + status: SUPPORTED + size: + type: scalar-unit.size + description: The requested storage size (default unit is MB) + required: false + status: SUPPORTED + constraints: + - greater_or_equal: 1 GB + read_only: + type: boolean + description: Enables or disables read-only access mode of volume + required: false + status: SUPPORTED + name: + type: string + description: A name used to distinguish the volume + required: false + status: SUPPORTED + scheduler_hints: + type: map + description: Arbitrary key-value pairs specified by the client to help the Cinder scheduler creating a volume + required: false + status: SUPPORTED + entry_schema: + type: string + swap_size: + type: scalar-unit.size + description: The size of the swap, in MB + required: false + status: SUPPORTED + delete_on_termination: + type: boolean + description: Indicate whether the volume should be deleted when the server is terminated + required: false + status: SUPPORTED + multiattach: + type: boolean + description: Whether allow the volume to be attached more than once + required: false + status: SUPPORTED + attributes: + display_description: + type: string + description: Description of the volume + status: SUPPORTED + attachments: + type: string + description: The list of attachments of the volume + status: SUPPORTED + entry_schema: + type: string + encrypted: + type: boolean + description: Boolean indicating if the volume is encrypted or not + status: SUPPORTED + show: + type: string + description: Detailed information about resource + status: SUPPORTED + created_at: + type: timestamp + description: The timestamp indicating volume creation + status: SUPPORTED + display_name: + type: string + description: Name of the volume + status: SUPPORTED + metadata_values: + type: map + description: Key/value pairs associated with the volume in raw dict form + status: SUPPORTED + bootable: + type: boolean + description: Boolean indicating if the volume can be booted or not + status: SUPPORTED + status: + type: string + description: The current status of the volume + status: SUPPORTED diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/CommonGlobalTypesServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/CommonGlobalTypesServiceTemplate.yaml new file mode 100644 index 0000000000..1a183e9c50 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/CommonGlobalTypesServiceTemplate.yaml @@ -0,0 +1,210 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: CommonGlobalTypes + template_version: 1.0.0 +description: TOSCA Global Types +data_types: + org.openecomp.datatypes.heat.network.AddressPair: + derived_from: tosca.datatypes.Root + description: MAC/IP address pairs + properties: + mac_address: + type: string + description: MAC address + required: false + status: SUPPORTED + ip_address: + type: string + description: IP address + required: false + status: SUPPORTED + org.openecomp.datatypes.heat.network.subnet.HostRoute: + derived_from: tosca.datatypes.Root + description: Host route info for the subnet + properties: + destination: + type: string + description: The destination for static route + required: false + status: SUPPORTED + nexthop: + type: string + description: The next hop for the destination + required: false + status: SUPPORTED + org.openecomp.datatypes.heat.network.neutron.Subnet: + derived_from: tosca.datatypes.Root + description: A subnet represents an IP address block that can be used for assigning IP addresses to virtual instances + properties: + tenant_id: + type: string + description: The ID of the tenant who owns the network + required: false + status: SUPPORTED + enable_dhcp: + type: boolean + description: Set to true if DHCP is enabled and false if DHCP is disabled + required: false + default: true + status: SUPPORTED + ipv6_address_mode: + type: string + description: IPv6 address mode + required: false + status: SUPPORTED + constraints: + - valid_values: + - dhcpv6-stateful + - dhcpv6-stateless + - slaac + ipv6_ra_mode: + type: string + description: IPv6 RA (Router Advertisement) mode + required: false + status: SUPPORTED + constraints: + - valid_values: + - dhcpv6-stateful + - dhcpv6-stateless + - slaac + value_specs: + type: map + description: Extra parameters to include in the request + required: false + default: { + } + status: SUPPORTED + entry_schema: + type: string + allocation_pools: + type: list + description: The start and end addresses for the allocation pools + required: false + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.network.AllocationPool + subnetpool: + type: string + description: The name or ID of the subnet pool + required: false + status: SUPPORTED + dns_nameservers: + type: list + description: A specified set of DNS name servers to be used + required: false + default: [ + ] + status: SUPPORTED + entry_schema: + type: string + host_routes: + type: list + description: The gateway IP address + required: false + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.network.subnet.HostRoute + ip_version: + type: integer + description: The gateway IP address + required: false + default: 4 + status: SUPPORTED + constraints: + - valid_values: + - '4' + - '6' + name: + type: string + description: The name of the subnet + required: false + status: SUPPORTED + prefixlen: + type: integer + description: Prefix length for subnet allocation from subnet pool + required: false + status: SUPPORTED + constraints: + - greater_or_equal: 0 + cidr: + type: string + description: The CIDR + required: false + status: SUPPORTED + gateway_ip: + type: string + description: The gateway IP address + required: false + status: SUPPORTED + org.openecomp.datatypes.heat.network.AllocationPool: + derived_from: tosca.datatypes.Root + description: The start and end addresses for the allocation pool + properties: + start: + type: string + description: Start address for the allocation pool + required: false + status: SUPPORTED + end: + type: string + description: End address for the allocation pool + required: false + status: SUPPORTED +relationship_types: + org.openecomp.relationships.AttachesTo: + derived_from: tosca.relationships.Root + description: This type represents an attachment relationship +group_types: + org.openecomp.groups.heat.HeatStack: + derived_from: tosca.groups.Root + description: Grouped all heat resources which are in the same heat stack + properties: + heat_file: + type: string + description: Heat file which associate to this group/heat stack + required: true + status: SUPPORTED + description: + type: string + description: Heat file description + required: false + status: SUPPORTED +policy_types: + org.openecomp.policies.placement.Colocate: + derived_from: tosca.policy.placement + description: Keep associated nodes (groups of nodes) based upon affinity value + properties: + name: + type: string + description: The name of the policy + required: false + status: SUPPORTED + affinity: + type: string + description: affinity + required: true + status: SUPPORTED + constraints: + - valid_values: + - host + - region + - compute + org.openecomp.policies.placement.Antilocate: + derived_from: tosca.policy.placement + description: My placement policy for separation based upon container type value + properties: + name: + type: string + description: The name of the policy + required: false + status: SUPPORTED + container_type: + type: string + description: container type + required: false + status: SUPPORTED + constraints: + - valid_values: + - host + - region + - compute diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/ContrailNetworkRuleGlobalTypeServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/ContrailNetworkRuleGlobalTypeServiceTemplate.yaml new file mode 100644 index 0000000000..98317310fa --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/ContrailNetworkRuleGlobalTypeServiceTemplate.yaml @@ -0,0 +1,117 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: ContrailNetworkRuleGlobalType + template_version: 1.0.0 +description: Contrail Network Rule Global Types +imports: + common_definitions: + file: CommonGlobalTypesServiceTemplate.yaml +data_types: + org.openecomp.datatypes.heat.contrail.network.rule.PortPairs: + derived_from: tosca.datatypes.Root + description: source and destination port pairs + properties: + start_port: + type: string + description: Start port + required: false + status: SUPPORTED + end_port: + type: string + description: End port + required: false + status: SUPPORTED + org.openecomp.datatypes.heat.contrail.network.rule.Rule: + derived_from: tosca.datatypes.Root + description: policy rule + properties: + src_ports: + type: list + description: Source ports + required: false + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.contrail.network.rule.PortPairs + protocol: + type: string + description: Protocol + required: false + status: SUPPORTED + dst_addresses: + type: list + description: Destination addresses + required: false + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.contrail.network.rule.VirtualNetwork + apply_service: + type: string + description: Service to apply + required: false + status: SUPPORTED + dst_ports: + type: list + description: Destination ports + required: false + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.contrail.network.rule.PortPairs + src_addresses: + type: list + description: Source addresses + required: false + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.contrail.network.rule.VirtualNetwork + direction: + type: string + description: Direction + required: false + status: SUPPORTED + org.openecomp.datatypes.heat.contrail.network.rule.RuleList: + derived_from: tosca.datatypes.Root + description: list of policy rules + properties: + policy_rule: + type: list + description: Contrail network rule + required: false + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.contrail.network.rule.Rule + org.openecomp.datatypes.heat.contrail.network.rule.VirtualNetwork: + derived_from: tosca.datatypes.Root + description: source and destination addresses + properties: + virtual_network: + type: string + description: Virtual network + required: false + status: SUPPORTED +node_types: + org.openecomp.resource.nodes.heat.network.contrail.NetworkRules: + derived_from: tosca.nodes.Root + properties: + entries: + type: org.openecomp.datatypes.heat.contrail.network.rule.RuleList + description: A symbolic name for this contrail network rule + required: false + status: SUPPORTED + name: + type: string + description: A symbolic name for this contrail network rule + required: false + status: SUPPORTED + attributes: + fq_name: + type: string + description: fq_name + status: SUPPORTED + requirements: + - network: + capability: tosca.capabilities.Attachment + node: tosca.nodes.network.Network + relationship: org.openecomp.relationships.AttachesTo + occurrences: + - 0 + - UNBOUNDED diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/ContrailVirtualNetworkGlobalTypeServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/ContrailVirtualNetworkGlobalTypeServiceTemplate.yaml new file mode 100644 index 0000000000..0927e3dd0e --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/ContrailVirtualNetworkGlobalTypeServiceTemplate.yaml @@ -0,0 +1,71 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: ContrailVirtualNetworkGlobalType + template_version: 1.0.0 +description: Contrail Virtual Network Global Types +imports: + common_definitions: + file: CommonGlobalTypesServiceTemplate.yaml +node_types: + org.openecomp.resource.vl.nodes.heat.network.contrail.VirtualNetwork: + derived_from: tosca.nodes.network.Network + properties: + shared: + type: string + description: Is virtual network shared + required: false + status: SUPPORTED + forwarding_mode: + type: string + description: forwarding mode of the virtual network + required: false + status: SUPPORTED + external: + type: string + description: Is virtual network external + required: false + status: SUPPORTED + flood_unknown_unicast: + type: string + description: flood L2 packets on network + required: false + status: SUPPORTED + route_targets: + type: list + description: route targets associated with the virtual network + required: false + status: SUPPORTED + entry_schema: + type: string + subnets: + type: map + description: Network related subnets + required: false + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.network.neutron.Subnet + attributes: + subnets_name: + type: list + description: Subnets name of this network + status: SUPPORTED + entry_schema: + type: string + subnets_show: + type: map + description: Detailed information about each subnet + status: SUPPORTED + entry_schema: + type: string + subnets: + type: map + description: Network related subnets + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.network.neutron.Subnet + capabilities: + attachment: + type: tosca.capabilities.Attachment + occurrences: + - 1 + - UNBOUNDED diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/GlobalSubstitutionTypesServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/GlobalSubstitutionTypesServiceTemplate.yaml new file mode 100644 index 0000000000..08c47bc646 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/GlobalSubstitutionTypesServiceTemplate.yaml @@ -0,0 +1,93 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: GlobalSubstitutionTypes +imports: + NeutronPortGlobalTypes: + file: NeutronPortGlobalTypesServiceTemplate.yaml + NeutronNetGlobalTypes: + file: NeutronNetGlobalTypesServiceTemplate.yaml + CommonGlobalTypes: + file: CommonGlobalTypesServiceTemplate.yaml + CinderVolumeGlobalTypes: + file: CinderVolumeGlobalTypesServiceTemplate.yaml + ContrailNetworkRuleGlobalType: + file: ContrailNetworkRuleGlobalTypeServiceTemplate.yaml + NeutronSecurityRulesGlobalTypes: + file: NeutronSecurityRulesGlobalTypesServiceTemplate.yaml + NovaServerGlobalTypes: + file: NovaServerGlobalTypesServiceTemplate.yaml + ContrailVirtualNetworkGlobalType: + file: ContrailVirtualNetworkGlobalTypeServiceTemplate.yaml + AbstractSubstituteGlobalTypes: + file: AbstractSubstituteGlobalTypesServiceTemplate.yaml +node_types: + org.openecomp.resource.abstract.nodes.heat.nested: + derived_from: org.openecomp.resource.abstract.nodes.AbstractSubstitute + properties: + cmaui_names: + type: list + description: CMAUI1, CMAUI2 server names + entry_schema: + type: String + p1: + type: string + description: UID of OAM network + cmaui_image: + type: string + description: Image for CMAUI server + cmaui_flavor: + type: string + description: Flavor for CMAUI server + security_group_name: + description: not impotrtant + availability_zone_0: + type: string + description: availabilityzone name + requirements: + - local_storage_server_cmaui: + capability: tosca.capabilities.Attachment + node: tosca.nodes.BlockStorage + relationship: tosca.relationships.AttachesTo + occurrences: + - 0 + - UNBOUNDED + - link_cmaui_port_0: + capability: tosca.capabilities.network.Linkable + node: tosca.nodes.Root + relationship: tosca.relationships.network.LinksTo + occurrences: + - 1 + - 1 + capabilities: + host_server_cmaui: + type: tosca.capabilities.Container + valid_source_types: + - tosca.nodes.SoftwareComponent + occurrences: + - 1 + - UNBOUNDED + os_server_cmaui: + type: tosca.capabilities.OperatingSystem + occurrences: + - 1 + - UNBOUNDED + endpoint_server_cmaui: + type: tosca.capabilities.Endpoint.Admin + occurrences: + - 1 + - UNBOUNDED + binding_server_cmaui: + type: tosca.capabilities.network.Bindable + occurrences: + - 1 + - UNBOUNDED + scalable_server_cmaui: + type: tosca.capabilities.Scalable + occurrences: + - 1 + - UNBOUNDED + attachment_cmaui_port_0: + type: tosca.capabilities.Attachment + occurrences: + - 1 + - UNBOUNDED
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NativeTypesServiceTemplateServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NativeTypesServiceTemplateServiceTemplate.yaml new file mode 100644 index 0000000000..e7dfd49ed9 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NativeTypesServiceTemplateServiceTemplate.yaml @@ -0,0 +1,194 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: NativeTypesServiceTemplate + template_version: 1.0.0 +description: TOSCA Native Node Types +node_types: + tosca.nodes.Compute: + derived_from: tosca.nodes.Root + attributes: + private_address: + type: string + description: private address + status: SUPPORTED + public_address: + type: string + description: public_address + status: SUPPORTED + networks: + type: map + description: networks + status: SUPPORTED + entry_schema: + type: tosca.datatypes.network.NetworkInfo + ports: + type: map + description: ports + status: SUPPORTED + entry_schema: + type: tosca.datatypes.network.PortInfo + requirements: + - local_storage: + capability: tosca.capabilities.Attachment + node: tosca.nodes.BlockStorage + relationship: tosca.relationships.AttachesTo + occurrences: + - 0 + - UNBOUNDED + capabilities: + scalable: + type: tosca.capabilities.Scalable + occurrences: + - 1 + - UNBOUNDED + endpoint: + type: tosca.capabilities.Endpoint.Admin + occurrences: + - 1 + - UNBOUNDED + os: + type: tosca.capabilities.OperatingSystem + occurrences: + - 1 + - UNBOUNDED + host: + type: tosca.capabilities.Container + valid_source_types: + - tosca.nodes.SoftwareComponent + occurrences: + - 1 + - UNBOUNDED + binding: + type: tosca.capabilities.network.Bindable + occurrences: + - 1 + - UNBOUNDED + tosca.nodes.network.Port: + derived_from: tosca.nodes.Root + properties: + ip_range_end: + type: string + required: false + status: SUPPORTED + ip_range_start: + type: string + required: false + status: SUPPORTED + ip_address: + type: string + required: false + status: SUPPORTED + is_default: + type: boolean + required: false + default: false + status: SUPPORTED + order: + type: integer + required: true + default: 0 + status: SUPPORTED + constraints: + - greater_or_equal: 0 + requirements: + - link: + capability: tosca.capabilities.network.Linkable + node: tosca.nodes.Root + relationship: tosca.relationships.network.LinksTo + - binding: + capability: tosca.capabilities.network.Bindable + node: tosca.nodes.Root + relationship: tosca.relationships.network.BindsTo + tosca.nodes.Root: + attributes: + tosca_name: + type: string + description: tosca name + status: SUPPORTED + state: + type: string + description: state + status: SUPPORTED + tosca_id: + type: string + description: tosca id + status: SUPPORTED + interfaces: { + } + tosca.nodes.network.Network: + derived_from: tosca.nodes.Root + properties: + physical_network: + type: string + required: false + status: SUPPORTED + segmentation_id: + type: string + required: false + status: SUPPORTED + network_id: + type: string + required: false + status: SUPPORTED + ip_version: + type: integer + required: false + default: 4 + status: SUPPORTED + constraints: + - valid_values: + - 4 + - 6 + start_ip: + type: string + required: false + status: SUPPORTED + network_name: + type: string + required: false + status: SUPPORTED + cidr: + type: string + required: false + status: SUPPORTED + gateway_ip: + type: string + required: false + status: SUPPORTED + network_type: + type: string + required: false + status: SUPPORTED + end_ip: + type: string + required: false + status: SUPPORTED + capabilities: + link: + type: tosca.capabilities.network.Linkable + occurrences: + - 1 + - UNBOUNDED + tosca.nodes.BlockStorage: + derived_from: tosca.nodes.Root + properties: + size: + type: scalar-unit.size + required: false + status: SUPPORTED + constraints: + - greater_or_equal: 1 MB + volume_id: + type: string + required: false + status: SUPPORTED + snapshot_id: + type: string + required: false + status: SUPPORTED + capabilities: + attachment: + type: tosca.capabilities.Attachment + occurrences: + - 1 + - UNBOUNDED diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NeutronNetGlobalTypesServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NeutronNetGlobalTypesServiceTemplate.yaml new file mode 100644 index 0000000000..e80e2727c7 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NeutronNetGlobalTypesServiceTemplate.yaml @@ -0,0 +1,97 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: NeutronNetGlobalTypes + template_version: 1.0.0 +description: Neutron Network TOSCA Global Types +imports: + common_definitions: + file: CommonGlobalTypesServiceTemplate.yaml +node_types: + org.openecomp.resource.vl.nodes.heat.network.neutron.Net: + derived_from: tosca.nodes.network.Network + properties: + dhcp_agent_ids: + type: list + description: The IDs of the DHCP agent to schedule the network + required: false + status: SUPPORTED + entry_schema: + type: string + tenant_id: + type: string + description: The ID of the tenant which will own the network + required: false + status: SUPPORTED + port_security_enabled: + type: boolean + description: Flag to enable/disable port security on the network + required: false + status: SUPPORTED + shared: + type: boolean + description: Whether this network should be shared across all tenants + required: false + default: false + status: SUPPORTED + admin_state_up: + type: boolean + description: A boolean value specifying the administrative status of the network + required: false + default: true + status: SUPPORTED + qos_policy: + type: string + description: The name or ID of QoS policy to attach to this network + required: false + status: SUPPORTED + subnets: + type: map + description: Network related subnets + required: false + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.network.neutron.Subnet + value_specs: + type: map + description: Extra parameters to include in the request + required: false + default: { + } + status: SUPPORTED + entry_schema: + type: string + attributes: + qos_policy_id: + type: string + description: The QoS policy ID attached to this network + status: SUPPORTED + show: + type: string + description: Detailed information about resource + status: SUPPORTED + subnets_name: + type: list + description: Subnets name of this network + status: SUPPORTED + entry_schema: + type: string + subnets: + type: map + description: Network related subnets + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.network.neutron.Subnet + mtu: + type: scalar-unit.size + description: The maximum transmission unit size(in bytes) for the network + status: SUPPORTED + status: + type: string + description: The status of the network + status: SUPPORTED + capabilities: + attachment: + type: tosca.capabilities.Attachment + occurrences: + - 1 + - UNBOUNDED diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NeutronPortGlobalTypesServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NeutronPortGlobalTypesServiceTemplate.yaml new file mode 100644 index 0000000000..a337d6ed18 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NeutronPortGlobalTypesServiceTemplate.yaml @@ -0,0 +1,151 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: NeutronPortGlobalTypes + template_version: 1.0.0 +description: Neutron Port TOSCA Global Types +imports: + common_definitions: + file: CommonGlobalTypesServiceTemplate.yaml +data_types: + org.openecomp.datatypes.heat.neutron.port.FixedIps: + derived_from: tosca.datatypes.Root + description: subnet/ip_address + properties: + subnet: + type: string + description: Subnet in which to allocate the IP address for this port + required: false + status: SUPPORTED + ip_address: + type: string + description: IP address desired in the subnet for this port + required: false + status: SUPPORTED +node_types: + org.openecomp.resource.cp.nodes.heat.network.neutron.Port: + derived_from: tosca.nodes.network.Port + properties: + port_security_enabled: + type: boolean + description: Flag to enable/disable port security on the network + required: false + status: SUPPORTED + device_id: + type: string + description: Device ID of this port + required: false + status: SUPPORTED + qos_policy: + type: string + description: The name or ID of QoS policy to attach to this network + required: false + status: SUPPORTED + allowed_address_pairs: + type: list + description: Additional MAC/IP address pairs allowed to pass through the port + required: false + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.network.AddressPair + binding:vnic_type: + type: string + description: The vnic type to be bound on the neutron port + required: false + status: SUPPORTED + constraints: + - valid_values: + - macvtap + - direct + - normal + value_specs: + type: map + description: Extra parameters to include in the request + required: false + default: { + } + status: SUPPORTED + entry_schema: + type: string + device_owner: + type: string + description: Name of the network owning the port + required: false + status: SUPPORTED + network: + type: string + description: Network this port belongs to + required: false + status: SUPPORTED + replacement_policy: + type: string + description: Policy on how to respond to a stack-update for this resource + required: false + default: AUTO + status: SUPPORTED + constraints: + - valid_values: + - REPLACE_ALWAYS + - AUTO + security_groups: + type: list + description: List of security group names or IDs + required: false + status: SUPPORTED + entry_schema: + type: string + fixed_ips: + type: list + description: Desired IPs for this port + required: false + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.neutron.port.FixedIps + mac_address: + type: string + description: MAC address to give to this port + required: false + status: SUPPORTED + admin_state_up: + type: boolean + description: A boolean value specifying the administrative status of the network + required: false + default: true + status: SUPPORTED + name: + type: string + description: A symbolic name for this port + required: false + status: SUPPORTED + attributes: + tenant_id: + type: string + description: Tenant owning the port + status: SUPPORTED + network_id: + type: string + description: Unique identifier for the network owning the port + status: SUPPORTED + qos_policy_id: + type: string + description: The QoS policy ID attached to this network + status: SUPPORTED + show: + type: string + description: Detailed information about resource + status: SUPPORTED + subnets: + type: list + description: Subnets of this network + status: SUPPORTED + entry_schema: + type: string + status: + type: string + description: The status of the network + status: SUPPORTED + capabilities: + attachment: + type: tosca.capabilities.Attachment + occurrences: + - 1 + - UNBOUNDED
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NeutronSecurityRulesGlobalTypesServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NeutronSecurityRulesGlobalTypesServiceTemplate.yaml new file mode 100644 index 0000000000..49c9a102c8 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NeutronSecurityRulesGlobalTypesServiceTemplate.yaml @@ -0,0 +1,116 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: NeutronSecurityRulesGlobalTypes + template_version: 1.0.0 +description: Neutron Security Rules TOSCA Global Types +imports: + common_definitions: + file: CommonGlobalTypesServiceTemplate.yaml +data_types: + org.openecomp.datatypes.heat.network.neutron.SecurityRules.Rule: + derived_from: tosca.datatypes.Root + description: Rules Pairs + properties: + remote_group_id: + type: string + description: The remote group ID to be associated with this security group rule + required: false + status: SUPPORTED + protocol: + type: string + description: The protocol that is matched by the security group rule + required: false + status: SUPPORTED + constraints: + - valid_values: + - tcp + - udp + - icmp + ethertype: + type: string + description: Ethertype of the traffic + required: false + default: IPv4 + status: SUPPORTED + constraints: + - valid_values: + - IPv4 + - IPv6 + port_range_max: + type: integer + description: 'The maximum port number in the range that is matched by the + security group rule. ' + required: false + status: SUPPORTED + constraints: + - in_range: + - 0 + - 65535 + remote_ip_prefix: + type: string + description: The remote IP prefix (CIDR) to be associated with this security group rule + required: false + status: SUPPORTED + remote_mode: + type: string + description: Whether to specify a remote group or a remote IP prefix + required: false + default: remote_ip_prefix + status: SUPPORTED + constraints: + - valid_values: + - remote_ip_prefix + - remote_group_id + direction: + type: string + description: The direction in which the security group rule is applied + required: false + default: ingress + status: SUPPORTED + constraints: + - valid_values: + - egress + - ingress + port_range_min: + type: integer + description: The minimum port number in the range that is matched by the security group rule. + required: false + status: SUPPORTED + constraints: + - in_range: + - 0 + - 65535 +node_types: + org.openecomp.resource.nodes.heat.network.neutron.SecurityRules: + derived_from: tosca.nodes.Root + properties: + description: + type: string + description: Description of the security group + required: false + status: SUPPORTED + name: + type: string + description: A symbolic name for this security group, which is not required to be unique. + required: false + status: SUPPORTED + rules: + type: list + description: List of security group rules + required: false + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.network.neutron.SecurityRules.Rule + attributes: + show: + type: string + description: Detailed information about resource + status: SUPPORTED + requirements: + - port: + capability: tosca.capabilities.Attachment + node: org.openecomp.resource.cp.nodes.heat.network.neutron.Port + relationship: org.openecomp.relationships.AttachesTo + occurrences: + - 0 + - UNBOUNDED
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NovaServerGlobalTypesServiceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NovaServerGlobalTypesServiceTemplate.yaml new file mode 100644 index 0000000000..2253a1e4af --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/globalServiceTemplates/NovaServerGlobalTypesServiceTemplate.yaml @@ -0,0 +1,249 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: NovaServerGlobalTypes + template_version: 1.0.0 +description: Nova Server TOSCA Global Types +imports: + common_definitions: + file: CommonGlobalTypesServiceTemplate.yaml +data_types: + org.openecomp.datatypes.heat.novaServer.network.PortExtraProperties: + derived_from: tosca.datatypes.Root + description: Nova server network expand properties for port + properties: + port_security_enabled: + type: boolean + description: Flag to enable/disable port security on the port + required: false + status: SUPPORTED + mac_address: + type: string + description: MAC address to give to this port + required: false + status: SUPPORTED + admin_state_up: + type: boolean + description: The administrative state of this port + required: false + default: true + status: SUPPORTED + qos_policy: + type: string + description: The name or ID of QoS policy to attach to this port + required: false + status: SUPPORTED + allowed_address_pairs: + type: list + description: Additional MAC/IP address pairs allowed to pass through the port + required: false + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.network.AddressPair + binding:vnic_type: + type: string + description: The vnic type to be bound on the neutron port + required: false + status: SUPPORTED + constraints: + - valid_values: + - macvtap + - direct + - normal + value_specs: + type: map + description: Extra parameters to include in the request + required: false + default: { + } + status: SUPPORTED + entry_schema: + type: string + org.openecomp.datatypes.heat.novaServer.network.AddressInfo: + derived_from: tosca.datatypes.network.NetworkInfo + description: Network addresses with corresponding port id + properties: + port_id: + type: string + description: Port id + required: false + status: SUPPORTED +node_types: + org.openecomp.resource.vfc.nodes.heat.nova.Server: + derived_from: tosca.nodes.Compute + properties: + admin_pass: + type: string + description: The administrator password for the server + required: false + status: SUPPORTED + availability_zone: + type: string + description: Availability zone to create servers in + required: false + status: SUPPORTED + image: + type: string + description: The ID or name of the image to boot with + required: false + status: SUPPORTED + image_update_policy: + type: string + description: Policy on how to apply an image-id update + required: false + default: REBUILD + status: SUPPORTED + constraints: + - valid_values: + - REBUILD_PRESERVE_EPHEMERAL + - REPLACE + - REBUILD + metadata: + type: map + description: Arbitrary key/value metadata to store for this server + required: false + status: SUPPORTED + constraints: + - max_length: 255 + entry_schema: + type: string + constraints: + - max_length: 255 + user_data_update_policy: + type: string + description: Policy on how to apply a user_data update + required: false + default: REPLACE + status: SUPPORTED + constraints: + - valid_values: + - REPLACE + - IGNORE + flavor_update_policy: + type: string + description: Policy on how to apply a flavor update + required: false + default: RESIZE + status: SUPPORTED + constraints: + - valid_values: + - RESIZE + - REPLACE + user_data: + type: string + description: User data script to be executed by cloud-init + required: false + default: '' + status: SUPPORTED + flavor: + type: string + description: The ID or name of the flavor to boot onto + required: true + status: SUPPORTED + key_name: + type: string + description: Name of keypair to inject into the server + required: false + status: SUPPORTED + reservation_id: + type: string + description: A UUID for the set of servers being requested + required: false + status: SUPPORTED + security_groups: + type: list + description: List of security group names or IDs + required: false + default: [ + ] + status: SUPPORTED + entry_schema: + type: string + config_drive: + type: boolean + description: enable config drive on the server + required: false + status: SUPPORTED + personality: + type: map + description: A map of files to create/overwrite on the server upon boot + required: false + default: { + } + status: SUPPORTED + entry_schema: + type: string + software_config_transport: + type: string + description: How the server should receive the metadata required for software configuration + required: false + default: POLL_SERVER_CFN + status: SUPPORTED + constraints: + - valid_values: + - POLL_SERVER_CFN + - POLL_SERVER_HEAT + - POLL_TEMP_URL + - ZAQAR_MESSAGE + user_data_format: + type: string + description: How the user_data should be formatted for the server + required: false + default: HEAT_CFNTOOLS + status: SUPPORTED + constraints: + - valid_values: + - SOFTWARE_CONFIG + - RAW + - HEAT_CFNTOOLS + diskConfig: + type: string + description: Control how the disk is partitioned when the server is created + required: false + status: SUPPORTED + constraints: + - valid_values: + - AUTO + - MANUAL + name: + type: string + description: Server name + required: false + status: SUPPORTED + scheduler_hints: + type: map + description: Arbitrary key-value pairs specified by the client to help boot a server + required: false + status: SUPPORTED + entry_schema: + type: string + attributes: + accessIPv4: + type: string + description: The manually assigned alternative public IPv4 address of the server + status: SUPPORTED + addresses: + type: map + description: A dict of all network addresses with corresponding port_id + status: SUPPORTED + entry_schema: + type: org.openecomp.datatypes.heat.novaServer.network.AddressInfo + accessIPv6: + type: string + description: The manually assigned alternative public IPv6 address of the server + status: SUPPORTED + instance_name: + type: string + description: AWS compatible instance name + status: SUPPORTED + name: + type: string + description: Name of the server + status: SUPPORTED + show: + type: string + description: Detailed information about resource + status: SUPPORTED + console_urls: + type: string + description: URLs of servers consoles + status: SUPPORTED
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplate.yaml new file mode 100644 index 0000000000..612bc2d2fa --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplate.yaml @@ -0,0 +1,116 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: Test + template_author: OPENECOMP + template_version: 1.0.0 +description: testing desc tosca service template +imports: + myfile1: + file: path1/path2/file1.yaml + myfile2: + file: path1/path2/file2.yaml +artifact_types: + one_artifact: + mime_type: application/java-archive + file_ext: + - yaml + - xml +node_types: + compute_node_type: + derived_from: tosca.nodes.Root + version: 1.0.0 + description: tosca compute test + properties: + cpu_num: + type: integer + description: Number of CPUs requested for a software node instance + required: true + default: 1 + status: SUPPORTED + constraints: + - greater_or_equal: 5.0 + - equal: 5 + - greater_than: 6.02 + - in_range: + - 0 + - UNBOUNDED + attributes: + attDef1: + type: string + default: hi + status: SUPPORTED + requirements: + - re1: + capability: tosca.cap1 + occurrences: + - 5 + - 1 + capabilities: + cap1: + type: tosca.cap + valid_source_types: + - node1 + - node2 + occurrences: + - 1 + - UNBOUNDED +topology_template: + description: topologi template descroption + inputs: + inParam1: + type: string + description: desc + required: false + default: my default val + constraints: + - greater_than: 6 + - greater_or_equal: 9 + entry_schema: + type: tosca.myType + node_templates: + firatNodeTemplate: + type: nodeTypeRef + directives: + - selectable + - substitutable + properties: + prop2: '{ get_input: my_mysql_rootpw }' + prop1: abcd + attributes: + att2: '{ get_input: my_mysql_rootpw }' + att1: att1Val + requirements: + - req1: + capability: capA + node: nodeA + relationship: relationB + node_filter: + properties: + propName1: + - greater_or_equal: 9 + propName2: + - min_length: 1 + - max_length: 2 + occurrences: + - 1 + - 2 + - req2: + capability: capA + node: nodeA + relationship: relationB + capabilities: + - cap1: + properties: + num_cpus: '{ get_input: cpus }' + attributes: + num_cpus: '66' + node_filter: + properties: + test1: + - equal: 1 MB + substitution_mappings: + node_type: myNodeType.node + capabilities: + database_endpoint: + - database + - database_endpoint diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateHeatExtend.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateHeatExtend.yaml new file mode 100644 index 0000000000..4515e3dee3 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateHeatExtend.yaml @@ -0,0 +1,117 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: Test + template_author: OPENECOMP + template_version: 1.0.0 +description: testing desc tosca service template +imports: + myfile1: + file: path1/path2/file1.yaml + myfile2: + file: path1/path2/file2.yaml +artifact_types: + one_artifact: + mime_type: application/java-archive + file_ext: + - yaml + - xml +node_types: + compute_node_type: + derived_from: tosca.nodes.Root + version: 1.0.0 + description: tosca compute test + properties: + cpu_num: + type: integer + description: Number of CPUs requested for a software node instance + required: true + default: 1 + status: SUPPORTED + constraints: + - greater_or_equal: 5.0 + - equal: 5 + - greater_than: 6.02 + - in_range: + - 0 + - UNBOUNDED + attributes: + attDef1: + type: string + default: hi + status: SUPPORTED + requirements: + - re1: + capability: tosca.cap1 + occurrences: + - 5 + - 1 + capabilities: + cap1: + type: tosca.cap + valid_source_types: + - node1 + - node2 + occurrences: + - 1 + - UNBOUNDED +topology_template: + description: topologi template descroption + inputs: + inParam1: + type: string + description: desc + required: false + default: my default val + label: my label + constraints: + - greater_than: 6 + - greater_or_equal: 9 + entry_schema: + type: tosca.myType + node_templates: + firatNodeTemplate: + type: nodeTypeRef + directives: + - selectable + - substitutable + properties: + prop2: '{ get_input: my_mysql_rootpw }' + prop1: abcd + attributes: + att2: '{ get_input: my_mysql_rootpw }' + att1: att1Val + requirements: + - req1: + capability: capA + node: nodeA + relationship: relationB + node_filter: + properties: + propName1: + - greater_or_equal: 9 + propName2: + - min_length: 1 + - max_length: 2 + occurrences: + - 1 + - 2 + - req2: + capability: capA + node: nodeA + relationship: relationB + capabilities: + - cap1: + properties: + num_cpus: '{ get_input: cpus }' + attributes: + num_cpus: '66' + node_filter: + properties: + test1: + - equal: 1 MB + substitution_mappings: + node_type: myNodeType.node + capabilities: + database_endpoint: + - database + - database_endpoint |