Update DCAE MOD smoke/verification test using simple app
[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         ../resources/dcae/inventory.robot
10 Resource         ../resources/dcae/deployment.robot
11
12
13 *** Variables ***
14
15 ${CLIENT_ID}                                  robot123
16 ${SESSION_NAME}                               nifi-api
17 ${DCAEMOD_SERVER}                             http://dcaemod.simpledemo.onap.org
18 ${IS_PROCESS_GROUP_SET}                       False
19 ${IS_FLOW_DISTRIBUTED}                        False
20 ${IS_SERVICE_DEPLOYED}                        False
21 ${PROCESS_GROUP_ID}                           ${EMPTY}
22 ${TYPE_ID}                                    ${EMPTY}
23 ${BLUEPRINT_NAME}                             ${EMPTY}
24 ${DISTRIBUTION_TARGET_ID}                     ${EMPTY}
25 ${REGISTRY_CLIENT_ID}                         ${EMPTY}
26 ${DCAEMOD_ONBOARDING_API_SERVER}              ${GLOBAL_DCAEMOD_ONBOARDING_API_SERVER_PROTOCOL}://${GLOBAL_DCAEMOD_ONBOARDING_API_SERVER_NAME}:${GLOBAL_DCAEMOD_ONBOARDING_API_SERVER_PORT}
27 ${DCAEMOD_DESIGNTOOL_SERVER}                  ${GLOBAL_DCAEMOD_DESIGNTOOL_SERVER_PROTOCOL}://${GLOBAL_DCAEMOD_DESIGNTOOL_SERVER_NAME}:${GLOBAL_DCAEMOD_DESIGNTOOL_SERVER_PORT}
28 ${DCAEMOD_DISTRIBUTOR_API_SERVER}             ${GLOBAL_DCAEMOD_DISTRIBUTOR_API_SERVER_PROTOCOL}://${GLOBAL_DCAEMOD_DISTRIBUTOR_API_SERVER_NAME}:${GLOBAL_DCAEMOD_DISTRIBUTOR_API_SERVER_PORT}
29
30 *** Keywords ***
31
32 Deploy DCAE Application
33     [Arguments]  ${componentSpec}  ${dict_values}  ${compSpecName}  ${processGroupName}
34
35     Onboard Component Spec  ${componentSpec}  ${dict_values}  ${compSpecName}
36     ${processGroupId} =  Create Process Group  ${processGroupName}
37     Set Test Variable  ${IS_PROCESS_GROUP_SET}  True
38     Set Test Variable  ${PROCESS_GROUP_ID}  ${processGroupId}
39
40     Create Processor  ${PROCESS_GROUP_ID}  ${compSpecName}
41     Save Flow By Version Controlling  ${processGroupName}  ${PROCESS_GROUP_ID}
42     Distribute The Flow  ${PROCESS_GROUP_ID}
43     Set Test Variable  ${IS_FLOW_DISTRIBUTED}  True
44
45     ${typeId}  ${blueprintName} =  Deploy Blueprint From Inventory  ${processGroupName}  ${compSpecName}
46     Set Test Variable  ${IS_SERVICE_DEPLOYED}  True
47     Set Test Variable  ${TYPE_ID}  ${typeId}
48     Set Test Variable  ${BLUEPRINT_NAME}  ${blueprintName}
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}') -- 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}') -- 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}') -- 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 Blueprint From Inventory
227     [Arguments]  ${processGroupName}  ${compSpecName}
228     ${blueprintName} =  Set Variable  ${processGroupName}_${compSpecName}
229     ${resp} =  Wait Until Keyword Succeeds  7 min  20s  Get Blueprint From Inventory  ${blueprintName}
230     ${typeId} =  Set Variable  ${resp.json().get('items')[0].get('typeId')}
231     ${data} =  Set Variable  {"serviceTypeId": "${typeId}"}
232     Deploy Service  ${data}  ${blueprintName}  10 minute
233
234     [Return]  ${typeId}  ${blueprintName}
235
236 Get Process Group Revision
237      [Arguments]  ${processGroupId}
238      ${session}=  Create Session   ${SESSION_NAME}  ${DCAEMOD_DESIGNTOOL_SERVER}
239      ${headers}=  Create Dictionary  content-type=application/json
240      ${resp} =  Get Request  ${SESSION_NAME}  /nifi-api/versions/process-groups/${processGroupId}  headers=${headers}
241      Should Be True  ${resp.status_code} < 300
242      ${currentProcessGrVersion} =  Set Variable  ${resp.json().get('processGroupRevision').get('version')}
243      ${clientId} =  Set Variable  ${resp.json().get('processGroupRevision').get('clientId')}
244
245      [Return]  ${currentProcessGrVersion}  ${clientId}
246
247 Delete Distribution Target
248     ${session}=  Create Session   distributor  ${DCAEMOD_DISTRIBUTOR_API_SERVER}
249     ${resp} =  Delete Request  distributor  /distributor/distribution-targets/${DISTRIBUTION_TARGET_ID}
250     Should Be True  ${resp.status_code} < 300
251
252 Delete Process Group
253     [Arguments]  ${processGroupId}
254     ${session}=  Create Session   ${SESSION_NAME}  ${DCAEMOD_DESIGNTOOL_SERVER}
255     ${processGrVersion}  ${clientId}=  Get Process Group Revision  ${processGroupId}
256     ${resp} =  Delete Request  ${SESSION_NAME}  /nifi-api/process-groups/${processGroupId}?version=${processGrVersion}&clientId=${clientId}
257     Should Be True  ${resp.status_code} < 300
258
259 Delete Registry Client
260     ${session}=  Create Session   ${SESSION_NAME}  ${DCAEMOD_DESIGNTOOL_SERVER}
261     ${resp} =  Delete Request  ${SESSION_NAME}  /nifi-api/controller/registry-clients/${REGISTRY_CLIENT_ID}?version=${REGISTRY_CLIENT_VERSION}
262     Should Be True  ${resp.status_code} < 300
263
264 Configure Nifi Registry And Distribution Target
265      Add Registry Client
266      Add Distribution Target
267
268 Delete Nifi Registry And Distribution Target
269     Run Keyword If  '${DISTRIBUTION_TARGET_ID}' != '${EMPTY}'  Wait Until Keyword Succeeds  2 min  5s  Delete Distribution Target
270     Run Keyword If  '${REGISTRY_CLIENT_ID}' != '${EMPTY}'      Wait Until Keyword Succeeds  2 min  5s  Delete Registry Client
271
272 Delete Process Group And Blueprint And Deployment
273     Run Keyword If  ${IS_PROCESS_GROUP_SET}  Run Keywords  Delete Process Group  ${PROCESS_GROUP_ID}
274     ...                                               AND  Set Suite Variable  ${IS_PROCESS_GROUP_SET}  False
275     Run Keyword If  ${IS_FLOW_DISTRIBUTED}   Run Keywords  Delete Blueprint From Inventory  ${TYPE_ID}
276     ...                                               AND  Set Suite Variable  ${IS_FLOW_DISTRIBUTED}  False
277     Run Keyword If  ${IS_SERVICE_DEPLOYED}   Run Keywords  Undeploy Service  ${BLUEPRINT_NAME}
278     ...                                               AND  Set Suite Variable  ${IS_SERVICE_DEPLOYED}  False