Add a new replica table in clampacm database in db migrator
[policy/docker.git] / csit / start-s3p-tests.sh
1 #!/bin/bash
2 # ============LICENSE_START=======================================================
3 #  Copyright (C) 2023 Nordix Foundation. All rights reserved.
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 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
19
20 # This script will be used to automatically trigger the S3P
21 # tests for policy components.
22
23 # Start Kubernetes
24 function start_kubernetes() {
25   bash run-k8s-csit.sh install
26   bash resources/scripts/get-cluster-info.sh
27 }
28
29 function install_jmeter() {
30
31   #NOTE: $TESTDIR is set by the component triggering this script
32   cd ${TESTDIR}/automate-performance
33
34   sudo apt-get update
35
36   # Install curl
37   sudo apt install curl -y
38
39   # Install JDK
40   sudo apt install -y default-jdk
41
42   # Install JMeter
43   curl -O https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.6.2.tgz
44   tar -xvf apache-jmeter-5.6.2.tgz
45   mv apache-jmeter-5.6.2 apache-jmeter
46
47   # Define your desired heap size values
48   echo 'export JVM_ARGS="-Xms2g -Xmx4g"' > apache-jmeter/bin/setenv.sh
49   echo 'export HEAP="-Xms1G -Xmx2G -XX:MaxMetaspaceSize=512m"' >> apache-jmeter/bin/setenv.sh
50
51
52   # Remove unnecessary files
53   rm -rf apache-jmeter/docs apache-jmeter/printable_docs
54
55   # Install CMD Runner
56   cd apache-jmeter/lib
57   curl -O https://repo1.maven.org/maven2/kg/apc/cmdrunner/2.2.1/cmdrunner-2.2.1.jar
58
59   # Move JMeter to /opt
60   sudo cp -r ../../apache-jmeter /opt/
61
62   # Add JMeter Path Variable
63   export JMETER_HOME="/opt/apache-jmeter"
64   export PATH="$JMETER_HOME/bin:$PATH"
65 }
66
67 function on_exit() {
68   # TODO: Generate report
69   echo "Generating report..."
70 }
71
72 function teardown() {
73   echo "Removing temp directories.."
74
75   rm -r ${TESTDIR}/automate-performance
76
77   echo "Removed directories"
78
79   echo "Tearing down kubernetes cluster..."
80   bash run-k8s-csit.sh uninstall
81
82   # DELETE created services
83   microk8s kubectl get svc | awk '/svc/{system("microk8s kubectl delete svc " $1)}'
84 }
85
86 #===MAIN===#
87
88 if [ $1 == "run" ]
89 then
90
91   echo "==========================="
92   echo "Starting K8s Environment"
93   echo "==========================="
94   start_kubernetes
95
96   echo "==========================="
97   echo "Installing JMeter"
98   echo "==========================="
99   install_jmeter
100
101   # Run the JMX test plan
102   echo "==========================="
103   echo "Executing tests"
104   echo "==========================="
105   cd ${TESTDIR}/automate-performance || exit
106   nohup jmeter -n -t $2 -l s3pTestResults.jtl
107
108   # TODO: Generate report on on_exit()
109
110 elif [ $1 == "uninstall" ]
111 then
112   echo "Uninstalling environment and removing temp folders..."
113   teardown
114 else
115   echo "Invalid arguments provided. Usage: $0 [option..] {run | uninstall}"
116 fi