elinuxhenrik | 115e109 | 2022-04-05 09:29:33 +0200 | [diff] [blame] | 1 | #!/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 | |
| 21 | BOLD="\033[1m" |
| 22 | EBOLD="\033[0m" |
| 23 | BOLD="\033[1m" |
| 24 | EBOLD="\033[0m" |
| 25 | RED="\033[31m\033[1m" |
| 26 | ERED="\033[0m" |
| 27 | GREEN="\033[32m\033[1m" |
| 28 | EGREEN="\033[0m" |
| 29 | |
| 30 | echo "" |
| 31 | echo "Start test" |
| 32 | |
| 33 | APP_TGZ="simple-app-0.1.0.tgz" |
| 34 | VALUES_YAML="simple-app-values.yaml" |
| 35 | INFO_JSON="simple-app.json" |
| 36 | INSTALL_JSON="simple-app-installation.json" |
| 37 | REPO_JSON="cm-repo.json" |
| 38 | |
| 39 | PORT="" |
| 40 | HOST="" |
| 41 | URL="" |
| 42 | HM_PATH="" |
| 43 | NAMESPACE="ckhm" #kube namespace for simple-app |
| 44 | PROXY_TAG="" |
| 45 | |
| 46 | OK="All tests ok" |
| 47 | USER=helmadmin |
| 48 | #USER="" |
| 49 | PWD=itisasecret |
| 50 | #PWD="" |
| 51 | PREFIX=/onap/k8sparticipant |
| 52 | PREFIX="" |
| 53 | print_usage() { |
| 54 | echo "usage: ./test.sh docker|(kube <cluster-ip>)" |
| 55 | } |
| 56 | if [ $# -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 |
| 67 | elif [ $# -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 |
| 78 | else |
| 79 | print_usage |
| 80 | exit 1 |
| 81 | fi |
| 82 | |
| 83 | |
| 84 | |
| 85 | run-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 | |
| 116 | echo "================" |
| 117 | echo "Get apps - empty" |
| 118 | echo "================" |
| 119 | cmd="/helm/charts" |
| 120 | run-curl $cmd |
| 121 | echo |
| 122 | |
| 123 | |
| 124 | echo "================" |
| 125 | echo "Add repo" |
| 126 | echo "================" |
| 127 | cmd="/helm/repo -X POST -H Content-Type:application/json -d @$REPO_JSON" |
| 128 | run-curl $cmd |
| 129 | echo |
| 130 | |
| 131 | |
| 132 | echo "============" |
| 133 | echo "Onboard app" |
| 134 | echo "===========" |
| 135 | cmd="/helm/onboard/chart -X POST -F chart=@$APP_TGZ -F values=@$VALUES_YAML -F info=<$INFO_JSON" |
| 136 | run-curl $cmd |
| 137 | echo |
| 138 | |
| 139 | |
| 140 | echo "=====================" |
| 141 | echo "Get apps - simple-app" |
| 142 | echo "=====================" |
| 143 | cmd="/helm/charts" |
| 144 | run-curl $cmd |
| 145 | echo |
| 146 | |
| 147 | |
| 148 | echo "===========" |
| 149 | echo "Install app" |
| 150 | echo "===========" |
| 151 | cmd="/helm/install -X POST -H Content-Type:application/json -d @$INSTALL_JSON" |
| 152 | run-curl $cmd |
| 153 | echo |
| 154 | |
| 155 | |
| 156 | |
| 157 | echo "=====================" |
| 158 | echo "Get apps - simple-app" |
| 159 | echo "=====================" |
| 160 | cmd="/helm/charts" |
| 161 | run-curl $cmd |
| 162 | echo |
| 163 | |
| 164 | echo "=================================================================" |
| 165 | echo "helm ls to list installed app - simpleapp chart should be visible" |
| 166 | echo "=================================================================" |
| 167 | helm ls -A |
| 168 | echo |
| 169 | |
| 170 | echo "==========================================" |
| 171 | echo "sleep 30 - give the app some time to start" |
| 172 | echo "==========================================" |
| 173 | sleep 30 |
| 174 | |
| 175 | echo "============================" |
| 176 | echo "List svc and pod of the app" |
| 177 | echo "============================" |
| 178 | kubectl get svc -n $NAMESPACE |
| 179 | kubectl get po -n $NAMESPACE |
| 180 | echo |
| 181 | |
| 182 | echo "========================" |
| 183 | echo "Uninstall app simple-app" |
| 184 | echo "========================" |
| 185 | cmd="/helm/uninstall/simple-app/0.1.0 -X DELETE" |
| 186 | run-curl $cmd |
| 187 | echo |
| 188 | |
| 189 | echo "===========================================" |
| 190 | echo "sleep 30 - give the app some time to remove" |
| 191 | echo "===========================================" |
| 192 | sleep 30 |
| 193 | |
| 194 | echo "============================================================" |
| 195 | echo "List svc and pod of the app - should be gone or terminating" |
| 196 | echo "============================================================" |
| 197 | kubectl get svc -n $NAMESPACE |
| 198 | kubectl get po -n $NAMESPACE |
| 199 | echo |
| 200 | |
| 201 | |
| 202 | echo "=====================" |
| 203 | echo "Get apps - simple-app" |
| 204 | echo "=====================" |
| 205 | cmd="/helm/charts" |
| 206 | run-curl $cmd |
| 207 | echo |
| 208 | |
| 209 | echo "============" |
| 210 | echo "Delete chart" |
| 211 | echo "===========" |
| 212 | cmd="/helm/chart/simple-app/0.1.0 -X DELETE" |
| 213 | run-curl $cmd |
| 214 | echo |
| 215 | |
| 216 | echo "================" |
| 217 | echo "Get apps - empty" |
| 218 | echo "================" |
| 219 | cmd="/helm/charts" |
| 220 | run-curl $cmd |
| 221 | echo |
| 222 | |
| 223 | echo -e "Test result $BOLD $OK $EBOLD" |
| 224 | echo "End of test" |