diff options
author | Abhai Singh <Abhai.Singh@amdocs.com> | 2017-11-21 11:51:29 +0530 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2017-11-22 09:39:00 +0000 |
commit | 83a7d1bdcfb13cbb303ffafc032680fcc7827565 (patch) | |
tree | 46139a18399216224392f278689050448999d650 /openecomp-be/lib/openecomp-sdc-validation-lib | |
parent | 9f459654bdd58ad7bbf303fa5f5446acddd2de8e (diff) |
Adding error codes to HEAT Validator
Added error code to ContrailValidator
Issue-Id :SDC-572
Change-Id: Ib0cb270d9c6222677373b2660c77cdd1aaa15367
Signed-off-by: Abhai Singh <Abhai.Singh@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib')
9 files changed, 180 insertions, 21 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ContrailValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ContrailValidator.java index 7d90726dd1..5045c80d11 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ContrailValidator.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ContrailValidator.java @@ -21,9 +21,10 @@ package org.openecomp.sdc.validation.impl.validators; import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.validation.ErrorMessageCode; import org.openecomp.sdc.tosca.services.YamlUtil; -import org.openecomp.sdc.validation.Validator; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; +import org.openecomp.sdc.validation.Validator; import org.openecomp.core.validation.types.GlobalValidationContext; import org.openecomp.sdc.common.errors.Messages; import org.openecomp.sdc.datatypes.error.ErrorLevel; @@ -50,6 +51,10 @@ import java.util.Optional; public class ContrailValidator implements Validator { public static final MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); protected static Logger logger = (Logger) LoggerFactory.getLogger(ContrailValidator.class); + private static final ErrorMessageCode ERROR_CODE_CTL_1 = new ErrorMessageCode("CTL1"); + private static final ErrorMessageCode ERROR_CODE_CTL_2 = new ErrorMessageCode("CTL2"); + private static final ErrorMessageCode ERROR_CODE_CTL_3 = new ErrorMessageCode("CTL3"); + private static final ErrorMessageCode ERROR_CODE_CTL_4 = new ErrorMessageCode("CTL4"); @Override public void validate(GlobalValidationContext globalContext) { @@ -113,7 +118,7 @@ public class ContrailValidator implements Validator { globalContext.addMessage( contrailResourcesMappingTo.getContrailV1Resources().keySet().iterator().next(), ErrorLevel.WARNING, ErrorMessagesFormatBuilder.getErrorWithParameters( - Messages.MERGE_OF_CONTRAIL2_AND_CONTRAIL3_RESOURCES.getErrorMessage(), + ERROR_CODE_CTL_2, Messages.MERGE_OF_CONTRAIL2_AND_CONTRAIL3_RESOURCES.getErrorMessage(), contrailResourcesMappingTo.fetchContrailV1Resources(), contrailResourcesMappingTo.fetchContrailV2Resources()), LoggerTragetServiceName.MERGE_OF_CONTRAIL_2_AND_3, @@ -128,8 +133,9 @@ public class ContrailValidator implements Validator { Optional<InputStream> fileContent = globalContext.getFileContent(fileName); if (!fileContent.isPresent()) { globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.INVALID_HEAT_FORMAT_REASON.getErrorMessage(), - "The file '" + fileName + "' has no content"), + .getErrorWithParameters(ERROR_CODE_CTL_1, Messages.INVALID_HEAT_FORMAT_REASON + .getErrorMessage(), + "The file '" + fileName + "' has no content"), LoggerTragetServiceName.VALIDATE_HEAT_FORMAT, LoggerErrorDescription.INVALID_HEAT_FORMAT); return Optional.empty(); } @@ -175,28 +181,33 @@ public class ContrailValidator implements Validator { GlobalValidationContext globalContext) { mdcDataDebugMessage.debugEntryMessage("file", fileName); - + globalContext.setMessageCode(ERROR_CODE_CTL_4); HeatOrchestrationTemplate heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext); if (heatOrchestrationTemplate == null) { return; } + validateResourcePrefix(fileName, globalContext, heatOrchestrationTemplate); + mdcDataDebugMessage.debugExitMessage("file", fileName); + } - Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources(); + private void validateResourcePrefix(String fileName, GlobalValidationContext globalContext, + HeatOrchestrationTemplate heatOrchestrationTemplate) { - if( ! MapUtils.isEmpty(resourcesMap)) { + mdcDataDebugMessage.debugEntryMessage("file", fileName); + Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources(); + if(!MapUtils.isEmpty(resourcesMap)) { for (Map.Entry<String, Resource> resourceEntry : resourcesMap.entrySet()) { String type = resourceEntry.getValue().getType(); if (Objects.nonNull(type) && type.startsWith(HeatConstants.CONTRAIL_RESOURCE_PREFIX)) { globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.CONTRAIL_2_IN_USE.getErrorMessage(), - resourceEntry.getKey()), LoggerTragetServiceName.CONTRAIL_2_IN_USE, + .getErrorWithParameters(ERROR_CODE_CTL_3, Messages.CONTRAIL_2_IN_USE.getErrorMessage(), + resourceEntry.getKey()), LoggerTragetServiceName.CONTRAIL_2_IN_USE, LoggerErrorDescription.CONTRAIL_2_IN_USE); } } } - mdcDataDebugMessage.debugExitMessage("file", fileName); } diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/ContrailValidatorTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/ContrailValidatorTest.java index 30b7f68230..f921102957 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/ContrailValidatorTest.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/ContrailValidatorTest.java @@ -36,32 +36,58 @@ import java.util.Map; */ public class ContrailValidatorTest { + private static final String RESOURCE_PATH = "/org/openecomp/validation/validators/contrailvalidatorresources"; private Validator validator = new ContrailValidator(); @Test public void testWarningMessageExistWhenConrailV1AndV2ResourcesCollidesInSameHeatFile() { Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator, - "/org/openecomp/validation/validators/contrailvalidatorresources/collidesinsameheatfile/"); + RESOURCE_PATH + "/collidesinsameheatfile/"); validateMessage(messages, - "WARNING: HEAT Package includes both Contrail 2 and Contrail 3 resources. Contrail 2 resources can be found in file 'first.yaml' , resources :'jsa_net1' . Contrail 3 resources can be found in file 'first.yaml' , resources :'jsa_net2' ", + "WARNING: [CTL2]: HEAT Package includes both Contrail 2 and Contrail 3 " + + "resources. Contrail 2 resources can be found in file 'first.yaml' , resources :" + + "'jsa_net1' . Contrail 3 resources can be found in file 'first.yaml' , resources :" + + "'jsa_net2' ", "first.yaml", 2); } @Test + public void testParseException(){ + Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator, + RESOURCE_PATH + "/parseException/"); + validateMessage(messages, + "ERROR: [CTL4]: Invalid HEAT format problem - [while scanning for the next " + + "token\n" + "found character '\\t(TAB)' that cannot start any token. " + + "(Do not use \\t(TAB) for indentation)\n" + + " in 'reader', line 10, column 1:\n" + + " \t\t\tresources:\n" + + " ^\n" + + "]", + "first.yaml", 1); + + } + + @Test public void testWarningMessageExistWhenConrailV1AndV2ResourcesCollidesInDifferentHeatFiles() { Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator, - "/org/openecomp/validation/validators/contrailvalidatorresources/collidesindifferentheatfiles/"); + RESOURCE_PATH + "/collidesindifferentheatfiles/"); validateMessage(messages, - "WARNING: HEAT Package includes both Contrail 2 and Contrail 3 resources. Contrail 2 resources can be found in file 'first.yaml' , resources :'jsa_net1', 'jsa_net3' . Contrail 3 resources can be found in file 'second.yaml' , resources :'jsa_net2', 'jsa_net4', file 'first.yaml' , resources :'jsa_net5' ", + "WARNING: [CTL2]: HEAT Package includes both Contrail 2 and Contrail 3 " + + "resources. Contrail 2 resources can be found in file 'first.yaml' , resources :" + + "'jsa_net1', 'jsa_net3' . Contrail 3 resources can be found in file 'second.yaml' , " + + "resources :'jsa_net2', 'jsa_net4', file 'first.yaml' , resources :'jsa_net5' ", "first.yaml", 3); } @Test public void testWarningMessageNotExistWhenConrailV1AndV2ResourcesCollidesInNonHeatFile() { Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator, - "/org/openecomp/validation/validators/contrailvalidatorresources/collidesinnontheatfiles/"); + RESOURCE_PATH + "/collidesinnontheatfiles/"); validateMessage(messages, - "WARNING: HEAT Package includes both Contrail 2 and Contrail 3 resources. Contrail 2 resources can be found in file 'first.yaml' , resources :'jsa_net1' . Contrail 3 resources can be found in file 'second.yaml' , resources :'jsa_net2' ", + "WARNING: [CTL2]: HEAT Package includes both Contrail 2 and Contrail 3 " + + "resources. Contrail 2 resources can be found in file 'first.yaml' , resources :" + + "'jsa_net1' . Contrail 3 resources can be found in file 'second.yaml' , " + + "resources :'jsa_net2' ", "first.yaml", 2); ; } @@ -69,9 +95,10 @@ public class ContrailValidatorTest { @Test public void testWarningMessageNotExistWhenOnlyConrailV1Resources() { Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator, - "/org/openecomp/validation/validators/contrailvalidatorresources/notcollides/"); + RESOURCE_PATH + "/notcollides/"); validateMessage(messages, - "WARNING: Contrail 2.x deprecated resource is in use, Resource ID [jsa_net1]", "first.yaml", + "WARNING: [CTL3]: Contrail 2.x deprecated resource is in use, " + + "Resource ID [jsa_net1]", "first.yaml", 2); } @@ -79,13 +106,34 @@ public class ContrailValidatorTest { @Test public void testWarningMessageOnResourceWithContrailType() { Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator, - "/org/openecomp/validation/validators/contrailvalidatorresources/validatenocontrailresource/"); + RESOURCE_PATH + "/validatenocontrailresource/"); validateMessage(messages, - "WARNING: Contrail 2.x deprecated resource is in use, Resource ID [template_NetworkPolicy]", + "WARNING: [CTL3]: Contrail 2.x deprecated resource is in use, " + + "Resource ID [template_NetworkPolicy]", "first.yaml", 1); - ; } + @Test + public void testInvalidHeatStructure(){ + Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator, + RESOURCE_PATH + "/invalidHeatStructure/"); + validateMessage(messages, + "ERROR: [CTL1]: Invalid HEAT format problem - [The file 'first.yaml' " + + "has no content]", + "first.yaml", 1); + } + + @Test + public void testInvalidHeatStructuredueToParsingError(){ + Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator, + RESOURCE_PATH + "/invalidHeatStructure/"); + validateMessage(messages, + "ERROR: [CTL1]: Invalid HEAT format problem - [The file 'first.yaml' " + + "has no content]", + "first.yaml", 1); + } + + private void validateMessage(Map<String, MessageContainer> messages, String expectedMessage, String fileNameWithErrorToCheck, int sizeOfFileMessageList) { Assert.assertEquals(messages.size(), 1); diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/invalidHeatStructure/MANIFEST.json b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/invalidHeatStructure/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/contrailvalidatorresources/invalidHeatStructure/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/contrailvalidatorresources/invalidHeatStructure/first.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/invalidHeatStructure/first.yaml new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/invalidHeatStructure/first.yaml diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/invalidHeatStructureParsingError/MANIFEST.json b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/invalidHeatStructureParsingError/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/contrailvalidatorresources/invalidHeatStructureParsingError/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/contrailvalidatorresources/invalidHeatStructureParsingError/first.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/invalidHeatStructureParsingError/first.yaml new file mode 100644 index 0000000000..a50ca86aa5 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/invalidHeatStructureParsingError/first.yaml @@ -0,0 +1,18 @@ +heat_template_version: 2013-05-23a +description: cmaui server template for vMMSC + +parameters: + nems_traffic_name: + description: dummy + type: string + +resources: + jsa_net1: + type: OS::Contrail::VirtualNetwork + proaperties: + name: {get_param: nems_traffic_name} + jsa_net2: + taype: OS::ContrailV2::VirtualNetwork + propaerties: + name: {get_param: nems_traffic_name} + diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/parseException/MANIFEST.json b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/parseException/MANIFEST.json new file mode 100644 index 0000000000..15650ae299 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/parseException/MANIFEST.json @@ -0,0 +1,17 @@ +{ + "name": "validTest", + "description": "Valid Test", + "version": "1610", + "data": [ + { + "file": "first.yaml", + "type": "HEAT", + "isBase": true + }, + { + "file": "second.yaml", + "type": "HEAT", + "isBase": false + } + ] +}
\ 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/contrailvalidatorresources/parseException/first.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/parseException/first.yaml new file mode 100644 index 0000000000..24fe19170d --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/parseException/first.yaml @@ -0,0 +1,22 @@ +heat_template_version: 2013-05-23 + +description: cmaui server template for vMMSC + +parameters: + nems_traffic_name: + description: dummy + type: string + + resources: + jsa_net1: + type: OS::Contrail::VirtualNetwork + properties: + name: {get_param: } + jsa_net3: + type: OS::Contrail::VirtualNetwork + properties: + name: {get_param: nems_traffic_name} + jsa_net5: + type: OS::ContrailV2::VirtualNetwork + properties: + name: {get_param: nems_traffic_name} diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/parseException/second.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/parseException/second.yaml new file mode 100644 index 0000000000..f8cadfee51 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/contrailvalidatorresources/parseException/second.yaml @@ -0,0 +1,19 @@ +heat_template_version: 2013-05-23 + +description: cmaui server template for vMMSC + +parameters: + nems_traffic_name: + description: dummy + type: string + +resources: + jsa_net2: + type: OS::ContrailV2::VirtualNetwork + properties: + name: {get_param: nems_traffic_name} + jsa_net4: + type: OS::ContrailV2::VirtualNetwork + properties: + name: {get_param: nems_traffic_name} + |