ForbiddenResourceGuideLine Validator 69/24869/1
authormojahidi <mojahidul.islam@amdocs.com>
Wed, 22 Nov 2017 12:22:37 +0000 (17:52 +0530)
committermojahidi <mojahidul.islam@amdocs.com>
Wed, 22 Nov 2017 12:26:28 +0000 (17:56 +0530)
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>
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidator.java
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidatorTest.java
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/TestInvalidResourceType/MANIFEST.json [new file with mode: 0644]
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/TestInvalidResourceType/first.env [new file with mode: 0644]
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/TestInvalidResourceType/first.yaml [new file with mode: 0644]
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/TestInvalidResourceType/firstVol.yaml [new file with mode: 0644]
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/parseException/MANIFEST.json [new file with mode: 0644]
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/parseException/first.yaml [new file with mode: 0644]
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/parseException/firstVol.yaml [new file with mode: 0644]
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/parseException/second.yaml [new file with mode: 0644]

index 569f2bb..2dad766 100644 (file)
@@ -1,6 +1,7 @@
 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;
@@ -29,6 +30,9 @@ import java.util.Set;
 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());
 
@@ -40,10 +44,6 @@ public class ForbiddenResourceGuideLineValidator implements Validator {
     forbiddenResourcesMap.entrySet().stream()
         .filter(entry -> isResourceEnabled(entry.getValue().get("enable")))
         .forEach(entry -> forbiddenResources.add(entry.getKey()));
-
-
-
-
   }
 
   private boolean isResourceEnabled(Object enableValue){
@@ -78,8 +78,10 @@ public class ForbiddenResourceGuideLineValidator implements Validator {
   }
 
   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;
     }
@@ -103,18 +105,19 @@ public class ForbiddenResourceGuideLineValidator implements Validator {
       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);
         }
index 90f9a75..e5240a3 100644 (file)
@@ -14,6 +14,8 @@ import java.util.Map;
  */
 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";
 
@@ -36,18 +38,41 @@ public class ForbiddenResourceGuideLineValidatorTest {
 
   @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]");
   }
 }
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/TestInvalidResourceType/MANIFEST.json b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/TestInvalidResourceType/MANIFEST.json
new file mode 100644 (file)
index 0000000..c541783
--- /dev/null
@@ -0,0 +1,22 @@
+{
+  "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
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/TestInvalidResourceType/first.env b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/TestInvalidResourceType/first.env
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/TestInvalidResourceType/first.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/TestInvalidResourceType/first.yaml
new file mode 100644 (file)
index 0000000..1244955
--- /dev/null
@@ -0,0 +1,25 @@
+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 }
+
+
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/TestInvalidResourceType/firstVol.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/TestInvalidResourceType/firstVol.yaml
new file mode 100644 (file)
index 0000000..7e82b2a
--- /dev/null
@@ -0,0 +1,19 @@
+
+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 }
+
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/parseException/MANIFEST.json b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/parseException/MANIFEST.json
new file mode 100644 (file)
index 0000000..76ce6de
--- /dev/null
@@ -0,0 +1,27 @@
+{
+  "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
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/parseException/first.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/parseException/first.yaml
new file mode 100644 (file)
index 0000000..2590f23
--- /dev/null
@@ -0,0 +1,37 @@
+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 }
+
+
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/parseException/firstVol.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/parseException/firstVol.yaml
new file mode 100644 (file)
index 0000000..7e82b2a
--- /dev/null
@@ -0,0 +1,19 @@
+
+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 }
+
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/parseException/second.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatFloatingIpResourceType/parseException/second.yaml
new file mode 100644 (file)
index 0000000..bb06b9d
--- /dev/null
@@ -0,0 +1,14 @@
+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 }
+
+