blob: 731657d9cec4f939ab01750476f81245cab2c36f [file] [log] [blame]
Ievgeniia Zadorozhna3a6f9e22023-05-12 18:31:28 +03001#!/bin/bash
2
3
4# Set variables
5HEAT_STACK_PREFIX=refapp
6ITERATIONS_START=1
7ITERATIONS_END=10
8LOG_FILE="./run-refapp-density-${ITERATIONS_START}-${ITERATIONS_END}.log"
9DATA_FILE="./run-refapp-density-${ITERATIONS_START}-${ITERATIONS_END}.csv"
10
11# source CVP project credentials
12source /opt/cmp-check/cvprc
13
14start_test() {
15 # Start test
16 #export OS_CLOUD=openstack
17 TEST_START_DATE=$(date +%s)
18 echo "Test started at $(date)" >> ${LOG_FILE}
19 echo "DATE;ITERATION_NUM;STACK_CREATION_DATE_DELTA;APP_REQUEST_TIME_ROOT;APP_REQUEST_TIME_POST_RECORD;APP_REQUEST_TIME_GET_RECORDS;APP_REQUEST_TIME_GET_RECORD" >> ${DATA_FILE}
20 for ITERATION_NUM in `seq ${ITERATIONS_START} ${ITERATIONS_END}`
21 do
22 STACK_CREATION_START_DATE=$(date +%s)
23 openstack stack create -t heat-templates/top.yaml ${HEAT_STACK_PREFIX}-${ITERATION_NUM} --wait | tee -a ${LOG_FILE}
24 STACK_STATUS=$(openstack stack show ${HEAT_STACK_PREFIX}-${ITERATION_NUM} -f value -c stack_status)
25 echo "$(date) ${HEAT_STACK_PREFIX}-${ITERATION_NUM} stack status is ${STACK_STATUS}" >> ${LOG_FILE}
26 STACK_CREATION_END_DATE=$(date +%s)
27 STACK_CREATION_DATE_DELTA=$((${STACK_CREATION_END_DATE} - ${STACK_CREATION_START_DATE}))
28 if [ ${STACK_STATUS} == "CREATE_COMPLETE" ]
29 then
30 APP_URL=$(openstack stack show ${HEAT_STACK_PREFIX}-${ITERATION_NUM} -f value -c outputs | jq -cr '.[] | select(.output_key | contains("app_url")) | .output_value')
31 # TODO implement awaiting for successful first curl
32 sleep 30
33 # Make sure that the app is already available
34 curl -m 60 -s -o /dev/null ${APP_URL}
35 EXIT_CODE=$(echo $?)
36 if [ ${EXIT_CODE} != 0 ]
37 then
38 echo "curl command can't reach ${APP_URL} from ${HEAT_STACK_PREFIX}-${ITERATION_NUM} stack. Exit code ${EXIT_CODE}" >> ${LOG_FILE}
39 fi
40
41 UNIQ_LB_MEMBERS_COUNT=0
42 RETRY_NUMBER=0
43 while (( ${UNIQ_LB_MEMBERS_COUNT} != 3 && ${RETRY_NUMBER} <= 600 ))
44 do
45 UNIQ_LB_MEMBERS_COUNT=$(for LB_MEMBER in {1..3}; do curl -m 10 -s ${APP_URL} | jq -r .host; done | sort | uniq | wc -l)
46 RETRY_NUMBER=$((${RETRY_NUMBER} + 1))
47 sleep 1
48 done
49 if [ ${UNIQ_LB_MEMBERS_COUNT} != 3 ]
50 then
51 echo "$(date) There are only ${UNIQ_LB_MEMBERS_COUNT} LB members instead of 3 for ${APP_URL} LB endpoint from ${HEAT_STACK_PREFIX}-${ITERATION_NUM} stack." >> ${LOG_FILE}
52 fi
53
54 APP_REQUEST_TIME_ROOT=$(curl -m 10 -s -w %{time_total} -o /dev/null ${APP_URL})
55 EXIT_CODE=$(echo $?)
56 if [ ${EXIT_CODE} != 0 ]
57 then
58 echo "curl command can't reach ${APP_URL} from ${HEAT_STACK_PREFIX}-${ITERATION_NUM} stack. Exit code ${EXIT_CODE}" >> ${LOG_FILE}
59 fi
60 APP_REQUEST_TIME_POST_RECORD=$(curl -m 10 -s -w %{time_total} -X POST -H "Content-Type: application/json" --data '{"record": {"data": "spam"}}' -o /dev/null ${APP_URL}/records)
61 EXIT_CODE=$(echo $?)
62 if [ ${EXIT_CODE} != 0 ]
63 then
64 echo "curl command can't reach ${APP_URL}/records with POST requst from ${HEAT_STACK_PREFIX}-${ITERATION_NUM} stack. Exit code ${EXIT_CODE}" >> ${LOG_FILE}
65 fi
66 APP_REQUEST_TIME_GET_RECORDS=$(curl -m 10 -s -w %{time_total} -o /dev/null ${APP_URL}/records)
67 EXIT_CODE=$(echo $?)
68 if [ ${EXIT_CODE} != 0 ]
69 then
70 echo "curl command can't reach ${APP_URL}/records from ${HEAT_STACK_PREFIX}-${ITERATION_NUM} stack. Exit code ${EXIT_CODE}" >> ${LOG_FILE}
71 fi
72 APP_REQUEST_TIME_GET_RECORD=$(curl -m 10 -s -w %{time_total} -o /dev/null ${APP_URL}/record/1)
73 EXIT_CODE=$(echo $?)
74 if [ ${EXIT_CODE} != 0 ]
75 then
76 echo "curl command can't reach ${APP_URL}/records/1 from ${HEAT_STACK_PREFIX}-${ITERATION_NUM} stack. Exit code ${EXIT_CODE}" >> ${LOG_FILE}
77 fi
78 # Write the results to CSV
79 echo "$(date);ITERATION-${ITERATION_NUM};${STACK_CREATION_DATE_DELTA};${APP_REQUEST_TIME_ROOT};${APP_REQUEST_TIME_POST_RECORD};${APP_REQUEST_TIME_GET_RECORDS};${APP_REQUEST_TIME_GET_RECORD}" >> ${DATA_FILE}
80 else
81 echo "$(date);ITERATION-${ITERATION_NUM};${STACK_STATUS}" >> ${DATA_FILE}
82 fi
83 done
84 TEST_END_DATE=$(date +%s)
85 TEST_DURATION=$((TEST_END_DATE - TEST_START_DATE))
86 echo "$(date) Full test duration is ${TEST_DURATION} seconds" >> ${LOG_FILE}
87}
88
89main() {
90 start_test
91}
92
93main