2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
17 source _common_test.sh
20 base_url="http://localhost:8081"
21 #Will resolve to file $KUBE_CONFIG_DIR/kud
24 csar_id="94e414f6-9ca4-11e8-bb6a-52540067263b"
27 profile_name="profile1"
28 release_name="testrelease"
29 vnf_customization_uuid="ebe353d2-30b7-11e9-9515-525400277b3d"
31 # _build_generic_sim() - Creates a generic simulator image in case that doesn't exist
32 function _build_generic_sim {
33 if [[ -n $(docker images -q generic_sim) ]]; then
36 BUILD_ARGS="--no-cache"
37 if [ $HTTP_PROXY ]; then
38 BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
40 if [ $HTTPS_PROXY ]; then
41 BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
44 pushd generic_simulator
45 echo "Building generic simulator image..."
46 docker build ${BUILD_ARGS} -t generic_sim:latest .
50 # start_aai_service() - Starts a simulator for AAI service
51 function start_aai_service {
53 if [[ $(docker ps -q --all --filter "name=aai") ]]; then
56 echo "Start AAI simulator.."
57 docker run --name aai -v $(mktemp):/tmp/generic_sim/ -v $(pwd)/generic_simulator/aai/:/etc/generic_sim/ -p 8443:8080 -d generic_sim
62 destroy_deployment $plugin_deployment_name
65 populate_CSAR_plugin $csar_id
66 populate_CSAR_rbdefinition $csar_id
69 print_msg "Create Resource Bundle Definition Metadata"
72 \"rb-name\": \"${rb_name}\",
73 \"rb-version\": \"${rb_version}\",
74 \"chart-name\": \"vault-consul-dev\",
75 \"description\": \"testing resource bundle definition api\",
77 \"vnf_customization_uuid\": \"${vnf_customization_uuid}\"
81 payload=$(echo $payload_raw | tr '\n' ' ')
82 rb_ret_name=$(curl -s -d "$payload" -X POST "${base_url}/v1/rb/definition" | jq -r '."rb-name"')
84 print_msg "Upload Resource Bundle Definition Content"
85 curl -s --data-binary @${CSAR_DIR}/${csar_id}/${rbd_content_tarball}.gz -X POST "${base_url}/v1/rb/definition/$rb_name/$rb_version/content"
87 print_msg "Listing Resource Bundle Definitions"
88 rb_list=$(curl -s -X GET "${base_url}/v1/rb/definition/$rb_name")
89 if [[ "$rb_list" != *"${rb_name}"* ]]; then
91 echo "Resource Bundle Definition not stored"
95 print_msg "Create Resource Bundle Profile Metadata"
96 kubeversion=$(kubectl version | grep 'Server Version' | awk -F '"' '{print $6}')
99 \"profile-name\": \"${profile_name}\",
100 \"rb-name\": \"${rb_name}\",
101 \"rb-version\": \"${rb_version}\",
102 \"release-name\": \"${release_name}\",
103 \"namespace\": \"$namespace\",
104 \"kubernetesversion\": \"$kubeversion\",
106 \"vnf_customization_uuid\": \"${vnf_customization_uuid}\"
110 payload=$(echo $payload_raw | tr '\n' ' ')
111 rbp_ret_name=$(curl -s -d "$payload" -X POST "${base_url}/v1/rb/definition/$rb_name/$rb_version/profile" | jq -r '."profile-name"')
113 print_msg "Upload Resource Bundle Profile Content"
114 curl -s --data-binary @${CSAR_DIR}/${csar_id}/${rbp_content_tarball}.gz -X POST "${base_url}/v1/rb/definition/$rb_name/$rb_version/profile/$profile_name/content"
116 print_msg "Getting Resource Bundle Profile"
117 rbp_ret=$(curl -s -X GET "${base_url}/v1/rb/definition/$rb_name/$rb_version/profile/$profile_name")
118 if [[ "$rbp_ret" != *"${profile_name}"* ]]; then
120 echo "Resource Bundle Profile not stored"
124 print_msg "Instantiate Profile"
127 \"cloud-region\": \"$cloud_region_id\",
128 \"rb-name\":\"$rb_name\",
129 \"rb-version\":\"$rb_version\",
130 \"profile-name\":\"$profile_name\"
133 payload=$(echo $payload_raw | tr '\n' ' ')
134 inst_id=$(curl -s -d "$payload" "${base_url}/v1/instance" | jq -r '.id')
136 print_msg "Validating Kubernetes"
137 kubectl get --no-headers=true --namespace=${namespace} deployment ${release_name}-vault-consul-dev
138 kubectl get --no-headers=true --namespace=${namespace} service override-vault-consul
139 echo "VNF Instance created succesfully with id: $inst_id"
141 print_msg "Getting $inst_id VNF Instance information"
142 vnf_details=$(curl -s -X GET "${base_url}/v1/instance/${inst_id}")
143 if [[ -z "$vnf_details" ]]; then
144 echo "Cannot retrieved VNF Instance details"
147 echo "VNF details $vnf_details"
149 print_msg "Deleting $rb_name/$rb_version Resource Bundle Definition"
150 curl -X DELETE "${base_url}/v1/rb/definition/$rb_name/$rb_version"
151 if [[ 500 -ne $(curl -o /dev/null -w %{http_code} -s -X GET "${base_url}/v1/rb/definition/$rb_name/$rb_version") ]]; then
152 echo "Resource Bundle Definition not deleted"
153 # TODO: Change the HTTP code for 404 when the resource is not found in the API
157 print_msg "Deleting $profile_name Resource Bundle Profile"
158 curl -X DELETE "${base_url}/v1/rb/definition/$rb_name/$rb_version/profile/$profile_name"
159 if [[ 500 -ne $(curl -o /dev/null -w %{http_code} -s -X GET "${base_url}/v1/rb/definition/$rb_name/$rb_version/profile/$profile_name") ]]; then
160 echo "Resource Bundle Profile not deleted"
161 # TODO: Change the HTTP code for 404 when the resource is not found in the API
165 print_msg "Deleting $inst_id VNF Instance"
166 curl -X DELETE "${base_url}/v1/instance/${inst_id}"
167 if [[ 404 -ne $(curl -o /dev/null -w %{http_code} -s -X GET "${base_url}/${inst_id}") ]]; then
168 echo "VNF Instance not deleted"
173 teardown $plugin_deployment_name