diff options
author | mojahidi <mojahidul.islam@amdocs.com> | 2017-11-20 18:24:20 +0530 |
---|---|---|
committer | mojahidi <mojahidul.islam@amdocs.com> | 2017-11-20 18:24:30 +0530 |
commit | 9b2e29efa7cc069a119ef2e4894a93a7fc31b6f5 (patch) | |
tree | 08aa50cae02c46f21553a36ea2c76d992fcd6136 /openecomp-be/lib | |
parent | 56d40d922c89b9837560c4ca739cafeef566287c (diff) |
ContrailServiceTemplate validator
This task is about updating error messages with error codes for ContrailServiceTemplateNamingConventionValidator validator
Change-Id: I7d06d0cae2cd3c1ecc10d971db3e7c89bca585a9
Issue-ID:SDC-572
Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
Diffstat (limited to 'openecomp-be/lib')
7 files changed, 124 insertions, 42 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidator.java index 05f2e4fcc7..280b723dd8 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidator.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidator.java @@ -4,6 +4,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; +import org.openecomp.core.validation.ErrorMessageCode; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; import org.openecomp.core.validation.types.GlobalValidationContext; import org.openecomp.sdc.common.errors.Messages; @@ -30,6 +31,9 @@ import static java.util.Objects.nonNull; */ public class ContrailServiceTemplateNamingConventionValidator implements ResourceValidator { private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + private static final ErrorMessageCode ERROR_CODE_NST1 = new ErrorMessageCode("NST1"); + private static final ErrorMessageCode ERROR_CODE_NST2 = new ErrorMessageCode("NST2"); + private static final ErrorMessageCode ERROR_CODE_NST3 = new ErrorMessageCode("NST3"); @Override public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, @@ -56,15 +60,15 @@ public class ContrailServiceTemplateNamingConventionValidator implements Resourc boolean errorExistValidatingImageOrFlavor = false; for (Pair<String, String> imageOrFlavor : imageFlavorPairs) { boolean errorExistWhenValidatingImageOrFlavorNames = - isErrorExistWhenValidatingImageOrFlavorNames(fileName, imageOrFlavor, entry, - propertiesMap, globalContext); + isErrorExistWhenValidatingImageOrFlavorNames(fileName, imageOrFlavor, entry, + propertiesMap, globalContext); errorExistValidatingImageOrFlavor = - errorExistValidatingImageOrFlavor || errorExistWhenValidatingImageOrFlavorNames; + errorExistValidatingImageOrFlavor || errorExistWhenValidatingImageOrFlavorNames; } if (!errorExistValidatingImageOrFlavor) { validateServiceTemplatePropertiesValuesVmtypesAreIdentical(fileName, entry, globalContext, - propertiesMap); + propertiesMap); } mdcDataDebugMessage.debugExitMessage("file", fileName); @@ -80,7 +84,7 @@ public class ContrailServiceTemplateNamingConventionValidator implements Resourc Pair<String, String> vmTypeImagePair = new ImmutablePair<>("image_name", "\\_image\\_name"); Pair<String, String> vmTypeFlavorPair = new ImmutablePair<>("flavor", "\\_flavor\\_name"); validatePropertiesValuesVmtypesAreIdentical(Arrays.asList(vmTypeImagePair, vmTypeFlavorPair), - fileName, entry, propertiesMap, globalContext); + fileName, entry, propertiesMap, globalContext); mdcDataDebugMessage.debugExitMessage("file", fileName); } @@ -101,14 +105,14 @@ public class ContrailServiceTemplateNamingConventionValidator implements Resourc String previousPropertyValueValue = null; for (Pair propertyToMatch : propertiesToMatch) { Optional<String> propertyVmType = - extractVmTypeFromProperty(fileName, resourceEntry, propertiesMap, globalContext, - propertyToMatch); + extractVmTypeFromProperty(fileName, resourceEntry, propertiesMap, globalContext, + propertyToMatch); if (propertyVmType.isPresent()) { String currentPropVmType = propertyVmType.get(); previousPropertyValueValue = - handleFirstIteration(previousPropertyValueValue, currentPropVmType); + handleFirstIteration(previousPropertyValueValue, currentPropVmType); if (addWarningIfCurrentVmTypeIsDifferentFromPrevious(fileName, resourceEntry, globalContext, - previousPropertyValueValue, currentPropVmType)) { + previousPropertyValueValue, currentPropVmType)) { mdcDataDebugMessage.debugExitMessage("file", fileName); return; } @@ -125,11 +129,12 @@ public class ContrailServiceTemplateNamingConventionValidator implements Resourc String currentPropVmType) { if (!Objects.equals(previousPropertyValueValue, currentPropVmType)) { globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters( - Messages.CONTRAIL_VM_TYPE_NAME_NOT_ALIGNED_WITH_NAMING_CONVENSION - .getErrorMessage(), resourceEntry.getKey()), - LoggerTragetServiceName.VALIDATE_CONTRAIL_VM_NAME, - LoggerErrorDescription.NAME_NOT_ALIGNED_WITH_GUIDELINES); + .getErrorWithParameters( + ERROR_CODE_NST1, Messages.CONTRAIL_VM_TYPE_NAME_NOT_ALIGNED_WITH_NAMING_CONVENSION + .getErrorMessage(), + resourceEntry.getKey()), + LoggerTragetServiceName.VALIDATE_CONTRAIL_VM_NAME, + LoggerErrorDescription.NAME_NOT_ALIGNED_WITH_GUIDELINES); return true; } @@ -143,24 +148,26 @@ public class ContrailServiceTemplateNamingConventionValidator implements Resourc GlobalValidationContext globalContext) { String propertyName = propertyNameAndRegex.getKey(); Object nameValue = - propertiesMap.get(propertyName) == null ? null : propertiesMap.get(propertyName); + propertiesMap.get(propertyName) == null ? null : propertiesMap.get(propertyName); String[] regexList = new String[]{propertyNameAndRegex.getValue()}; - if (nonNull(nameValue)) { if (nameValue instanceof Map) { + globalContext.setMessageCode(ERROR_CODE_NST3); if (ValidationUtil.validateMapPropertyValue(fileName, resourceEntry, globalContext, - propertyName, - nameValue, regexList)) { + propertyName, + nameValue, regexList)) { return true; } } else { globalContext.addMessage( - fileName, - ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.MISSING_GET_PARAM.getErrorMessage(), propertyName, - resourceEntry.getKey()), - LoggerTragetServiceName.VALIDATE_IMAGE_AND_FLAVOR_NAME, - LoggerErrorDescription.MISSING_GET_PARAM); + fileName, + ErrorLevel.WARNING, ErrorMessagesFormatBuilder + .getErrorWithParameters( + ERROR_CODE_NST2, Messages.MISSING_GET_PARAM.getErrorMessage(), + propertyName, + resourceEntry.getKey()), + LoggerTragetServiceName.VALIDATE_IMAGE_AND_FLAVOR_NAME, + LoggerErrorDescription.MISSING_GET_PARAM); return true; } @@ -180,19 +187,21 @@ public class ContrailServiceTemplateNamingConventionValidator implements Resourc if (nonNull(propertyVal)) { if (propertyVal instanceof Map) { String propertyValFromGetParam = ValidationUtil.getWantedNameFromPropertyValueGetParam - (propertyVal); + (propertyVal); if (nonNull(propertyValFromGetParam)) { Pattern pattern = Pattern.compile("" + propertyKeyRegex.getValue()); return Optional.ofNullable(pattern.split(propertyValFromGetParam)[0]); } } else { globalContext.addMessage( - fileName, - ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.MISSING_GET_PARAM.getErrorMessage(), propertyName, - resourceEntry.getKey()), - LoggerTragetServiceName.VALIDATE_VM_SYNC_IN_IMAGE_FLAVOR, - LoggerErrorDescription.MISSING_GET_PARAM); + fileName, + ErrorLevel.WARNING, ErrorMessagesFormatBuilder + .getErrorWithParameters( + ERROR_CODE_NST2, Messages.MISSING_GET_PARAM.getErrorMessage(), + propertyName, + resourceEntry.getKey()), + LoggerTragetServiceName.VALIDATE_VM_SYNC_IN_IMAGE_FLAVOR, + LoggerErrorDescription.MISSING_GET_PARAM); return Optional.empty(); } } diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidatorTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidatorTest.java index 1a04d94748..681c54b12e 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidatorTest.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidatorTest.java @@ -18,40 +18,55 @@ public class ContrailServiceTemplateNamingConventionValidatorTest { HeatResourceValidator baseValidator = new HeatResourceValidator(); ContrailServiceTemplateNamingConventionValidator resourceValidator = new ContrailServiceTemplateNamingConventionValidator(); + private static final String PATH="/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/"; @Test public void testContrailServiceTemplateImageAndFlavorNamesAlignedWithNamingConventionButDifferentVmType() { Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator, - resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(), - "/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/imageandflavordifferentvmtype"); + resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(), + PATH + "imageandflavordifferentvmtype"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 1); Assert.assertEquals( - messages.get(messages.keySet().iterator().next()).getErrorMessageList().size(), 1); + messages.get(messages.keySet().iterator().next()).getErrorMessageList().size(), 1); Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(), - "WARNING: Service Template naming convention in Image and Flavor properties is not consistent in Resource, Resource ID service_template"); + "WARNING: [NST1]: Service Template naming convention in Image and Flavor properties is not consistent in Resource, Resource ID service_template"); } @Test public void testContrailServiceTemplateImageAndFlavorNamesNotAlignedWithNamingConvention() { Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator, - resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(), - "/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/notaligned"); + resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(), + PATH + "/notaligned"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 1); Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 2); Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(), - "WARNING: Service Template 'image_name' Parameter Name not aligned with Guidelines, Parameter Name [st_imaage_name], Resource ID [service_template]. As a result, VF/VFC Profile may miss this information"); + "WARNING: [NST3]: Service Template 'image_name' Parameter Name not aligned with Guidelines, Parameter Name [st_imaage_name], Resource ID [service_template]. As a result, VF/VFC Profile may miss this information"); Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(1).getMessage(), - "WARNING: Service Template 'flavor' Parameter Name not aligned with Guidelines, Parameter Name [st_flavaor_name], Resource ID [service_template]. As a result, VF/VFC Profile may miss this information"); + "WARNING: [NST3]: Service Template 'flavor' Parameter Name not aligned with Guidelines, Parameter Name [st_flavaor_name], Resource ID [service_template]. As a result, VF/VFC Profile may miss this information"); } @Test public void testContrailServiceTemplateImageAndFlavorNamesAlignedWithNamingConvention() { Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator, - resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(), - "/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/aligned"); + resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(), + PATH + "aligned"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 0); } + + @Test + public void testContrailServiceTemplateMissingParam() { + Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator, + resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(), + PATH + "missingparam"); + Assert.assertNotNull(messages); + Assert.assertEquals(messages.size(), 1); + Assert.assertEquals( + messages.get(messages.keySet().iterator().next()).getErrorMessageList().size(), 1); + Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(), + "WARNING: [NST2]: Missing get_param in image_name, Resource Id [service_template]"); + } + } diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/missingparam/MANIFEST.json b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/missingparam/MANIFEST.json new file mode 100644 index 0000000000..0e8bebb1d1 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/missingparam/MANIFEST.json @@ -0,0 +1,12 @@ +{ + "name": "validTest", + "description": "Valid Test", + "version": "1610", + "data": [ + { + "file": "first.yaml", + "type": "HEAT", + "isBase": true + } + ] +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/missingparam/first.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/missingparam/first.yaml new file mode 100644 index 0000000000..214206b831 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/missingparam/first.yaml @@ -0,0 +1,17 @@ +heat_template_version: 2013-05-23 + +description: heat expose volume resource + +resources: + service_template: + type: OS::Contrail::ServiceTemplate + properties: + name: { get_param: st_name } + service_mode: { get_param: st_mode } + service_type: { get_param: st_type } + image_name: st1_image_name + flavor: { get_param: st_flavor_name } + service_interface_type_list: { "Fn::Split" : [ ",", "management,left,right,other" ] } + shared_ip_list: { "Fn::Split" : [ ",", Ref: st_shared_ip_list ] } + static_routes_list: { "Fn::Split" : [ ",", Ref: st_static_routes_list ] } + service_scaling: { get_param: st_scaling }
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/missingvmparam/MANIFEST.json b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/missingvmparam/MANIFEST.json new file mode 100644 index 0000000000..0e8bebb1d1 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/missingvmparam/MANIFEST.json @@ -0,0 +1,12 @@ +{ + "name": "validTest", + "description": "Valid Test", + "version": "1610", + "data": [ + { + "file": "first.yaml", + "type": "HEAT", + "isBase": true + } + ] +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/missingvmparam/first.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/missingvmparam/first.yaml new file mode 100644 index 0000000000..9da16fe0d2 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/missingvmparam/first.yaml @@ -0,0 +1,17 @@ +heat_template_version: 2013-05-23 + +description: heat expose volume resource + +resources: + service_template: + type: OS::Contrail::ServiceTemplate + properties: + name: { get_param: st_name } + service_mode: { get_param: st_mode } + service_type: { get_param: st_type } + image_name: { get_param: st1_image_name } + flavor: { get_param: st_flavor_name } + service_interface_type_list: { "Fn::Split" : [ ",", "management,left,right,other" ] } + shared_ip_list: { "Fn::Split" : [ ",", Ref: st_shared_ip_list ] } + static_routes_list: { "Fn::Split" : [ ",", Ref: st_static_routes_list ] } + service_scaling: { get_param: st_scaling }
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationUtil.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationUtil.java index 41300f3852..217ff857f6 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationUtil.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationUtil.java @@ -163,7 +163,7 @@ public class ValidationUtil { globalContext.addMessage( fileName, ErrorLevel.WARNING, - ErrorMessagesFormatBuilder.getErrorWithParameters( + ErrorMessagesFormatBuilder.getErrorWithParameters(globalContext.getMessageCode(), Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(), getMessagePartAccordingToResourceType(resourceEntry), propertyName, propertyValue, resourceEntry.getKey()), |