Updates to usage and add directso tag
[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> instantiateVFWdirectso  csar_filename"
45         echo "               - Instantiate vFW module using direct SO interface using previously distributed model "
46         echo "                 that is in /tmp/csar in robot container"
47         echo " "
48         echo "       demo-k8s.sh <namespace> deleteVNF <module_name from instantiateVFW>"
49         echo "               - Delete the module created by instantiateVFW"
50         echo " "
51         echo "       demo-k8s.sh <namespace> heatbridge <stack_name> <service_instance_id> <service> <oam-ip-address>"
52         echo "               - Run heatbridge against the stack for the given service instance and service"
53         echo " "
54         echo "       demo-k8s.sh <namespace> vfwclosedloop <pgn-ip-address>"
55         echo "           - vFWCL: Sets the packet generator to high and low rates, and checks whether the policy "
56         echo "             kicks in to modulate the rates back to medium"
57         echo " "
58 }
59
60 # Set the defaults
61
62 echo "Number of parameters:" 
63 echo $#
64
65 if [ $# -lt 2 ];then
66         usage
67         exit
68 fi
69
70 NAMESPACE=$1
71 shift
72
73 ##
74 ## if more than 1 tag is supplied, the must be provided with -i or -e
75 ##
76 while [ $# -gt 0 ]
77 do
78         key="$1"
79         echo "KEY:"
80         echo $key
81
82         case $key in
83         init_robot)
84                         TAG="UpdateWebPage"
85                         read -s -p "WEB Site Password for user 'test': " WEB_PASSWORD
86                         if [ "$WEB_PASSWORD" = "" ]; then
87                                 echo ""
88                                 echo "WEB Password is required for user 'test'"
89                                 exit
90                         fi
91                         VARIABLES="$VARIABLES -v WEB_PASSWORD:$WEB_PASSWORD"
92                         shift
93                         if [ $# -eq 2 ];then
94                                 VARIABLES="$VARIABLES -v HOSTS_PREFIX:$1"
95                         fi
96                         shift
97                         ;;
98         init)
99                         TAG="InitDemo"
100                         shift
101                         ;;
102         init_customer)
103                         TAG="InitCustomer"
104                         shift
105                         ;;
106         distribute)
107                         TAG="InitDistribution"
108                         shift
109                         if [ $# -eq 1 ];then
110                                 VARIABLES="$VARIABLES -v DEMO_PREFIX:$1"
111                         fi
112                         shift
113                         ;;
114         preload)
115                         TAG="PreloadDemo"
116                         shift
117                         if [ $# -ne 2 ];then
118                                 echo "Usage: demo-k8s.sh <namespace> preload <vnf_name> <module_name>"
119                                 exit
120                         fi
121                         VARIABLES="$VARIABLES -v VNF_NAME:$1"
122                         shift
123                         VARIABLES="$VARIABLES -v MODULE_NAME:$1"
124                         shift
125                         ;;
126         appc)
127                         TAG="APPCMountPointDemo"
128                         shift
129                         if [ $# -ne 1 ];then
130                                         echo "Usage: demo-k8s.sh <namespace> appc <module_name>"
131                                         exit
132                                 fi
133                         VARIABLES="$VARIABLES -v MODULE_NAME:$1"
134                         shift
135                         ;;
136         instantiateVFW)
137                         TAG="instantiateVFW"
138                         VARIABLES="$VARIABLES -v GLOBAL_BUILD_NUMBER:$$"
139                         shift
140                         ;;
141         instantiateVFWdirectso)
142                         TAG="instantiateVFWdirectso"
143                         shift
144                         if [ $# -ne 1 ];then
145                                         echo "Usage: demo-k8s.sh <namespace> instantiateVFWdirectso <csar_filename>"
146                                         exit
147                                 fi
148                         VARIABLES="$VARIABLES -v CSAR_FILE:$1 -v GLOBAL_BUILD_NUMBER:$$"
149                         shift
150                         ;;
151         deleteVNF)
152                         TAG="deleteVNF"
153                         shift
154                         if [ $# -ne 1 ];then
155                                 echo "Usage: demo-k8s.sh <namespace> deleteVNF <module_name from instantiateVFW>"
156                                 exit
157                         fi
158                         VARFILE=$1.py
159                         if [ -e /opt/eteshare/${VARFILE} ]; then
160                                 VARIABLES="$VARIABLES -V /share/${VARFILE}"
161                         else
162                                 echo "Cache file ${VARFILE} is not found"
163                                 exit
164                         fi
165                         shift
166                         ;;
167         heatbridge)
168                         TAG="heatbridge"
169                         shift
170                         if [ $# -ne 4 ];then
171                                 echo "Usage: demo-k8s.sh <namespace> heatbridge <stack_name> <service_instance_id> <service> <oam-ip-address>"
172                                 exit
173                         fi
174                         VARIABLES="$VARIABLES -v HB_STACK:$1"
175                         shift
176                         VARIABLES="$VARIABLES -v HB_SERVICE_INSTANCE_ID:$1"
177                         shift
178                         VARIABLES="$VARIABLES -v HB_SERVICE:$1"
179                         shift
180                         VARIABLES="$VARIABLES -v HB_IPV4_OAM_ADDRESS:$1"
181                         shift
182                         ;;
183         cds)
184                         TAG="cds"
185                         shift
186                         ;;
187         distributeVFWNG)
188                         TAG="distributeVFWNG"
189                         shift
190                         ;;
191         distributeDemoVFWDT)
192                         TAG="DistributeDemoVFWDT"
193                         shift
194                         ;;
195         instantiateDemoVFWDT)
196                         TAG="instantiateVFWDT"
197                         shift
198                         ;;
199         vfwclosedloop)
200                         TAG="vfwclosedloop"
201                         shift
202                         VARIABLES="$VARIABLES -v pkg_host:$1"
203                         shift
204                         ;;
205         *)
206                         usage
207                         exit
208         esac
209 done
210
211 set -x
212
213 POD=$(kubectl --namespace $NAMESPACE get pods | sed 's/ .*//'| grep robot)
214
215 ETEHOME=/var/opt/ONAP
216
217 export GLOBAL_BUILD_NUMBER=$(kubectl --namespace $NAMESPACE exec  ${POD}  -- bash -c "ls -1q /share/logs/ | wc -l")
218 OUTPUT_FOLDER=$(printf %04d $GLOBAL_BUILD_NUMBER)_demo_$key
219 DISPLAY_NUM=$(($GLOBAL_BUILD_NUMBER + 90))
220
221 VARIABLEFILES="-V /share/config/vm_properties.py -V /share/config/integration_robot_properties.py -V /share/config/integration_preload_parameters.py"
222
223 kubectl --namespace $NAMESPACE exec ${POD} -- ${ETEHOME}/runTags.sh ${VARIABLEFILES} ${VARIABLES} -d /share/logs/${OUTPUT_FOLDER} -i ${TAG} --display $DISPLAY_NUM 2> ${TAG}.out
224