dab6c26084c192cab1e34974dc2009a29283d50d
[it/test.git] / ric_robot_suite / helm / ric-robot / ete-k8s.e2sim.sh
1 #!/bin/bash
2 ################################################################################
3 #   Copyright (c) 2019 AT&T Intellectual Property.                             #
4 #   Copyright (c) 2019 Nokia.                                                  #
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 ################################################################################
18
19
20 #
21 # Run the testsuite for the passed tag. Valid tags are health
22 # Please clean up logs when you are done...
23 # Note: Do not run multiple concurrent ete.sh as the --display is not parameterized and tests will collide
24 #
25 if [ "$1" == "" ] || [ "$2" == "" ] || [ "$3" == "" ]; then
26    echo "Usage: ete-k8s.sh <namespace> <tag> <override_file> [input variable]"
27    echo "  [input variable] is added to runTags with "-v" prepended"
28    echo "         example :   TEST_NODE_B_IP:10.240.0.217 "
29    echo "         example :   \"TEST_NODE_B_IP:10.240.0.217 -v TEST_NODE_B_PORT:34622 -v TEST_NODE_B_NAME:BBBB654321\""
30    echo "         note:   TEST_NODE_B_NAME is 4 upper case letters and then 6 numbers in Dashboard validation  "
31    echo "           "
32    echo "  <tag>         "
33    echo "         health   "
34    echo "         etetests  "
35    echo "         e2setup   "
36    echo "         x2setup   "
37    echo "         e2setup_dash   "
38    echo "         x2setup_dash   "
39    exit
40 fi
41
42 # setup a detail log file
43 current_time=$(date "+%Y.%m.%d-%H.%M.%S")
44 LOGFILE=/tmp/ete-k8s.e2sim.$current_time.log
45
46 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
47
48
49 # extract the base to find root to dep
50
51 BASE=${DIR%/test*}
52
53 BASEDIR50=$BASE/dep/ric-platform/50-RIC-Platform
54 #OVERRIDEYAML=$BASE/dep/RECIPE_EXAMPLE/ric-platform
55 OVERRIDEYAML=$3
56
57 echo "Using etc/ric.conf from $BASEDIR50"
58
59 source $BASEDIR50/etc/ric.conf
60
61
62 if [ -z "$RICPLT_RELEASE_NAME" ];then
63    RELEASE_NAME=$helm_release_name
64 else
65    RELEASE_NAME=$RICPLT_RELEASE_NAME
66 fi
67
68
69
70 # first parameter: number of expected running pods
71 # second parameter: namespace (all-namespaces means all namespaces)
72 # third parameter: [optional] keyword
73 wait_for_pods_running () {
74   NS="$2"
75   CMD="kubectl get pods --all-namespaces "
76   if [ "$NS" != "all-namespaces" ]; then
77     CMD="kubectl get pods -n $2 "
78   fi
79   KEYWORD="Running"
80   if [ "$#" == "3" ]; then
81     KEYWORD="${3}.*Running"
82   fi
83
84   CMD2="$CMD | grep \"$KEYWORD\" | wc -l"
85   NUMPODS=$(eval "$CMD2")
86   echo "waiting for $NUMPODS/$1 pods running in namespace [$NS] with keyword [$KEYWORD]"
87   while [  $NUMPODS -lt $1 ]; do
88     sleep 5
89     NUMPODS=$(eval "$CMD2")
90     echo -n "."
91   done
92   echo "."
93 }
94
95 wait_for_pods_terminated() {
96   NS="$2"
97   CMD="kubectl get pods --all-namespaces "
98   if [ "$NS" != "all-namespaces" ]; then
99     CMD="kubectl get pods -n $2 "
100   fi
101   KEYWORD="Running"
102   if [ "$#" == "3" ]; then
103     KEYWORD="${3}"
104   fi
105
106   CMD2="$CMD | grep \"$KEYWORD\" | wc -l"
107   NUMPODS=$(eval "$CMD2")
108   echo "waiting for $NUMPODS/$1 pods terminated (gone) in namespace [$NS] with keyword [$KEYWORD]"
109   while [  $NUMPODS -gt $1 ]; do
110     sleep 5
111     NUMPODS=$(eval "$CMD2")
112     echo -n "."
113   done
114   echo "."
115 }
116
117
118 # wait_for_e2mgr
119 #  e2mgr can take a few seconds after the POD is running to be up
120 #  
121
122 wait_for_e2mgr() {
123   E2MGR_IP=$(kubectl -n ricplt  get services | grep e2mgr-http | awk '{print $3}')
124   #echo $E2MGR_IP
125   CMD3="curl -s -o /dev/null -w \"%{http_code}\" http://$E2MGR_IP:3800/v1/nodeb-ids"
126   echo $CMD3
127   HTTP_CODE=$(eval "$CMD3")
128   echo $HTTP_CODE
129   while [  $HTTP_CODE  -ne 200 ]; do
130     sleep 1
131     HTTP_CODE=$(eval "$CMD3")
132     echo -n "."
133   done
134 }
135
136
137
138
139
140 if [ "$4" != "" ] ; then
141     VARIABLES="-v $4"
142 fi
143
144 #set -x
145
146 export NAMESPACE="$1"
147
148 POD=$(kubectl --namespace $NAMESPACE get pods | sed 's/ .*//'| grep robot)
149
150 TAG="$2"
151 TAGS="-i $2"
152
153
154 # if $2 is e2setup or x2setup then helm delete/helm install
155 shift
156 while [ $# -gt 0 ]
157 do
158         key="$1"
159         echo -n "KEY:"
160         echo $key
161         case $key in
162         e2setup|e2setup_dash|x2setup|x2setup_dash)
163                         helm delete  ${RELEASE_NAME}-e2term   --purge  >> $LOGFILE
164                         helm delete  ${RELEASE_NAME}-e2mgr   --purge   >> $LOGFILE
165                         helm delete  ${RELEASE_NAME}-e2sim  --purge  >> $LOGFILE
166                         wait_for_pods_terminated  0  $NAMESPACE e2sim
167                         wait_for_pods_terminated  0  $NAMESPACE e2term
168                         wait_for_pods_terminated  0  $NAMESPACE e2mgr
169                         helm install -f $OVERRIDEYAML --namespace "${NAMESPACE}" --name "${RELEASE_NAME}-e2term" $BASEDIR50/helm/e2term >> $LOGFILE
170                         helm install -f $OVERRIDEYAML --namespace "${NAMESPACE}" --name "${RELEASE_NAME}-e2mgr" $BASEDIR50/helm/e2mgr >> $LOGFILE
171                         cd /root/test/simulators/e2sim/helm
172                         ./e2sim_install.sh     >> $LOGFILE
173                         wait_for_pods_running 1 $NAMESPACE e2term
174                         wait_for_pods_running 1 $NAMESPACE e2mgr
175                         wait_for_pods_running 1 $NAMESPACE e2sim
176                         # wait for application
177                         wait_for_e2mgr
178                         E2SIMIP=$(kubectl -n ricplt get pod -o=wide | grep e2sim | sed 's/\s\s*/ /g' | cut -d ' ' -f6)
179                         VARIABLES="$VARIABLES -v TEST_NODE_B_IP:$E2SIMIP"
180                         shift
181                         ;;
182         *)
183                         shift
184                         ;;
185         esac
186 done
187
188
189 ETEHOME=/var/opt/RIC
190 export GLOBAL_BUILD_NUMBER=$(kubectl --namespace $NAMESPACE exec  ${POD}  -- bash -c "ls -1q /share/logs/ | wc -l")
191 OUTPUT_FOLDER=$(printf %04d $GLOBAL_BUILD_NUMBER)_ete_$TAG
192 DISPLAY_NUM=$(($GLOBAL_BUILD_NUMBER + 90))
193
194 VARIABLEFILES="-V /share/config/vm_properties.py -V /share/config/integration_robot_properties.py"
195 #VARIABLEFILES="-V /tmp/vm_properties.py -V /share/config/integration_robot_properties.py"
196 VARIABLES="$VARIABLES -v GLOBAL_BUILD_NUMBER:$$"
197
198
199
200 kubectl --namespace $NAMESPACE exec ${POD} -- ${ETEHOME}/runTags.sh ${VARIABLEFILES} ${VARIABLES} -d /share/logs/${OUTPUT_FOLDER} ${TAGS} --display $DISPLAY_NUM