Merge "[AAI] Add model-loader tracing config"
[oom.git] / kubernetes / robot / demo-k8s.sh
1 #!/bin/sh
2
3 # Copyright (C) 2018 Amdocs, Bell Canada
4 # Modifications Copyright (C) 2019 Samsung
5 # Modifications Copyright (C) 2020 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 # Execute tags built to support the hands-on demo
20 #
21 usage ()
22 {
23     echo "Usage: demo-k8s.sh <namespace> <command> [<parameters>] [execscript]"
24     echo " "
25     echo "       demo-k8s.sh <namespace> init"
26     echo "               - Execute both init_customer + distribute + registrySynch"
27     echo " "
28     echo "       demo-k8s.sh <namespace> init_customer"
29     echo "               - Create demo customer (Demonstration) and services, etc."
30     echo " "
31     echo "       demo-k8s.sh <namespace> registrySynch [ repo  <chart name>  | path [ <path to helm charts> ]"
32     echo "               [ <chart prefix> ] ]"
33     echo "               - Synchronize chart museum inside of onap k8s cluster with"
34     echo "                 onap helm charts git repository (OOM)"
35     echo "                 By default following charts are synchronized:"
36     echo "                 - oom/kubernetes/dcaegen2-services/charts/,"
37     echo "                 - oom/kubernetes/common/common/charts,"
38     echo "                 - oom/kubernetes/common/postgres/charts/,"
39     echo "                 - oom/kubernetes/common/repositoryGenerator/charts/,"
40     echo "                 - oom/kubernetes/common/readinessCheck/charts/,"
41     echo "                 User is able also to synchronize custom helm charts by providing"
42     echo "                 flag 'path' and path to charts into command and chart name/s prefix for example:"
43     echo "                 demo-k8s.sh onap registrySynch /home/ubuntu/oom/kubernetes/common/postgres/charts/ postgres"
44     echo "               - Synchronize chart museum inside of onap k8s cluster with"
45     echo "                 onap installation server 'local' helm charts repository"
46     echo "                 By default following charts are synchronized:"
47     echo "                 - local/certInitializer"
48     echo "                 User is able also to synchronize custom helm charts by providing"
49     echo "                 flag 'repo' and chart name in 'local' repo into command for example:"
50     echo "                 demo-k8s.sh onap registrySynch repo certInitializer"
51     echo " "
52     echo "       demo-k8s.sh <namespace> distribute  [<prefix>]"
53     echo "               - Distribute demo models (demoVFW and demoVLB)"
54     echo " "
55     echo "       demo-k8s.sh <namespace> preload <vnf_name> <module_name>"
56     echo "               - Preload data for VNF for the <module_name>"
57     echo " "
58     echo "       demo-k8s.sh <namespace> init_robot [ <etc_hosts_prefix> ]"
59     echo "               - Initialize robot after all ONAP VMs have started"
60     echo " "
61     echo "       demo-k8s.sh <namespace> instantiateVFW"
62     echo "               - Instantiate vFW module for the demo customer (DemoCust<uuid>)"
63     echo " "
64     echo "       demo-k8s.sh <namespace> instantiateVFWdirectso  csar_filename"
65     echo "               - Instantiate vFW module using direct SO interface using previously distributed model "
66     echo "                 that is in /tmp/csar in robot container"
67     echo " "
68     echo "       demo-k8s.sh <namespace> instantiateVLB_CDS"
69     echo "               - Instantiate vLB module using CDS with a preloaded CBA "
70     echo " "
71     echo "       demo-k8s.sh <namespace> deleteVNF <module_name from instantiateVFW>"
72     echo "               - Delete the module created by instantiateVFW"
73     echo " "
74     echo "       demo-k8s.sh <namespace> vfwclosedloop <pgn-ip-address>"
75     echo "               - vFWCL: Sets the packet generator to high and low rates, and checks whether the policy "
76     echo "                 kicks in to modulate the rates back to medium"
77     echo " "
78     echo "       demo-k8s.sh <namespace> <command> [<parameters>] execscript"
79     echo "               - Optional parameter to execute user custom scripts located in scripts/demoscript directory"
80     echo " "
81 }
82
83 # Check if execscript flag is used and drop it from input arguments
84
85 if [ "${!#}" = "execscript" ]; then
86         set -- "${@:1:$#-1}"
87         execscript=true
88 fi
89
90 # Set the defaults
91
92 echo "Number of parameters:"
93 echo $#
94
95 if [ $# -lt 2 ]; then
96     usage
97     exit
98 fi
99
100 NAMESPACE=$1
101 shift
102
103 ##
104 ## if more than 1 tag is supplied, the must be provided with -i or -e
105 ##
106 while [ $# -gt 0 ]
107 do
108     key="$1"
109         echo "KEY:"
110         echo $key
111
112     case $key in
113         init_robot)
114             TAG="UpdateWebPage"
115             echo "WEB Site Password for user 'test': "
116             stty -echo
117             read WEB_PASSWORD
118             stty echo
119             if [ "$WEB_PASSWORD" = "" ]; then
120                 echo ""
121                 echo "WEB Password is required for user 'test'"
122                 exit
123             fi
124             VARIABLES="$VARIABLES -v WEB_PASSWORD:$WEB_PASSWORD"
125             shift
126             if [ $# -eq 2 ];then
127                 VARIABLES="$VARIABLES -v HOSTS_PREFIX:$1"
128             fi
129             shift
130             ;;
131         init)
132             TAG="InitDemo"
133             dcaeRegistrySynch=true
134             shift
135             ;;
136         vescollector)
137             TAG="vescollector"
138             shift
139             ;;
140         distribute_vcpe)
141             TAG="distributeVCPE"
142             shift
143             ;;
144         init_customer)
145             TAG="InitCustomer"
146             shift
147             ;;
148         distribute)
149             TAG="InitDistribution"
150             shift
151             if [ $# -eq 1 ];then
152                 VARIABLES="$VARIABLES -v DEMO_PREFIX:$1"
153             fi
154             shift
155             ;;
156         preload)
157             TAG="PreloadDemo"
158             shift
159             if [ $# -ne 2 ];then
160                 echo "Usage: demo-k8s.sh <namespace> preload <vnf_name> <module_name>"
161                 exit
162             fi
163             VARIABLES="$VARIABLES -v VNF_NAME:$1"
164             shift
165             VARIABLES="$VARIABLES -v MODULE_NAME:$1"
166             shift
167             ;;
168         instantiateVFW)
169             TAG="instantiateVFW"
170             VARIABLES="$VARIABLES -v GLOBAL_BUILD_NUMBER:$$"
171             shift
172             ;;
173         instantiateVFWdirectso)
174                         TAG="instantiateVFWdirectso"
175                         shift
176                         if [ $# -ne 1 ];then
177                                         echo "Usage: demo-k8s.sh <namespace> instantiateVFWdirectso <csar_filename>"
178                                         exit
179                                 fi
180                         VARIABLES="$VARIABLES -v CSAR_FILE:$1 -v GLOBAL_BUILD_NUMBER:$$"
181                         shift
182                         ;;
183         instantiateVLB_CDS)
184                         TAG="instantiateVLB_CDS"
185                         VARIABLES="$VARIABLES -v GLOBAL_BUILD_NUMBER:$$"
186                         shift
187                         ;;
188         deleteVNF)
189             TAG="deleteVNF"
190             shift
191             if [ $# -ne 1 ];then
192                 echo "Usage: demo-k8s.sh <namespace> deleteVNF <module_name from instantiateVFW>"
193                 exit
194             fi
195             VARFILE=$1.py
196             VARIABLES="$VARIABLES -V /share/${VARFILE}"
197             shift
198             ;;
199         cds)
200             TAG="cds"
201             shift
202             ;;
203         distributeVFWNG)
204                         TAG="distributeVFWNG"
205                         shift
206                         ;;
207         distributeDemoVFWDT)
208                         TAG="DistributeDemoVFWDT"
209                         shift
210                         ;;
211         instantiateDemoVFWDT)
212                         TAG="instantiateVFWDT"
213                         shift
214                         ;;
215         vfwclosedloop)
216                         TAG="vfwclosedloop"
217                         shift
218                         VARIABLES="$VARIABLES -v PACKET_GENERATOR_HOST:$1 -v pkg_host:$1"
219                         shift
220                         ;;
221        registrySynch)
222                         dcaeRegistrySynch=true
223                         echo $dcaeRegistrySynch
224                         shift
225                         echo $1
226                         if [ "$1" = "path"  ]; then
227                           shift
228                           customHelmChartsPath=$1
229                           shift
230                           customHelmChartsPref=$1
231                           shift
232                         elif [ "$1" = "repo"  ]; then
233                           shift
234                           customHelmChartFromLocalRepo=$1
235                           echo $customHelmChartFromLocalRepo
236                           shift
237                         else
238                           echo "demo-k8s.sh <namespace> registrySynch { repo  <chart name>  | path [ <path to helm charts> ] [ <chart prefix> ] }"
239                         fi
240                         ;;
241         *)
242             usage
243             exit
244     esac
245 done
246
247 set -x
248
249 POD=$(kubectl --namespace $NAMESPACE get pods | sed 's/ .*//'| grep robot)
250 HELM_RELEASE=$(kubectl --namespace onap get pods | sed 's/ .*//' | grep robot | sed 's/-.*//')
251
252 DIR=$(dirname "$0")
253 SCRIPTDIR=scripts/demoscript
254
255 ETEHOME=/var/opt/ONAP
256
257 if [ $execscript ]; then
258    for script in $(ls -1 "$DIR/$SCRIPTDIR"); do
259       [ -f "$DIR/$SCRIPTDIR/$script" ] && [ -x "$DIR/$SCRIPTDIR/$script" ] && . "$DIR/$SCRIPTDIR/$script"
260    done
261 fi
262
263 export GLOBAL_BUILD_NUMBER=$(kubectl --namespace $NAMESPACE exec  ${POD}  -- sh -c "ls -1q /share/logs/ | wc -l")
264 OUTPUT_FOLDER=$(printf %04d $GLOBAL_BUILD_NUMBER)_demo_$key
265 DISPLAY_NUM=$(($GLOBAL_BUILD_NUMBER + 90))
266
267 if [ $dcaeRegistrySynch ]; then
268    CURRENT_DIR=$PWD
269    PARENT_PATH=${0%/*}
270    cd $PARENT_PATH
271    cd ../contrib/tools
272    if [ -n "$customHelmChartsPath"  ]; then
273      ./registry-initialize.sh -d $customHelmChartsPath -n $NAMESPACE -r $HELM_RELEASE -p customHelmChartsPref
274    elif [ -n "$customHelmChartFromLocalRepo"  ]; then
275      ./registry-initialize.sh -h $customHelmChartFromLocalRepo -n $NAMESPACE -r $HELM_RELEASE
276    else
277      ./registry-initialize.sh -d ../../dcaegen2-services/charts/ -n $NAMESPACE -r $HELM_RELEASE
278      ./registry-initialize.sh -d ../../dcaegen2-services/charts/ -n $NAMESPACE -r $HELM_RELEASE -p common
279      ./registry-initialize.sh -h certInitializer -n $NAMESPACE -r $HELM_RELEASE
280      ./registry-initialize.sh -h repositoryGenerator -n $NAMESPACE -r $HELM_RELEASE
281      ./registry-initialize.sh -h readinessCheck -n $NAMESPACE -r $HELM_RELEASE
282      ./registry-initialize.sh -h dcaegen2-services-common -n $NAMESPACE -r $HELM_RELEASE
283      ./registry-initialize.sh -h postgres -n $NAMESPACE -r $HELM_RELEASE
284      ./registry-initialize.sh -h serviceAccount -n $NAMESPACE -r $HELM_RELEASE
285      ./registry-initialize.sh -h mongo -n $NAMESPACE -r $HELM_RELEASE
286      ./registry-initialize.sh -h common -n $NAMESPACE -r $HELM_RELEASE
287    fi
288    cd $CURRENT_DIR
289 fi
290
291 if [ -n "$TAG" ]; then
292   VARIABLEFILES="-V /share/config/robot_properties.py"
293   kubectl --namespace $NAMESPACE exec ${POD} -- ${ETEHOME}/runTags.sh ${VARIABLEFILES} ${VARIABLES} -d /share/logs/${OUTPUT_FOLDER} -i ${TAG} --display $DISPLAY_NUM 2> ${TAG}.out
294 fi