09dec5c490809868eed1a4676487c6a9d7af8fb9
[multicloud/k8s.git] / kud / tests / plugin_collection_v2.sh
1 # /*
2 #  * Copyright 2020 Intel Corporation, Inc
3 #  *
4 #  * Licensed under the Apache License, Version 2.0 (the "License");
5 #  * you may not use this file except in compliance with the License.
6 #  * You may obtain a copy of the License at
7 #  *
8 #  *     http://www.apache.org/licenses/LICENSE-2.0
9 #  *
10 #  * Unless required by applicable law or agreed to in writing, software
11 #  * distributed under the License is distributed on an "AS IS" BASIS,
12 #  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #  * See the License for the specific language governing permissions and
14 #  * limitations under the License.
15 #  */
16
17 set -o errexit
18 set -o nounset
19 set -o pipefail
20 #set -o xtrace
21
22 source _common_test.sh
23 source _functions.sh
24 source _common.sh
25
26 if [ ${1:+1} ]; then
27     if [ "$1" == "--external" ]; then
28         master_ip=$(kubectl cluster-info | grep "Kubernetes master" | \
29             awk -F ":" '{print $2}' | awk -F "//" '{print $2}')
30         onap_svc_node_port=30498
31         base_url="http://$master_ip:$onap_svc_node_port/v1"
32     fi
33 fi
34
35 base_url=${base_url:-"http://localhost:9015/v2"}
36 kubeconfig_path="$HOME/.kube/config"
37 csar_id=cb009bfe-bbee-11e8-9766-525400435678
38
39
40 project_name="test_project"
41 project_description="test_project_description"
42 userData1="user1"
43 userData2="user2"
44
45 composite_app_name="test_composite_app_collection"
46 composite_app_description="test_project_description"
47 composite_app_version="test_composite_app_version"
48 app1_helm_path="$CSAR_DIR/$csar_id/collectd.tar.gz"
49 app2_helm_path="$CSAR_DIR/$csar_id/prometheus.tar.gz"
50 app1_profile_path="$CSAR_DIR/$csar_id/collectd_profile.tar.gz"
51 app2_profile_path="$CSAR_DIR/$csar_id/prometheus_profile.tar.gz"
52
53 app1_name="collectd"
54 app2_name="prometheus"
55 app1_desc="collectd_desc"
56 app2_desc="prometheus_desc"
57
58 main_composite_profile_name="main_composite_profile"
59 sub_composite_profile_name1="test_composite_profile1"
60 sub_composite_profile_name2="test_composite_profile2"
61 main_composite_profile_description="main_composite_profile_description"
62 sub_composite_profile_description="sub_composite_profile_description"
63
64 genericPlacementIntentName="test_gen_placement_intent1"
65 genericPlacementIntentDesc="test_gen_placement_intent_desc"
66 logicalCloud="logical_cloud_name"
67
68 appIntentNameForApp1="appIntentForApp1"
69 appIntentForApp1Desc="AppIntentForApp1Desc"
70 appIntentNameForApp2="appIntentForApp2"
71 appIntentForApp2Desc="AppIntentForApp2Desc"
72 providerName1="aws"
73 providerName2="azure"
74 clusterName1="edge1"
75 clusterName2="edge2"
76 clusterLabelName1="east-us1"
77 clusterLabelName2="east-us2"
78
79 deploymentIntentGroupName="test_deployment_intent_group"
80 deploymentIntentGroupNameDesc="test_deployment_intent_group_desc"
81 releaseName="test"
82 intentToBeAddedinDeploymentIntentGroup="name_of_intent_to_be_added_in_deployment_group"
83 intentToBeAddedinDeploymentIntentGroupDesc="desc_of_intent_to_be_added_in_deployment_group"
84
85 chart_name="edgex"
86 profile_name="test_profile"
87 release_name="test-release"
88 namespace="plugin-tests-namespace"
89 cloud_region_id="kud"
90 cloud_region_owner="localhost"
91
92 # Setup
93 install_deps
94 populate_CSAR_composite_app_helm "$csar_id"
95
96 # BEGIN: Register project API
97 print_msg "Registering project"
98 payload="$(cat <<EOF
99 {
100   "metadata": {
101     "name": "${project_name}",
102     "description": "${project_description}",
103     "userData1": "${userData1}",
104     "userData2": "${userData2}"
105    }
106 }
107 EOF
108 )"
109 call_api -d "${payload}" "${base_url}/projects"
110 # END: Register project API
111
112 # BEGIN: Register composite-app API
113 print_msg "Registering composite-app"
114 payload="$(cat <<EOF
115 {
116   "metadata": {
117     "name": "${composite_app_name}",
118     "description": "${composite_app_description}",
119     "userData1": "${userData1}",
120     "userData2": "${userData2}"
121    },
122    "spec":{
123       "version":"${composite_app_version}"
124    }
125 }
126 EOF
127 )"
128 call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps"
129 # END: Register composite-app API
130
131
132
133
134 # BEGIN: Create entries for app1&app2 in the database
135 print_msg "Making app entry in the database"
136 payload="$(cat <<EOF
137 {
138   "metadata": {
139     "name": "${app1_name}",
140     "description": "${app1_desc}",
141     "userData1": "${userData1}",
142     "userData2": "${userData2}"
143    }
144 }
145 EOF
146 )"
147
148 call_api -F "metadata=$payload" \
149          -F "file=@$app1_helm_path" \
150          "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/apps"
151
152
153 # BEGIN: Create an entry for app2 in the database
154 print_msg "Making app entry in the database"
155 payload="$(cat <<EOF
156 {
157   "metadata": {
158     "name": "${app2_name}",
159     "description": "${app2_desc}",
160     "userData1": "${userData1}",
161     "userData2": "${userData2}"
162    }
163 }
164 EOF
165 )"
166
167 call_api -F "metadata=$payload" \
168          -F "file=@$app2_helm_path" \
169          "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/apps"
170 # END: Create entries for app1&app2 in the database
171
172
173 # BEGIN: Register the main composite-profile
174 print_msg "Registering the main composite-profile"
175 payload="$(cat <<EOF
176 {
177    "metadata":{
178       "name":"${main_composite_profile_name}",
179       "description":"${main_composite_profile_description}",
180       "userData1":"${userData1}",
181       "userData2":"${userData2}"
182    }
183 }
184 EOF
185 )"
186 call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles"
187 # BEGIN: Register the main composite-profile
188
189
190 # BEGIN : Adding profile to each of the two apps - app1(collectd) and app2(prometheus)
191 print_msg "Registering profile with app1(collectd)"
192 payload="$(cat <<EOF
193 {
194    "metadata":{
195       "name":"${sub_composite_profile_name1}",
196       "description":"${sub_composite_profile_description}",
197       "userData1":"${userData1}",
198       "userData2":"${userData2}"
199    },
200    "spec":{
201       "app-name":  "${app1_name}"
202    }
203 }
204 EOF
205 )"
206
207 call_api -F "metadata=$payload" \
208          -F "file=@$app1_profile_path" \
209          "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}/profiles"
210
211 print_msg "Registering profile with app2(prometheus)"
212 payload="$(cat <<EOF
213 {
214    "metadata":{
215       "name":"${sub_composite_profile_name2}",
216       "description":"${sub_composite_profile_description}",
217       "userData1":"${userData1}",
218       "userData2":"${userData2}"
219    },
220    "spec":{
221       "app-name":  "${app2_name}"
222    }
223 }
224 EOF
225 )"
226
227 call_api -F "metadata=$payload" \
228          -F "file=@$app2_profile_path" \
229          "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}/profiles"
230 # END : Adding profile to each of the two apps - app1(collectd) and app2(prometheus)
231
232 # BEGIN: Register GenericPlacementIntents with the database
233 print_msg "Registering GenericPlacementIntent for app1"
234 payload="$(cat <<EOF
235 {
236    "metadata":{
237       "name":"${genericPlacementIntentName}",
238       "description":"${genericPlacementIntentDesc}",
239       "userData1":"${userData1}",
240       "userData2":"${userData2}"
241    },
242    "spec":{
243       "logical-cloud":"${logicalCloud}"
244    }
245 }
246 EOF
247 )"
248 call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents"
249 # END: Register GenericPlacementIntents with the database
250
251 # BEGIN: Adding placement intent for each app in the composite app.
252 print_msg "Adding placement intent for app1(collectd)"
253 payload="$(cat <<EOF
254 {
255    "metadata":{
256       "name":"${appIntentNameForApp1}",
257       "description":"${appIntentForApp1Desc}",
258       "userData1":"${userData1}",
259       "userData2":"${userData2}"
260    },
261    "spec":{
262       "app-name":"${app1_name}",
263       "intent":{
264          "allOf":[
265             {  "provider-name":"${providerName1}",
266                "cluster-name":"${clusterName1}"
267             },
268             {
269                "provider-name":"${providerName2}",
270                "cluster-name":"${clusterName2}"
271             },
272             {
273                "anyOf":[
274                   {
275                      "provider-name":"${providerName1}",
276                      "cluster-label-name":"${clusterLabelName1}"
277                   },
278                   {
279                      "provider-name":"${providerName2}",
280                      "cluster-label-name":"${clusterLabelName2}"
281                   }
282                ]
283             }
284          ]
285       }
286    }
287 }
288 EOF
289 )"
290 call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}/app-intents"
291
292 print_msg "Adding placement intent for app2(prometheus)"
293 payload="$(cat <<EOF
294 {
295    "metadata":{
296       "name":"${appIntentNameForApp2}",
297       "description":"${appIntentForApp2Desc}",
298       "userData1":"${userData1}",
299       "userData2":"${userData2}"
300    },
301    "spec":{
302       "app-name":"${app2_name}",
303       "intent":{
304          "allOf":[
305             {
306                "provider-name":"${providerName1}",
307                "cluster-name":"${clusterName1}"
308             },
309             {
310                "provider-name":"${providerName2}",
311                "cluster-name":"${clusterName2}"
312             },
313             {
314                "anyOf":[
315                   {
316                      "provider-name":"${providerName1}",
317                      "cluster-label-name":"${clusterLabelName1}"
318                   },
319                   {
320                      "provider-name":"${providerName2}",
321                      "cluster-label-name":"${clusterLabelName2}"
322                   }
323                ]
324             }
325          ]
326       }
327    }
328 }
329 EOF
330 )"
331 call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}/app-intents"
332 # END: Adding placement intent for each app in the composite app.
333
334 # BEGIN: Registering DeploymentIntentGroup in the database
335 print_msg "Registering DeploymentIntentGroup"
336 payload="$(cat <<EOF
337 {
338    "metadata":{
339       "name":"${deploymentIntentGroupName}",
340       "description":"${deploymentIntentGroupNameDesc}",
341       "userData1":"${userData1}",
342       "userData2":"${userData2}"
343    },
344    "spec":{
345       "profile":"${main_composite_profile_name}",
346       "version":"${releaseName}",
347       "override-values":[
348          {
349             "app-name":"${app1_name}",
350             "values":
351                {
352                   "collectd_prometheus.service.targetPort":"9104"
353                }
354          },
355          {
356             "app-name":"${app2_name}",
357             "values":
358                {
359                   "prometheus.service.nameOfPort":"WebPort9090"
360                }
361          }
362       ]
363    }
364 }
365 EOF
366 )"
367 call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups"
368 # END: Registering DeploymentIntentGroup in the database
369
370 # BEGIN: Adding intents to an intent group
371 print_msg "Adding the genericPlacement intent to the deploymentIntent group"
372 payload="$(cat <<EOF
373 {
374    "metadata":{
375       "name":"${intentToBeAddedinDeploymentIntentGroup}",
376       "description":"${intentToBeAddedinDeploymentIntentGroupDesc}",
377       "userData1":"${userData1}",
378       "userData2":"${userData2}"
379    },
380    "spec":{
381       "intent":{
382          "generic-placement-intent":"${genericPlacementIntentName}"
383       }
384    }
385 }
386 EOF
387 )"
388 call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}/intents"
389 # END: Adding intents to an intent group
390
391 #BEGIN: Instantiation
392 print_msg "Getting the sorted templates for each of the apps.."
393 call_api -d "" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}/instantiate"
394 # END: Instantiation
395