1 package org.openecomp.sdc.validation.impl.validators.validators;
3 import org.openecomp.sdc.validation.impl.validators.HeatValidator;
4 import org.openecomp.sdc.validation.impl.validators.ValidatorBaseTest;
5 import org.openecomp.core.validation.types.MessageContainer;
7 import org.testng.Assert;
8 import org.testng.annotations.Test;
10 import java.io.IOException;
13 public class HeatValidatorTest extends ValidatorBaseTest {
17 public void testInvalidHeatFormat(){
18 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/invalid_heat_format/negative_test/input");
20 Assert.assertNotNull(messages);
21 Assert.assertEquals(messages.size(), 1);
23 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
24 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Invalid HEAT format problem - [Cannot create property=kuku for JavaBean=Resource{type='null', properties=null, metadata=null, depends_on=null, update_policy='null', deletion_policy='null'}\n" +
25 " in 'reader', line 25, column 5:\n" +
28 "Unable to find property 'kuku' on class: org.openecomp.sdc.heat.datatypes.model.Resource\n" +
29 " in 'reader', line 25, column 11:\n" +
37 public void testResourcesReferencesExistInHeat() throws IOException {
38 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/resource_references_exist_in_heat/negative_test/input");
40 Assert.assertNotNull(messages);
41 Assert.assertEquals(messages.size(), 1);
43 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2);
44 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Referenced resource - not_existing_resource not found");
45 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(), "invalid get_resource syntax is in use - null , get_resource function should get the resource id of the referenced resource");
50 public void testGetResourceValueIsValid(){
51 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/get_resource_value_valid/negative_test/input");
53 Assert.assertNotNull(messages);
54 Assert.assertEquals(messages.size(), 1);
56 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 3);
57 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "invalid get_resource syntax is in use - [param_1, param_2] , get_resource function should get the resource id of the referenced resource");
58 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(), "invalid get_resource syntax is in use - {get_param=param_1} , get_resource function should get the resource id of the referenced resource");
59 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(2).getMessage(), "invalid get_resource syntax is in use - null , get_resource function should get the resource id of the referenced resource");
63 public void testTwoResourcesDoesNotHoldSameId() throws IOException {
64 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/two_resources_does_not_hold_same_id/positive_test/input");
65 Assert.assertNotNull(messages);
66 Assert.assertEquals(messages.size(), 0);
70 public void negativeTestGetParamPointToExistingParameter() throws IOException {
71 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/get_param_points_to_existing_parameter/negative_test/input");
73 Assert.assertNotNull(messages);
74 Assert.assertEquals(messages.size(), 1);
76 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
77 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Referenced parameter - not_existing_param_1 - not found, used in resource - server_pcrf_psm_001");
81 public void testGetAttrFromNested() throws IOException {
82 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/get_attr_from_nested/negative_test/input");
84 Assert.assertNotNull(messages);
85 Assert.assertEquals(messages.size(), 1);
87 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
88 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "get_attr attribute not found - nested_output in resource server_pcrf_psm_001");
92 public void testPropertiesMatchNestedParameters() throws IOException {
93 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/properties_match_nested_parameters/negative_test/input");
95 Assert.assertNotNull(messages);
96 Assert.assertEquals(messages.size(), 1);
98 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
99 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Referenced parameter not found in nested file - nested-pps_v1.0.yaml, resource name - server_pcrf_pps_001, parameter name - parameter_not_existing_in_nested");
103 public void testNovaPropertiesHasAssignedValue() throws IOException {
104 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/nova_properties_has_assigned_value/negative_test/input");
106 Assert.assertNotNull(messages);
107 Assert.assertEquals(messages.size(), 1);
109 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
110 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Missing both Image and Flavor in NOVA Server - nova_server_resource_missing_both");
114 public void testNoLoopsNesting() throws IOException {
115 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/no_loops_nesting/negative_test/input");
117 Assert.assertNotNull(messages);
118 Assert.assertEquals(messages.size(), 4);
120 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 2);
121 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "A resource has an invalid or unsupported type - null, Resource ID [server_pcrf_psm_002]");
122 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(1).getMessage(), "Nested files loop - [hot-nimbus-psm_v1.0.yaml -- nested-psm_v1.0.yaml -- nested-points-to-hot-nimbus-psm.yaml -- hot-nimbus-psm_v1.0.yaml]");
124 Assert.assertEquals(messages.get("nested-points-to-hot-nimbus-psm.yaml").getErrorMessageList().size(), 2);
125 Assert.assertEquals(messages.get("nested-points-to-hot-nimbus-psm.yaml").getErrorMessageList().get(0).getMessage(), "Nested files loop - [nested-points-to-hot-nimbus-psm.yaml -- hot-nimbus-psm_v1.0.yaml -- nested-psm_v1.0.yaml -- nested-points-to-hot-nimbus-psm.yaml]");
126 Assert.assertEquals(messages.get("nested-points-to-hot-nimbus-psm.yaml").getErrorMessageList().get(1).getMessage(), "Nested files loop - [nested-points-to-hot-nimbus-psm.yaml -- nested-psm_v1.0.yaml -- nested-points-to-hot-nimbus-psm.yaml]");
128 Assert.assertEquals(messages.get("yaml-point-to-itself.yaml").getErrorMessageList().size(), 1);
129 Assert.assertEquals(messages.get("yaml-point-to-itself.yaml").getErrorMessageList().get(0).getMessage(), "Nested files loop - [yaml-point-to-itself.yaml -- yaml-point-to-itself.yaml]");
131 Assert.assertEquals(messages.get("nested-psm_v1.0.yaml").getErrorMessageList().size(), 1);
132 Assert.assertEquals(messages.get("nested-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Nested files loop - [nested-psm_v1.0.yaml -- nested-points-to-hot-nimbus-psm.yaml -- hot-nimbus-psm_v1.0.yaml -- nested-psm_v1.0.yaml]");
136 public void testOnlyOneNovaPointsToOnePort() throws IOException {
137 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/one_nova_points_to_one_port/negative_test/input");
139 Assert.assertNotNull(messages);
140 Assert.assertEquals(messages.size(), 1);
142 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
143 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Resource Port oam1_int_port exceed allowed relations from NovaServer");
147 public void testServerGroupsPointedByServersDefinedCorrectly() throws IOException {
148 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/server_groups_defined_correctly/negative_test/input");
150 Assert.assertNotNull(messages);
151 Assert.assertEquals(messages.size(), 1);
153 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 3);
154 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Missing server group definition - BE_Affinity_2, nova_server_1");
155 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(), "Missing server group definition - BE_Affinity_2, nova_server_2");
156 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(2).getMessage(), "Referenced resource - BE_Affinity_1 not found");
161 public void testPolicyIsAffinityOrAntiAffinity() throws IOException {
162 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/policy_is_affinity_or_anti_affinity/negative_test/input");
164 Assert.assertNotNull(messages);
165 Assert.assertEquals(messages.size(), 1);
167 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
168 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Wrong policy in server group - pcrf_server_policies_1");
173 public void testEnvContentIsSubSetOfHeatParameters() throws IOException {
174 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/env_content_is_subset_of_heat/negative_test/input");
176 Assert.assertNotNull(messages);
177 Assert.assertEquals(messages.size(), 1);
179 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().size(), 1);
180 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().get(0).getMessage(), "Env file hot-nimbus-pps_v1.0.env includes a parameter not in HEAT - mock_param");
184 public void testDefaultValueAlignWithType() throws IOException {
185 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/default_value_align_with_type/negative_test/input");
187 Assert.assertNotNull(messages);
188 Assert.assertEquals(messages.size(), 1);
190 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
191 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Parameter - pcrf_pps_image_name_1 default value not align with type number");
196 public void testEnvParametersMatchDefinedHeatParameterTypes() throws IOException {
197 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/env_parameters_match_defined_types/negative_test/input");
199 Assert.assertNotNull(messages);
200 Assert.assertEquals(messages.size(), 1);
202 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().size(), 1);
203 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().get(0).getMessage(), "Parameter env value pcrf_pps_flavor_name not align with type");
208 public void testReferencedArtifactsExist() throws IOException {
209 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/referenced_artifacts_exist/negative_test/input");
211 Assert.assertNotNull(messages);
212 Assert.assertEquals(messages.size(), 1);
214 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
215 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Missing artifact - nimbus-ethernet");
221 public void testResourcesGroupWithNested() throws IOException {
222 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/resources_group_with_nested/negative_test/input");
224 Assert.assertNotNull(messages);
225 Assert.assertEquals(messages.size(), 3);
227 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 2);
228 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Referenced parameter not found in nested file - nested-from-resources-group.yaml, resource name - nested-from-resources-group.yaml, parameter name - property_not_in_nested");
229 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(1).getMessage(), "OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_without_resources_group], resource_def type [OS::Nova::Server]");
231 Assert.assertEquals(messages.get("nested-pps_v1.0.yaml").getErrorMessageList().size(), 1);
232 Assert.assertEquals(messages.get("nested-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Nested files loop - [nested-pps_v1.0.yaml -- nested-from-resources-group.yaml -- hot-nimbus-pps_v1.0.yaml -- nested-pps_v1.0.yaml]");
234 Assert.assertEquals(messages.get("nested-not-exist.yaml").getErrorMessageList().size(), 1);
235 Assert.assertEquals(messages.get("nested-not-exist.yaml").getErrorMessageList().get(0).getMessage(), "Missing nested file - nested-not-exist.yaml");
240 public void testResourceGroupWithInvalidType(){
241 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/resource_group_invalid_type/negative_test/input");
243 Assert.assertNotNull(messages);
244 Assert.assertEquals(messages.size(), 1);
246 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 3);
247 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_with_resources_group_1], resource_def type [{get_param=pcrf_vnf_id}]");
248 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(1).getMessage(), "OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_with_resources_group_2], resource_def type [OS::Nova::Server]");
249 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(2).getMessage(), "A resource has an invalid or unsupported type - null, Resource ID [resource_with_resources_group_3]");
254 public void testNetworkPolicyAssociatedWithAttachPolicy() throws IOException {
255 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/network_policy_associated_with_attach_policy/input");
257 Assert.assertNotNull(messages);
258 Assert.assertEquals(messages.size(), 1);
260 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
261 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "NetworkPolicy not in use, Resource Id [not_used_server_pcrf_policy]");
266 public void testSecurityGroupsCalledByPort() throws IOException {
267 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/security_group_called_by_port/input");
269 Assert.assertNotNull(messages);
270 Assert.assertEquals(messages.size(), 1);
272 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2);
273 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "SecurityGroup not in use, Resource Id [not_used_security_group]");
274 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(), "Port not bind to any NOVA Server, Resource Id [attach_policy_resource]");
279 public void testServerGroupCalledByServer() throws IOException {
280 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/server_group_called_by_nova_server/input");
282 Assert.assertNotNull(messages);
283 Assert.assertEquals(messages.size(), 1);
285 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
286 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "ServerGroup not in use, Resource Id [not_used_server_group]");
292 public void testSecurityGroupBaseFileNoPorts() throws IOException {
293 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/security_group_base_file_no_ports/input");
295 Assert.assertNotNull(messages);
296 Assert.assertEquals(messages.size(), 1);
298 Assert.assertEquals(messages.get("baseFile.yaml").getErrorMessageList().size(), 1);
299 Assert.assertEquals(messages.get("baseFile.yaml").getErrorMessageList().get(0).getMessage(), "SecurityGroup not in use, Resource Id [shared_security_group_id3]");
304 public void testDependsOn(){
305 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/depends_on_points_to_existing_resource/input");
307 Assert.assertNotNull(messages);
308 Assert.assertEquals(messages.size(), 1);
310 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2);
311 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "a Missing resource in depend On Missing Resource ID [resource_not_exist]");
312 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(), "a Missing resource in depend On Missing Resource ID [resource_3]");
317 public void testSharedResourcesValidation(){
318 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/shared_resources/input");
320 Assert.assertNotNull(messages);
321 Assert.assertEquals(messages.size(), 1);
323 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2);
324 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "SecurityGroup not in use, Resource Id [not_used_security_group]");
325 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(), "Port not bind to any NOVA Server, Resource Id [attach_policy_resource]");
330 public void testNoErrorWhenEmptyValueForParameterInEnv(){
331 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/env_empty_value/input");
333 Assert.assertNotNull(messages);
334 Assert.assertEquals(messages.size(), 1);
336 MessageContainer envMessages = messages.get("env_empty_value.env");
337 Assert.assertNull(envMessages);
342 public void testGetParamPseudoParameters(){
343 Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/pseudo_parameters/input");
345 Assert.assertNotNull(messages);
346 Assert.assertEquals(messages.size(), 0);
352 public Map<String, MessageContainer> runValidation(String path) {
353 HeatValidator heatValidator = new HeatValidator();
354 return testValidator(heatValidator, path);