aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/validators/HeatValidatorTest.java
blob: 9ff375c1a342aa5b00a8337f685b1d5b8d382d89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
package org.openecomp.sdc.validation.impl.validators.validators;

import org.openecomp.sdc.validation.impl.validators.HeatValidator;
import org.openecomp.sdc.validation.impl.validators.ValidatorBaseTest;
import org.openecomp.core.validation.types.MessageContainer;

import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.Map;

public class HeatValidatorTest extends ValidatorBaseTest {


    @Test
    public void testInvalidHeatFormat(){
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/invalid_heat_format/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
        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" +
                " in 'reader', line 25, column 5:\n" +
                "        kuku: kuku\n" +
                "        ^\n" +
                "Unable to find property 'kuku' on class: org.openecomp.sdc.heat.datatypes.model.Resource\n" +
                " in 'reader', line 25, column 11:\n" +
                "        kuku: kuku\n" +
                "              ^\n" +
                "]");
    }


    @Test
    public void testResourcesReferencesExistInHeat() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/resource_references_exist_in_heat/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2);
        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Referenced resource - not_existing_resource not found");
        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");
    }


    @Test
    public void testGetResourceValueIsValid(){
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/get_resource_value_valid/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 3);
        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");
        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");
        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");
    }

    @Test
    public void testTwoResourcesDoesNotHoldSameId() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/two_resources_does_not_hold_same_id/positive_test/input");
        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 0);
    }

    @Test
    public void negativeTestGetParamPointToExistingParameter() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/get_param_points_to_existing_parameter/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
        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");
    }

    @Test
    public void testGetAttrFromNested() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/get_attr_from_nested/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
        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");
    }

    @Test
    public void testPropertiesMatchNestedParameters() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/properties_match_nested_parameters/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
        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");
    }

    @Test
    public void testNovaPropertiesHasAssignedValue() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/nova_properties_has_assigned_value/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
        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");
    }

    @Test
    public void testNoLoopsNesting() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/no_loops_nesting/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 4);

        Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 2);
        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]");
        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]");

        Assert.assertEquals(messages.get("nested-points-to-hot-nimbus-psm.yaml").getErrorMessageList().size(), 2);
        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]");
        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]");

        Assert.assertEquals(messages.get("yaml-point-to-itself.yaml").getErrorMessageList().size(), 1);
        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]");

        Assert.assertEquals(messages.get("nested-psm_v1.0.yaml").getErrorMessageList().size(), 1);
        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]");
    }

    @Test
    public void testOnlyOneNovaPointsToOnePort() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/one_nova_points_to_one_port/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
        Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Resource Port oam1_int_port exceed allowed relations from NovaServer");
    }

    @Test
    public void testServerGroupsPointedByServersDefinedCorrectly() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/server_groups_defined_correctly/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 3);
        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Missing server group definition - BE_Affinity_2, nova_server_1");
        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(), "Missing server group definition - BE_Affinity_2, nova_server_2");
        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(2).getMessage(), "Referenced resource - BE_Affinity_1 not found");
    }


    @Test
    public void testPolicyIsAffinityOrAntiAffinity() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/policy_is_affinity_or_anti_affinity/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
        Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Wrong policy in server group - pcrf_server_policies_1");
    }


    @Test
    public void testEnvContentIsSubSetOfHeatParameters() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/env_content_is_subset_of_heat/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().size(), 1);
        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");
    }

    @Test
    public void testDefaultValueAlignWithType() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/default_value_align_with_type/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
        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");
    }


    @Test
    public void testEnvParametersMatchDefinedHeatParameterTypes() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/env_parameters_match_defined_types/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().size(), 1);
        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");

    }

    @Test
    public void testReferencedArtifactsExist() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/referenced_artifacts_exist/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "Missing artifact - nimbus-ethernet");

    }


    @Test
    public void testResourcesGroupWithNested() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/resources_group_with_nested/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 3);

        Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 2);
        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");
        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]");

        Assert.assertEquals(messages.get("nested-pps_v1.0.yaml").getErrorMessageList().size(), 1);
        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]");

        Assert.assertEquals(messages.get("nested-not-exist.yaml").getErrorMessageList().size(), 1);
        Assert.assertEquals(messages.get("nested-not-exist.yaml").getErrorMessageList().get(0).getMessage(), "Missing nested file - nested-not-exist.yaml");
    }


    @Test
    public void testResourceGroupWithInvalidType(){
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/resource_group_invalid_type/negative_test/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 3);
        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}]");
        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]");
        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]");
    }


    @Test
    public void testNetworkPolicyAssociatedWithAttachPolicy() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/network_policy_associated_with_attach_policy/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
        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]");
    }


    @Test
    public void testSecurityGroupsCalledByPort() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/security_group_called_by_port/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2);
        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "SecurityGroup not in use, Resource Id [not_used_security_group]");
        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]");
    }


    @Test
    public void testServerGroupCalledByServer() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/server_group_called_by_nova_server/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "ServerGroup not in use, Resource Id [not_used_server_group]");

    }


    @Test
    public void testSecurityGroupBaseFileNoPorts() throws IOException {
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/security_group_base_file_no_ports/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("baseFile.yaml").getErrorMessageList().size(), 1);
        Assert.assertEquals(messages.get("baseFile.yaml").getErrorMessageList().get(0).getMessage(), "SecurityGroup not in use, Resource Id [shared_security_group_id3]");
    }


    @Test
    public void testDependsOn(){
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/depends_on_points_to_existing_resource/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2);
        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]");
        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]");
    }


    @Test
    public void testSharedResourcesValidation(){
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/shared_resources/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2);
        Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), "SecurityGroup not in use, Resource Id [not_used_security_group]");
        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]");
    }


    @Test
    public void testNoErrorWhenEmptyValueForParameterInEnv(){
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/env_empty_value/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 1);

        MessageContainer envMessages = messages.get("env_empty_value.env");
        Assert.assertNull(envMessages);
    }


    @Test
    public void testGetParamPseudoParameters(){
        Map<String, MessageContainer> messages = runValidation("/openecomp/org/validation/validators/heat_validator/pseudo_parameters/input");

        Assert.assertNotNull(messages);
        Assert.assertEquals(messages.size(), 0);

    }


    @Override
    public Map<String, MessageContainer> runValidation(String path) {
        HeatValidator heatValidator = new HeatValidator();
        return testValidator(heatValidator, path);
    }
}