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
|
/*-
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.onap.sdc.backend.ci.tests.utils.general;
import org.onap.sdc.backend.ci.tests.datatypes.enums.XnfTypeEnum;
import org.onap.sdc.backend.ci.tests.datatypes.http.HttpHeaderEnum;
import org.onap.sdc.backend.ci.tests.datatypes.http.HttpRequest;
import org.onap.sdc.backend.ci.tests.datatypes.http.RestResponse;
import org.openecomp.sdc.be.model.User;
import org.onap.sdc.backend.ci.tests.api.Urls;
import org.onap.sdc.backend.ci.tests.config.Config;
import org.onap.sdc.backend.ci.tests.utils.Utils;
import org.onap.sdc.backend.ci.tests.utils.rest.ResponseParser;
import java.util.*;
public class OnboardingUtils {
/**
* excluded VNF or PNF file list
*/
public static List<String> excludeXnfList =
// new ArrayList<>();
Arrays.asList(
// DUPLICATE_RESOURCE_ID_IN_DIFFERENT_FILES:
"2017-376_vMOG_11_1.zip",
"HeatCandidate_2017-09-20_15-06_66Name_2016-20-visbc1vf-v6.0-(VOIP).zip",
"1 Apndns-1710-vf v3.0.zip",
"1 AVPN_vRE_BV_volume-V2.zip",
"1-Vf-zrdm5bpxtc02-092017-(MOBILITY)_v3.0.zip",
"1-Mobility_vprobe_fe_11_2_1_vf_(MOBILITY)_v1.0.zip",
// ORCHESTRATION_NOT_FOUND:
"1-2017-491-4vshaken-HTTP-CM-vf-(VOIP)_v2.0.zip",
// did not succeed to create package of new VSP expected:<200> but was:<500>:
"1-Riverbed-WANx1710VFv_v2.0.zip",
"1-LMSP_v5-062317_v3.0.zip",
"1-VF-Cisco-vCSR-1710_v2.0.zip",
"1-mDNS-preload_1710-0914_v3.0.zip",
"1-Firewall_170_Pala_Aloto_VF_v2.0.zip",
"2-mDNS-preload-1710-0914_v3.1VF.zip",
"1-2016-233_xsp_bfsa_nin2-vf-V1.0-VOIP-10-20.zip",
// did not succeed to submit new VSP expected:<200> but was:<417>
"1-VF_vEPDG_v4.0.zip",
"1-VF-2017-491_9vShaken-F5-LB_v1.0.zip",
"2-2016-73_Mow-AVPN-vpe-BV-L_v1.0.zip",
"VF-2017389vTSBCDPA2-v4.0.zip",
"1-vEPDG_V1.0(3).zip",
"1-vHSS-EPC-RDM3-Lab-VF-0830_V3.0.zip",
"2-2016-73_Mow-AVPN-vPE-BV-L_VF_V2.0_1027.zip",
"1-ADIOD_base_vPE_BV_v9.0.zip",
"Vhss-epc-rdm3-lab-vf-0921-v2.0-MOBILITY-10-20.zip",
"1-Vhss-epc-rdm3-lab-vf-0921_VF00816v2.0-MOBILITY-10-20.zip",
"1-VF-vUSP-CCF-DB-0620_v1.0base_vDB.zip",
"1-Vusp_vhss-ims_cm-repo1_V1.zip",
"1-base_vepdg_volume_v4.0.zip",
"1-Vocg_1710-2017-509(2)_v1.0.zip",
"1-2016-20-vISBC3VF_v3.0.zip",
"Apndns-1710-vf-v3.0-10-20.zip",
"1-VF-EFMC_DBE_Nin_v27.0.zip",
"2-APNDNS_1710-VF_v4.0.zip",
"1-Mow_adig_vpe_bv-V3.0.zip",
"1-VF-2017-488_ADOID_vPE_v9.0.zip",
"1-MOBT_Nimbus_3_Sprint-1.zip",
"1-VF-2017-491_9vShaken-CM_v1.0.zip",
"1-VF_zrdm5bpxtc02_092017_v2.0.zip",
// Error: TOSCA yaml file %1 cannot be modeled to VF as it does not contain \u0027topology_template
"1-VF-Checkpoint_vFW-1710_v1.0.zip"
);
/**
* additional files to excludeXnfList files for tosca parser tests
*/
protected static List<String> excludeXnfListForToscaParser = //new ArrayList<String>();
Arrays.asList(
"1-Vvig-062017-(MOBILITY)_v5.1.zip",
"1-Mvm-sbc-1710-092017-(MOBILITY)_v7.0.zip",
"1-2017-492-5vshaken-SIP-AS-vf-(VOIP)_v2.0.zip",
"1-201712-488-adiod-vpe-(Layer-0-3)_v2.0.zip",
"2017-502.zip",
"1-2017-505-urlb-vhepe-(Layer-0-3)_v2.0.zip",
"2017-376_vMOG_11_1.zip",
"HeatCandidate_2017-09-22_01-30_60Name_Vdbe-vsp-15.1x49-d50.3-v3.0-(VOIP).zip",
"HeatCandidate_2017-09-22_01-42_57Name_2017389vtsbc4vf-v10.0-(VOIP).zip",
"HeatCandidate_2017-09-20_13-47_68Name_2017-492-5vshaken-SIP-AS-vf-v1.0-(VOIP)_10202017.zip",
"1-2016-20-visbc3vf-(VOIP)_v2.1.zip",
"1-2017-404_vUSP_vCCF_AIC3.0-(VOIP)_v6.0.zip",
"1-2017389vtsbc4vf-(VOIP)_v11.0.zip"
);
public static String handleFilename(String heatFileName) {
final String namePrefix = String.format("%sVF%s", ElementFactory.getResourcePrefix(), "Onboarded-");
final String nameSuffix = "-" + getShortUUID();
String subHeatFileName = heatFileName.substring(0, heatFileName.lastIndexOf("."));
if ((namePrefix + subHeatFileName + nameSuffix).length() >= 50) {
subHeatFileName = subHeatFileName.substring(0, 50 - namePrefix.length() - nameSuffix.length());
}
if (subHeatFileName.contains("(") || subHeatFileName.contains(")")) {
subHeatFileName = subHeatFileName.replace("(", "-");
subHeatFileName = subHeatFileName.replace(")", "-");
}
String vnfName = namePrefix + subHeatFileName + nameSuffix;
return vnfName;
}
public static String getShortUUID() {
return UUID.randomUUID().toString().split("-")[0];
}
private static RestResponse actionOnComponent(String vspid, String body, String onboardComponent, User user, String componentVersion) throws Exception {
Config config = Utils.getConfig();
String url = String.format(Urls.ACTION_ON_COMPONENT, config.getOnboardingBeHost(), config.getOnboardingBePort(), onboardComponent, vspid, componentVersion);
String userId = user.getUserId();
Map<String, String> headersMap = prepareHeadersMap(userId);
HttpRequest http = new HttpRequest();
RestResponse response = http.httpSendPut(url, body, headersMap);
return response;
}
public static String getVspValidationConfiguration() throws Exception {
Config config = Utils.getConfig();
String url = String.format(Urls.VSP_VALIDATION_CONFIGURATION, config.getOnboardingBeHost(), config.getOnboardingBePort());
Map<String, String> headersMap = prepareHeadersMap("cs0008");
HttpRequest http = new HttpRequest();
RestResponse response = http.httpSendGet(url, headersMap);
if(response.getErrorCode().intValue() == 200){
return ResponseParser.getValueFromJsonResponse(response.getResponse(), "enabled");
}
throw new Exception("Cannot get configuration file");
//return response;
}
public static String putVspValidationConfiguration(boolean value) throws Exception {
Config config = Utils.getConfig();
String url = String.format(Urls.VSP_VALIDATION_CONFIGURATION, config.getOnboardingBeHost(), config.getOnboardingBePort());
Map<String, String> headersMap = prepareHeadersMap("cs0008");
String body = String.format("{\"enabled\": \"%s\"}", value);
HttpRequest http = new HttpRequest();
RestResponse response = http.httpSendPut(url, body, headersMap);
if(response.getErrorCode().intValue() == 200){
return ResponseParser.getValueFromJsonResponse(response.getResponse(), "enabled");
}
throw new Exception("Cannot set configuration file");
//return response;
}
protected static Map<String, String> prepareHeadersMap(String userId) {
Map<String, String> headersMap = new HashMap<String, String>();
headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json");
headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json");
headersMap.put(HttpHeaderEnum.USER_ID.getValue(), userId);
return headersMap;
}
/**
* @return
* The method returns XNF names list from Files directory under sdc repository
*/
public static List<String> getXnfNamesFileList(XnfTypeEnum xnfTypeEnum) {
String filepath = FileHandling.getXnfRepositoryPath(xnfTypeEnum);
List<String> fileNamesFromFolder = FileHandling.getZipFileNamesFromFolder(filepath);
fileNamesFromFolder.removeAll(excludeXnfList);
return fileNamesFromFolder;
}
/**
* @param vnfNamesFileList
* @return divide List according to day of month, if day of month is even as get first half part of the List, else - second
*/
public static List<String> divideListByDayOfMonth(List<String> vnfNamesFileList){
Calendar cal = Calendar.getInstance();
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH)+1;
int filesCount = vnfNamesFileList.size();
if(dayOfMonth%2 == 0){
return vnfNamesFileList.subList(0,filesCount/2);
}else{
return vnfNamesFileList.subList(filesCount/2, filesCount);
}
}
/**
* @return
* The method returns VNF names list from Files directory under sdc-vnfs repository excluding zip files that known as failed in tosca parser
*/
public static List<String> getVnfNamesFileListExcludeToscaParserFailure() {
List<String> fileNamesFromFolder = getXnfNamesFileList(XnfTypeEnum.VNF);
fileNamesFromFolder.removeAll(excludeXnfListForToscaParser);
return fileNamesFromFolder;
}
public static Object[][] filterObjectArrWithExcludedVnfs(Object[][] objectArr)
{
Object[][] filteredArObject = new Object[objectArr.length][];
int index = 0;
for (int i = 0; i < objectArr.length ; i++) {
String vnfSourceFile = (String) objectArr[i][0];
String vnfUpdateFile = (String) objectArr[i][1];
if(!excludeXnfList.contains(vnfSourceFile) && !excludeXnfList.contains(vnfUpdateFile))
{
filteredArObject[index] = new Object[]{vnfSourceFile , vnfUpdateFile };
index++;
}
}
return filteredArObject;
}
}
|