This task is about updating error messages with error codes for ForbiddenResourceGuideLine
Change-Id: Id692b43e05443dc1313b51533e685dd3c7ad6ca6
Issue-ID: SDC-572
Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
package org.openecomp.sdc.validation.impl.validators;
import org.apache.commons.collections4.MapUtils;
+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;
public class ForbiddenResourceGuideLineValidator implements Validator {
private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
private static Set<String> forbiddenResources = new HashSet<>();
+ private static final ErrorMessageCode ERROR_CODE_FRG_1 = new ErrorMessageCode("FRG1");
+ private static final ErrorMessageCode ERROR_CODE_FRG_2 = new ErrorMessageCode("FRG2");
+ private static final ErrorMessageCode ERROR_CODE_FRG_3 = new ErrorMessageCode("FRG3");
private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName());
forbiddenResourcesMap.entrySet().stream()
.filter(entry -> isResourceEnabled(entry.getValue().get("enable")))
.forEach(entry -> forbiddenResources.add(entry.getKey()));
-
-
-
-
}
private boolean isResourceEnabled(Object enableValue){
}
private void validate(String fileName, GlobalValidationContext globalContext) {
+ globalContext.setMessageCode(ERROR_CODE_FRG_3);
HeatOrchestrationTemplate
- heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext);
+ heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(
+ fileName, globalContext);
if (heatOrchestrationTemplate == null) {
return;
}
String resourceType = resourceEntry.getValue().getType();
if (Objects.isNull(resourceType)) {
globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.INVALID_RESOURCE_TYPE.getErrorMessage(), "null",
+ .getErrorWithParameters(ERROR_CODE_FRG_1,
+ Messages.INVALID_RESOURCE_TYPE.getErrorMessage(),"null",
resourceEntry.getKey()), LoggerTragetServiceName.VALIDATE_RESOURCE_TYPE,
LoggerErrorDescription.INVALID_RESOURCE_TYPE);
} else {
- if(isResourceForbidden(resourceType)){
- globalContext.addMessage(
+ if (isResourceForbidden(resourceType)){
+ globalContext.addMessage(
fileName,
ErrorLevel.WARNING,
ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.FORBIDDEN_RESOURCE_IN_USE.getErrorMessage(),
- resourceType,
- resourceEntry.getKey()),
+ .getErrorWithParameters(ERROR_CODE_FRG_2, Messages.FORBIDDEN_RESOURCE_IN_USE
+ .getErrorMessage(),
+ resourceType, resourceEntry.getKey()),
LoggerTragetServiceName.VALIDATE_FORBIDDEN_RESOURCE,
LoggerErrorDescription.FLOATING_IP_IN_USE);
}
*/
public class ForbiddenResourceGuideLineValidatorTest {
+ private static final String RESOURCE_PATH = "/org/openecomp/validation/validators" +
+ "/guideLineValidator/heatFloatingIpResourceType";
private static String mockConfigFileName =
"/org/openecomp/validation/configuration/mock_resource_validator_configuration.json";
@Test
public void testFloatingIpResourceType() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(forbiddenResourceGuideLineValidator,
- "/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/positive");
+ Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
+ forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/positive");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
messages = ValidationTestUtil.testValidator(forbiddenResourceGuideLineValidator,
- "/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/negative");
+ RESOURCE_PATH + "/negative");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
- "WARNING: OS::Neutron::FloatingIP is in use, Resource ID [FSB2]");
+ "WARNING: [FRG2]: OS::Neutron::FloatingIP is in use, Resource ID [FSB2]");
+ }
+ @Test
+ public void testParseException(){
+ Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
+ forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/parseException");
+ Assert.assertEquals(messages.size(), 1);
+ Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
+ Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
+ "ERROR: [FRG3]: 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 5, column 1:\n" +
+ " \t\t\tresources:\n" +
+ " ^\n" +
+ "]");
+ }
+
+ @Test
+ public void testInvalidResourceType(){
+ Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
+ forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/TestInvalidResourceType");
+ Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
+ "WARNING: [FRG1]: A resource has an invalid or unsupported type - null, " +
+ "Resource ID [FSB2]");
}
}
--- /dev/null
+{
+ "name": "validTest",
+ "description": "Valid Test",
+ "version": "1610",
+ "data": [
+ {
+ "file": "first.yaml",
+ "type": "HEAT",
+ "isBase": true,
+ "data": [
+ {
+ "file": "first.env",
+ "type": "HEAT_ENV"
+ },
+ {
+ "file": "firstVol.yaml",
+ "type": "HEAT_VOL"
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
--- /dev/null
+heat_template_version: 2013-05-23
+
+description: heat expose volume resource
+
+resources:
+ FSB2:
+ type:
+ properties:
+ name: { get_param: fsb_name_2 }
+ block_device_mapping: [{device_name: "vda", volume_id : {get_param: VMME_FSB2_boot_volume }, delete_on_termination: "false" }]
+ flavor: { get_param: fsb2-flavor }
+ availability_zone: { get_param: availability_zone_0 }
+ metadata:
+ VNF_id: { get_param: vnfvfVF_id }
+ vf_module_id: { get_param: vf_module_id }
+ networks:
+ - port: { get_resource: FSB2_Internal1 }
+ - port: { get_resource: FSB2_Internal2 }
+ - port: { get_resource: FSB2_OAM }
+outputs:
+ expose_resource_nove_output:
+ description: the pcrf_server
+ value: { get_resource: FSB2 }
+
+
--- /dev/null
+
+heat_template_version: 2013-05-23
+
+parameters:
+ not_null:
+ type: number
+ label: not_number
+
+
+resources:
+ volume_expose:
+ type: OS::Cinder::Volume
+ properties:
+ not_null: not_null
+outputs:
+ not_expose_resource_network_output:
+ description: the pcrf_server
+ value: { get_resource: volume_expose }
+
--- /dev/null
+{
+ "name": "validTest",
+ "description": "Valid Test",
+ "version": "1610",
+ "data": [
+ {
+ "file": "first.yaml",
+ "type": "HEAT",
+ "isBase": true,
+ "data": [
+ {
+ "file": "first.env",
+ "type": "HEAT_ENV"
+ },
+ {
+ "file": "firstVol.yaml",
+ "type": "HEAT_VOL"
+ }
+ ]
+ },
+ {
+ "file": "second.yaml",
+ "type": "HEAT",
+ "isBase": false
+ }
+ ]
+}
\ No newline at end of file
--- /dev/null
+heat_template_version: 2013-05-23
+
+description: heat expose volume resource
+
+ resources:
+ FSB2_Internal1:
+ type: OS::Neutron::Port
+ properties:
+ network_id: { get_param: Internal1_net_id }
+ FSB2_Internal2:
+ type: OS::Neutron::Port
+ properties:
+ network_id: { get_param: Internal2_net_name }
+ FSB2_OAM:
+ type: OS::Neutron::Port
+ properties:
+ network_id: { get_param: Internal3_net_id }
+ FSB2:
+ type: OS::Nova::Server
+ properties:
+ name: { get_param: fsb2_name_2 }
+ block_device_mapping: [{device_name: "vda", volume_id : {get_param: VMME_FSB2_boot_volume }, delete_on_termination: "false" }]
+ flavor: { get_param: fsb2_flavor_name }
+ availability_zone: { get_param: availability_zone_0 }
+ metadata:
+ VNF_id: { get_param: vnfvfVF_id }
+ vf_module_id: { get_param: vf_module_id }
+ networks:
+ - port: { get_resource: FSB2_Internal1 }
+ - port: { get_resource: FSB2_Internal2 }
+ - port: { get_resource: FSB2_OAM }
+outputs:
+ expose_resource_nove_output:
+ description: the pcrf_server
+ value: { get_resource: FSB2 }
+
+
--- /dev/null
+
+heat_template_version: 2013-05-23
+
+parameters:
+ not_null:
+ type: number
+ label: not_number
+
+
+resources:
+ volume_expose:
+ type: OS::Cinder::Volume
+ properties:
+ not_null: not_null
+outputs:
+ not_expose_resource_network_output:
+ description: the pcrf_server
+ value: { get_resource: volume_expose }
+
--- /dev/null
+heat_template_version: 2013-05-23
+
+description: heat second
+
+resources:
+ network_expose:
+ type: OS::Neutron::Net
+
+outputs:
+ expose_resource_network_output:
+ description: the pcrf_server
+ value: { get_resource: network_expose }
+
+