blob: 9dda0a00970bb9c7d80eebae2125d59b87b17028 [file] [log] [blame]
Katarzyna Wasield1bc6cb2021-02-10 08:50:57 +01001*** Settings ***
2Library ONAPLibrary.Templating WITH NAME Templating
3Library ONAPLibrary.Utilities
4Library RequestsLibrary
5Library Collections
6Library String
7Library OperatingSystem
8Resource ../resources/global_properties.robot
9Resource ../resources/dcae/inventory.robot
10Resource ../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
32Deploy 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
51Delete 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
56Delete 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
61Create 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
68Config 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
73Get 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
81Get 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
89Verify If Volume Is Mounted
90 [Arguments] ${podYaml} ${volumeMountPath}
91 Should Contain ${podYaml} ${volumeMountPath}
92
93Verify If Config Map Is Mounted As Volume
94 [Arguments] ${podYaml} ${configMapName}
95 Should Contain ${podYaml} ${configMapName}
96
97Verify If Mounted Folder Is Empty
98 [Arguments] ${mountedFolderContent}
99 Should Be Empty ${mountedFolderContent}
100
101Verify 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
108Verify 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
115Verify 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
124Onboard 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
137Add 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
148Add 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
157Create 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
176Verify 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
184Create 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 ${data} = Set Variable {"revision": {"clientId": "${CLIENT_ID}", "version": 0},"component": {"parentGroupId": "${processGroupId}", "name": "${compSpecName}", "type": "org.onap.dcae.${typeName}"}}
190 Wait Until Keyword Succeeds 60s 5s Verify If NIFI Processor Is Created ${typeName}
191 ${resp} = Post Request ${SESSION_NAME} /nifi-api/process-groups/${processGroupId}/processors data=${data} headers=${headers}
192 Should Be True ${resp.status_code} < 300
193
194
195Save Flow By Version Controlling
196 [Arguments] ${flowName} ${processGroupId}
197
198 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_DESIGNTOOL_SERVER}
199 ${headers}= Create Dictionary content-type=application/json
200
201 ${resp} = Get Request ${SESSION_NAME} /nifi-api/flow/registries/${REGISTRY_CLIENT_ID}/buckets headers=${headers}
202 Should Be True ${resp.status_code} < 300
203 Log ${resp.json()}
204 ${bucketId} = Set Variable ${resp.json().get('buckets')[0].get('id')}
205
206 ${processGrVersion} ${_}= Get Process Group Revision ${processGroupId}
207
208 ${data} = Set Variable {"versionedFlow": {"flowName": "${flowName}", "bucketId": "${bucketId}", "registryId": "${REGISTRY_CLIENT_ID}"}, "processGroupRevision": {"clientId": "${CLIENT_ID}", "version": ${processGrVersion}}}
209 ${resp} = Post Request ${SESSION_NAME} /nifi-api/versions/process-groups/${processGroupId} data=${data} headers=${headers}
210 Should Be True ${resp.status_code} < 300
211
212Distribute The Flow
213 [Arguments] ${processGroupId}
214 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_DESIGNTOOL_SERVER}
215 ${session}= Create Session distributor ${DCAEMOD_DISTRIBUTOR_API_SERVER}
216 ${headers}= Create Dictionary content-type=application/json
217 ${resp} = Get Request ${SESSION_NAME} /nifi-api/process-groups/${processGroupId} headers=${headers}
218 Should Be True ${resp.status_code} < 300
219 Log ${resp.json()}
220 ${flowId} = Set Variable ${resp.json().get('component').get('versionControlInformation').get('flowId')}
221 ${data} = Set Variable {"processGroupId": "${flowId}"}
222 ${resp} = Post Request distributor /distributor/distribution-targets/${DISTRIBUTION_TARGET_ID}/process-groups data=${data} headers=${headers}
223 Should Be True ${resp.status_code} < 300
224
225Deploy Blueprint From Inventory
226 [Arguments] ${processGroupName} ${compSpecName}
227 ${blueprintName} = Set Variable ${processGroupName}_${compSpecName}
228 ${resp} = Wait Until Keyword Succeeds 7 min 20s Get Blueprint From Inventory ${blueprintName}
229 ${typeId} = Set Variable ${resp.json().get('items')[0].get('typeId')}
230 ${data} = Set Variable {"serviceTypeId": "${typeId}"}
231 Deploy Service ${data} ${blueprintName} 10 minute
232
233 [Return] ${typeId} ${blueprintName}
234
235Get Process Group Revision
236 [Arguments] ${processGroupId}
237 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_DESIGNTOOL_SERVER}
238 ${headers}= Create Dictionary content-type=application/json
239 ${resp} = Get Request ${SESSION_NAME} /nifi-api/versions/process-groups/${processGroupId} headers=${headers}
240 Should Be True ${resp.status_code} < 300
241 ${currentProcessGrVersion} = Set Variable ${resp.json().get('processGroupRevision').get('version')}
242 ${clientId} = Set Variable ${resp.json().get('processGroupRevision').get('clientId')}
243
244 [Return] ${currentProcessGrVersion} ${clientId}
245
246Delete Distribution Target
247 ${session}= Create Session distributor ${DCAEMOD_DISTRIBUTOR_API_SERVER}
248 ${resp} = Delete Request distributor /distributor/distribution-targets/${DISTRIBUTION_TARGET_ID}
249 Should Be True ${resp.status_code} < 300
250
251Delete Process Group
252 [Arguments] ${processGroupId}
253 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_DESIGNTOOL_SERVER}
254 ${processGrVersion} ${clientId}= Get Process Group Revision ${processGroupId}
255 ${resp} = Delete Request ${SESSION_NAME} /nifi-api/process-groups/${processGroupId}?version=${processGrVersion}&clientId=${clientId}
256 Should Be True ${resp.status_code} < 300
257
258Delete Registry Client
259 ${session}= Create Session ${SESSION_NAME} ${DCAEMOD_DESIGNTOOL_SERVER}
260 ${resp} = Delete Request ${SESSION_NAME} /nifi-api/controller/registry-clients/${REGISTRY_CLIENT_ID}?version=${REGISTRY_CLIENT_VERSION}
261 Should Be True ${resp.status_code} < 300
262
263Configure Nifi Registry And Distribution Target
264 Add Registry Client
265 Add Distribution Target
266
267Delete Nifi Registry And Distribution Target
268 Run Keyword If '${DISTRIBUTION_TARGET_ID}' != '${EMPTY}' Wait Until Keyword Succeeds 2 min 5s Delete Distribution Target
269 Run Keyword If '${REGISTRY_CLIENT_ID}' != '${EMPTY}' Wait Until Keyword Succeeds 2 min 5s Delete Registry Client
270
271Delete Process Group And Blueprint And Deployment
272 Run Keyword If ${IS_PROCESS_GROUP_SET} Run Keywords Delete Process Group ${PROCESS_GROUP_ID}
273 ... AND Set Suite Variable ${IS_PROCESS_GROUP_SET} False
274 Run Keyword If ${IS_FLOW_DISTRIBUTED} Run Keywords Delete Blueprint From Inventory ${TYPE_ID}
275 ... AND Set Suite Variable ${IS_FLOW_DISTRIBUTED} False
276 Run Keyword If ${IS_SERVICE_DEPLOYED} Run Keywords Undeploy Service ${BLUEPRINT_NAME}
277 ... AND Set Suite Variable ${IS_SERVICE_DEPLOYED} False