2 # ============LICENSE_START=======================================================
3 # dcaegen2-collectors-veshv
4 # ================================================================================
5 # Copyright (C) 2019 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
11 # http://www.apache.org/licenses/LICENSE-2.0
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 # ============LICENSE_END=========================================================
20 SCRIPT_DIRECTORY="$(pwd "$0")"
22 PROPERTIES_FILE=${SCRIPT_DIRECTORY}/test.properties
23 CONFIG_MAP_NAME=performance-test-config
24 PRODUCER_APPS_LABEL=hv-collector-producer
25 CONSUMER_APPS_LABEL=hv-collector-kafka-consumer
26 PROMETHEUS_CONF_LABEL=prometheus-server-conf
27 PROMETHEUS_APPS_LABEL=hv-collector-prometheus
29 MAXIMUM_BACK_OFF_CHECK_ITERATIONS=30
31 NAME_REASON_PATTERN="custom-columns=NAME:.metadata.name,REASON:.status.containerStatuses[].state.waiting.reason"
34 echo "Cleaning up environment"
36 echo "Attempting to delete test parameters ConfigMap"
37 kubectl delete configmap ${CONFIG_MAP_NAME} -n ${ONAP_NAMESPACE}
39 echo "Attempting to delete prometheus ConfigMap"
40 kubectl delete configmap -l name=${PROMETHEUS_CONF_LABEL} -n ${ONAP_NAMESPACE}
42 echo "Attempting to delete prometheus deployment and service"
43 kubectl delete service,deployments -l app=${PROMETHEUS_APPS_LABEL} -n ${ONAP_NAMESPACE}
45 echo "Attempting to delete consumer deployments"
46 kubectl delete deployments -l app=${CONSUMER_APPS_LABEL} -n ${ONAP_NAMESPACE}
48 echo "Attempting to delete producer pods"
49 kubectl delete pods -l app=${PRODUCER_APPS_LABEL} -n ${ONAP_NAMESPACE}
51 echo "Environment clean up finished!"
54 function create_producers() {
56 for i in $(seq 1 ${CONTAINERS_COUNT});
58 echo "Creating ${i}/${CONTAINERS_COUNT} producer"
59 kubectl create -f producer-pod.yaml -n ${ONAP_NAMESPACE}
61 echo "Producers created"
67 echo "Run cloud based HV-VES performance test"
68 echo "Usage $0 setup|start|clean|help"
69 echo " setup : set up ConfigMap and consumers"
70 echo " start : create producers - start the performance test"
71 echo " Optional parameters:"
72 echo " --containers : number of producer containers to create (1)"
73 echo " --properties-file : path to file with benchmark properties (./test.properties)"
74 echo " clean : remove ConfigMap, HV-VES consumers and producers"
75 echo " help : print usage"
76 echo "Example invocations:"
77 echo "./cloud-based-performance-test.sh setup"
78 echo "./cloud-based-performance-test.sh start"
79 echo "./cloud-based-performance-test.sh start --containers 10"
80 echo "./cloud-based-performance-test.sh start --properties-file ~/other_test.properties"
81 echo "./cloud-based-performance-test.sh clean"
85 function setup_environment() {
86 echo "Setting up environment"
87 echo "Creating test properties ConfigMap from: $PROPERTIES_FILE"
88 kubectl create configmap ${CONFIG_MAP_NAME} --from-env-file=${PROPERTIES_FILE} -n ${ONAP_NAMESPACE}
90 echo "Creating consumer deployment"
91 kubectl apply -f consumer-deployment.yaml
93 echo "Creating ConfigMap for prometheus deployment"
94 kubectl apply -f prometheus-config-map.yaml
96 echo "Creating prometheus deployment"
97 kubectl apply -f prometheus-deployment.yaml
99 echo "Waiting for consumers to be running."
100 while [[ $(kubectl get pods -l app=${CONSUMER_APPS_LABEL} -n ${ONAP_NAMESPACE} | grep -c "unhealthy\|starting") -ne 0 ]] ; do
103 echo "Setting up environment finished!"
106 function start_performance_test() {
107 echo "Starting cloud based performance tests"
108 echo "________________________________________"
109 echo "Test configuration:"
110 echo "Producer containers count: ${CONTAINERS_COUNT}"
111 echo "Properties file path: ${PROPERTIES_FILE}"
112 echo "________________________________________"
116 echo "Waiting for producers completion"
118 COMPLETED_PRODUCERS=$(kubectl get pods -l app=${PRODUCER_APPS_LABEL} -n ${ONAP_NAMESPACE} | grep -c "Completed")
119 IMAGE_PULL_BACK_OFFS=$(kubectl get pods -l app=${PRODUCER_APPS_LABEL} -n ${ONAP_NAMESPACE} -o ${NAME_REASON_PATTERN} | grep -c "ImagePullBackOff \| ErrImagePull")
121 if [[ ${IMAGE_PULL_BACK_OFFS} -gt 0 ]]; then
122 CHECK_NUMBER=$((CHECK_NUMBER + 1))
123 if [[ ${CHECK_NUMBER} -gt ${MAXIMUM_BACK_OFF_CHECK_ITERATIONS} ]]; then
124 echo "Error: Image pull problem"
129 [[ ${COMPLETED_PRODUCERS} -eq ${CONTAINERS_COUNT} || ${CHECK_NUMBER} -gt ${MAXIMUM_BACK_OFF_CHECK_ITERATIONS} ]] && break
133 echo "Performance test finished"
137 cd ${SCRIPT_DIRECTORY}
139 if [[ $# -eq 0 ]]; then
150 while [[ $(($#)) -gt 0 ]]; do
153 CONTAINERS_COUNT=${2}
159 echo "Unknown option: ${1}"
165 start_performance_test
174 echo "Unknown action: ${arg}" >&2