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