2 # * Copyright 2020 Intel Corporation, Inc
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
8 # * http://www.apache.org/licenses/LICENSE-2.0
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.
22 source _common_test.sh
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"
35 base_url=${base_url:-"http://localhost:9015/v2"}
37 kubeconfig_path="$HOME/.kube/config"
38 csar_id=cb009bfe-bbee-11e8-9766-525400435678
41 project_name="test_project"
42 project_description="test_project_description"
46 composite_app_name="test_composite_app_collection"
47 composite_app_description="test_project_description"
48 composite_app_version="test_composite_app_version"
49 app1_helm_path="$CSAR_DIR/$csar_id/collectd.tar.gz"
50 app2_helm_path="$CSAR_DIR/$csar_id/prometheus.tar.gz"
51 app1_profile_path="$CSAR_DIR/$csar_id/collectd_profile.tar.gz"
52 app2_profile_path="$CSAR_DIR/$csar_id/prometheus_profile.tar.gz"
55 app2_name="prometheus"
56 app1_desc="collectd_desc"
57 app2_desc="prometheus_desc"
59 main_composite_profile_name="main_composite_profile"
60 sub_composite_profile_name1="test_composite_profile1"
61 sub_composite_profile_name2="test_composite_profile2"
62 main_composite_profile_description="main_composite_profile_description"
63 sub_composite_profile_description="sub_composite_profile_description"
65 genericPlacementIntentName="test_gen_placement_intent1"
66 genericPlacementIntentDesc="test_gen_placement_intent_desc"
67 logicalCloud="logical_cloud_name"
69 appIntentNameForApp1="appIntentForApp1"
70 appIntentForApp1Desc="AppIntentForApp1Desc"
71 appIntentNameForApp2="appIntentForApp2"
72 appIntentForApp2Desc="AppIntentForApp2Desc"
73 providerName1="cluster_provider1"
74 providerName2="cluster_provider2"
75 clusterName1="clusterName1"
76 clusterName2="clusterName2"
77 clusterLabelName1="clusterLabel1"
78 clusterLabelName2="clusterLabel2"
80 deploymentIntentGroupName="test_deployment_intent_group"
81 deploymentIntentGroupNameDesc="test_deployment_intent_group_desc"
83 intentToBeAddedinDeploymentIntentGroup="name_of_intent_to_be_added_in_deployment_group"
84 intentToBeAddedinDeploymentIntentGroupDesc="desc_of_intent_to_be_added_in_deployment_group"
85 hpaIntentName="hpaIntentName"
86 trafficIntentName="trafficIntentName"
89 profile_name="test_profile"
90 release_name="test-release"
91 namespace="plugin-tests-namespace"
93 cloud_region_owner="localhost"
97 genericPlacementIntent="genericPlacementIntent"
99 OVNintentName="OVNintentName"
100 OVNHostName="OVNHostName"
102 CostBasedIntent="costBasedIntent"
103 CostBasedIntentName="CostBasedIntentName"
104 CostBasedHostName="OVNHostName"
106 hpaIntent="hpaIntent"
107 trafficIntent="trafficIntent"
108 gpcHostName="gpcHostName"
110 hpaControllerIntentName="hpaControllerIntentName"
111 hpaHostName="hpaHostName"
113 trafficControllerIntentName="trafficControllerIntentName"
114 trafficHostName="trafficHostName"
119 populate_CSAR_composite_app_helm "$csar_id"
121 # BEGIN :: Delete statements are issued so that we clean up the 'orchestrator' collection
122 # and freshly populate the documents, also it serves as a direct test
123 # for all our DELETE APIs and an indirect test for all GET APIs
124 print_msg "Deleting controller ${genericPlacementIntent}"
125 delete_resource "${base_url}/controllers/${genericPlacementIntent}"
127 print_msg "Deleting controller ${hpaIntent}"
128 delete_resource "${base_url}/controllers/${hpaIntent}"
130 print_msg "Deleting controller ${trafficIntent}"
131 delete_resource "${base_url}/controllers/${trafficIntent}"
133 print_msg "Deleting controller ${CostBasedIntent}"
134 delete_resource "${base_url}/controllers/${CostBasedIntent}"
136 print_msg "Deleting controller ${OVNintent}"
137 delete_resource "${base_url}/controllers/${OVNintent}"
139 print_msg "Deleting intentToBeAddedinDeploymentIntentGroup"
140 delete_resource "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}/intents/${intentToBeAddedinDeploymentIntentGroup}"
142 print_msg "Deleting ${deploymentIntentGroupName}"
143 delete_resource "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}"
145 print_msg "Deleting ${appIntentNameForApp2}"
146 delete_resource "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}/app-intents/${appIntentNameForApp2}"
148 print_msg "Deleting ${appIntentNameForApp1}"
149 delete_resource "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}/app-intents/${appIntentNameForApp1}"
151 print_msg "Deleting ${genericPlacementIntentName}"
152 delete_resource "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}"
154 print_msg "Deleting ${sub_composite_profile_name2}"
155 delete_resource "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}/profiles/${sub_composite_profile_name2}"
157 print_msg "Deleting ${sub_composite_profile_name1}"
158 delete_resource "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}/profiles/${sub_composite_profile_name1}"
160 print_msg "Deleting ${main_composite_profile_name}"
161 delete_resource "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}"
163 print_msg "Deleting ${app2_name}"
164 delete_resource "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/apps/${app2_name}"
166 print_msg "Deleting ${app1_name}"
167 delete_resource "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/apps/${app1_name}"
169 print_msg "Deleting ${composite_app_name}/${composite_app_version}"
170 delete_resource "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}"
172 print_msg "Deleting ${project_name}"
173 delete_resource "${base_url}/projects/${project_name}"
178 # END :: Delete statements were issued so that we clean up the db
179 # and freshly populate the documents, also it serves as a direct test
180 # for all our DELETE APIs and an indirect test for all GET APIs
183 # BEGIN: Register project
184 print_msg "Registering project"
188 "name": "${project_name}",
189 "description": "${project_description}",
190 "userData1": "${userData1}",
191 "userData2": "${userData2}"
196 call_api -d "${payload}" "${base_url}/projects"
197 # END: Register project
199 # BEGIN: Register composite-app
200 print_msg "Registering composite-app"
204 "name": "${composite_app_name}",
205 "description": "${composite_app_description}",
206 "userData1": "${userData1}",
207 "userData2": "${userData2}"
210 "version":"${composite_app_version}"
215 call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps"
216 # END: Register composite-app
221 # BEGIN: Create entries for app1&app2 in the database
222 print_msg "Making app entry in the database"
226 "name": "${app1_name}",
227 "description": "${app1_desc}",
228 "userData1": "${userData1}",
229 "userData2": "${userData2}"
235 call_api -F "metadata=$payload" \
236 -F "file=@$app1_helm_path" \
237 "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/apps"
240 # BEGIN: Create an entry for app2 in the database
241 print_msg "Making app entry in the database"
245 "name": "${app2_name}",
246 "description": "${app2_desc}",
247 "userData1": "${userData1}",
248 "userData2": "${userData2}"
254 call_api -F "metadata=$payload" \
255 -F "file=@$app2_helm_path" \
256 "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/apps"
257 # END: Create entries for app1&app2 in the database
260 # BEGIN: Register the main composite-profile
261 print_msg "Registering the main composite-profile"
265 "name":"${main_composite_profile_name}",
266 "description":"${main_composite_profile_description}",
267 "userData1":"${userData1}",
268 "userData2":"${userData2}"
273 call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles"
274 # BEGIN: Register the main composite-profile
277 # BEGIN : Adding profile to each of the two apps - app1(collectd) and app2(prometheus)
278 print_msg "Registering profile with app1(collectd)"
282 "name":"${sub_composite_profile_name1}",
283 "description":"${sub_composite_profile_description}",
284 "userData1":"${userData1}",
285 "userData2":"${userData2}"
288 "app-name": "${app1_name}"
294 call_api -F "metadata=$payload" \
295 -F "file=@$app1_profile_path" \
296 "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}/profiles"
298 print_msg "Registering profile with app2(prometheus)"
302 "name":"${sub_composite_profile_name2}",
303 "description":"${sub_composite_profile_description}",
304 "userData1":"${userData1}",
305 "userData2":"${userData2}"
308 "app-name": "${app2_name}"
314 call_api -F "metadata=$payload" \
315 -F "file=@$app2_profile_path" \
316 "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}/profiles"
317 # END : Adding profile to each of the two apps - app1(collectd) and app2(prometheus)
319 # BEGIN: Register GenericPlacementIntents with the database
320 print_msg "Registering GenericPlacementIntent for app1"
324 "name":"${genericPlacementIntentName}",
325 "description":"${genericPlacementIntentDesc}",
326 "userData1":"${userData1}",
327 "userData2":"${userData2}"
330 "logical-cloud":"${logicalCloud}"
335 call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents"
336 # END: Register GenericPlacementIntents with the database
338 # BEGIN: Adding placement intent for each app in the composite app.
339 print_msg "Adding placement intent for app1(collectd)"
343 "name":"${appIntentNameForApp1}",
344 "description":"${appIntentForApp1Desc}",
345 "userData1":"${userData1}",
346 "userData2":"${userData2}"
349 "app-name":"${app1_name}",
352 { "provider-name":"${providerName1}",
353 "cluster-name":"${clusterName1}"
356 "provider-name":"${providerName2}",
357 "cluster-name":"${clusterName2}"
362 "provider-name":"${providerName1}",
363 "cluster-label-name":"${clusterLabelName1}"
366 "provider-name":"${providerName2}",
367 "cluster-label-name":"${clusterLabelName2}"
377 call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}/app-intents"
379 print_msg "Adding placement intent for app2(prometheus)"
383 "name":"${appIntentNameForApp2}",
384 "description":"${appIntentForApp2Desc}",
385 "userData1":"${userData1}",
386 "userData2":"${userData2}"
389 "app-name":"${app2_name}",
393 "provider-name":"${providerName1}",
394 "cluster-name":"${clusterName1}"
397 "provider-name":"${providerName2}",
398 "cluster-name":"${clusterName2}"
403 "provider-name":"${providerName1}",
404 "cluster-label-name":"${clusterLabelName1}"
407 "provider-name":"${providerName2}",
408 "cluster-label-name":"${clusterLabelName2}"
418 call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}/app-intents"
419 # END: Adding placement intent for each app in the composite app.
421 # BEGIN: Registering DeploymentIntentGroup in the database
422 print_msg "Registering DeploymentIntentGroup"
426 "name":"${deploymentIntentGroupName}",
427 "description":"${deploymentIntentGroupNameDesc}",
428 "userData1":"${userData1}",
429 "userData2":"${userData2}"
432 "profile":"${main_composite_profile_name}",
433 "version":"${releaseName}",
436 "app-name":"${app1_name}",
439 "collectd_prometheus.service.targetPort":"9104"
443 "app-name":"${app2_name}",
446 "prometheus.service.nameOfPort":"WebPort9090"
454 call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups"
455 # END: Registering DeploymentIntentGroup in the database
457 # BEGIN: Adding intents to an intent group
458 print_msg "Adding all the intents to the deploymentIntent group"
462 "name":"${intentToBeAddedinDeploymentIntentGroup}",
463 "description":"${intentToBeAddedinDeploymentIntentGroupDesc}",
464 "userData1":"${userData1}",
465 "userData2":"${userData2}"
469 "${genericPlacementIntent}":"${genericPlacementIntentName}",
470 "${hpaIntent}" : "${hpaControllerIntentName}",
471 "${trafficIntent}" : "${trafficControllerIntentName}",
472 "${CostBasedIntent}" : "${CostBasedIntentName}",
473 "${OVNintent}" : "${OVNintentName}"
479 call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}/intents"
480 # END: Adding intents to an intent group
482 # BEGIN: Adding controllers
483 print_msg "Adding CostBased placement contoller"
487 "name":"${CostBasedIntent}",
488 "description":"${CostBasedIntentName}",
489 "userData1":"${userData1}",
490 "userData2":"${userData2}"
493 "host": "${CostBasedHostName}",
494 "port": ${CostBasedPort},
501 call_api -d "${payload}" "${base_url}/controllers"
503 print_msg "Adding HPA contoller"
507 "name":"${hpaIntent}",
508 "description":"${hpaControllerIntentName}",
509 "userData1":"${userData1}",
510 "userData2":"${userData2}"
513 "host": "${hpaHostName}",
521 call_api -d "${payload}" "${base_url}/controllers"
523 print_msg "Adding traffic contoller"
527 "name":"${trafficIntent}",
528 "description":"${trafficControllerIntentName}",
529 "userData1":"${userData1}",
530 "userData2":"${userData2}"
533 "host": "${trafficHostName}",
534 "port": ${trafficPort},
541 call_api -d "${payload}" "${base_url}/controllers"
543 print_msg "Adding OVN action contoller"
547 "name":"${OVNintent}",
548 "description":"${OVNintentName}",
549 "userData1":"${userData1}",
550 "userData2":"${userData2}"
553 "host": "${OVNHostName}",
561 call_api -d "${payload}" "${base_url}/controllers"
562 # END: Adding controllers
564 #BEGIN: Instantiation
565 print_msg "Getting the sorted templates for each of the apps.."
566 call_api -d "" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}/instantiate"