[COMMON] Fix read -s, echo -e and $'...' bashisms
[oom.git] / kubernetes / robot / demo-k8s.sh
1 #!/bin/bash
2 # Copyright (C) 2018 Amdocs, Bell Canada
3 # Modifications Copyright (C) 2019 Samsung
4 # Modifications Copyright (C) 2020 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 # Execute tags built to support the hands-on demo
19 #
20 usage ()
21 {
22         echo "Usage: demo-k8s.sh <namespace> <command> [<parameters>] [execscript]"
23         echo " "
24         echo "       demo-k8s.sh <namespace> init"
25         echo "               - Execute both init_customer + distribute"
26         echo " "
27         echo "       demo-k8s.sh <namespace> init_customer"
28         echo "               - Create demo customer (Demonstration) and services, etc."
29         echo " "
30         echo "       demo-k8s.sh <namespace> distribute  [<prefix>]"
31         echo "               - Distribute demo models (demoVFW and demoVLB)"
32         echo " "
33         echo "       demo-k8s.sh <namespace> preload <vnf_name> <module_name>"
34         echo "               - Preload data for VNF for the <module_name>"
35         echo " "
36         echo "       demo-k8s.sh <namespace> appc <module_name>"
37         echo "               - provide APPC with vFW module mount point for closed loop"
38         echo " "
39         echo "       demo-k8s.sh <namespace> init_robot [ <etc_hosts_prefix> ]"
40         echo "               - Initialize robot after all ONAP VMs have started"
41         echo " "
42         echo "       demo-k8s.sh <namespace> instantiateVFW"
43         echo "               - Instantiate vFW module for the demo customer (DemoCust<uuid>)"
44         echo " "
45         echo "       demo-k8s.sh <namespace> instantiateVFWdirectso  csar_filename"
46         echo "               - Instantiate vFW module using direct SO interface using previously distributed model "
47         echo "                 that is in /tmp/csar in robot container"
48         echo " "
49         echo "       demo-k8s.sh <namespace> instantiateVLB_CDS"
50         echo "               - Instantiate vLB module using CDS with a preloaded CBA "
51         echo " "
52         echo "       demo-k8s.sh <namespace> deleteVNF <module_name from instantiateVFW>"
53         echo "               - Delete the module created by instantiateVFW"
54         echo " "
55         echo "       demo-k8s.sh <namespace> vfwclosedloop <pgn-ip-address>"
56         echo "               - vFWCL: Sets the packet generator to high and low rates, and checks whether the policy "
57         echo "                 kicks in to modulate the rates back to medium"
58         echo " "
59         echo "       demo-k8s.sh <namespace> <command> [<parameters>] execscript"
60         echo "               - Optional parameter to execute user custom scripts located in scripts/demoscript directory"
61         echo " "
62 }
63
64 # Check if execscript flag is used and drop it from input arguments
65
66 if [ "${!#}" = "execscript" ]; then
67         set -- "${@:1:$#-1}"
68         execscript=true
69 fi
70
71 # Set the defaults
72
73 echo "Number of parameters:"
74 echo $#
75
76 if [ $# -lt 2 ];then
77         usage
78         exit
79 fi
80
81 NAMESPACE=$1
82 shift
83
84 ##
85 ## if more than 1 tag is supplied, the must be provided with -i or -e
86 ##
87 while [ $# -gt 0 ]
88 do
89         key="$1"
90         echo "KEY:"
91         echo $key
92
93         case $key in
94         init_robot)
95                         TAG="UpdateWebPage"
96                         echo "WEB Site Password for user 'test': "
97                         stty -echo
98                         read WEB_PASSWORD
99                         stty echo
100                         if [ "$WEB_PASSWORD" = "" ]; then
101                                 echo ""
102                                 echo "WEB Password is required for user 'test'"
103                                 exit
104                         fi
105                         VARIABLES="$VARIABLES -v WEB_PASSWORD:$WEB_PASSWORD"
106                         shift
107                         if [ $# -eq 2 ];then
108                                 VARIABLES="$VARIABLES -v HOSTS_PREFIX:$1"
109                         fi
110                         shift
111                         ;;
112         init)
113                         TAG="InitDemo"
114                         shift
115                         ;;
116             vescollector)
117                         TAG="vescollector"
118                         shift
119                         ;;
120         distribute_vcpe)
121                         TAG="distributeVCPE"
122                         shift
123                         ;;
124         init_customer)
125                         TAG="InitCustomer"
126                         shift
127                         ;;
128         distribute)
129                         TAG="InitDistribution"
130                         shift
131                         if [ $# -eq 1 ];then
132                                 VARIABLES="$VARIABLES -v DEMO_PREFIX:$1"
133                         fi
134                         shift
135                         ;;
136         preload)
137                         TAG="PreloadDemo"
138                         shift
139                         if [ $# -ne 2 ];then
140                                 echo "Usage: demo-k8s.sh <namespace> preload <vnf_name> <module_name>"
141                                 exit
142                         fi
143                         VARIABLES="$VARIABLES -v VNF_NAME:$1"
144                         shift
145                         VARIABLES="$VARIABLES -v MODULE_NAME:$1"
146                         shift
147                         ;;
148         appc)
149                         TAG="APPCMountPointDemo"
150                         shift
151                         if [ $# -ne 1 ];then
152                                         echo "Usage: demo-k8s.sh <namespace> appc <module_name>"
153                                         exit
154                                 fi
155                         VARIABLES="$VARIABLES -v MODULE_NAME:$1"
156                         shift
157                         ;;
158         instantiateVFW)
159                         TAG="instantiateVFW"
160                         VARIABLES="$VARIABLES -v GLOBAL_BUILD_NUMBER:$$"
161                         shift
162                         ;;
163         instantiateVFWdirectso)
164                         TAG="instantiateVFWdirectso"
165                         shift
166                         if [ $# -ne 1 ];then
167                                         echo "Usage: demo-k8s.sh <namespace> instantiateVFWdirectso <csar_filename>"
168                                         exit
169                                 fi
170                         VARIABLES="$VARIABLES -v CSAR_FILE:$1 -v GLOBAL_BUILD_NUMBER:$$"
171                         shift
172                         ;;
173         instantiateVLB_CDS)
174                         TAG="instantiateVLB_CDS"
175                         VARIABLES="$VARIABLES -v GLOBAL_BUILD_NUMBER:$$"
176                         shift
177                         ;;
178         deleteVNF)
179                         TAG="deleteVNF"
180                         shift
181                         if [ $# -ne 1 ];then
182                                 echo "Usage: demo-k8s.sh <namespace> deleteVNF <module_name from instantiateVFW>"
183                                 exit
184                         fi
185                         VARFILE=$1.py
186                         VARIABLES="$VARIABLES -V /share/${VARFILE}"
187                         shift
188                         ;;
189         cds)
190                         TAG="cds"
191                         shift
192                         ;;
193         distributeVFWNG)
194                         TAG="distributeVFWNG"
195                         shift
196                         ;;
197         distributeDemoVFWDT)
198                         TAG="DistributeDemoVFWDT"
199                         shift
200                         ;;
201         instantiateDemoVFWDT)
202                         TAG="instantiateVFWDT"
203                         shift
204                         ;;
205         vfwclosedloop)
206                         TAG="vfwclosedloop"
207                         shift
208                         VARIABLES="$VARIABLES -v PACKET_GENERATOR_HOST:$1 -v pkg_host:$1"
209                         shift
210                         ;;
211         *)
212                         usage
213                         exit
214         esac
215 done
216
217 set -x
218
219 POD=$(kubectl --namespace $NAMESPACE get pods | sed 's/ .*//'| grep robot)
220
221 DIR=$(dirname "$0")
222 SCRIPTDIR=scripts/demoscript
223
224 ETEHOME=/var/opt/ONAP
225
226 if [ $execscript ]; then
227    for script in $(ls -1 "$DIR/$SCRIPTDIR"); do
228       [ -f "$DIR/$SCRIPTDIR/$script" ] && [ -x "$DIR/$SCRIPTDIR/$script" ] && . "$DIR/$SCRIPTDIR/$script"
229    done
230 fi
231
232 export GLOBAL_BUILD_NUMBER=$(kubectl --namespace $NAMESPACE exec  ${POD}  -- bash -c "ls -1q /share/logs/ | wc -l")
233 OUTPUT_FOLDER=$(printf %04d $GLOBAL_BUILD_NUMBER)_demo_$key
234 DISPLAY_NUM=$(($GLOBAL_BUILD_NUMBER + 90))
235
236 VARIABLEFILES="-V /share/config/robot_properties.py"
237
238 kubectl --namespace $NAMESPACE exec ${POD} -- ${ETEHOME}/runTags.sh ${VARIABLEFILES} ${VARIABLES} -d /share/logs/${OUTPUT_FOLDER} -i ${TAG} --display $DISPLAY_NUM 2> ${TAG}.out