summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceInstanceNamingConventionValidator.java40
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceInstanceNamingConventionValidatorTest.java24
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailserviceinstanceavailabilityzone/missingparam/MANIFEST.json12
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailserviceinstanceavailabilityzone/missingparam/first.yaml45
4 files changed, 96 insertions, 25 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/ContrailServiceInstanceNamingConventionValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceInstanceNamingConventionValidator.java
index 957658e8cc..51a174f9fa 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceInstanceNamingConventionValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceInstanceNamingConventionValidator.java
@@ -1,6 +1,7 @@
package org.openecomp.sdc.validation.impl.validators.namingconvention;
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;
@@ -22,6 +23,8 @@ import static java.util.Objects.nonNull;
*/
public class ContrailServiceInstanceNamingConventionValidator implements ResourceValidator {
private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+ private static final ErrorMessageCode ERROR_CODE_NSI1 = new ErrorMessageCode("NSI1");
+ private static final ErrorMessageCode ERROR_CODE_NSI2 = new ErrorMessageCode("NSI2");
@Override
public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
@@ -37,45 +40,44 @@ public class ContrailServiceInstanceNamingConventionValidator implements Resourc
mdcDataDebugMessage.debugEntryMessage("file", fileName);
String[] regexList = new String[]{"availability_zone_(\\d+)"};
-
if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
mdcDataDebugMessage.debugExitMessage("file", fileName);
return;
}
Object availabilityZoneMap =
- resourceEntry.getValue().getProperties().containsKey("availability_zone") ? resourceEntry
- .getValue().getProperties().get("availability_zone") : null;
+ resourceEntry.getValue().getProperties().containsKey("availability_zone") ? resourceEntry
+ .getValue().getProperties().get("availability_zone") : null;
if (nonNull(availabilityZoneMap)) {
if (availabilityZoneMap instanceof Map) {
String availabilityZoneName = ValidationUtil.getWantedNameFromPropertyValueGetParam
- (availabilityZoneMap);
+ (availabilityZoneMap);
if (availabilityZoneName != null) {
if (!ValidationUtil.evalPattern(availabilityZoneName, regexList)) {
globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder.getErrorWithParameters(
- Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
- ValidationUtil.getMessagePartAccordingToResourceType(resourceEntry),
- "Availability Zone",
- availabilityZoneName, resourceEntry.getKey()),
- LoggerTragetServiceName.VALIDATE_AVAILABILITY_ZONE_NAME,
- LoggerErrorDescription.NAME_NOT_ALIGNED_WITH_GUIDELINES);
+ fileName,
+ ErrorLevel.WARNING, ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_NSI1,
+ Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
+ ValidationUtil.getMessagePartAccordingToResourceType(resourceEntry),
+ "Availability Zone",
+ availabilityZoneName, resourceEntry.getKey()),
+ LoggerTragetServiceName.VALIDATE_AVAILABILITY_ZONE_NAME,
+ LoggerErrorDescription.NAME_NOT_ALIGNED_WITH_GUIDELINES);
}
}
} else {
globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.MISSING_GET_PARAM.getErrorMessage(),
- "availability_zone", resourceEntry.getKey()),
- LoggerTragetServiceName.VALIDATE_AVAILABILITY_ZONE_NAME,
- LoggerErrorDescription.MISSING_GET_PARAM);
+ fileName,
+ ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NSI2, Messages.MISSING_GET_PARAM.getErrorMessage(),
+ "availability_zone", resourceEntry.getKey()),
+ LoggerTragetServiceName.VALIDATE_AVAILABILITY_ZONE_NAME,
+ LoggerErrorDescription.MISSING_GET_PARAM);
}
}
mdcDataDebugMessage.debugExitMessage("file", fileName);
}
-}
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceInstanceNamingConventionValidatorTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceInstanceNamingConventionValidatorTest.java
index 7c07da98d7..2fb86f8556 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceInstanceNamingConventionValidatorTest.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceInstanceNamingConventionValidatorTest.java
@@ -17,25 +17,37 @@ public class ContrailServiceInstanceNamingConventionValidatorTest {
HeatResourceValidator baseValidator = new HeatResourceValidator();
ContrailServiceInstanceNamingConventionValidator resourceValidator = new
ContrailServiceInstanceNamingConventionValidator();
+ private static final String PATH = "/org/openecomp/validation/validators/guideLineValidator/heatcontrailserviceinstanceavailabilityzone/";
@Test
public void testContrailServiceInstanceAvailabilityZoneNotAlignedWithNamingConvention() {
Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
- resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE.getHeatResource(),
- "/org/openecomp/validation/validators/guideLineValidator/heatcontrailserviceinstanceavailabilityzone/notaligned");
+ resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE.getHeatResource(),
+ PATH + "notaligned");
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: Service Instance 'Availability Zone' Parameter Name not aligned with Guidelines, Parameter Name [availability_zone_1a], Resource ID [service_instance_1]. As a result, VF/VFC Profile may miss this information");
+ "WARNING: [NSI1]: Service Instance 'Availability Zone' Parameter Name not aligned with Guidelines, Parameter Name [availability_zone_1a], Resource ID [service_instance_1]. As a result, VF/VFC Profile may miss this information");
}
@Test
public void testContrailServiceInstanceAvailabilityZoneAlignedWithNamingConvention() {
Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
- resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE.getHeatResource(),
- "/org/openecomp/validation/validators/guideLineValidator/heatcontrailserviceinstanceavailabilityzone/aligned");
+ resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE.getHeatResource(),
+ PATH + "aligned");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
}
-}
+ @Test
+ public void testContrailServiceInstanceAvailabilityZoneNotAlignedWithNamingConventionMissingParam() {
+ Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE.getHeatResource(),
+ PATH + "missingparam");
+ 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: [NSI2]: Missing get_param in availability_zone, Resource Id [service_instance_1]");
+ }
+} \ 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/heatcontrailserviceinstanceavailabilityzone/missingparam/MANIFEST.json b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailserviceinstanceavailabilityzone/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/heatcontrailserviceinstanceavailabilityzone/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/heatcontrailserviceinstanceavailabilityzone/missingparam/first.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailserviceinstanceavailabilityzone/missingparam/first.yaml
new file mode 100644
index 0000000000..c4db7c71cf
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/heatcontrailserviceinstanceavailabilityzone/missingparam/first.yaml
@@ -0,0 +1,45 @@
+heat_template_version: 2013-05-23
+
+description: heat expose volume resource
+
+resources:
+ service_instance_1:
+ type: OS::Contrail::ServiceInstance
+ depends_on: [ hsl_ip_subnet]
+ properties:
+ name: { get_param: service_instance_name }
+ availability_zone: get_param
+ service_template: { get_resource: service_template_1 }
+ scale_out:
+ max_instances: {get_param: max_num_fw_instances}
+ interface_list: [
+ {
+ virtual_network: { get_param: oam_mgmt_net_0_id }
+ },
+ {
+ virtual_network: { get_param: Cricket_OCS_direct_net_id }
+ },
+ {
+ virtual_network: { get_resource: hsl_direct_net }
+ },
+ {
+ virtual_network: {get_param: oam_mgmt_net_1_id},
+ static_routes: [
+ { "prefix": {get_param: prefix_0} },
+ { "prefix": {get_param: prefix_1} },
+ { "prefix": {get_param: prefix_2} },
+ ],
+ }
+ ]
+ service_template_1:
+ 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: st_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