Adding cluster meta data and saving in etcd
[multicloud/k8s.git] / kud / tests / plugin.sh
index 6cf93ce..aff0412 100755 (executable)
@@ -14,15 +14,21 @@ set -o pipefail
 #set -o xtrace
 
 source _common.sh
+source _common_test.sh
 source _functions.sh
 
-base_url="http://localhost:8081"
+base_url="http://localhost:9015/v1"
+kubeconfig_path="$HOME/.kube/config"
+#Will resolve to file $KUBE_CONFIG_DIR/kud
 cloud_region_id="kud"
-namespace="default"
+cloud_region_owner="test_owner"
+namespace="testns"
 csar_id="94e414f6-9ca4-11e8-bb6a-52540067263b"
-rbd_csar_id="7eb09e38-4363-9942-1234-3beb2e95fd85"
-definition_id="9d117af8-30b8-11e9-af94-525400277b3d"
-profile_id="ebe353d2-30b7-11e9-9515-525400277b3d"
+rb_name="test-rbdef"
+rb_version="v1"
+profile_name="profile1"
+release_name="testrelease"
+vnf_customization_uuid="ebe353d2-30b7-11e9-9515-525400277b3d"
 
 # _build_generic_sim() - Creates a generic simulator image in case that doesn't exist
 function _build_generic_sim {
@@ -30,10 +36,10 @@ function _build_generic_sim {
         return
     fi
     BUILD_ARGS="--no-cache"
-    if [ $HTTP_PROXY ]; then
+    if [ ${HTTP_PROXY:-} ]; then
         BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
     fi
-    if [ $HTTPS_PROXY ]; then
+    if [ ${HTTPS_PROXY:-} ]; then
         BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
     fi
 
@@ -54,108 +60,113 @@ function start_aai_service {
 }
 
 # Setup
+install_deps
 destroy_deployment $plugin_deployment_name
 
 #start_aai_service
 populate_CSAR_plugin $csar_id
-populate_CSAR_rbdefinition $rbd_csar_id
+populate_CSAR_rbdefinition $csar_id
 
 # Test
 print_msg "Create Resource Bundle Definition Metadata"
-payload_raw="
+payload="
 {
-    \"name\": \"test-rbdef\",
+    \"rb-name\": \"${rb_name}\",
+    \"rb-version\": \"${rb_version}\",
     \"chart-name\": \"vault-consul-dev\",
     \"description\": \"testing resource bundle definition api\",
-    \"uuid\": \"$definition_id\",
-    \"service-type\": \"firewall\"
+    \"labels\": {
+        \"vnf_customization_uuid\": \"${vnf_customization_uuid}\"
+    }
 }
 "
-payload=$(echo $payload_raw | tr '\n' ' ')
-rbd_id=$(curl -s -d "$payload" -X POST "${base_url}/v1/rb/definition" | jq -r '.uuid')
+call_api -d "$payload" "${base_url}/rb/definition"
 
 print_msg "Upload Resource Bundle Definition Content"
-curl -s --data-binary @${CSAR_DIR}/${rbd_csar_id}/${rbd_content_tarball}.gz -X POST "${base_url}/v1/rb/definition/$rbd_id/content"
+call_api --data-binary "@${CSAR_DIR}/${csar_id}/vault-consul-dev-0.0.0.tgz" "${base_url}/rb/definition/$rb_name/$rb_version/content"
 
 print_msg "Listing Resource Bundle Definitions"
-rbd_id_list=$(curl -s -X GET "${base_url}/v1/rb/definition")
-if [[ "$rbd_id_list" != *"${rbd_id}"* ]]; then
-    echo $rbd_id_list
+rb_list=$(call_api "${base_url}/rb/definition/$rb_name")
+if [[ "$rb_list" != *"${rb_name}"* ]]; then
+    echo $rb_list
     echo "Resource Bundle Definition not stored"
     exit 1
 fi
 
 print_msg "Create Resource Bundle Profile Metadata"
 kubeversion=$(kubectl version | grep 'Server Version' | awk -F '"' '{print $6}')
-payload_raw="
+payload="
 {
-    \"name\": \"test-rbprofile\",
+    \"profile-name\": \"${profile_name}\",
+    \"rb-name\": \"${rb_name}\",
+    \"rb-version\": \"${rb_version}\",
+    \"release-name\": \"${release_name}\",
     \"namespace\": \"$namespace\",
-    \"rbdid\": \"$definition_id\",
-    \"uuid\": \"$profile_id\",
-    \"kubernetesversion\": \"$kubeversion\"
+    \"kubernetesversion\": \"$kubeversion\",
+    \"labels\": {
+        \"vnf_customization_uuid\": \"${vnf_customization_uuid}\"
+    }
 }
 "
-payload=$(echo $payload_raw | tr '\n' ' ')
-rbp_id=$(curl -s -d "$payload" -X POST "${base_url}/v1/rb/profile" | jq -r '.uuid')
+call_api -d "$payload" "${base_url}/rb/definition/$rb_name/$rb_version/profile"
 
 print_msg "Upload Resource Bundle Profile Content"
-curl -s --data-binary @${CSAR_DIR}/${rbd_csar_id}/${rbp_content_tarball}.gz -X POST "${base_url}/v1/rb/profile/$rbp_id/content"
+call_api --data-binary "@${CSAR_DIR}/${csar_id}/rb_profile.tar.gz" "${base_url}/rb/definition/$rb_name/$rb_version/profile/$profile_name/content"
 
