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:9015/v1"
21 kubeconfig_path="$HOME/.kube/config"
22 #Will resolve to file $KUBE_CONFIG_DIR/kud
24 cloud_region_owner="test_owner"
26 csar_id="94e414f6-9ca4-11e8-bb6a-52540067263b"
29 profile_name="profile1"
30 release_name="testrelease"
31 vnf_customization_uuid="ebe353d2-30b7-11e9-9515-525400277b3d"
33 # _build_generic_sim() - Creates a generic simulator image in case that doesn't exist
34 function _build_generic_sim {
35 if [[ -n $(docker images -q generic_sim) ]]; then
38 BUILD_ARGS="--no-cache"
39 if [ ${HTTP_PROXY:-} ]; then
40 BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
42 if [ ${HTTPS_PROXY:-} ]; then
43 BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
46 pushd generic_simulator
47 echo "Building generic simulator image..."
48 docker build ${BUILD_ARGS} -t generic_sim:latest .
52 # start_aai_service() - Starts a simulator for AAI service
53 function start_aai_service {
55 if [[ $(docker ps -q --all --filter "name=aai") ]]; then
58 echo "Start AAI simulator.."
59 docker run --name aai -v $(mktemp):/tmp/generic_sim/ -v $(pwd)/generic_simulator/aai/:/etc/generic_sim/ -p 8443:8080 -d generic_sim
64 destroy_deployment $plugin_deployment_name
67 populate_CSAR_plugin $csar_id
68 populate_CSAR_rbdefinition $csar_id
71 print_msg "Create Resource Bundle Definition Metadata"
74 \"rb-name\": \"${rb_name}\",
75 \"rb-version\": \"${rb_version}\",
76 \"chart-name\": \"vault-consul-dev\",
77 \"description\": \"testing resource bundle definition api\",
79 \"vnf_customization_uuid\": \"${vnf_customization_uuid}\"
83 call_api -d "$payload" "${base_url}/rb/definition"
85 print_msg "Upload Resource Bundle Definition Content"
86 call_api --data-binary "@${CSAR_DIR}/${csar_id}/vault-consul-dev-0.0.0.tgz" "${base_url}/rb/definition/$rb_name/$rb_version/content"
88 print_msg "Listing Resource Bundle Definitions"
89 rb_list=$(call_api "${base_url}/rb/definition/$rb_name")
90 if [[ "$rb_list" != *"${rb_name}"* ]]; then
92 echo "Resource Bundle Definition not stored"
96 print_msg "Create Resource Bundle Profile Metadata"
97 kubeversion=$(kubectl version | grep 'Server Version' | awk -F '"' '{print $6}')
100 \"profile-name\": \"${profile_name}\",
101 \"rb-name\": \"${rb_name}\",
102 \"rb-version\": \"${rb_version}\",
103 \"release-name\": \"${release_name}\",
104 \"namespace\": \"$namespace\",
105 \"kubernetesversion\": \"$kubeversion\",
107 \"vnf_customization_uuid\": \"${vnf_customization_uuid}\"
111 call_api -d "$payload" "${base_url}/rb/definition/$rb_name/$rb_version/profile"
113 print_msg "Upload Resource Bundle Profile Content"
114 call_api --data-binary "@${CSAR_DIR}/${csar_id}/rb_profile.tar.gz" "${base_url}/rb/definition/$rb_name/$rb_version/profile/$profile_name/content"
116 print_msg "Getting Resource Bundle Profile"
117 rbp_ret=$(call_api "${base_url}/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 "Setup cloud data"
127 "cloud-region": "$cloud_region_id",
128 "cloud-owner": "$cloud_region_owner"
132 call_api -F "metadata=$payload" \
133 -F "file=@$kubeconfig_path" \
134 "${base_url}/connectivity-info" >/dev/null
136 print_msg "Instantiate Profile"
139 \"cloud-region\": \"$cloud_region_id\",
140 \"rb-name\":\"$rb_name\",
141 \"rb-version\":\"$rb_version\",
142 \"profile-name\":\"$profile_name\"
145 inst_id=$(call_api -d "$payload" "${base_url}/instance")
147 inst_id=$(jq -r '.id' <<< "$inst_id")
149 print_msg "Validating Kubernetes"
150 kubectl get --no-headers=true --namespace=${namespace} deployment ${release_name}-vault-consul-dev
151 kubectl get --no-headers=true --namespace=${namespace} service override-vault-consul
152 echo "VNF Instance created succesfully with id: $inst_id"
154 print_msg "Getting $inst_id VNF Instance information"
155 call_api "${base_url}/instance/${inst_id}"
158 print_msg "Deleting $rb_name/$rb_version Resource Bundle Definition"
159 # TODO: Change the HTTP code for 404 when the resource is not found in the API
160 delete_resource "${base_url}/rb/definition/$rb_name/$rb_version"
162 print_msg "Deleting $profile_name Resource Bundle Profile"
163 # TODO: Change the HTTP code for 404 when the resource is not found in the API
164 delete_resource "${base_url}/rb/definition/$rb_name/$rb_version/profile/$profile_name"
166 print_msg "Deleting $inst_id VNF Instance"
167 delete_resource "${base_url}/instance/${inst_id}"
169 print_msg "Deleting ${cloud_region_id} cloud region connection"
170 delete_resource "${base_url}/connectivity-info/${cloud_region_id}"
172 teardown $plugin_deployment_name