This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
/
scability_test.sh
executable file
·79 lines (65 loc) · 1.75 KB
/
scability_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
#
# Copyright (c) 2023 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
set -o pipefail
# General env
SCRIPT_PATH=$(dirname "$(readlink -f "$0")")
source "${SCRIPT_PATH}/../metrics/lib/common.bash"
NUM_CONTAINERS="$1"
TIMEOUT_LAUNCH="$2"
PAYLOAD_ARGS="${PAYLOAD_ARGS:-tail -f /dev/null}"
IMAGE="${IMAGE:-quay.io/prometheus/busybox:latest}"
# Show help about this script
help(){
cat << EOF
Usage: $0 <count> <timeout>
Description:
This script launches n number of containers.
Options:
<count> : Number of containers to run.
<timeout>: Timeout to launch the containers.
EOF
}
function check_containers_are_up() {
info "Verify that the containers are running"
local containers_launched=0
while (( "${containers_launched}" < "${NUM_CONTAINERS}" )); do
containers_launched="$(sudo ctr t list | grep -c "RUNNING")"
sleep 1
done
}
function main() {
# Verify enough arguments
if [ $# != 2 ]; then
echo >&2 "error: Not enough arguments [$@]"
help
exit 1
fi
local i=0
local containers=()
local not_started_count="${NUM_CONTAINERS}"
init_env
check_cmds "${cmds[@]}"
sudo -E ctr i pull "${IMAGE}"
info "Creating ${NUM_CONTAINERS} containers"
for ((i=1; i<= "${NUM_CONTAINERS}"; i++)); do
containers+=($(random_name))
sudo -E ctr run -d --runtime "${CTR_RUNTIME}" "${IMAGE}" "${containers[-1]}" sh -c "${PAYLOAD_ARGS}"
((not_started_count--))
info "$not_started_count remaining containers"
done
# Check that the requested number of containers are running
check_containers_are_up & pid=$!
(sleep "${TIMEOUT_LAUNCH}" && kill -HUP "${pid}") 2>/dev/null & pid_tout=$!
if wait "${pid}" 2>/dev/null; then
pkill -HUP -P "${pid_tout}"
wait "${pid_tout}"
else
warn "Time out exceeded"
return 1
fi
clean_env_ctr
}
main "$@"