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