Merge "Add scripts to automate S3P tests"
[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 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.3.tgz
44   tar -xvf apache-jmeter-5.3.tgz
45
46   # Remove unnecessary files
47   rm -rf apache-jmeter-5.3/docs apache-jmeter-5.3/printable_docs
48
49   # Install CMD Runner
50   cd apache-jmeter-5.3/lib
51   curl -O https://repo1.maven.org/maven2/kg/apc/cmdrunner/2.2.1/cmdrunner-2.2.1.jar
52
53   # Install Plugin Manager
54   cd ext/
55   curl -O https://repo1.maven.org/maven2/kg/apc/jmeter-plugins-manager/1.6/jmeter-plugins-manager-1.6.jar
56
57   # Download Plugins
58   cd ..
59   java  -jar cmdrunner-2.2.1.jar --tool org.jmeterplugins.repository.PluginManagerCMD install-all-except jpgc-hadoop,jpgc-oauth,ulp-jmeter-autocorrelator-plugin,ulp-jmeter-videostreaming-plugin,ulp-jmeter-gwt-plugin,tilln-iso8583
60
61   # Move JMeter to /opt
62   sudo cp -r ../../apache-jmeter-5.3 /opt/
63
64   # Add JMeter Path Variable
65   nano .profile
66   JMETER_HOME="/opt/apache-jmeter-5.3"
67   PATH="$JMETER_HOME/bin:$PATH"
68   source ~/.profile
69 }
70
71 function on_exit() {
72   # TODO: Generate report
73   echo "Generating report..."
74 }
75
76 function teardown() {
77   echo "Removing temp directories.."
78
79   rm -r ${TESTDIR}/automate-performance
80
81   echo "Removed directories"
82
83   echo "Tearing down kubernetes cluster..."
84   bash run-k8s-csit.sh uninstall
85
86   # DELETE created services
87   microk8s kubectl get svc | awk '/svc/{system("microk8s kubectl delete svc " $1)}'
88 }
89
90 #===MAIN===#
91
92 if [ $1 == "run" ]
93 then
94
95   echo "==========================="
96   echo "Starting K8s Environment"
97   echo "==========================="
98   start_kubernetes
99
100   echo "==========================="
101   echo "Installing JMeter"
102   echo "==========================="
103   install_jmeter
104
105   # Run the JMX test plan
106   echo "==========================="
107   echo "Executing tests"
108   echo "==========================="
109   cd ${TESTDIR}/automate-performance || exit
110   nohup apache-jmeter-5.3/bin/jmeter -n -t $2 -l s3pTestResults.jtl
111
112   # TODO: Generate report on on_exit()
113
114 elif [ $1 == "uninstall" ]
115 then
116   echo "Uninstalling environment and removing temp folders..."
117   teardown
118 else
119   echo "Invalid arguments provided. Usage: $0 [option..] {run | uninstall}"
120 fi
121