From 13b4de462eb4892e1614ebb98c04a8052629571d Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Wed, 31 Mar 2021 21:53:05 +0100 Subject: Fix NSD properties Signed-off-by: MichaelMorris Issue-ID: SDC-3545 Change-Id: I090bdcc85e85f1ec86851de3f957ad2ccd148ed5 (cherry picked from commit 49e74d3a9d5f77af3e2aa321a863fd83a1ca6f73) --- .../nsd/generator/NsDescriptorGeneratorImpl.java | 18 ++++++---- .../generator/NsDescriptorGeneratorImplTest.java | 41 ++++++++++++++++++---- .../execute/sanity/EtsiNetworkServiceUiTests.java | 1 + 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImpl.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImpl.java index f024d8f52a..fc3dac2e31 100644 --- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImpl.java +++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImpl.java @@ -71,6 +71,8 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator { .getDefaultImports(); private static final List PROPERTIES_TO_EXCLUDE_FROM_ETSI_SOL_NSD_NS_NODE_TYPE = Arrays .asList("cds_model_name", "cds_model_version", "skip_post_instantiation_configuration", "controller_actor"); + private static final List ETSI_SOL_NSD_NS_NODE_TYPE_PROPERTIES = Arrays + .asList("descriptor_id", "designer", "version", "name", "invariant_id", "flavour_id", "ns_profile", "service_availability_level"); private static final List PROPERTIES_TO_EXCLUDE_FROM_ETSI_SOL_NSD_NS_NODE_TEMPLATE = Arrays .asList("nf_function", "nf_role", "nf_naming_code", "nf_type", "nf_naming", "availability_zone_max_count", "min_instances", "max_instances", "multi_stage_design", "sdnc_model_name", "sdnc_model_version", "sdnc_artifact_name", "skip_post_instantiation_configuration", @@ -175,7 +177,7 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator { componentToscaTemplate.getNode_types().putAll(nodeTypeMap); } handleNodeTemplates(componentToscaTemplate); - removeOnapPropertiesFromInputs(componentToscaTemplate); + removeOnapAndEtsiNsdPropertiesFromInputs(componentToscaTemplate); handleSubstitutionMappings(componentToscaTemplate, nsNodeTypeName); final Map nodeTemplates = new HashMap<>(); nodeTemplates.put(nsNodeTypeName, @@ -248,7 +250,7 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator { for (final Entry property : propertyMap.entrySet()) { if (!PROPERTIES_TO_EXCLUDE_FROM_ETSI_SOL_NSD_NS_NODE_TEMPLATE.contains(property.getKey()) && propertyIsDefinedInNodeType( property.getKey())) { - editedPropertyMap.put(property.getKey().substring(property.getKey().indexOf('_') + 1), property.getValue()); + editedPropertyMap.put(property.getKey(), property.getValue()); } } if (editedPropertyMap.isEmpty()) { @@ -276,11 +278,13 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator { nodeTemplate.getValue().setCapabilities(null); } - private void removeOnapPropertiesFromInputs(final ToscaTemplate template) { + private void removeOnapAndEtsiNsdPropertiesFromInputs(final ToscaTemplate template) { final ToscaTopolgyTemplate topologyTemplate = template.getTopology_template(); final Map inputMap = topologyTemplate.getInputs(); + + if (MapUtils.isNotEmpty(inputMap)) { - inputMap.entrySet().removeIf(entry -> PROPERTIES_TO_EXCLUDE_FROM_ETSI_SOL_NSD_NS_NODE_TYPE.contains(entry.getKey())); + inputMap.entrySet().removeIf(entry -> PROPERTIES_TO_EXCLUDE_FROM_ETSI_SOL_NSD_NS_NODE_TYPE.contains(entry.getKey()) || ETSI_SOL_NSD_NS_NODE_TYPE_PROPERTIES.contains(entry.getKey())); } if (MapUtils.isEmpty(inputMap)) { topologyTemplate.setInputs(null); @@ -324,7 +328,7 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator { final Map propertiesInNsNodeType = nsNodeType.getProperties(); for (final Entry property : propertiesInNsNodeType.entrySet()) { final ToscaProperty toscaProperty = property.getValue(); - if (toscaProperty.getDefaultp() != null) { + if (toscaProperty.getDefaultp() != null && ETSI_SOL_NSD_NS_NODE_TYPE_PROPERTIES.contains(property.getKey())) { final ToscaPropertyConstraintValidValues constraint = new ToscaPropertyConstraintValidValues( Collections.singletonList(toscaProperty.getDefaultp().toString())); toscaProperty.setConstraints(Collections.singletonList(constraint)); @@ -370,7 +374,9 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator { final Map properties = toscaNodeType.getProperties(); final Map nodeTemplateProperties = new HashMap<>(); for (final Entry property : properties.entrySet()) { - nodeTemplateProperties.put(property.getKey(), property.getValue().getDefaultp()); + if (property.getValue().getDefaultp() != null) { + nodeTemplateProperties.put(property.getKey(), property.getValue().getDefaultp()); + } } if (!nodeTemplateProperties.isEmpty()) { nodeTemplate.setProperties(nodeTemplateProperties); diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java index cfd0ef7b90..516c2ec7bf 100644 --- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java +++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java @@ -44,6 +44,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -127,6 +128,7 @@ class NsDescriptorGeneratorImplTest { } @Test + @SuppressWarnings("unchecked") void testGenerate() throws IOException, NsdException { //given final Component component = mock(Component.class); @@ -158,13 +160,19 @@ class NsDescriptorGeneratorImplTest { capabilities.put("capability", capabilitiesAssignment); when(substitutionMapping.getCapabilities()).thenReturn(capabilities); componentToscaTopologyTemplate.setSubstitution_mappings(substitutionMapping); + + Map inputs = new HashMap<>(); + inputs.put("invariant_id", new ToscaProperty()); + inputs.put("other_property", new ToscaProperty()); + componentToscaTopologyTemplate.setInputs(inputs ); final ToscaTemplate componentInterfaceToscaTemplate = new ToscaTemplate(""); final String designerPropertyValue = "designerValue"; final String versionPropertyValue = "versionValue"; final String namePropertyValue = "nameValue"; final String invariantIdPropertyValue = "invariantIdValue"; + final String otherPropertyValue = "otherValue"; final ToscaNodeType interfaceToscaNodeType = createDefaultInterfaceToscaNodeType(designerPropertyValue, versionPropertyValue, - namePropertyValue, invariantIdPropertyValue); + namePropertyValue, invariantIdPropertyValue, otherPropertyValue); List> interfaceNodeTypeRequirements = new ArrayList<>(); Map interfaceNodeTypeRequirementMap = new HashMap<>(); interfaceNodeTypeRequirementMap.put("VNF1" + DOT + VIRTUAL_LINK_REQUIREMENT_NAME, mock(ToscaRequirement.class)); @@ -191,9 +199,9 @@ class NsDescriptorGeneratorImplTest { assertThat("Nsd name should be as expected", nsd.getName(), is(namePropertyValue)); assertThat("Nsd invariantId should be as expected", nsd.getInvariantId(), is(invariantIdPropertyValue)); final Map toscaTemplateYaml = readYamlAsMap(nsd.getContents()); - @SuppressWarnings("unchecked") final Map topologyTemplate = (Map) toscaTemplateYaml.get("topology_template"); + final Map topologyTemplate = (Map) toscaTemplateYaml.get("topology_template"); assertThat("topology_template should not be empty", topologyTemplate, is(not(anEmptyMap()))); - @SuppressWarnings("unchecked") final Map substitutionMappings = (Map) topologyTemplate + final Map substitutionMappings = (Map) topologyTemplate .get("substitution_mappings"); assertThat("substitution_mappings should not be empty", substitutionMappings, is(not(anEmptyMap()))); assertThat("substitution_mappings->node_type should not be null", substitutionMappings.get("node_type"), is(notNullValue())); @@ -205,19 +213,39 @@ class NsDescriptorGeneratorImplTest { final Map> subMappingCapabilities = (Map>) substitutionMappings.get("capabilities"); assertNull(subMappingCapabilities); - @SuppressWarnings("unchecked") final Map nodeType = (Map) ((Map) toscaTemplateYaml.get("node_types")).get(nsNodeTypeName); + final Map topologyInputs = (Map) topologyTemplate.get("inputs"); + assertTrue(topologyInputs.containsKey("other_property")); + assertEquals(1, topologyInputs.size()); + + final Map nodeTemplates = (Map) ((Map) topologyTemplate.get("node_templates")); + final Map nodeTemplateVnfd = (Map) ((Map) nodeTemplates.get(VNFD_AMF_NODE_NAME)); + final Map nodeTemplateProperties = (Map) ((Map) nodeTemplateVnfd.get("properties")); + assertTrue(nodeTemplateProperties.containsKey("will_not_be_excluded")); + + final Map nodeType = (Map) ((Map) toscaTemplateYaml.get("node_types")).get(nsNodeTypeName); assertTrue(((List>)nodeType.get("requirements")).get(0).containsKey("VNF1" + DOT + VIRTUAL_LINK_REQUIREMENT_NAME)); assertFalse(((List>)nodeType.get("requirements")).get(0).containsKey("VNF1" + DOT + VIRTUAL_BINDING_REQUIREMENT_NAME)); + + assertEquals(5, ((Map)nodeType.get("properties")).size()); + for (final Entry property: ((Map)nodeType.get("properties")).entrySet()) { + if (property.getKey().equals("other_property")) { + assertNull(property.getValue().get("constraints")); + } else { + assertEquals(1, ((List)property.getValue().get("constraints")).size()); + } + } + } private ToscaNodeType createDefaultInterfaceToscaNodeType(final String designerPropertyValue, final String versionPropertyValue, - final String namePropertyValue, final String invariantIdPropertyValue) { + final String namePropertyValue, final String invariantIdPropertyValue, String otherPropertyValue) { final ToscaNodeType interfaceToscaNodeType = new ToscaNodeType(); final Map propertyMap = new HashMap<>(); propertyMap.put("designer", createToscaProperty(designerPropertyValue)); propertyMap.put("version", createToscaProperty(versionPropertyValue)); propertyMap.put("name", createToscaProperty(namePropertyValue)); propertyMap.put("invariant_id", createToscaProperty(invariantIdPropertyValue)); + propertyMap.put("other_property", createToscaProperty(otherPropertyValue)); interfaceToscaNodeType.setProperties(propertyMap); return interfaceToscaNodeType; } @@ -230,8 +258,7 @@ class NsDescriptorGeneratorImplTest { private ToscaProperty createToscaProperty(final String value) { final ToscaProperty toscaProperty = new ToscaProperty(); - final ToscaPropertyConstraint toscaPropertyConstraint = new ToscaPropertyConstraintValidValues(ImmutableList.of(value)); - toscaProperty.setConstraints(ImmutableList.of(toscaPropertyConstraint)); + toscaProperty.setDefaultp(value); return toscaProperty; } diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/EtsiNetworkServiceUiTests.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/EtsiNetworkServiceUiTests.java index 0854bec785..03a73aaeb3 100644 --- a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/EtsiNetworkServiceUiTests.java +++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/EtsiNetworkServiceUiTests.java @@ -81,6 +81,7 @@ public class EtsiNetworkServiceUiTests extends SetupCDTest { assertThat("No artifact download was found", toscaArtifactsPage.getDownloadedArtifactList(), not(empty())); final String downloadedCsarName = toscaArtifactsPage.getDownloadedArtifactList().get(0); + propertyMap.entrySet().removeIf(e -> e.getValue() == null); checkEtsiNsPackage(createServiceFlow.getServiceCreateData().getName(), downloadedCsarName, propertyMap); } -- cgit 1.2.3-korg