blob: 89c79da10e107e045e86cbcc0517a62d052eed85 [file] [log] [blame]
elinuxhenrik115e1092022-04-05 09:29:33 +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"
37REPO_JSON="cm-repo.json"
38
39PORT=""
40HOST=""
41URL=""
42HM_PATH=""
43NAMESPACE="ckhm" #kube namespace for simple-app
44PROXY_TAG=""
45
46OK="All tests ok"
47USER=helmadmin
48#USER=""
49PWD=itisasecret
50#PWD=""
51PREFIX=/onap/k8sparticipant
52PREFIX=""
53print_usage() {
54 echo "usage: ./test.sh docker|(kube <cluster-ip>)"
55}
56if [ $# -eq 1 ]; then
57 if [ $1 == "docker" ]; then
58 PORT=8112
59 HOST="localhost"
60 URL="http://$USER:$PWD@$HOST:$PORT"$PREFIX
61 #URL="http://$HOST:$PORT"$PREFIX
62 HM_PATH=$URL
63 else
64 print_usage
65 exit 1
66 fi
67elif [ $# -eq 2 ]; then
68 if [ $1 == "kube" ]; then
69 PORT=$(kubectl get svc helmmanagerservice -n nonrtric -o jsonpath='{...ports[?(@.name=="'http'")].nodePort}')
70 HOST=$2
71 URL="http://$USER:$PWD@$HOST:$PORT"$PREFIX
72 #URL="http://$HOST:$PORT"$PREFIX
73 HM_PATH=$URL
74 else
75 print_usage
76 exit 1
77 fi
78else
79 print_usage
80 exit 1
81fi
82
83
84
85run-curl() {
86 curl_cmd="curl -sw %{http_code} $PROXY_TAG $HM_PATH$@"
87 echo $curl_cmd
88 res=$($curl_cmd)
89 retcode=$?
90 status=${res:${#res}-3}
91 if [ -z "$res" ]; then
92 body="<no-body-returned>"
93 elif [ ${#res} -gt 2 ]; then
94 body=${res:0:${#res}-3}
95 else
96 body="<no-body-returned>"
97 fi
98 if [ $retcode -ne 0 ]; then
99 echo -e $RED" FAIL - Curl failed"$ERED
100 echo " Curl return code: $retcode"
101 OK="One or more tests failed"
102 else
103 if [[ $status -gt 199 ]] && [[ $status -lt 300 ]]; then
104 echo -e $GREEN" Curl OK"$EGREEN
105 echo " Response: "$status
106 echo " Body: "$body
107 else
108 echo -e $RED" FAIL, non 2XX response"$ERED
109 echo " Response: "$status
110 echo " Body: "$body
111 OK="One or more tests failed"
112 fi
113 fi
114}
115
116echo "================"
117echo "Get apps - empty"
118echo "================"
119cmd="/helm/charts"
120run-curl $cmd
121echo
122
123
124echo "================"
125echo "Add repo"
126echo "================"
127cmd="/helm/repo -X POST -H Content-Type:application/json -d @$REPO_JSON"
128run-curl $cmd
129echo
130
131
132echo "============"
133echo "Onboard app"
134echo "==========="
135cmd="/helm/onboard/chart -X POST -F chart=@$APP_TGZ -F values=@$VALUES_YAML -F info=<$INFO_JSON"
136run-curl $cmd
137echo
138
139
140echo "====================="
141echo "Get apps - simple-app"
142echo "====================="
143cmd="/helm/charts"
144run-curl $cmd
145echo
146
147
148echo "==========="
149echo "Install app"
150echo "==========="
151cmd="/helm/install -X POST -H Content-Type:application/json -d @$INSTALL_JSON"
152run-curl $cmd
153echo
154
155
156
157echo "====================="
158echo "Get apps - simple-app"
159echo "====================="
160cmd="/helm/charts"
161run-curl $cmd
162echo
163
164echo "================================================================="
165echo "helm ls to list installed app - simpleapp chart should be visible"
166echo "================================================================="
167helm ls -A
168echo
169
170echo "=========================================="
171echo "sleep 30 - give the app some time to start"
172echo "=========================================="
173sleep 30
174
175echo "============================"
176echo "List svc and pod of the app"
177echo "============================"
178kubectl get svc -n $NAMESPACE
179kubectl get po -n $NAMESPACE
180echo
181
182echo "========================"
183echo "Uninstall app simple-app"
184echo "========================"
185cmd="/helm/uninstall/simple-app/0.1.0 -X DELETE"
186run-curl $cmd
187echo
188
189echo "==========================================="
190echo "sleep 30 - give the app some time to remove"
191echo "==========================================="
192sleep 30
193
194echo "============================================================"
195echo "List svc and pod of the app - should be gone or terminating"
196echo "============================================================"
197kubectl get svc -n $NAMESPACE
198kubectl get po -n $NAMESPACE
199echo
200
201
202echo "====================="
203echo "Get apps - simple-app"
204echo "====================="
205cmd="/helm/charts"
206run-curl $cmd
207echo
208
209echo "============"
210echo "Delete chart"
211echo "==========="
212cmd="/helm/chart/simple-app/0.1.0 -X DELETE"
213run-curl $cmd
214echo
215
216echo "================"
217echo "Get apps - empty"
218echo "================"
219cmd="/helm/charts"
220run-curl $cmd
221echo
222
223echo -e "Test result $BOLD $OK $EBOLD"
224echo "End of test"