blob: 1b652bf2ded634f8aa0bd4ff007ae015e104168c [file] [log] [blame]
BjornMagnussonXA31b09882021-06-02 01:56:26 +02001#!/bin/bash
2
3# ============LICENSE_START===============================================
4# Copyright (C) 2021 Nordix Foundation. All rights reserved.
5# ========================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# ============LICENSE_END=================================================
18#
19
20
21BOLD="\033[1m"
22EBOLD="\033[0m"
23BOLD="\033[1m"
24EBOLD="\033[0m"
25RED="\033[31m\033[1m"
26ERED="\033[0m"
27GREEN="\033[32m\033[1m"
28EGREEN="\033[0m"
29
30echo ""
31echo "Start test"
32
33APP_TGZ="simple-app-0.1.0.tgz"
34VALUES_YAML="simple-app-values.yaml"
35INFO_JSON="simple-app.json"
36INSTALL_JSON="simple-app-installation.json"
37
38PORT=""
39HOST=""
40URL=""
41HM_PATH=""
42NAMESPACE="ckhm" #kube namespace for simple-app
43PROXY_TAG=""
44
45OK="All tests ok"
46
47print_usage() {
48 echo "usage: ./test.sh docker|(kube <cluster-ip>)"
49}
50if [ $# -eq 1 ]; then
51 if [ $1 == "docker" ]; then
52 PORT=8112
53 HOST="localhost"
54 URL="http://$HOST:$PORT"
55 HM_PATH=$URL
56 else
57 print_usage
58 exit 1
59 fi
60elif [ $# -eq 2 ]; then
61 if [ $1 == "kube" ]; then
62 PORT=$(kubectl get svc helmmanagerservice -n nonrtric -o jsonpath='{...ports[?(@.name=="'http'")].nodePort}')
63 HOST=$2
64 URL="http://$HOST:$PORT"
65 HM_PATH=$URL
66 else
67 print_usage
68 exit 1
69 fi
70else
71 print_usage
72 exit 1
73fi
74
75
76
77run-curl() {
78 curl_cmd="curl -sw %{http_code} $PROXY_TAG $HM_PATH$@"
79 echo $curl_cmd
80 res=$($curl_cmd)
81 retcode=$?
82 status=${res:${#res}-3}
83 if [ -z "$res" ]; then
84 body="<no-body-returned>"
85 elif [ ${#res} -gt 2 ]; then
86 body=${res:0:${#res}-3}
87 else
88 body="<no-body-returned>"
89 fi
90 if [ $retcode -ne 0 ]; then
91 echo -e $RED" FAIL - Curl failed"$ERED
92 echo " Curl return code: $retcode"
93 OK="One or more tests failed"
94 else
95 if [[ $status -gt 199 ]] && [[ $status -lt 300 ]]; then
96 echo -e $GREEN" Curl OK"$EGREEN
97 echo " Response: "$status
98 echo " Body: "$body
99 else
100 echo -e $RED" FAIL, non 2XX response"$ERED
101 echo " Response: "$status
102 echo " Body: "$body
103 OK="One or more tests failed"
104 fi
105 fi
106}
107
108echo "================"
109echo "Get apps - empty"
110echo "================"
111cmd="/helm/charts"
112run-curl $cmd
113echo
114
115
116echo "============"
117echo "Onboard app"
118echo "==========="
119cmd="/helm/charts -X POST -F chart=@$APP_TGZ -F values=@$VALUES_YAML -F info=<$INFO_JSON"
120run-curl $cmd
121echo
122
123
124echo "====================="
125echo "Get apps - simple-app"
126echo "====================="
127cmd="/helm/charts"
128run-curl $cmd
129echo
130
131
132echo "==========="
133echo "Install app"
134echo "==========="
135cmd="/helm/install -X POST -H Content-Type:application/json -d @$INSTALL_JSON"
136run-curl $cmd
137echo
138
139
140
141echo "====================="
142echo "Get apps - simple-app"
143echo "====================="
144cmd="/helm/charts"
145run-curl $cmd
146echo
147
148echo "================================================================="
149echo "helm ls to list installed app - simpleapp chart should be visible"
150echo "================================================================="
151helm ls -A
152echo
153
154echo "=========================================="
155echo "sleep 30 - give the app some time to start"
156echo "=========================================="
157sleep 30
158
159echo "============================"
160echo "List svc and pod of the app"
161echo "============================"
162kubectl get svc -n $NAMESPACE
163kubectl get po -n $NAMESPACE
164echo
165
166echo "========================"
167echo "Uninstall app simple-app"
168echo "========================"
169cmd="/helm/uninstall/simple-app/0.1.0 -X DELETE"
170run-curl $cmd
171echo
172
173echo "==========================================="
174echo "sleep 30 - give the app some time to remove"
175echo "==========================================="
176sleep 30
177
178echo "============================================================"
179echo "List svc and pod of the app - should be gone or terminating"
180echo "============================================================"
181kubectl get svc -n $NAMESPACE
182kubectl get po -n $NAMESPACE
183echo
184
185
186echo "====================="
187echo "Get apps - simple-app"
188echo "====================="
189cmd="/helm/charts"
190run-curl $cmd
191echo
192
193echo "============"
194echo "Delete chart"
195echo "==========="
196cmd="/helm/charts/simple-app/0.1.0 -X DELETE"
197run-curl $cmd
198echo
199
200echo "================"
201echo "Get apps - empty"
202echo "================"
203cmd="/helm/charts"
204run-curl $cmd
205echo
206
207echo -e "Test result $BOLD $OK $EBOLD"
208echo "End of test"