4f947fbffe05655d15f78ba015ebf9855f88beb2
[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" == "" ]; then
26    echo "Usage: ete-k8s.sh <namespace> <tag> [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
43 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
44
45 #/root/test/ric_robot_suite/helm
46 # extract the base to find root to dep
47
48 BASE=${DIR%/test*}
49
50 BASEDIR50=$BASE/dep/ric-platform/50-RIC-Platform/
51 OVERRIDEYAML=$BASE/dep/RECIPE_EXAMPLE/RIC_PLATFORM_RECIPE_EXAMPLE
52
53 echo "Using etc/ric.conf from $BASEDIR50"
54
55 source $BASEDIR50/etc/ric.conf
56
57
58 if [ -z "$RICPLT_RELEASE_NAME" ];then
59    RELEASE_NAME=$helm_release_name
60 else
61    RELEASE_NAME=$RICPLT_RELEASE_NAME
62 fi
63
64
65
66 # first parameter: number of expected running pods
67 # second parameter: namespace (all-namespaces means all namespaces)
68 # third parameter: [optional] keyword
69 wait_for_pods_running () {
70   NS="$2"
71   CMD="kubectl get pods --all-namespaces "
72   if [ "$NS" != "all-namespaces" ]; then
73     CMD="kubectl get pods -n $2 "
74   fi
75   KEYWORD="Running"
76   if [ "$#" == "3" ]; then
77     KEYWORD="${3}.*Running"
78   fi
79
80   CMD2="$CMD | grep \"$KEYWORD\" | wc -l"
81   NUMPODS=$(eval "$CMD2")
82   echo "waiting for $NUMPODS/$1 pods running in namespace [$NS] with keyword [$KEYWORD]"
83   while [  $NUMPODS -lt $1 ]; do
84     sleep 5
85     NUMPODS=$(eval "$CMD2")
86     echo "> waiting for $NUMPODS/$1 pods running in namespace [$NS] with keyword [$KEYWORD]"
87   done
88 }
89
90 wait_for_pods_terminated() {
91   NS="$2"
92   CMD="kubectl get pods --all-namespaces "
93   if [ "$NS" != "all-namespaces" ]; then
94     CMD="kubectl get pods -n $2 "
95   fi
96   KEYWORD="Running"
97   if [ "$#" == "3" ]; then
98     KEYWORD="${3}"
99   fi
100
101   CMD2="$CMD | grep \"$KEYWORD\" | wc -l"
102   NUMPODS=$(eval "$CMD2")
103   echo "waiting for $NUMPODS/$1 pods terminated (gone) in namespace [$NS] with keyword [$KEYWORD]"
104   while [  $NUMPODS -gt $1 ]; do
105     sleep 5
106     NUMPODS=$(eval "$CMD2")
107     echo "> waiting for $NUMPODS/$1 pods terminated (gone) in namespace [$NS] with keyword [$KEYWORD]"
108   done
109 }
110
111
112 if [ "$3" != "" ] ; then
113     VARIABLES="-v $3"
114 fi
115
116 set -x
117
118 export NAMESPACE="$1"
119
120 POD=$(kubectl --namespace $NAMESPACE get pods | sed 's/ .*//'| grep robot)
121
122 TAG="$2"
123 TAGS="-i $2"
124
125
126 # if $2 is e2setup or x2setup then helm delete/helm install 
127 shift
128 while [ $# -gt 0 ]
129 do
130         key="$1"
131         echo "KEY:"
132         echo $key
133         case $key in
134         e2setup|e2setup_dash|x2setup|x2setup_dash)
135                         #/root/dep/ric-platform/50-RIC-Platform/bin/harry-uninstall
136                         helm delete  ${RELEASE_NAME}-e2term   --purge
137                         helm delete  ${RELEASE_NAME}-e2mgr   --purge
138                         helm delete  ${RELEASE_NAME}-e2sim  --purge
139                         wait_for_pods_terminated  0  $NAMESPACE e2sim
140                         wait_for_pods_terminated  0  $NAMESPACE e2term
141                         wait_for_pods_terminated  0  $NAMESPACE e2mgr
142                         helm install -f $OVERRIDEYAML --namespace "${NAMESPACE}" --name "${RELEASE_NAME}-e2term" $BASEDIR50/helm/e2term
143                         helm install -f $OVERRIDEYAML --namespace "${NAMESPACE}" --name "${RELEASE_NAME}-e2mgr" $BASEDIR50/helm/e2mgr
144                         cd /root/test/simulators/e2sim/helm
145                         ./e2sim_install.sh
146                         wait_for_pods_running 1 $NAMESPACE e2term
147                         wait_for_pods_running 1 $NAMESPACE e2mgr
148                         wait_for_pods_running 1 $NAMESPACE e2sim
149                         E2SIMIP=$(kubectl -n ricplt get pod -o=wide | grep e2sim | sed 's/\s\s*/ /g' | cut -d ' ' -f6)
150                         echo $E2SIMIP
151                         VARIABLES="$VARIABLES -v TEST_NODE_B_IP:$E2SIMIP"
152                         shift
153                         ;;
154         *)
155                         shift
156                         ;;
157         esac
158 done
159
160
161 ETEHOME=/var/opt/RIC
162 export GLOBAL_BUILD_NUMBER=$(kubectl --namespace $NAMESPACE exec  ${POD}  -- bash -c "ls -1q /share/logs/ | wc -l")
163 OUTPUT_FOLDER=$(printf %04d $GLOBAL_BUILD_NUMBER)_ete_$TAG
164 DISPLAY_NUM=$(($GLOBAL_BUILD_NUMBER + 90))
165
166 VARIABLEFILES="-V /share/config/vm_properties.py -V /share/config/integration_robot_properties.py"
167 #VARIABLEFILES="-V /tmp/vm_properties.py -V /share/config/integration_robot_properties.py"
168 VARIABLES="$VARIABLES -v GLOBAL_BUILD_NUMBER:$$"
169
170
171
172 kubectl --namespace $NAMESPACE exec ${POD} -- ${ETEHOME}/runTags.sh ${VARIABLEFILES} ${VARIABLES} -d /share/logs/${OUTPUT_FOLDER} ${TAGS} --display $DISPLAY_NUM