Update plugin.sh with new helper functions
[multicloud/k8s.git] / kud / tests / plugin_edgex.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018
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 ##############################################################################
10
11 set -o errexit
12 set -o nounset
13 set -o pipefail
14 #set -o xtrace
15
16 source _common_test.sh
17 source _functions.sh
18 source _common.sh
19
20 base_url="http://localhost:9015/v1"
21 kubeconfig_path="$HOME/.kube/config"
22 csar_id=cb009bfe-bbee-11e8-9766-525400435678
23 rb_name="edgex"
24 rb_version="plugin_test"
25 chart_name="edgex"
26 profile_name="test_profile"
27 release_name="test-release"
28 namespace="plugin-tests-namespace"
29 cloud_region_id="kud"
30 cloud_region_owner="localhost"
31
32 # Setup
33 install_deps
34 populate_CSAR_edgex_rbdefinition "$csar_id"
35
36 print_msg "Registering resource bundle"
37 payload="$(cat <<EOF
38 {
39     "rb-name": "${rb_name}",
40     "rb-version": "${rb_version}",
41     "chart-name": "${chart_name}"
42 }
43 EOF
44 )"
45 call_api -d "${payload}" "${base_url}/rb/definition"
46
47 print_msg "Uploading resource bundle content"
48 call_api --data-binary "@${CSAR_DIR}/${csar_id}/rb_definition.tar.gz" \
49          "${base_url}/rb/definition/${rb_name}/${rb_version}/content"
50
51 print_msg "Registering rb's profile"
52 payload="$(cat <<EOF
53 {
54     "rb-name": "${rb_name}",
55     "rb-version": "${rb_version}",
56     "profile-name": "${profile_name}",
57     "release-name": "${release_name}",
58     "namespace": "${namespace}"
59 }
60 EOF
61 )"
62 call_api -d "${payload}" "${base_url}/rb/definition/${rb_name}/${rb_version}/profile"
63
64 print_msg "Uploading profile data"
65 call_api --data-binary "@${CSAR_DIR}/${csar_id}/rb_profile.tar.gz" \
66          "${base_url}/rb/definition/${rb_name}/${rb_version}/profile/${profile_name}/content"
67
68 print_msg "Setup cloud data"
69 payload="$(cat <<EOF
70 {
71     "cloud-region": "$cloud_region_id",
72     "cloud-owner": "$cloud_region_owner"
73 }
74 EOF
75 )"
76 call_api -F "metadata=$payload" \
77          -F "file=@$kubeconfig_path" \
78          "${base_url}/connectivity-info" >/dev/null #massive output
79
80 print_msg "Creating EdgeX VNF Instance"
81 payload="$(cat <<EOF
82 {
83     "rb-name": "${rb_name}",
84     "rb-version": "${rb_version}",
85     "profile-name": "${profile_name}",
86     "cloud-region": "${cloud_region_id}"
87 }
88 EOF
89 )"
90 response="$(call_api -d "${payload}" "${base_url}/instance")"
91 echo "$response"
92 vnf_id="$(jq -r '.id' <<< "${response}")"
93
94 print_msg "Validating Kubernetes"
95 kubectl get --no-headers=true --namespace=${namespace} deployment edgex-core-command
96 kubectl get --no-headers=true --namespace=${namespace} service edgex-core-command
97 # TODO: Add health checks to verify EdgeX services
98
99 print_msg "Retrieving VNF details"
100 call_api "${base_url}/instance/${vnf_id}"
101
102 #Teardown
103 print_msg "Deleting VNF Instance"
104 delete_resource "${base_url}/instance/${vnf_id}"
105
106 print_msg "Deleting Profile"
107 delete_resource "${base_url}/rb/definition/${rb_name}/${rb_version}/profile/${profile_name}"
108
109 print_msg "Deleting Resource Bundle"
110 delete_resource "${base_url}/rb/definition/${rb_name}/${rb_version}"
111
112 print_msg "Deleting ${cloud_region_id} cloud region connection"
113 delete_resource "${base_url}/connectivity-info/${cloud_region_id}"