-print_msg "Listing Resource Bundle Profiles"
-rbp_id_list=$(curl -s -X GET "${base_url}/v1/rb/profile")
-if [[ "$rbp_id_list" != *"${rbp_id}"* ]]; then
-    echo $rbd_id_list
+print_msg "Getting Resource Bundle Profile"
+rbp_ret=$(call_api "${base_url}/rb/definition/$rb_name/$rb_version/profile/$profile_name")
+if [[ "$rbp_ret" != *"${profile_name}"* ]]; then
+    echo $rbp_ret
     echo "Resource Bundle Profile not stored"
     exit 1
 fi
 
+print_msg "Setup cloud data"
+payload="$(cat <<EOF
+{
+    "cloud-region": "$cloud_region_id",
+    "cloud-owner": "$cloud_region_owner"
+}
+EOF
+)"
+call_api -F "metadata=$payload" \
+    -F "file=@$kubeconfig_path" \
+    "${base_url}/connectivity-info" >/dev/null
+
 print_msg "Instantiate Profile"
-payload_raw="
+payload="
 {
-    \"cloud_region_id\": \"$cloud_region_id\",
-    \"rb_profile_id\":\"$profile_id\",
-    \"csar_id\": \"$csar_id\"
+    \"cloud-region\": \"$cloud_region_id\",
+    \"rb-name\":\"$rb_name\",
+    \"rb-version\":\"$rb_version\",
+    \"profile-name\":\"$profile_name\"
 }
 "
-payload=$(echo $payload_raw | tr '\n' ' ')
-vnf_id=$(curl -s -d "$payload" "${base_url}/v1/vnf_instances/" | jq -r '.vnf_id')
+inst_id=$(call_api -d "$payload" "${base_url}/instance")
+echo "$inst_id"
+inst_id=$(jq -r '.id' <<< "$inst_id")
 
 print_msg "Validating Kubernetes"
-kubectl get --no-headers=true --namespace=${namespace} deployment ${cloud_region_id}-${namespace}-${vnf_id}-test-rbprofile-vault-consul-dev
-kubectl get --no-headers=true --namespace=${namespace} service ${cloud_region_id}-${namespace}-${vnf_id}-override-vault-consul
-echo "VNF Instance created succesfully with id: $vnf_id"
-
-print_msg "Listing VNF Instances"
-vnf_id_list=$(curl -s -X GET "${base_url}/v1/vnf_instances/${cloud_region_id}/${namespace}" | jq -r '.vnf_id_list')
-if [[ "$vnf_id_list" != *"${vnf_id}"* ]]; then
-    echo $vnf_id_list
-    echo "VNF Instance not stored"
-    exit 1
-fi
+kubectl get --no-headers=true --namespace=${namespace} deployment ${release_name}-vault-consul-dev
+kubectl get --no-headers=true --namespace=${namespace} service override-vault-consul
+echo "VNF Instance created succesfully with id: $inst_id"
 
-print_msg "Getting $vnf_id VNF Instance information"
-vnf_details=$(curl -s -X GET "${base_url}/v1/vnf_instances/${cloud_region_id}/${namespace}/${vnf_id}")
-if [[ -z "$vnf_details" ]]; then
-    echo "Cannot retrieved VNF Instance details"
-    exit 1
-fi
-echo "VNF details $vnf_details"
+print_msg "Getting $inst_id VNF Instance information"
+call_api "${base_url}/instance/${inst_id}"
+
+# Teardown
+print_msg "Deleting $rb_name/$rb_version Resource Bundle Definition"
+# TODO: Change the HTTP code for 404 when the resource is not found in the API
+delete_resource "${base_url}/rb/definition/$rb_name/$rb_version"
 
-print_msg "Deleting $rbd_id Resource Bundle Definition"
-curl -X DELETE "${base_url}/v1/rb/definition/$rbd_id"
-if [[ 500 -ne $(curl -o /dev/null -w %{http_code} -s -X GET "${base_url}/v1/rb/definition/$rbd_id") ]]; then
-    echo "Resource Bundle Definition not deleted"
+print_msg "Deleting $profile_name Resource Bundle Profile"
 # TODO: Change the HTTP code for 404 when the resource is not found in the API
-    exit 1
-fi
+delete_resource "${base_url}/rb/definition/$rb_name/$rb_version/profile/$profile_name"
 
-print_msg "Deleting $vnf_id VNF Instance"
-curl -X DELETE "${base_url}/v1/vnf_instances/${cloud_region_id}/${namespace}/${vnf_id}"
-if [[ 404 -ne $(curl -o /dev/null -w %{http_code} -s -X GET "${base_url}${cloud_region_id}/${namespace}/${vnf_id}") ]]; then
-    echo "VNF Instance not deleted"
-    exit 1
-fi
+print_msg "Deleting $inst_id VNF Instance"
+delete_resource "${base_url}/instance/${inst_id}"
+
+print_msg "Deleting ${cloud_region_id} cloud region connection"
+delete_resource "${base_url}/connectivity-info/${cloud_region_id}"
 
-# Teardown
 teardown $plugin_deployment_name