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 ##############################################################################
19 base_url="http://localhost:8081"
22 csar_id="94e414f6-9ca4-11e8-bb6a-52540067263b"
23 rbd_csar_id="7eb09e38-4363-9942-1234-3beb2e95fd85"
24 definition_id="9d117af8-30b8-11e9-af94-525400277b3d"
25 profile_id="ebe353d2-30b7-11e9-9515-525400277b3d"
27 # _build_generic_sim() - Creates a generic simulator image in case that doesn't exist
28 function _build_generic_sim {
29 if [[ -n $(docker images -q generic_sim) ]]; then
32 BUILD_ARGS="--no-cache"
33 if [ $HTTP_PROXY ]; then
34 BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
36 if [ $HTTPS_PROXY ]; then
37 BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
40 pushd generic_simulator
41 echo "Building generic simulator image..."
42 docker build ${BUILD_ARGS} -t generic_sim:latest .
46 # start_aai_service() - Starts a simulator for AAI service
47 function start_aai_service {
49 if [[ $(docker ps -q --all --filter "name=aai") ]]; then
52 echo "Start AAI simulator.."
53 docker run --name aai -v $(mktemp):/tmp/generic_sim/ -v $(pwd)/generic_simulator/aai/:/etc/generic_sim/ -p 8443:8080 -d generic_sim
57 destroy_deployment $plugin_deployment_name
60 populate_CSAR_plugin $csar_id
61 populate_CSAR_rbdefinition $rbd_csar_id
64 print_msg "Create Resource Bundle Definition Metadata"
67 \"name\": \"test-rbdef\",
68 \"chart-name\": \"vault-consul-dev\",
69 \"description\": \"testing resource bundle definition api\",
70 \"uuid\": \"$definition_id\",
71 \"service-type\": \"firewall\"
74 payload=$(echo $payload_raw | tr '\n' ' ')
75 rbd_id=$(curl -s -d "$payload" -X POST "${base_url}/v1/rb/definition" | jq -r '.uuid')
77 print_msg "Upload Resource Bundle Definition Content"
78 curl -s --data-binary @${CSAR_DIR}/${rbd_csar_id}/${rbd_content_tarball}.gz -X POST "${base_url}/v1/rb/definition/$rbd_id/content"
80 print_msg "Listing Resource Bundle Definitions"
81 rbd_id_list=$(curl -s -X GET "${base_url}/v1/rb/definition")
82 if [[ "$rbd_id_list" != *"${rbd_id}"* ]]; then
84 echo "Resource Bundle Definition not stored"
88 print_msg "Create Resource Bundle Profile Metadata"
89 kubeversion=$(kubectl version | grep 'Server Version' | awk -F '"' '{print $6}')
92 \"name\": \"test-rbprofile\",
93 \"namespace\": \"$namespace\",
94 \"rbdid\": \"$definition_id\",
95 \"uuid\": \"$profile_id\",
96 \"kubernetesversion\": \"$kubeversion\"
99 payload=$(echo $payload_raw | tr '\n' ' ')
100 rbp_id=$(curl -s -d "$payload" -X POST "${base_url}/v1/rb/profile" | jq -r '.uuid')
102 print_msg "Upload Resource Bundle Profile Content"
103 curl -s --data-binary @${CSAR_DIR}/${rbd_csar_id}/${rbp_content_tarball}.gz -X POST "${base_url}/v1/rb/profile/$rbp_id/content"
105 print_msg "Listing Resource Bundle Profiles"
106 rbp_id_list=$(curl -s -X GET "${base_url}/v1/rb/profile")
107 if [[ "$rbp_id_list" != *"${rbp_id}"* ]]; then
109 echo "Resource Bundle Profile not stored"
113 print_msg "Instantiate Profile"
116 \"cloud_region_id\": \"$cloud_region_id\",
117 \"rb_profile_id\":\"$profile_id\",
118 \"csar_id\": \"$csar_id\"
121 payload=$(echo $payload_raw | tr '\n' ' ')
122 vnf_id=$(curl -s -d "$payload" "${base_url}/v1/vnf_instances/" | jq -r '.vnf_id')
124 print_msg "Validating Kubernetes"
125 kubectl get --no-headers=true --namespace=${namespace} deployment ${cloud_region_id}-${namespace}-${vnf_id}-test-rbprofile-vault-consul-dev
126 kubectl get --no-headers=true --namespace=${namespace} service ${cloud_region_id}-${namespace}-${vnf_id}-override-vault-consul
127 echo "VNF Instance created succesfully with id: $vnf_id"
129 print_msg "Listing VNF Instances"
130 vnf_id_list=$(curl -s -X GET "${base_url}/v1/vnf_instances/${cloud_region_id}/${namespace}" | jq -r '.vnf_id_list')
131 if [[ "$vnf_id_list" != *"${vnf_id}"* ]]; then
133 echo "VNF Instance not stored"
137 print_msg "Getting $vnf_id VNF Instance information"
138 vnf_details=$(curl -s -X GET "${base_url}/v1/vnf_instances/${cloud_region_id}/${namespace}/${vnf_id}")
139 if [[ -z "$vnf_details" ]]; then
140 echo "Cannot retrieved VNF Instance details"
143 echo "VNF details $vnf_details"
145 print_msg "Deleting $rbd_id Resource Bundle Definition"
146 curl -X DELETE "${base_url}/v1/rb/definition/$rbd_id"
147 if [[ 500 -ne $(curl -o /dev/null -w %{http_code} -s -X GET "${base_url}/v1/rb/definition/$rbd_id") ]]; then
148 echo "Resource Bundle Definition not deleted"
149 # TODO: Change the HTTP code for 404 when the resource is not found in the API
153 print_msg "Deleting $vnf_id VNF Instance"
154 curl -X DELETE "${base_url}/v1/vnf_instances/${cloud_region_id}/${namespace}/${vnf_id}"
155 if [[ 404 -ne $(curl -o /dev/null -w %{http_code} -s -X GET "${base_url}${cloud_region_id}/${namespace}/${vnf_id}") ]]; then
156 echo "VNF Instance not deleted"
161 teardown $plugin_deployment_name