BjornMagnussonXA | 31b0988 | 2021-06-02 01:56:26 +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 | |
| 38 | PORT="" |
| 39 | HOST="" |
| 40 | URL="" |
| 41 | HM_PATH="" |
| 42 | NAMESPACE="ckhm" #kube namespace for simple-app |
| 43 | PROXY_TAG="" |
| 44 | |
| 45 | OK="All tests ok" |
| 46 | |
| 47 | print_usage() { |
| 48 | echo "usage: ./test.sh docker|(kube <cluster-ip>)" |
| 49 | } |
| 50 | if [ $# -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 |
| 60 | elif [ $# -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 |
| 70 | else |
| 71 | print_usage |
| 72 | exit 1 |
| 73 | fi |
| 74 | |
| 75 | |
| 76 | |
| 77 | run-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 | |
| 108 | echo "================" |
| 109 | echo "Get apps - empty" |
| 110 | echo "================" |
| 111 | cmd="/helm/charts" |
| 112 | run-curl $cmd |
| 113 | echo |
| 114 | |
| 115 | |
| 116 | echo "============" |
| 117 | echo "Onboard app" |
| 118 | echo "===========" |
| 119 | cmd="/helm/charts -X POST -F chart=@$APP_TGZ -F values=@$VALUES_YAML -F info=<$INFO_JSON" |
| 120 | run-curl $cmd |
| 121 | echo |
| 122 | |
| 123 | |
| 124 | echo "=====================" |
| 125 | echo "Get apps - simple-app" |
| 126 | echo "=====================" |
| 127 | cmd="/helm/charts" |
| 128 | run-curl $cmd |
| 129 | echo |
| 130 | |
| 131 | |
| 132 | echo "===========" |
| 133 | echo "Install app" |
| 134 | echo "===========" |
| 135 | cmd="/helm/install -X POST -H Content-Type:application/json -d @$INSTALL_JSON" |
| 136 | run-curl $cmd |
| 137 | echo |
| 138 | |
| 139 | |
| 140 | |
| 141 | echo "=====================" |
| 142 | echo "Get apps - simple-app" |
| 143 | echo "=====================" |
| 144 | cmd="/helm/charts" |
| 145 | run-curl $cmd |
| 146 | echo |
| 147 | |
| 148 | echo "=================================================================" |
| 149 | echo "helm ls to list installed app - simpleapp chart should be visible" |
| 150 | echo "=================================================================" |
| 151 | helm ls -A |
| 152 | echo |
| 153 | |
| 154 | echo "==========================================" |
| 155 | echo "sleep 30 - give the app some time to start" |
| 156 | echo "==========================================" |
| 157 | sleep 30 |
| 158 | |
| 159 | echo "============================" |
| 160 | echo "List svc and pod of the app" |
| 161 | echo "============================" |
| 162 | kubectl get svc -n $NAMESPACE |
| 163 | kubectl get po -n $NAMESPACE |
| 164 | echo |
| 165 | |
| 166 | echo "========================" |
| 167 | echo "Uninstall app simple-app" |
| 168 | echo "========================" |
| 169 | cmd="/helm/uninstall/simple-app/0.1.0 -X DELETE" |
| 170 | run-curl $cmd |
| 171 | echo |
| 172 | |
| 173 | echo "===========================================" |
| 174 | echo "sleep 30 - give the app some time to remove" |
| 175 | echo "===========================================" |
| 176 | sleep 30 |
| 177 | |
| 178 | echo "============================================================" |
| 179 | echo "List svc and pod of the app - should be gone or terminating" |
| 180 | echo "============================================================" |
| 181 | kubectl get svc -n $NAMESPACE |
| 182 | kubectl get po -n $NAMESPACE |
| 183 | echo |
| 184 | |
| 185 | |
| 186 | echo "=====================" |
| 187 | echo "Get apps - simple-app" |
| 188 | echo "=====================" |
| 189 | cmd="/helm/charts" |
| 190 | run-curl $cmd |
| 191 | echo |
| 192 | |
| 193 | echo "============" |
| 194 | echo "Delete chart" |
| 195 | echo "===========" |
| 196 | cmd="/helm/charts/simple-app/0.1.0 -X DELETE" |
| 197 | run-curl $cmd |
| 198 | echo |
| 199 | |
| 200 | echo "================" |
| 201 | echo "Get apps - empty" |
| 202 | echo "================" |
| 203 | cmd="/helm/charts" |
| 204 | run-curl $cmd |
| 205 | echo |
| 206 | |
| 207 | echo -e "Test result $BOLD $OK $EBOLD" |
| 208 | echo "End of test" |