2 Library ONAPLibrary.Templating WITH NAME Templating
3 Library ONAPLibrary.Utilities
4 Library RequestsLibrary
7 Library OperatingSystem
8 Resource ../resources/global_properties.robot
9 Resource chart_museum.robot
15 ${SESSION_NAME} nifi-api
16 ${DCAEMOD_SERVER} http://dcaemod.simpledemo.onap.org
17 ${IS_PROCESS_GROUP_SET} False
18 ${IS_FLOW_DISTRIBUTED} False
19 ${IS_SERVICE_DEPLOYED} False
20 ${PROCESS_GROUP_ID} ${EMPTY}
22 ${BLUEPRINT_NAME} ${EMPTY}
23 ${DISTRIBUTION_TARGET_ID} ${EMPTY}
24 ${REGISTRY_CLIENT_ID} ${EMPTY}
25 ${DCAEMOD_ONBOARDING_API_SERVER} ${GLOBAL_DCAEMOD_ONBOARDING_API_SERVER_PROTOCOL}://${GLOBAL_DCAEMOD_ONBOARDING_API_SERVER_NAME}:${GLOBAL_DCAEMOD_ONBOARDING_API_SERVER_PORT}
26 ${DCAEMOD_DESIGNTOOL_SERVER} ${GLOBAL_DCAEMOD_DESIGNTOOL_SERVER_PROTOCOL}://${GLOBAL_DCAEMOD_DESIGNTOOL_SERVER_NAME}:${GLOBAL_DCAEMOD_DESIGNTOOL_SERVER_PORT}
27 ${DCAEMOD_DISTRIBUTOR_API_SERVER} ${GLOBAL_DCAEMOD_DISTRIBUTOR_API_SERVER_PROTOCOL}://${GLOBAL_DCAEMOD_DISTRIBUTOR_API_SERVER_NAME}:${GLOBAL_DCAEMOD_DISTRIBUTOR_API_SERVER_PORT}
28 ${HELM_RELEASE} kubectl --namespace onap get pods | sed 's/ .*//' | grep robot | sed 's/-.*//'
33 Deploy DCAE Application
34 [Arguments] ${componentSpec} ${dict_values} ${compSpecName} ${processGroupName}
36 Onboard Component Spec ${componentSpec} ${dict_values} ${compSpecName}
37 ${processGroupId} = Create Process Group ${processGroupName}
38 Set Test Variable ${IS_PROCESS_GROUP_SET} True
39 Set Test Variable ${PROCESS_GROUP_ID} ${processGroupId}
41 Create Processor ${PROCESS_GROUP_ID} ${compSpecName}
42 Save Flow By Version Controlling ${processGroupName} ${PROCESS_GROUP_ID}
43 Distribute The Flow ${PROCESS_GROUP_ID}
44 Set Test Variable ${IS_FLOW_DISTRIBUTED} True
46 Deploy Applictaion ${processGroupName} ${compSpecName}
47 Set Test Variable ${CHART_NAME} ${compSpecName}
51 Delete Config Map With Mounted Config File
52 ${configMapStatus} = Run Keyword And Return Status Config Map Exists ${CONFIG_MAP_NAME}
53 Run Keyword If ${configMapStatus} Delete Config Map ${CONFIG_MAP_NAME}
54 Remove File ${CONFIG_MAP_FILE}
57 [Arguments] ${configMapName}
58 ${configMapDelete} = Run And Return Rc kubectl -n onap delete configmap ${configMapName}
59 Should Be Equal As Integers ${configMapDelete} 0
61 Create Config Map From File
62 [Arguments] ${configMapName} ${configMapFilePath}
64 ${createConfigMapRC} = Run And Return Rc kubectl -n onap create configmap ${configMapName} --from-file=${configMapFilePath}
65 Should Be Equal As Integers ${createConfigMapRC} 0
66 Wait Until Keyword Succeeds 1 min 5s Config Map Exists ${configMapName}
69 [Arguments] ${configMapName}
70 ${configMapExists} = Run And Return Rc kubectl -n onap get configmap | grep ${configMapName}
71 Should Be Equal As Integers ${configMapExists} 0
74 [Arguments] ${compSpecName}
75 ${podYaml} = Run And Return Rc And Output kubectl -n onap get pod $(kubectl get pod -n onap | grep ${compSpecName} | awk '{print $1}') -o yaml
76 Should Be Equal As Integers ${podYaml[0]} 0
77 ${podYaml} = Set Variable ${podYaml[1]}
81 Get Content Of Mounted Folder Inside Container
82 [Arguments] ${compSpecName} ${volumeMountPath}
83 ${mountedFolderContent} = Run And Return Rc And Output kubectl -n onap exec $(kubectl get pod -n onap | grep ${compSpecName} | awk '{print $1}') -c ${compSpecName} -- ls ${volumeMountPath}
84 Should Be Equal As Integers ${mountedFolderContent[0]} 0
85 ${mountedFolderContent} = Set Variable ${mountedFolderContent[1]}
87 [Return] ${mountedFolderContent}
89 Verify If Volume Is Mounted
90 [Arguments] ${podYaml} ${volumeMountPath}
91 Should Contain ${podYaml} ${volumeMountPath}
93 Verify If Config Map Is Mounted As Volume
94 [Arguments] ${podYaml} ${configMapName}
95 Should Contain ${podYaml} ${configMapName}
97 Verify If Mounted Folder Is Empty
98 [Arguments] ${mountedFolderContent}
99 Should Be Empty ${mountedFolderContent}
101 Verify If Mounted Folder Contains File
102 [Arguments] ${compSpecName} ${fileName} ${configMapDir}
104 ${dirContent} = Run And Return Rc And Output kubectl -n onap exec $(kubectl get pod -n onap | grep ${compSpecName} | awk '{print $1}') -c ${compSpecName} -- ls ${configMapDir}
105 Should Be Equal As Integers ${dirContent[0]} 0
106 Should Contain ${dirContent[1]} ${fileName}
109 [Arguments] ${compSpecName} ${configMapFilePath} ${content}
111 ${fileContent} = Run And Return Rc And Output kubectl -n onap exec $(kubectl get pod -n onap | grep ${compSpecName} | awk '{print $1}') -c ${compSpecName} -- cat ${configMapFilePath}
112 Should Be Equal As Integers ${fileContent[0]} 0
113 Should Contain ${fileContent[1]} ${content}
115 Verify If Component Is Onboarded
116 [Arguments] ${compSpecName}
117 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_ONBOARDING_API_SERVER}
118 ${headers}= Create Dictionary content-type=application/json
119 ${resp} = Get Request ${SESSION_NAME} /onboarding/components?name=${compSpecName} headers=${headers}
121 Should Not Be Empty ${resp.json().get('components')}
124 Onboard Component Spec
125 [Arguments] ${componentSpec} ${dict_values} ${compSpecName}
126 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_ONBOARDING_API_SERVER}
127 ${headers}= Create Dictionary content-type=application/json
128 Templating.Create Environment dcaemod ${GLOBAL_TEMPLATE_FOLDER}
129 ${componentSpec}= Templating.Apply Template dcaemod ${componentSpec} ${dict_values}
130 ${resp} = Post Request ${SESSION_NAME} /onboarding/components data=${componentSpec} headers=${headers}
131 Should Be True ${resp.status_code} < 300
133 Wait Until Keyword Succeeds 2 min 5s Verify If Component Is Onboarded ${compSpecName}
139 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_DESIGNTOOL_SERVER}
140 ${headers}= Create Dictionary content-type=application/json
141 ${data} = Set Variable {"revision": {"version": 0}, "component": {"name": "registry_test", "uri": "http://dcaemod-nifi-registry:18080"}}
142 ${resp} = Post Request ${SESSION_NAME} /nifi-api/controller/registry-clients data=${data} headers=${headers}
143 Should Be True ${resp.status_code} < 300
145 Set Global Variable ${REGISTRY_CLIENT_ID} ${resp.json().get('id')}
146 Set Global Variable ${REGISTRY_CLIENT_VERSION} ${resp.json().get('revision').get('version')}
148 Add Distribution Target
150 ${session}= Create Session distributor ${DCAEMOD_DISTRIBUTOR_API_SERVER}
151 ${headers}= Create Dictionary content-type=application/json
152 ${data} = Set Variable {"name": "runtime_test", "runtimeApiUrl": "http://dcaemod-runtime-api:9090"}
153 ${resp} = Post Request distributor /distributor/distribution-targets data=${data} headers=${headers}
154 Should Be True ${resp.status_code} < 300
155 Set Global Variable ${DISTRIBUTION_TARGET_ID} ${resp.json().get('id')}
159 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_DESIGNTOOL_SERVER}
160 ${headers}= Create Dictionary content-type=application/json
161 ${resp} = Get Request ${SESSION_NAME} /nifi-api/flow/process-groups/root/ headers=${headers}
162 Should Be True ${resp.status_code} < 300
164 ${parentGroupId} = Set Variable ${resp.json().get('processGroupFlow').get('id')}
166 ${data} = Set Variable {"revision": {"clientId": "${CLIENT_ID}", "version": 0}, "component" : {"parentGroupId" : "${parentGroupId}", "name" : "${name}"}}
167 ${resp} = Post Request ${SESSION_NAME} /nifi-api/process-groups/${parentGroupId}/process-groups data=${data} headers=${headers}
168 Should Be True ${resp.status_code} < 300
171 ${processGroupId} = Set Variable ${resp.json().get('id')}
173 [Return] ${processGroupId}
176 Verify If NIFI Processor Is Created
177 [Arguments] ${typeName}
178 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_DESIGNTOOL_SERVER}
179 ${headers}= Create Dictionary content-type=application/json
180 ${resp} = Get Request ${SESSION_NAME} /nifi-api/flow/processor-types?type=org.onap.dcae.${typeName} headers=${headers}
182 Should Not Be Empty ${resp.json().get('processorTypes')}
185 [Arguments] ${processGroupId} ${compSpecName}
186 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_DESIGNTOOL_SERVER}
187 ${headers}= Create Dictionary content-type=application/json
188 ${typeName} = Evaluate $compSpecName.title()
189 ${typeName} = Remove String ${typeName} -
190 ${data} = Set Variable {"revision": {"clientId": "${CLIENT_ID}", "version": 0},"component": {"parentGroupId": "${processGroupId}", "name": "${compSpecName}", "type": "org.onap.dcae.${typeName}"}}
191 Wait Until Keyword Succeeds 60s 5s Verify If NIFI Processor Is Created ${typeName}
192 ${resp} = Post Request ${SESSION_NAME} /nifi-api/process-groups/${processGroupId}/processors data=${data} headers=${headers}
193 Should Be True ${resp.status_code} < 300
196 Save Flow By Version Controlling
197 [Arguments] ${flowName} ${processGroupId}
199 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_DESIGNTOOL_SERVER}
200 ${headers}= Create Dictionary content-type=application/json
202 ${resp} = Get Request ${SESSION_NAME} /nifi-api/flow/registries/${REGISTRY_CLIENT_ID}/buckets headers=${headers}
203 Should Be True ${resp.status_code} < 300
205 ${bucketId} = Set Variable ${resp.json().get('buckets')[0].get('id')}
207 ${processGrVersion} ${_}= Get Process Group Revision ${processGroupId}
209 ${data} = Set Variable {"versionedFlow": {"flowName": "${flowName}", "bucketId": "${bucketId}", "registryId": "${REGISTRY_CLIENT_ID}"}, "processGroupRevision": {"clientId": "${CLIENT_ID}", "version": ${processGrVersion}}}
210 ${resp} = Post Request ${SESSION_NAME} /nifi-api/versions/process-groups/${processGroupId} data=${data} headers=${headers}
211 Should Be True ${resp.status_code} < 300
214 [Arguments] ${processGroupId}
215 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_DESIGNTOOL_SERVER}
216 ${session}= Create Session distributor ${DCAEMOD_DISTRIBUTOR_API_SERVER}
217 ${headers}= Create Dictionary content-type=application/json
218 ${resp} = Get Request ${SESSION_NAME} /nifi-api/process-groups/${processGroupId} headers=${headers}
219 Should Be True ${resp.status_code} < 300
221 ${flowId} = Set Variable ${resp.json().get('component').get('versionControlInformation').get('flowId')}
222 ${data} = Set Variable {"processGroupId": "${flowId}"}
223 ${resp} = Post Request distributor /distributor/distribution-targets/${DISTRIBUTION_TARGET_ID}/process-groups data=${data} headers=${headers}
224 Should Be True ${resp.status_code} < 300
227 [Arguments] ${processGroupName} ${compSpecName}
228 ${command_output} = Run And Return Rc And Output helm repo update
229 Should Be Equal As Integers ${command_output[0]} 0
230 ${helm_install}= Set Variable helm -n onap install ${ONAP_HELM_RELEASE}-${compSpecName} chart-museum/${compSpecName} --set global.repository=${registry_ovveride}
231 ${helm_install_command_output} = Run And Return Rc And Output ${helm_install}
232 Log ${helm_install_command_output[1]}
233 Should Be Equal As Integers ${helm_install_command_output[0]} 0
234 Set Test Variable ${IS_SERVICE_DEPLOYED} True
235 ${kubectl_patch}= Set Variable kubectl -n onap patch deployment ${ONAP_HELM_RELEASE}-${compSpecName} -p '{"spec":{"template":{"spec":{"containers":[{"name": "${compSpecName}","image":"docker.io/nginx:latest"}]}}}}'
236 ${kubectl_patch_command_output}= Run And Return Rc And Output ${kubectl_patch}
237 Log ${kubectl_patch_command_output[1]}
238 Should Be Equal As Integers ${kubectl_patch_command_output[0]} 0
239 Wait Until Keyword Succeeds 4 min 15s Check NGINX Applictaion ${compSpecName}
241 Check NGINX Applictaion
242 [Arguments] ${compSpecName}
243 ${check_command}= Set Variable kubectl get deployment -n onap | grep ${compSpecName} | grep 1/1
244 ${check_command_command_output}= Run And Return Rc And Output ${check_command}
245 Log ${check_command_command_output[1]}
246 Should Be Equal As Integers ${check_command_command_output[0]} 0
249 [Arguments] ${CHART_NAME}
250 Uninstall helm charts ${ONAP_HELM_RELEASE}-${CHART_NAME}
252 Get Process Group Revision
253 [Arguments] ${processGroupId}
254 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_DESIGNTOOL_SERVER}
255 ${headers}= Create Dictionary content-type=application/json
256 ${resp} = Get Request ${SESSION_NAME} /nifi-api/versions/process-groups/${processGroupId} headers=${headers}
257 Should Be True ${resp.status_code} < 300
258 ${currentProcessGrVersion} = Set Variable ${resp.json().get('processGroupRevision').get('version')}
259 ${clientId} = Set Variable ${resp.json().get('processGroupRevision').get('clientId')}
261 [Return] ${currentProcessGrVersion} ${clientId}
263 Delete Distribution Target
264 ${session}= Create Session distributor ${DCAEMOD_DISTRIBUTOR_API_SERVER}
265 ${resp} = Delete Request distributor /distributor/distribution-targets/${DISTRIBUTION_TARGET_ID}
266 Should Be True ${resp.status_code} < 300
269 [Arguments] ${processGroupId}
270 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_DESIGNTOOL_SERVER}
271 ${processGrVersion} ${clientId}= Get Process Group Revision ${processGroupId}
272 ${resp} = Delete Request ${SESSION_NAME} /nifi-api/process-groups/${processGroupId}?version=${processGrVersion}&clientId=${clientId}
273 Should Be True ${resp.status_code} < 300
275 Delete Registry Client
276 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_DESIGNTOOL_SERVER}
277 ${resp} = Delete Request ${SESSION_NAME} /nifi-api/controller/registry-clients/${REGISTRY_CLIENT_ID}?version=${REGISTRY_CLIENT_VERSION}
278 Should Be True ${resp.status_code} < 300
280 Configure Nifi Registry And Distribution Target
283 Add Distribution Target
284 Add chart repository chart-museum http://chart-museum:80 onapinitializer demo123456!
285 ${command_output} = Run And Return Rc And Output ${HELM_RELEASE}
286 Should Be Equal As Integers ${command_output[0]} 0
287 Set Global Variable ${ONAP_HELM_RELEASE} ${command_output[1]}
290 ${restart_command}= Set Variable kubectl delete pod $(kubectl get pods -n onap | grep dcaemod-runtime-api | awk '{print $1}') -n onap
291 ${restart_command_command_output}= Run And Return Rc And Output ${restart_command}
292 Log ${restart_command_command_output[1]}
293 Should Be Equal As Integers ${restart_command_command_output[0]} 0
294 Wait Until Keyword Succeeds 2 min 5s Check Runtime API
297 ${check_command}= Set Variable kubectl get deployment -n onap | grep dcaemod-runtime-api | grep 1/1
298 ${check_command_command_output}= Run And Return Rc And Output ${check_command}
299 Log ${check_command_command_output[1]}
300 Should Be Equal As Integers ${check_command_command_output[0]} 0
302 Delete Nifi Registry And Distribution Target
303 Run Keyword If '${DISTRIBUTION_TARGET_ID}' != '${EMPTY}' Wait Until Keyword Succeeds 2 min 5s Delete Distribution Target
304 Run Keyword If '${REGISTRY_CLIENT_ID}' != '${EMPTY}' Wait Until Keyword Succeeds 2 min 5s Delete Registry Client
306 Delete Process Group And Deployment
307 Run Keyword If ${IS_PROCESS_GROUP_SET} Run Keywords Delete Process Group ${PROCESS_GROUP_ID}
308 ... AND Set Suite Variable ${IS_PROCESS_GROUP_SET} False
309 Run Keyword If ${IS_SERVICE_DEPLOYED} Run Keywords Undeploy Application ${CHART_NAME}
310 ... AND Set Suite Variable ${IS_SERVICE_DEPLOYED} False