From ec3b877ab6d9ed87bdecfe420fcfe0436b3cfe7a Mon Sep 17 00:00:00 2001 From: ojasdubey Date: Thu, 14 Jun 2018 20:14:39 +0530 Subject: VLAN Tagging - Display naming convention warning Vlan tagging HEAT validation doesn't show appropriate warning when naming convention is not followed Change-Id: I98d998ac425a66f0f0b362aecd5da6c867c5b7eb Issue-ID: SDC-1431 Signed-off-by: ojasdubey --- .../VirtualMachineInterfaceGuidelineValidator.java | 88 ++++++++-------------- ...tualMachineInterfaceGuidelineValidatorTest.java | 10 +-- .../negative_get_resource/input/nested.yml | 2 +- .../negative_test/input/nested.yml | 2 +- .../negative_test_non_string/input/nested.yml | 2 +- .../positive_test/input/nested.yml | 2 +- .../positive_test/input/nested.yml | 2 +- .../negative_test/two_vlans/nested.yml | 4 +- .../negative_test/vlan_and_nova/nested.yml | 2 +- .../positive_test/input/nested.yml | 2 +- 10 files changed, 44 insertions(+), 72 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src') diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/VirtualMachineInterfaceGuidelineValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/VirtualMachineInterfaceGuidelineValidator.java index de4dc79207..4347d6cef9 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/VirtualMachineInterfaceGuidelineValidator.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/VirtualMachineInterfaceGuidelineValidator.java @@ -1,5 +1,17 @@ package org.openecomp.sdc.validation.impl.validators.namingconvention; +import static org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE; +import static org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE; +import static org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + import org.openecomp.core.validation.ErrorMessageCode; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; import org.openecomp.core.validation.types.GlobalValidationContext; @@ -7,29 +19,12 @@ import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.heat.datatypes.DefinedHeatParameterTypes; import org.openecomp.sdc.heat.datatypes.model.Resource; import org.openecomp.sdc.heat.services.HeatConstants; +import org.openecomp.sdc.heat.services.HeatResourceUtil; import org.openecomp.sdc.heat.services.HeatStructureUtil; import org.openecomp.sdc.validation.ResourceValidator; import org.openecomp.sdc.validation.ValidationContext; import org.openecomp.sdc.validation.type.NamingConventionValidationContext; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE; -import static org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE; -import static org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE; - -/** - * @author KATYR - * @since February 05, 2018 - */ - public class VirtualMachineInterfaceGuidelineValidator implements ResourceValidator { private static final ErrorMessageCode ERROR_CODE_VLAN_GUIDELINE1 = new ErrorMessageCode ("VlANG1"); @@ -37,8 +32,6 @@ public class VirtualMachineInterfaceGuidelineValidator implements ResourceValida ("VlANG2"); private static final ErrorMessageCode ERROR_CODE_VLAN_GUIDELINE3 = new ErrorMessageCode ("VlANG3"); - private static final String UNDERSCORE = "_"; - private static final String VMI = "vmi"; @Override @@ -53,8 +46,7 @@ public class VirtualMachineInterfaceGuidelineValidator implements ResourceValida namingConventionValidationContext); validateSingleVirtualMachineInterfaceInFile(fileName, globalContext, namingConventionValidationContext); - validateNamingConvention(fileName, resourceEntry, globalContext - ); + validateSubInterfaceNamingConvention(fileName, resourceEntry, globalContext); } } @@ -63,32 +55,28 @@ public class VirtualMachineInterfaceGuidelineValidator implements ResourceValida GlobalValidationContext globalContext, NamingConventionValidationContext namingConventionValidationContext) { - Object refsPropertyValue = resourceEntry.getValue().getProperties() - .get(HeatConstants.VMI_REFS_PROPERTY_NAME); + Object refsPropertyValue = resourceEntry.getValue().getProperties().get(HeatConstants.VMI_REFS_PROPERTY_NAME); if (Objects.isNull(refsPropertyValue)) { addViolationToContext(fileName, globalContext, ErrorLevel.WARNING, ERROR_CODE_VLAN_GUIDELINE1, - Messages.VLAN_GUIDELINE_VALIDATION_NOT_MODELED_THROUGH_RESOURCE_GROUP, - resourceEntry.getKey()); + Messages.VLAN_GUIDELINE_VALIDATION_NOT_MODELED_THROUGH_RESOURCE_GROUP, resourceEntry.getKey()); return; } - final boolean modeledThroughResourceGroup = - isModeledThroughResourceGroup(fileName, globalContext, - namingConventionValidationContext, - refsPropertyValue); + final boolean modeledThroughResourceGroup = isModeledThroughResourceGroup(fileName, globalContext, + namingConventionValidationContext, refsPropertyValue); if (!modeledThroughResourceGroup) { addViolationToContext(fileName, globalContext, ErrorLevel.WARNING, ERROR_CODE_VLAN_GUIDELINE1, - Messages.VLAN_GUIDELINE_VALIDATION_NOT_MODELED_THROUGH_RESOURCE_GROUP, - resourceEntry.getKey()); + Messages.VLAN_GUIDELINE_VALIDATION_NOT_MODELED_THROUGH_RESOURCE_GROUP, resourceEntry.getKey()); } } - private void validateNamingConvention(String fileName, Map.Entry - resourceEntry, GlobalValidationContext globalContext) { + private void validateSubInterfaceNamingConvention(String fileName, Map.Entry resourceEntry, + GlobalValidationContext globalContext) { final String resourceId = resourceEntry.getKey(); - final String networkRole = extractNetworkRoleFromResourceId(resourceId); - if (Objects.isNull(networkRole)) { + final Optional networkRole = HeatResourceUtil.extractNetworkRoleFromSubInterfaceId(resourceId, resourceEntry + .getValue().getType()); + if (!networkRole.isPresent()) { addViolationToContext(fileName, globalContext, ErrorLevel.WARNING, ERROR_CODE_VLAN_GUIDELINE3, Messages.VLAN_GUIDELINE_VALIDATION_NAMING_CONVENTION, resourceId); } @@ -115,8 +103,8 @@ public class VirtualMachineInterfaceGuidelineValidator implements ResourceValida private boolean fileContainsNonVlanResources(Map resources, Set forbiddenTypes) { - for (String resourceName : resources.keySet()) { - if (forbiddenTypes.contains(resources.get(resourceName).getType())) { + for (Map.Entry resourceEntry : resources.entrySet()) { + if (forbiddenTypes.contains(resourceEntry.getValue().getType())) { return true; } } @@ -125,8 +113,8 @@ public class VirtualMachineInterfaceGuidelineValidator implements ResourceValida private int countVlanResources(Map resources) { int numVlanResources = 0; - for (String resourceName : resources.keySet()) { - final String resourceType = resources.get(resourceName).getType(); + for (Map.Entry resourceEntry : resources.entrySet()) { + final String resourceType = resourceEntry.getValue().getType(); if (resourceType.equals (CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource())) { numVlanResources++; @@ -149,8 +137,7 @@ public class VirtualMachineInterfaceGuidelineValidator implements ResourceValida private Optional getVlanTagPropertyValue(Resource resource) { - Object vmiProperties = resource.getProperties() - .get(HeatConstants.VMI_PROPERTIES_PROPERTY_NAME); + Object vmiProperties = resource.getProperties().get(HeatConstants.VMI_PROPERTIES_PROPERTY_NAME); if (Objects.nonNull(vmiProperties) && vmiProperties instanceof Map) { return Optional.ofNullable(((Map) vmiProperties) .get(HeatConstants.VMI_SUB_INTERFACE_VLAN_TAG_PROPERTY_NAME)); @@ -205,19 +192,6 @@ public class VirtualMachineInterfaceGuidelineValidator implements ResourceValida } - private static String extractNetworkRoleFromResourceId(String resourceId) { - - List splitSubInterfaceResourceId = - Arrays.asList(resourceId.toLowerCase().split(UNDERSCORE)); - - int vmiIndex = splitSubInterfaceResourceId.indexOf(VMI); - if (vmiIndex > 0) { - return splitSubInterfaceResourceId.get(vmiIndex - 1); - } - - return null; - } - private enum Messages { VLAN_GUIDELINE_VALIDATION_NOT_MODELED_THROUGH_RESOURCE_GROUP("VLAN Resource will not be " + @@ -225,9 +199,7 @@ public class VirtualMachineInterfaceGuidelineValidator implements ResourceValida VLAN_GUIDELINE_VALIDATION_SINGLE_VLAN("There should not be any Compute Server Node, Port, " + "Parent Port in nested file [%s]"), VLAN_GUIDELINE_VALIDATION_NAMING_CONVENTION( - "Network role associated with VLAN Sub-interface " + - "id" + - "[%s] is not following the naming convention"); + "Network role associated with VLAN Sub-interface id[%s] is not following the naming convention"); private final String errorMessage; diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/VirtualMachineInterfaceGuidelineValidatorTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/VirtualMachineInterfaceGuidelineValidatorTest.java index 407adae932..4d3718ee8d 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/VirtualMachineInterfaceGuidelineValidatorTest.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/VirtualMachineInterfaceGuidelineValidatorTest.java @@ -1,5 +1,7 @@ package org.openecomp.sdc.validation.impl.validators.namingconvention; +import java.util.Map; + import org.openecomp.core.validation.types.MessageContainer; import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes; import org.openecomp.sdc.validation.impl.validators.NamingConventionGuideLineValidator; @@ -7,8 +9,6 @@ import org.openecomp.sdc.validation.util.ValidationTestUtil; import org.testng.Assert; import org.testng.annotations.Test; -import java.util.Map; - public class VirtualMachineInterfaceGuidelineValidatorTest { private static final String PATH = "/org/openecomp/validation/validators/guideLineValidator/vlan_validation/"; @@ -47,7 +47,7 @@ public class VirtualMachineInterfaceGuidelineValidatorTest { Assert.assertEquals( messages.get("nested.yml").getErrorMessageList().get(0).getMessage(), "WARNING: [VlANG1]: VLAN Resource will not be translated as the VLAN Sub-interface " + - "[template_vmi_Vlan_2] is not modeled as resource group"); + "[vdbe_0_subint_untr_vmi_0] is not modeled as resource group"); } @Test @@ -68,7 +68,7 @@ public class VirtualMachineInterfaceGuidelineValidatorTest { Assert.assertEquals( messages.get("nested.yml").getErrorMessageList().get(0).getMessage(), "WARNING: [VlANG1]: VLAN Resource will not be translated as the VLAN Sub-interface " + - "[template_vmi_Vlan_2] is not modeled as resource group"); + "[vdbe_0_subint_untr_vmi_0] is not modeled as resource group"); } @Test @@ -89,7 +89,7 @@ public class VirtualMachineInterfaceGuidelineValidatorTest { Assert.assertEquals( messages.get("nested.yml").getErrorMessageList().get(0).getMessage(), "WARNING: [VlANG1]: VLAN Resource will not be translated as the VLAN Sub-interface " + - "[template_vmi_Vlan_2] is not modeled as resource group"); + "[vdbe_0_subint_untr_vmi_0] is not modeled as resource group"); } diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/negative_get_resource/input/nested.yml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/negative_get_resource/input/nested.yml index a1846b72c7..6f8c5e7518 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/negative_get_resource/input/nested.yml +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/negative_get_resource/input/nested.yml @@ -29,7 +29,7 @@ parameters: resources: - template_vmi_Vlan_2: + vdbe_0_subint_untr_vmi_0: type: OS::ContrailV2::VirtualMachineInterface properties: name: diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/negative_test/input/nested.yml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/negative_test/input/nested.yml index 5b128f5ea2..4253933c16 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/negative_test/input/nested.yml +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/negative_test/input/nested.yml @@ -29,7 +29,7 @@ parameters: resources: - template_vmi_Vlan_2: + vdbe_0_subint_untr_vmi_0: type: OS::ContrailV2::VirtualMachineInterface properties: name: diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/negative_test_non_string/input/nested.yml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/negative_test_non_string/input/nested.yml index 1b4c03fa26..18eb29efb5 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/negative_test_non_string/input/nested.yml +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/negative_test_non_string/input/nested.yml @@ -29,7 +29,7 @@ parameters: resources: - template_vmi_Vlan_2: + vdbe_0_subint_untr_vmi_0: type: OS::ContrailV2::VirtualMachineInterface properties: name: diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/positive_test/input/nested.yml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/positive_test/input/nested.yml index 272543c2a1..6519bffb16 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/positive_test/input/nested.yml +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/modeled_through_resource_group/positive_test/input/nested.yml @@ -29,7 +29,7 @@ parameters: resources: - template_vmi_Vlan_2: + vdbe_0_subint_untr_vmi_0: type: OS::ContrailV2::VirtualMachineInterface properties: name: diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/naming_convention/positive_test/input/nested.yml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/naming_convention/positive_test/input/nested.yml index f45f6928c9..eed04cf3e3 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/naming_convention/positive_test/input/nested.yml +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/naming_convention/positive_test/input/nested.yml @@ -29,7 +29,7 @@ parameters: resources: - template_vmi_Vlan_2: + vdbe_0_subint_untr_vmi_0: type: OS::ContrailV2::VirtualMachineInterface properties: name: diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/single_vlan_resource/negative_test/two_vlans/nested.yml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/single_vlan_resource/negative_test/two_vlans/nested.yml index 0975493b7d..785bb794b7 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/single_vlan_resource/negative_test/two_vlans/nested.yml +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/single_vlan_resource/negative_test/two_vlans/nested.yml @@ -29,7 +29,7 @@ parameters: resources: - template_vmi_Vlan_2: + vdbe_0_subint_untr_vmi_0: type: OS::ContrailV2::VirtualMachineInterface properties: name: @@ -72,7 +72,7 @@ resources: virtual_network_refs: [{ get_param: net2 },{ get_param: net1 }] virtual_machine_interface_refs: [ { get_param: p1 }] - template_vmi_Vlan_3_arrayParameter: + vdbe_0_subint_untr_vmi_1: type: OS::ContrailV2::VirtualMachineInterface properties: name: diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/single_vlan_resource/negative_test/vlan_and_nova/nested.yml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/single_vlan_resource/negative_test/vlan_and_nova/nested.yml index 32f9b9b578..f5f8d76728 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/single_vlan_resource/negative_test/vlan_and_nova/nested.yml +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/single_vlan_resource/negative_test/vlan_and_nova/nested.yml @@ -35,7 +35,7 @@ resources: security_groups: [{get_param: p1}, {get_param: p2}] replacement_policy: AUTO - template_vmi_Vlan_2: + vdbe_0_subint_untr_vmi_0: type: OS::ContrailV2::VirtualMachineInterface properties: name: diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/single_vlan_resource/positive_test/input/nested.yml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/single_vlan_resource/positive_test/input/nested.yml index f45f6928c9..eed04cf3e3 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/single_vlan_resource/positive_test/input/nested.yml +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/vlan_validation/single_vlan_resource/positive_test/input/nested.yml @@ -29,7 +29,7 @@ parameters: resources: - template_vmi_Vlan_2: + vdbe_0_subint_untr_vmi_0: type: OS::ContrailV2::VirtualMachineInterface properties: name: -- cgit 1.2.3-korg