github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/stability/scability_test.sh (about)

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