Fix script name in usage output
[oom.git] / kubernetes / robot / demo-k8s.sh
1 #!/bin/bash
2 # Copyright (C) 2018 Amdocs, Bell Canada
3 # Modifications Copyright (C) 2019 Samsung
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # Execute tags built to support the hands-on demo
18 #
19 function usage
20 {
21         echo "Usage: demo-k8s.sh <namespace> <command> [<parameters>]"
22         echo " "
23         echo "       demo-k8s.sh <namespace> init"
24         echo "               - Execute both init_customer + distribute"
25         echo " "
26         echo "       demo-k8s.sh <namespace> init_customer"
27         echo "               - Create demo customer (Demonstration) and services, etc."
28         echo " "
29         echo "       demo-k8s.sh <namespace> distribute  [<prefix>]"
30         echo "               - Distribute demo models (demoVFW and demoVLB)"
31         echo " "
32         echo "       demo-k8s.sh <namespace> preload <vnf_name> <module_name>"
33         echo "               - Preload data for VNF for the <module_name>"
34         echo " "
35         echo "       demo-k8s.sh <namespace> appc <module_name>"
36         echo "               - provide APPC with vFW module mount point for closed loop"
37         echo " "
38         echo "       demo-k8s.sh <namespace> init_robot [ <etc_hosts_prefix> ]"
39         echo "               - Initialize robot after all ONAP VMs have started"
40         echo " "
41         echo "       demo-k8s.sh <namespace> instantiateVFW"
42         echo "               - Instantiate vFW module for the demo customer (DemoCust<uuid>)"
43         echo " "
44         echo "       demo-k8s.sh <namespace> deleteVNF <module_name from instantiateVFW>"
45         echo "               - Delete the module created by instantiateVFW"
46         echo " "
47         echo "       demo-k8s.sh <namespace> heatbridge <stack_name> <service_instance_id> <service> <oam-ip-address>"
48         echo "               - Run heatbridge against the stack for the given service instance and service"
49         echo " "
50         echo "       demo-k8s.sh <namespace> vfwclosedloop <pgn-ip-address>"
51         echo "           - vFWCL: Sets the packet generator to high and low rates, and checks whether the policy "
52         echo "             kicks in to modulate the rates back to medium"
53         echo " "
54 }
55
56 # Set the defaults
57
58 echo "Number of parameters:" 
59 echo $#
60
61 if [ $# -lt 2 ];then
62         usage
63         exit
64 fi
65
66 NAMESPACE=$1
67 shift
68
69 ##
70 ## if more than 1 tag is supplied, the must be provided with -i or -e
71 ##
72 while [ $# -gt 0 ]
73 do
74         key="$1"
75         echo "KEY:"
76         echo $key
77
78         case $key in
79         init_robot)
80                         TAG="UpdateWebPage"
81                         read -s -p "WEB Site Password for user 'test': " WEB_PASSWORD
82                         if [ "$WEB_PASSWORD" = "" ]; then
83                                 echo ""
84                                 echo "WEB Password is required for user 'test'"
85                                 exit
86                         fi
87                         VARIABLES="$VARIABLES -v WEB_PASSWORD:$WEB_PASSWORD"
88                         shift
89                         if [ $# -eq 2 ];then
90                                 VARIABLES="$VARIABLES -v HOSTS_PREFIX:$1"
91                         fi
92                         shift
93                         ;;
94         init)
95                         TAG="InitDemo"
96                         shift
97                         ;;
98         init_customer)
99                         TAG="InitCustomer"
100                         shift
101                         ;;
102         distribute)
103                         TAG="InitDistribution"
104                         shift
105                         if [ $# -eq 1 ];then
106                                 VARIABLES="$VARIABLES -v DEMO_PREFIX:$1"
107                         fi
108                         shift
109                         ;;
110         preload)
111                         TAG="PreloadDemo"
112                         shift
113                         if [ $# -ne 2 ];then
114                                 echo "Usage: demo-k8s.sh <namespace> preload <vnf_name> <module_name>"
115                                 exit
116                         fi
117                         VARIABLES="$VARIABLES -v VNF_NAME:$1"
118                         shift
119                         VARIABLES="$VARIABLES -v MODULE_NAME:$1"
120                         shift
121                         ;;
122         appc)
123                         TAG="APPCMountPointDemo"
124                         shift
125                         if [ $# -ne 1 ];then
126                                         echo "Usage: demo-k8s.sh <namespace> appc <module_name>"
127                                         exit
128                                 fi
129                         VARIABLES="$VARIABLES -v MODULE_NAME:$1"
130                         shift
131                         ;;
132         instantiateVFW)
133                         TAG="instantiateVFW"
134                         VARIABLES="$VARIABLES -v GLOBAL_BUILD_NUMBER:$$"
135                         shift
136                         ;;
137         deleteVNF)
138                         TAG="deleteVNF"
139                         shift
140                         if [ $# -ne 1 ];then
141                                 echo "Usage: demo-k8s.sh <namespace> deleteVNF <module_name from instantiateVFW>"
142                                 exit
143                         fi
144                         VARFILE=$1.py
145                         if [ -e /opt/eteshare/${VARFILE} ]; then
146                                 VARIABLES="$VARIABLES -V /share/${VARFILE}"
147                         else
148                                 echo "Cache file ${VARFILE} is not found"
149                                 exit
150                         fi
151                         shift
152                         ;;
153         heatbridge)
154                         TAG="heatbridge"
155                         shift
156                         if [ $# -ne 4 ];then
157                                 echo "Usage: demo-k8s.sh <namespace> heatbridge <stack_name> <service_instance_id> <service> <oam-ip-address>"
158                                 exit
159                         fi
160                         VARIABLES="$VARIABLES -v HB_STACK:$1"
161                         shift
162                         VARIABLES="$VARIABLES -v HB_SERVICE_INSTANCE_ID:$1"
163                         shift
164                         VARIABLES="$VARIABLES -v HB_SERVICE:$1"
165                         shift
166                         VARIABLES="$VARIABLES -v HB_IPV4_OAM_ADDRESS:$1"
167                         shift
168                         ;;
169         cds)
170                         TAG="cds"
171                         shift
172                         ;;
173         distributeVFWNG)
174                         TAG="distributeVFWNG"
175                         shift
176                         ;;
177         distributeDemoVFWDT)
178                         TAG="DistributeDemoVFWDT"
179                         shift
180                         ;;
181         instantiateDemoVFWDT)
182                         TAG="instantiateVFWDT"
183                         shift
184                         ;;
185         vfwclosedloop)
186                         TAG="vfwclosedloop"
187                         shift
188                         VARIABLES="$VARIABLES -v pkg_host:$1"
189                         shift
190                         ;;
191         *)
192                         usage
193                         exit
194         esac
195 done
196
197 set -x
198
199 POD=$(kubectl --namespace $NAMESPACE get pods | sed 's/ .*//'| grep robot)
200
201 ETEHOME=/var/opt/ONAP
202
203 export GLOBAL_BUILD_NUMBER=$(kubectl --namespace $NAMESPACE exec  ${POD}  -- bash -c "ls -1q /share/logs/ | wc -l")
204 OUTPUT_FOLDER=$(printf %04d $GLOBAL_BUILD_NUMBER)_demo_$key
205 DISPLAY_NUM=$(($GLOBAL_BUILD_NUMBER + 90))
206
207 VARIABLEFILES="-V /share/config/vm_properties.py -V /share/config/integration_robot_properties.py -V /share/config/integration_preload_parameters.py"
208
209 kubectl --namespace $NAMESPACE exec ${POD} -- ${ETEHOME}/runTags.sh ${VARIABLEFILES} ${VARIABLES} -d /share/logs/${OUTPUT_FOLDER} -i ${TAG} --display $DISPLAY_NUM 2> ${TAG}.out
210