ae3ae62b6455e9819e5e9862b829561c04b466d5
[it/test.git] / ric_robot_suite / helm / ric-robot / demo-k8s.sh
1 #!/bin/bash
2
3 ################################################################################
4 #   Copyright (c) 2019 AT&T Intellectual Property.                             #
5 #   Copyright (c) 2019 Nokia.                                                  #
6 #                                                                              #
7 #   Licensed under the Apache License, Version 2.0 (the "License");            #
8 #   you may not use this file except in compliance with the License.           #
9 #   You may obtain a copy of the License at                                    #
10 #                                                                              #
11 #       http://www.apache.org/licenses/LICENSE-2.0                             #
12 #                                                                              #
13 #   Unless required by applicable law or agreed to in writing, software        #
14 #   distributed under the License is distributed on an "AS IS" BASIS,          #
15 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
16 #   See the License for the specific language governing permissions and        #
17 #   limitations under the License.                                             #
18 ################################################################################
19
20
21 function usage
22 {
23         echo "Usage: demo.sh namespace <command> [<parameters>]"
24         echo " "
25         echo "       demo.sh <namespace> init_robot"
26     echo "               - Initialize robot after all RIC VMs have started"
27 }
28
29
30
31 # Set the defaults
32
33 echo "Number of parameters:" 
34 echo $#
35
36 if [ $# -lt 2 ];then
37         usage
38         exit
39 fi
40
41 NAMESPACE=$1
42 POD=$(kubectl --namespace $NAMESPACE get pods | sed 's/ .*//'| grep robot)
43
44 shift
45
46 ##
47 ## if more than 1 tag is supplied, the must be provided with -i or -e
48 ##
49 while [ $# -gt 0 ]
50 do
51         key="$1"
52         echo "KEY:"
53         echo $key
54
55         case $key in
56         init_robot)
57                         TAG="UpdateWebPage"
58                         read -s -p "WEB Site Password for user 'test': " WEB_PASSWORD
59                         if [ "$WEB_PASSWORD" = "" ]; then
60                                 echo ""
61                                 echo "WEB Password is required for user 'test'"
62                                 exit
63                         fi
64                         VARIABLES="$VARIABLES -v WEB_PASSWORD:$WEB_PASSWORD"
65                         shift
66                         if [ $# -eq 2 ];then
67                                 VARIABLES="$VARIABLES -v HOSTS_PREFIX:$1"
68                         fi
69                         # copy the .kube/config into the robot container
70                         kubectl -n $NAMESPACE cp /root/.kube/config $POD:/root/.kube/config
71                         shift
72                         ;;
73         *)
74                         usage
75                         exit
76         esac
77 done
78
79 set -x
80
81
82 ETEHOME=/var/opt/RIC
83
84 export GLOBAL_BUILD_NUMBER=$(kubectl --namespace $NAMESPACE exec  ${POD}  -- bash -c "ls -1q /share/logs/ | wc -l")
85 OUTPUT_FOLDER=$(printf %04d $GLOBAL_BUILD_NUMBER)_demo_$key
86 DISPLAY_NUM=$(($GLOBAL_BUILD_NUMBER + 90))
87
88 VARIABLEFILES="-V /share/config/vm_properties.py -V /share/config/integration_robot_properties.py -V /share/config/integration_preload_parameters.py"
89
90 kubectl --namespace $NAMESPACE exec ${POD} -- ${ETEHOME}/runTags.sh ${VARIABLEFILES} ${VARIABLES} -d /share/logs/${OUTPUT_FOLDER} -i ${TAG} --display $DISPLAY_NUM 2> ${TAG}.out
91