[ROBOT] Fix HVVES and 5GBulkPM testcases
[testsuite.git] / robot / resources / dcaemod_interface.robot
1 *** Settings ***
2 Library          ONAPLibrary.Templating    WITH NAME    Templating
3 Library          ONAPLibrary.Utilities
4 Library          RequestsLibrary
5 Library          Collections
6 Library          String
7 Library          OperatingSystem
8 Resource         ../resources/global_properties.robot
9 Resource         chart_museum.robot
10
11
12 *** Variables ***
13
14 ${CLIENT_ID}                                  robot123
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}
21 ${TYPE_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/-.*//'
29
30
31 *** Keywords ***
32
33 Deploy DCAE Application
34     [Arguments]  ${componentSpec}  ${dict_values}  ${compSpecName}  ${processGroupName}
35
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}
40
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
45
46     Deploy Applictaion  ${processGroupName}  ${compSpecName}
47     Set Test Variable  ${CHART_NAME}  ${compSpecName}
48
49
50
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}
55
56 Delete Config Map
57     [Arguments]  ${configMapName}
58     ${configMapDelete} =  Run And Return Rc  kubectl -n onap delete configmap ${configMapName}
59     Should Be Equal As Integers  ${configMapDelete}  0
60
61 Create Config Map From File
62     [Arguments]  ${configMapName}  ${configMapFilePath}
63
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}
67
68 Config Map Exists
69     [Arguments]  ${configMapName}
70     ${configMapExists} =  Run And Return Rc  kubectl -n onap get configmap | grep ${configMapName}
71     Should Be Equal As Integers  ${configMapExists}  0
72
73 Get Pod Yaml
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]}
78
79     [Return]  ${podYaml}
80
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]}
86
87     [Return]  ${mountedFolderContent}
88
89 Verify If Volume Is Mounted
90     [Arguments]  ${podYaml}  ${volumeMountPath}
91     Should Contain  ${podYaml}  ${volumeMountPath}
92
93 Verify If Config Map Is Mounted As Volume
94     [Arguments]  ${podYaml}  ${configMapName}
95     Should Contain  ${podYaml}  ${configMapName}
96
97 Verify If Mounted Folder Is Empty
98     [Arguments]  ${mountedFolderContent}
99     Should Be Empty  ${mountedFolderContent}
100
101 Verify If Mounted Folder Contains File
102     [Arguments]  ${compSpecName}  ${fileName}  ${configMapDir}
103
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}
107
108 Verify File Content
109     [Arguments]  ${compSpecName}  ${configMapFilePath}  ${content}
110
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}
114
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}
120     Log  ${resp.json()}
121     Should Not Be Empty  ${resp.json().get('components')}
122
123
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
132
133     Wait Until Keyword Succeeds  2 min  5s  Verify If Component Is Onboarded  ${compSpecName}
134
135     Log  ${resp.json()}
136
137 Add Registry Client
138
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
144
145     Set Global Variable  ${REGISTRY_CLIENT_ID}  ${resp.json().get('id')}
146     Set Global Variable  ${REGISTRY_CLIENT_VERSION}  ${resp.json().get('revision').get('version')}
147
148 Add Distribution Target
149
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')}
156
157 Create Process Group
158     [Arguments]  ${name}
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
163     Log  ${resp.json()}
164     ${parentGroupId} =  Set Variable  ${resp.json().get('processGroupFlow').get('id')}
165
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
169     Log  ${resp.json()}
170
171     ${processGroupId} =  Set Variable  ${resp.json().get('id')}
172
173     [Return]  ${processGroupId}
174
175
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}
181     Log  ${resp.json()}
182     Should Not Be Empty  ${resp.json().get('processorTypes')}
183
184 Create Processor
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
194
195
196 Save Flow By Version Controlling
197     [Arguments]  ${flowName}  ${processGroupId}
198
199     ${session}=  Create Session   ${SESSION_NAME}  ${DCAEMOD_DESIGNTOOL_SERVER}
200     ${headers}=  Create Dictionary  content-type=application/json
201
202     ${resp} =  Get Request  ${SESSION_NAME}  /nifi-api/flow/registries/${REGISTRY_CLIENT_ID}/buckets  headers=${headers}
203     Should Be True  ${resp.status_code} < 300
204     Log  ${resp.json()}
205     ${bucketId} =  Set Variable  ${resp.json().get('buckets')[0].get('id')}
206
207     ${processGrVersion}  ${_}=  Get Process Group Revision  ${processGroupId}
208
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
212
213 Distribute The Flow
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
220     Log  ${resp.json()}
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
225
226 Deploy Applictaion
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}
240
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
247
248 Undeploy Application
249      [Arguments]  ${CHART_NAME}
250      Uninstall helm charts               ${ONAP_HELM_RELEASE}-${CHART_NAME}
251
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')}
260
261      [Return]  ${currentProcessGrVersion}  ${clientId}
262
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
267
268 Delete Process Group
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
274
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
279
280 Configure Nifi Registry And Distribution Target
281      Restart Runtime API
282      Add Registry Client
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]}
288
289 Restart Runtime API
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
295
296 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
301
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
305
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