From 17188bb0419adfec836a4627aceee92b03309504 Mon Sep 17 00:00:00 2001 From: vitaly4n Date: Mon, 16 Sep 2024 21:15:13 +0300 Subject: [PATCH] remove automation scripts --- performance-test/automation/_agent_create.sh | 190 ----------------- performance-test/automation/_agent_delete.sh | 115 ----------- .../automation/_compose_test_create_args.sh | 180 ---------------- performance-test/automation/_functions.sh | 155 -------------- performance-test/automation/_test_check.sh | 117 ----------- performance-test/automation/_test_run.sh | 194 ------------------ performance-test/automation/_variables.sh | 169 --------------- performance-test/automation/agent.sh | 120 ----------- .../automation/default_check_report.sh | 35 ---- .../automation/default_check_summary.sh | 14 -- performance-test/automation/s3_upload.sh | 28 --- performance-test/automation/test.sh | 138 ------------- 12 files changed, 1455 deletions(-) delete mode 100755 performance-test/automation/_agent_create.sh delete mode 100755 performance-test/automation/_agent_delete.sh delete mode 100755 performance-test/automation/_compose_test_create_args.sh delete mode 100755 performance-test/automation/_functions.sh delete mode 100755 performance-test/automation/_test_check.sh delete mode 100755 performance-test/automation/_test_run.sh delete mode 100755 performance-test/automation/_variables.sh delete mode 100755 performance-test/automation/agent.sh delete mode 100755 performance-test/automation/default_check_report.sh delete mode 100755 performance-test/automation/default_check_summary.sh delete mode 100755 performance-test/automation/s3_upload.sh delete mode 100755 performance-test/automation/test.sh diff --git a/performance-test/automation/_agent_create.sh b/performance-test/automation/_agent_create.sh deleted file mode 100755 index dc5aa769b..000000000 --- a/performance-test/automation/_agent_create.sh +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail - -# shellcheck disable=SC2155 -export _SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) - -# shellcheck source=_functions.sh -source "$_SCRIPT_DIR/_functions.sh" - -# shellcheck source=_variables.sh -source "$_SCRIPT_DIR/_variables.sh" - -# ---------------------------------------------------------------------------- # -# Retrieve arguments from command line # -# ---------------------------------------------------------------------------- # - -_ARGS=() -while [[ $# -gt 0 ]]; do - case "$1" in - -h | --help) - echo "Usage: $(basename "$0") [ARG]..." - echo "" - echo "Create an agent and wait until it is READY_FOR_TEST" - echo "" - echo "Provided arguments are passed to 'yc loadtesting agent create [ARG]...' as is." - echo "If missing, some argument values are defaulted YC_LT_* environment variables." - exit 0 - ;; - --service-account-id) - VAR_AGENT_SA_ID=$2 - shift - shift - ;; - --name) - _AGENT_NAME=$2 - shift - shift - ;; - --description) - VAR_AGENT_DESCRIPTION=$2 - shift - shift - ;; - --labels) - VAR_AGENT_LABELS=$2 - shift - shift - ;; - --zone) - VAR_AGENT_ZONE=$2 - shift - shift - ;; - --cores) - VAR_AGENT_CORES=$2 - shift - shift - ;; - --memory) - VAR_AGENT_MEMORY=$2 - shift - shift - ;; - --network-interface) - VAR_AGENT_SUBNET_ID= - VAR_AGENT_SECURITY_GROUP_IDS= - _ARGS+=(--network-interface "$2") - shift - shift - ;; - --) - shift - ;; - *) - _ARGS+=("$1") - shift - ;; - esac -done - -assert_installed yc jq -assert_not_empty YC_LT_AGENT_SA_ID -assert_not_empty YC_LT_AGENT_SUBNET_ID -assert_not_empty YC_LT_AGENT_SECURITY_GROUP_IDS - -if [[ -z "$_AGENT_NAME" ]]; then - _AGENT_NAME="$VAR_AGENT_NAME_PREFIX$(rand_str)" -fi - -# ---------------------------------------------------------------------------- # -# Assert variables # -# ---------------------------------------------------------------------------- # - -if [[ -z "${VAR_FOLDER_ID:-$(yc_ config get folder-id)}" ]]; then - _log "Folder ID must be specified either via YC_LT_FOLDER_ID or via CLI profile." - exit 1 -fi - -# ---------------------------------------------------------------------------- # -# Compose command line options # -# ---------------------------------------------------------------------------- # - -if [[ -n $_AGENT_NAME ]]; then - _ARGS+=(--name "$_AGENT_NAME") -fi -if [[ -n $VAR_AGENT_SA_ID ]]; then - _ARGS+=(--service-account-id "$VAR_AGENT_SA_ID") -fi -if [[ -n $VAR_AGENT_DESCRIPTION ]]; then - _ARGS+=(--description "$VAR_AGENT_DESCRIPTION") -fi -if [[ -n $VAR_AGENT_LABELS ]]; then - _ARGS+=(--labels "$VAR_AGENT_LABELS") -fi -if [[ -n $VAR_AGENT_ZONE ]]; then - _ARGS+=(--zone "$VAR_AGENT_ZONE") -fi -if [[ -n $VAR_AGENT_CORES ]]; then - _ARGS+=(--cores "$VAR_AGENT_CORES") -fi -if [[ -n $VAR_AGENT_MEMORY ]]; then - _ARGS+=(--memory "$VAR_AGENT_MEMORY") -fi -if [[ -n ${VAR_AGENT_SUBNET_ID} || -n ${VAR_AGENT_SECURITY_GROUP_IDS} ]]; then - _ARGS+=(--network-interface) - _ARGS+=("subnet-id=$VAR_AGENT_SUBNET_ID,security-group-ids=$VAR_AGENT_SECURITY_GROUP_IDS") -fi - -# ---------------------------------------------------------------------------- # -# Create an agent # -# ---------------------------------------------------------------------------- # - -_log_stage "[$_AGENT_NAME]" -_log_push_stage "[CREATE]" - -_log "Creating..." - -if ! _agent=$(yc_lt agent create "${_ARGS[@]}"); then - _log "Failed to create an agent. $_agent" - exit 1 -fi - -_agent_id=$(echo "$_agent" | jq -r '.id') -_log "Agent created. id=$_agent_id" - -# ---------------------------------------------------------------------------- # -# Wait until agent is READY_FOR_TEST # -# ---------------------------------------------------------------------------- # - -_log_stage "[WAIT]" -_log "Waiting for agent to be ready..." - -_TICK="5" -_TIMEOUT="600" - -_ts_start=$(date +%s) -_ts_timeout=$((_ts_start + _TIMEOUT)) -while [ "$(date +%s)" -lt $_ts_timeout ]; do - _elapsed=$(($(date +%s) - _ts_start)) - - if ! _status=$(yc_lt agent get "$_agent_id" | jq -r '.status'); then - _log "Failed to get agent status" - sleep "$_TICK" - continue - fi - - if [[ "$_status" == "READY_FOR_TEST" ]]; then - _log_stage "[READY]" - _logv 1 "Wow! Just ${_elapsed}s!" - _log "READY_FOR_TEST" - - echo "$_agent_id" - exit 0 - fi - - if ((_elapsed % (_TICK * 6) == 0)); then - _logv 1 "${_elapsed}s passed. Status is $_status. Waiting..." - fi - - _logv 2 "$_status. Next check in ${_TICK}s" - sleep "$_TICK" -done - -echo "$_agent_id" - -_log_stage "[WAIT_FAILED]" -_log "STATUS=$_status. Timeout of ${_TIMEOUT}s exceeded" -_log "Agent is not ready and likely cant be used in tests!" -exit 1 diff --git a/performance-test/automation/_agent_delete.sh b/performance-test/automation/_agent_delete.sh deleted file mode 100755 index 0c5fa7cfb..000000000 --- a/performance-test/automation/_agent_delete.sh +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail - -# shellcheck disable=SC2155 -export _SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) - -# shellcheck source=_functions.sh -source "$_SCRIPT_DIR/_functions.sh" - -# shellcheck source=_variables.sh -source "$_SCRIPT_DIR/_variables.sh" - -# ---------------------------------------------------------------------------- # -# Retrieve arguments from command line # -# ---------------------------------------------------------------------------- # - -_NAME_SUBSTRING="$VAR_AGENT_NAME_PREFIX" -_LABELS="$VAR_AGENT_LABELS" -_IDS=() -while [[ $# -gt 0 ]]; do - case "$1" in - -h | --help) - echo "Usage: $(basename "$0") [--name-substring] [--labels LABELS] [ID1 [...IDN]]" - echo "" - echo "Delete agents matching given parameters." - echo " --name-substring NAME_SUBSTRING - delete agents with name containing this substring [default env YC_LT_AGENT_NAME_PREFIX]" - echo " --labels KEY1=VAL1[,KEYN=VALN] - delete agents with these labels [default env YC_LT_AGENT_LABELS]" - echo " ID1 [...IDN] - agent's id must be one of the specified" - exit 0 - ;; - --name-substring) - _NAME_SUBSTRING=$2 - shift - shift - ;; - --labels) - _LABELS=$2 - shift - shift - ;; - *) - _IDS+=("$1") - shift - ;; - esac -done - -assert_installed yc jq curl - -if [[ -z $_NAME_SUBSTRING && -z $_LABELS && -z ${_IDS[*]} ]]; then - _log "Cannot pick an agent to delete. At least one of arguments must be specified." - exit 1 -fi - -# ---------------------------------------------------------------------------- # -# Compose filter # -# ---------------------------------------------------------------------------- # - -_filters=() -if [[ -n $_NAME_SUBSTRING ]]; then - _filters+=("name contains \"$_NAME_SUBSTRING\"") -fi -if [[ -n $_LABELS ]]; then - IFS=',' read -ra _labels_arr <<<"$_LABELS" - for _kv in "${_labels_arr[@]}"; do - IFS='=' read -r _key _value <<<"$_kv" - _filters+=("labels.$_key = \"$_value\"") - done -fi -if [[ -n ${_IDS[*]} ]]; then - _joined=$(IFS=','; echo "${_IDS[*]}") - _filter+=("id in ($_joined)") -fi - -_filter_str='' -for _f in "${_filters[@]}"; do - if [[ -n $_filter_str ]]; then - _filter_str="$_filter_str and $_f" - else - _filter_str="$_f" - fi -done - -if [[ -z $_filter_str ]]; then - _log "Error! Filter is empty" - exit 1 -fi - -_log "Filter: $_filter_str" - -# ---------------------------------------------------------------------------- # -# Determine which agents should be deleted # -# ---------------------------------------------------------------------------- # - -_log "Determining which agents to be deleted..." - - -_delete_ids=() -IFS=' ' read -ra _delete_ids < \ - <(yc_lt agent list --filter "$_filter_str" | jq -r '[.[].id] | join(" ")') - -if [[ ${#_delete_ids} -eq 0 ]]; then - _log "No agents were found for given filter" - exit 0 -fi - -_log "Agents to be deleted: ${_delete_ids[*]}" - -# ---------------------------------------------------------------------------- # -# Delete agents # -# ---------------------------------------------------------------------------- # - -_log "Deleting agents..." -yc_lt agent delete "${_delete_ids[@]}" diff --git a/performance-test/automation/_compose_test_create_args.sh b/performance-test/automation/_compose_test_create_args.sh deleted file mode 100755 index 822461e12..000000000 --- a/performance-test/automation/_compose_test_create_args.sh +++ /dev/null @@ -1,180 +0,0 @@ -#!/usr/bin/env bash - -_metafile='' -_config_ids=() -_extra_description='' -_extra_labels='' -_extra_agent_filter='' -_extra_data_fnames=() -_extra_data_fspecs=() -while [[ $# -gt 0 ]]; do - case "$1" in - -m | --meta) - [[ -n $2 ]] - _metafile=$2 - shift - shift - ;; - -c | --config-id) - [[ -n $2 ]] - _config_ids+=("$2") - shift - shift - ;; - -d | --extra-test-data) - [[ -n $2 && -n $3 && -n $4 ]] - _extra_data_fnames+=("$2") - _extra_data_fspecs+=("name=$2,s3file=$3,s3bucket=$4") - shift - shift - shift - shift - ;; - --extra-labels) - [[ -n $2 ]] - [[ -z $_extra_labels ]] - _extra_labels=$2 - shift - shift - ;; - --extra-agent-filter) - [[ -n $2 ]] - [[ -z $_extra_agent_filter ]] - _extra_agent_filter=$2 - shift - shift - ;; - --extra-description) - [[ -n $2 ]] - [[ -z $_extra_description ]] - _extra_description=$2 - shift - shift - ;; - --help | -h | *) - echo "Usage: $(basename "$0") [-m META_JSON_FILE] [-c CONFIG_ID]... [-d FILE_LOCAL_NAME FILE_BUCKET_NAME BUCKET_NAME]... [... OPTIONS]" - echo "" - echo "Compose arguments for 'yc loadtesting test create'." - echo " -m|--meta META_JSON_FILE - path to a json file with test description" - echo " -c|--config-id CONFIG_ID - ID of a test configuration file (may be defined multiple times)" - echo " -d|--extra-test-data FILE_NAME FILE_NAME_IN_BUCKET BUCKET - extra test data (may be defined multiple times)" - echo " --extra-labels KEY1=VAL1[,KEYN=VALN] - extra labels" - echo " --extra-agent-filter AGENT_FILTER - extra agent filter" - echo " --extra-description DESCRIPTION - extra description" - exit 0 - ;; - esac -done - -_multi_factor="1" -_name=$(readlink -f "$_metafile" | xargs dirname | xargs basename) -_description='' -_labels='' -_agent_filter='' -_data_fnames=() -_data_fspecs=() - -# ---------------------------------------------------------------------------- # -# read from metafile # -# ---------------------------------------------------------------------------- # - -if [[ -f "$_metafile" ]]; then - function read_meta { - jq -re "$@" < "$_metafile" - return 0 - } - - # shellcheck disable=SC2016 - _multi_factor=$(read_meta --arg d "$_multi_factor" ' - .multi // $d - | tostring - ') - # shellcheck disable=SC2016 - _name=$(read_meta --arg d "$_name" ' - .name // $d - | tostring - ') - _description=$(read_meta ' - .description // "" - | tostring - ') - _labels=$(read_meta ' - .labels // {} - | to_entries - | map("\(.key)=\(.value)") - | join(",") - ') - _agent_filter=$(read_meta ' - .agent_labels // {} - | to_entries - | map("labels.\(.key)=\"\(.value)\"") - | join(" and ") - ') - IFS=$'\n' read -d '' -ra _data_fnames < <(read_meta ' - .external_data // [] - | [.[] | select(.name? and .s3file? and .s3bucket?)] - | map("\(.name)") - | join("\n") - ') || true - IFS=$'\n' read -d '' -ra _data_fspecs < <(read_meta ' - .external_data // [] - | [.[] | select(.name? and .s3file? and .s3bucket?)] - | map("name=\(.name),s3file=\(.s3file),s3bucket=\(.s3bucket)") - | join("\n") - ') || true -fi - -# ---------------------------------------------------------------------------- # -# add extras # -# ---------------------------------------------------------------------------- # - -if [[ -n ${_extra_description} ]]; then - if [[ -n ${_description} ]]; then - _description="$_description\n\n$_extra_description" - else - _description="$_extra_description" - fi -fi - -if [[ -n ${_extra_labels} ]]; then - if [[ -n ${_labels} ]]; then - _labels="$_labels,$_extra_labels" - else - _labels="$_extra_labels" - fi -fi - -if [[ -n ${_extra_agent_filter} ]]; then - if [[ -n ${_agent_filter} ]]; then - _agent_filter="$_agent_filter and $_extra_agent_filter" - else - _agent_filter="$_extra_agent_filter" - fi -fi - -_data_fnames+=("${_extra_data_fnames[@]}") -_data_fspecs+=("${_extra_data_fspecs[@]}") - -# ---------------------------------------------------------------------------- # -# compose args # -# ---------------------------------------------------------------------------- # - -ARGS=() -ARGS+=(--name "$_name") -ARGS+=(--description "$_description") -ARGS+=(--labels "$_labels") -for _ in $(seq 1 "$_multi_factor"); do - for _config_id in "${_config_ids[@]}"; do - _cfg="id=$_config_id,agent-by-filter=$_agent_filter" - for _fname in "${_data_fnames[@]}"; do - _cfg="$_cfg,test-data=$_fname" - done - - ARGS+=(--configuration "$_cfg") - done -done -for _fspec in "${_data_fspecs[@]}"; do - ARGS+=(--test-data "$_fspec") -done - -(IFS=$'\t'; echo "${ARGS[*]}") diff --git a/performance-test/automation/_functions.sh b/performance-test/automation/_functions.sh deleted file mode 100755 index 854f4a54d..000000000 --- a/performance-test/automation/_functions.sh +++ /dev/null @@ -1,155 +0,0 @@ -#!/usr/bin/env bash - -if [[ -v _LOG_STAGE_STR ]]; then - export _LOG_STAGE=() - IFS=$'\n' read -d '' -ra _LOG_STAGE <<< "$_LOG_STAGE_STR" || true -else - export _LOG_STAGE_STR='' - export _LOG_STAGE=() -fi - -function _log_push_stage { - _LOG_STAGE+=("$1") - _LOG_STAGE_STR=$(IFS=$'\n'; echo "${_LOG_STAGE[*]}") -} - -function _log_pop_stage { - if [[ ${#_LOG_STAGE[@]} -gt 0 ]]; then - _N=${#_LOG_STAGE[@]} - _LOG_STAGE=("${_LOG_STAGE[@]::${_N}-1}") - fi - _LOG_STAGE_STR=$(IFS=$'\n'; echo "${_LOG_STAGE[*]}") -} - -function _log_stage { - _log_pop_stage - _log_push_stage "$1" -} - -function _log { - if [[ "$1" == '-f' ]]; then - shift - echo >&2 "${_LOG_STAGE[*]}" ":" && cat >&2 "$@" - else - echo >&2 "${_LOG_STAGE[*]}" ":" "$@" - fi -} - -function _logv { - if [[ $VAR_VERBOSE -ge "$1" ]]; then - shift - _log "$@" - fi -} - -function assert_installed { - for _cmd in "$@"; do - if ! command -v "$_cmd" 1>/dev/null 2>&1; then - _log "ERROR!!! Assertion failed: $_cmd is not installed" - exit 1 - fi - done - return 0 -} - -function assert_not_empty { - if [[ -z "${!1}" ]]; then - _log "ERROR!!! Assertion failed: variable $1 is empty or not defined" - exit 1 - fi - return 0 -} - -function rand_str { - ( - set +o pipefail - LC_ALL=C tr -d -c '0-9a-f' /dev/null \ - <"$file" - - return $? -} - -function yc_s3_delete { - local -r bucket_path=$1 - local -r bucket=${2:-"$VAR_DATA_BUCKET"} - - assert_not_empty bucket - assert_not_empty bucket_path - - local -r token=${VAR_TOKEN:-$(yc_get_token)} - local -r auth_h="X-YaCloud-SubjectToken: $token" - curl -L -H "$auth_h" -X DELETE "$VAR_OBJECT_STORAGE_URL/$bucket/$bucket_path" \ - 2>/dev/null - - return $? -} - -function yc_test_url { - local -r test_id=$1 - local -r folder_id=${VAR_FOLDER_ID:-$(yc_ config get folder-id)} - echo "$VAR_WEB_CONSOLE_URL/folders/$folder_id/load-testing/tests/$test_id" -} - -function check_json_val { - local -r description=${1:-"$2 $3"} - local -r filter=$2 - local -r condition=$3 - local -r file=${4:-$_CHECK_JSON_FILE} - echo "- $description" - echo "-- $(jq -r "$filter" "$file" 2>/dev/null) $condition" - if jq -re "($filter) $condition" "$file" >/dev/null ; then - echo "-- OK" - return 0 - else - echo "-- filter: $filter" - echo "-- FAIL" - return 1 - fi -} diff --git a/performance-test/automation/_test_check.sh b/performance-test/automation/_test_check.sh deleted file mode 100755 index 1acfac0fc..000000000 --- a/performance-test/automation/_test_check.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail - -# shellcheck disable=SC2155 -export _SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) - -# shellcheck source=_functions.sh -source "$_SCRIPT_DIR/_functions.sh" - -# shellcheck source=_variables.sh -source "$_SCRIPT_DIR/_variables.sh" - -# ---------------------------------------------------------------------------- # -# Arguments and constants # -# ---------------------------------------------------------------------------- # - -while [[ $# -gt 0 ]]; do - case "$1" in - --dir) - _TEST_DIR=$2 - shift - shift - ;; - --id) - _TEST_ID=$2 - shift - shift - ;; - --output | -o) - _OUTPUT_DIR=$2 - shift - shift - ;; - --help | -h | *) - echo "Usage: $(basename "$0") --id TEST_ID [--dir SCRIPT_DIR] [-o OUTPUT_DIR]" - echo "" - echo "Obtain test results and check them with two check scripts in passed SCRIPT_DIR directory:" - # shellcheck disable=SC2016 - echo '- SCRIPT_DIR/check_summary.sh $(yc --format json loadtesting test get TEST_ID)' - # shellcheck disable=SC2016 - echo '- SCRIPT_DIR/check_report.sh $(yc --format json loadtesting test get-report-table TEST_ID)' - echo "" - echo "If corresponding checks are not found in SCRIPT_DIR, the default checks will be run instead." - exit 0 - ;; - esac -done - -assert_installed yc jq curl -assert_not_empty _TEST_DIR -assert_not_empty _TEST_ID - -_OUTPUT_DIR=${_OUTPUT_DIR:-"./check-$_TEST_DIR"} -mkdir -p "$_OUTPUT_DIR" - -set +e -export -f run_script -export -f check_json_val - -rc=0 - -# ------------------------------- Check summary ------------------------------ # -# -------------- (yc --format json loadtesting test get TEST_ID) ------------- # - -if ! yc_lt test get "$_TEST_ID" >"$_OUTPUT_DIR/summary.json"; then - echo "ERROR!!! failed to download test summary" - exit 1 -fi - -export _DEFAULT_CHECK="$_SCRIPT_DIR/default_check_summary.sh" -if [[ -f "$_TEST_DIR/check_summary.sh" ]]; then - echo "Running: $_TEST_DIR/check_summary.sh $_OUTPUT_DIR/summary.json" - if ! /usr/bin/env bash "$_TEST_DIR/check_summary.sh" "$_OUTPUT_DIR/summary.json"; then - rc=1 - fi - -elif [[ -f "$_DEFAULT_CHECK" ]]; then - echo "Running: $_DEFAULT_CHECK $_OUTPUT_DIR/summary.json" - if ! /usr/bin/env bash "$_DEFAULT_CHECK" "$_OUTPUT_DIR/summary.json"; then - rc=1 - fi - -else - echo "ERROR: check_summary.sh script not found" - rc=1 -fi - -# ------------------------------- Check report ------------------------------- # -# ------- (yc --format json loadtesting test get-report-table TEST_ID) ------- # - -if ! yc_lt test get-report-table "$_TEST_ID" >"$_OUTPUT_DIR/report.json"; then - echo "ERROR!!! failed to download test report" - exit 1 -fi - -export _DEFAULT_CHECK="$_SCRIPT_DIR/default_check_report.sh" -if [[ -f "$_TEST_DIR/check_report.sh" ]]; then - echo "Running: $_TEST_DIR/check_report.sh $_OUTPUT_DIR/report.json" - if ! /usr/bin/env bash "$_TEST_DIR/check_report.sh" "$_OUTPUT_DIR/report.json"; then - rc=1 - fi - -elif [[ -f "$_DEFAULT_CHECK" ]]; then - echo "Running: $_DEFAULT_CHECK $_OUTPUT_DIR/report.json" - if ! /usr/bin/env bash "$_DEFAULT_CHECK" "$_OUTPUT_DIR/report.json"; then - rc=1 - fi - -else - echo "ERROR: check_summary.sh script not found" - rc=1 -fi - -# ----------------------------------- exit ----------------------------------- # - -exit $rc diff --git a/performance-test/automation/_test_run.sh b/performance-test/automation/_test_run.sh deleted file mode 100755 index 106897bfd..000000000 --- a/performance-test/automation/_test_run.sh +++ /dev/null @@ -1,194 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail - -# shellcheck disable=SC2155 -export _SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) - -# shellcheck source=_functions.sh -source "$_SCRIPT_DIR/_functions.sh" - -# shellcheck source=_variables.sh -source "$_SCRIPT_DIR/_variables.sh" - -# ---------------------------------------------------------------------------- # -# Arguments and constants # -# ---------------------------------------------------------------------------- # - -while [[ $# -gt 0 ]]; do - case "$1" in - --help | -h) - echo "Usage: $(basename "$0") TEST_DIR" - echo "" - echo "Run test with configurations defined in TEST_DIR/$VAR_TEST_CONFIG_MASK" - echo "Additional test parameters may be defined in TEST_DIR/meta.json" - exit 0 - ;; - *) - _TEST_DIR=$1 - break - ;; - esac -done - -assert_installed yc jq curl -assert_not_empty _TEST_DIR - -_TEMP_BUCKET_DIR="test-runs/$(rand_str)" -declare -r _TEMP_BUCKET_DIR - -# ---------------------------------------------------------------------------- # -# sanity check, before anything is created # -# ---------------------------------------------------------------------------- # - -_logv 1 "## Sanity check..." -run_script "$_SCRIPT_DIR/_compose_test_create_args.sh" \ - --meta "$_TEST_DIR/meta.json" \ - -c 12345 \ - -c 54321 \ - -d local1 inbucket1 bucket1 \ - -d local2 inbucket2 bucket2 \ - >/dev/null - -# ---------------------------------------------------------------------------- # -# prepare test configuration files # -# ---------------------------------------------------------------------------- # - -_logv 1 "## Prepare test configurations" -_config_ids=() - -# ------------------------- list configuration files ------------------------- # - -_config_files=() -while IFS= read -d '' -r _file; do _config_files+=("$_file"); done < \ - <(find "$_TEST_DIR" -type f -name "$VAR_TEST_CONFIG_MASK" -maxdepth 1 -print0) - -if [[ ${#_config_files[@]} -eq 0 ]]; then - _log "ERROR!!! No config files found in $_TEST_DIR. Config file mask: $VAR_TEST_CONFIG_MASK" - exit 1 -fi - -_logv 1 "Found test configuration files: ${_config_files[*]}" - -# ------------------------ upload configuration files ------------------------ # - -_logv 1 "Uploading configurations..." -for _file in "${_config_files[@]}"; do - _args=() - - # substitute YC_LT_TARGET in config file if the variable is set - if [[ -n $YC_LT_TARGET ]]; then - _config_content=$(cat "$_file") - # shellcheck disable=SC2016 - _config_content=${_config_content/'${YC_LT_TARGET}'/"$YC_LT_TARGET"} - _args+=(--yaml-string "$_config_content") - else - _args+=(--from-yaml-file "$_file") - fi - - _config_id=$(yc_lt test-config create "${_args[@]}" | jq -r '.id') - _logv 1 "- created test configuration $_config_id from $_file" - - _config_ids+=("$_config_id") -done - -# ---------------------------------------------------------------------------- # -# prepare local data files # -# ---------------------------------------------------------------------------- # - -_logv 1 "## Prepare local data files" -_local_data_fnames=() - -function cleanup_temp_data_files { - _log "Cleaning up data files..." - for _fname in "${_local_data_fnames[@]}"; do - _temp_s3_file="$_TEMP_BUCKET_DIR/$_fname" - if ! yc_s3_delete "$_temp_s3_file" "$VAR_DATA_BUCKET" >/dev/null; then - _log "- failed to delete $_temp_s3_file" - fi - done -} -trap cleanup_temp_data_files EXIT - -# --------------------------- list local data files -------------------------- # - -function is_data_file { - _non_data_files=("${_config_files[@]}") - _non_data_files+=("$_TEST_DIR/meta.json") - _non_data_files+=("$_TEST_DIR/check_summary.sh") - _non_data_files+=("$_TEST_DIR/check_report.sh") - for _ndf in "${_non_data_files[@]}"; do - if [[ $1 == "$_ndf" ]]; then - return 1 - fi - done - return 0 -} - -_local_data_files=() -while IFS= read -d '' -r _file; do - if is_data_file "$_file"; then - _local_data_files+=("$_file") - fi -done < <(find "$_TEST_DIR" -type f -print0) - -_logv 1 "Found local data files: ${_local_data_files[*]}" - -# --------------------- upload local data files to bucket -------------------- # - -if [[ ${#_local_data_files[@]} -gt 0 && -n $VAR_DATA_BUCKET ]]; then - _logv 1 "Uploading local data files... (should be deleted after test)" - _logv 1 "upload params: bucket=$VAR_DATA_BUCKET; common-prefix=$_TEMP_BUCKET_DIR/" - - for _file in "${_local_data_files[@]}"; do - _fname=${_file#"$_TEST_DIR/"} - _temp_s3_file="$_TEMP_BUCKET_DIR/$_fname" - if ! yc_s3_upload "$_file" "$_temp_s3_file" "$VAR_DATA_BUCKET" >/dev/null; then - _log "- failed to upload $_temp_s3_file" - continue - fi - - _logv 1 "- uploaded local data file $_fname" - _local_data_fnames+=("$_fname") - done - -elif [[ ${#_local_data_files[@]} -gt 0 ]]; then - _logv 1 "Upload failed: YC_LT_DATA_BUCKET is not specified." -fi - -# ---------------------------------------------------------------------------- # -# Determine test parameters # -# ---------------------------------------------------------------------------- # - -_logv 1 "## Compose command arguments" - -_composer_args=() -_composer_args+=(--meta "$_TEST_DIR/meta.json") -_composer_args+=(--extra-agent-filter "${VAR_TEST_AGENT_FILTER:-}") -_composer_args+=(--extra-labels "${VAR_TEST_EXTRA_LABELS:-}") -_composer_args+=(--extra-description "${VAR_TEST_EXTRA_DESCRIPTION:-}") -for _id in "${_config_ids[@]}"; do - _composer_args+=(-c "$_id") -done -for _fname in "${_local_data_fnames[@]}"; do - _composer_args+=(-d "$_fname" "$_TEMP_BUCKET_DIR/$_fname" "$VAR_DATA_BUCKET") -done - -RUN_ARGS=() -IFS=$'\t' read -d '' -ra RUN_ARGS < \ - <(run_script "$_SCRIPT_DIR/_compose_test_create_args.sh" "${_composer_args[@]}") \ - || true - -_logv 1 "Test run arguments: ${RUN_ARGS[*]}" - -# ---------------------------------------------------------------------------- # -# Run the test # -# ---------------------------------------------------------------------------- # - -_logv 1 "## Starting test..." -_test_id=$(yc_lt test create "${RUN_ARGS[@]}" | jq -r '.id') - -_logv 1 "Started. Test url: $(yc_test_url "$_test_id")/test-report" - -_logv 1 "## Waiting for test to finish..." -yc_lt test wait --idle-timeout 60s "$_test_id" diff --git a/performance-test/automation/_variables.sh b/performance-test/automation/_variables.sh deleted file mode 100755 index e2996df7a..000000000 --- a/performance-test/automation/_variables.sh +++ /dev/null @@ -1,169 +0,0 @@ -#!/usr/bin/env bash - -if [[ -n ${__YC_LT_VARS_DEFINED} ]]; then - return 0 -fi - -export __YC_LT_VARS_DEFINED=1 - -function _def_var { - local -r _name=$1 - - local -r _env="YC_LT_${_name}" - - local -r _var_default="__DEFAULT_${_name}" - local -r _var="VAR_${_name}" - - local -r _val_default=$2 - local -r _val=${!_env-"${_val_default}"} - - export "$_var_default=$_val_default" - export "$_var=$_val" - - local -r _gap=$(printf -- '.%.0s' {1..80}) - local -r _info_actual="$_var: \"${!_var:0:60}\"" - local -r _info_env="$_env: \"${!_env:0:60}\"" - _logv 2 "${_info_actual} ${_gap:${#_info_actual}} env ${_info_env}" -} - -# ---------------------------------------------------------------------------- # -# General # -# ---------------------------------------------------------------------------- # - -# env: YC_LT_VERBOSE -# format: 0, 1, 2 -# Scripts verbosity level -_def_var VERBOSE "0" - -# env: YC_LT_OUTPUT_DIR -# format: path to local directory -_def_var OUTPUT_DIR "$PWD/.loadtesting" - -# env: YC_LT_CLI_PROFILE -# format: string -# YC CLI profile which will be used to create agents and tests. -# An ID of a folder is taken from profile, or, if specified, from YC_LT_FOLDER_ID. -_def_var CLI_PROFILE "" - -# env: YC_LT_FOLDER_ID -# format: string, cloud-id -# ID of a cloud folder where tests are performed. -_def_var FOLDER_ID "" - -# env: YC_LT_DATA_BUCKET -# format: string, bucket-name -# Name of an object storage bucket used as a storage for test data. If needed, -# local files are automatically uploaded to the bucket. -_def_var DATA_BUCKET "" - -# env: YC_LT_CLI_INTERACTIVE -# format: 0 or 1 -# Defines whether interactive CLI input is allowed. -_def_var CLI_INTERACTIVE "1" - -# env: YC_LT_TOKEN -# format: string, token -# A token. Normally, no need to specify explicitly -_def_var TOKEN "" - -# ---------------------------------------------------------------------------- # -# Agent # -# ---------------------------------------------------------------------------- # - -# env: YC_LT_AGENTS_CNT -# format: positive number -# Number of agents which should be created when 'agent.sh create' is called. -_def_var AGENTS_CNT "1" - -# env: YC_LT_AGENT_SA_ID -# format: string, cloud-id -# ID of a service account with which agent VM will be created. -_def_var AGENT_SA_ID "" - -# ---------------------------- Agent: VM settings ---------------------------- # - -# env: YC_LT_AGENT_ZONE -# format: identifier of an availability zone -# Agent's VM will be created in the specified zone -_def_var AGENT_ZONE "ru-central1-b" - -# env: YC_LT_AGENT_SUBNET_ID -# format: string, cloud-id -# ID of a subnet in which agent's VM will be created -_def_var AGENT_SUBNET_ID "" - -# env: YC_LT_AGENT_SECURITY_GROUP_IDS -# format: list of cloud-id in format [id[,id[,...]]] -# IDS of security groups assigned to created agent. -_def_var AGENT_SECURITY_GROUP_IDS "" - -# env: YC_LT_AGENT_CORES -# format: positive number > 1 -# A number of CPU cores with which agent VM will be created. -_def_var AGENT_CORES "2" - -# env: YC_LT_AGENT_MEMORY -# format: positive number + scale specifier -# Amount of RAM with which agent VM will be created. -_def_var AGENT_MEMORY "2G" - -# ----------------- Agent: service settings and customization ---------------- # - -# env: YC_LT_AGENT_LABELS -# format: list of key-value pairs in format [key=value[,key=value[,...]]] -# Labels of an agent created by 'agent.sh create' -_def_var AGENT_LABELS "ci=true,author=$USER" - -# env: YC_LT_AGENT_NAME_PREFIX -# format: string -# Name (or prefix) of an agent created by 'agent.sh create' -_def_var AGENT_NAME_PREFIX "ci-lt-agent" - -# env: YC_LT_AGENT_DESCRIPTION -# format: string -# Description of an agent created by 'agent.sh create' -_def_var AGENT_DESCRIPTION "Created via script by $USER" - -# ---------------------------------------------------------------------------- # -# Test # -# ---------------------------------------------------------------------------- # - -# env: YC_LT_SKIP_TEST_CHECK -# format: 0 or 1 -# Specifies whether checks should be performed after a test has finished. -_def_var SKIP_TEST_CHECK "0" - -# env: YC_LT_TEST_AGENT_FILTER -# format: filter string -# Filter expression by which agents will be selected to execute a test. -# The expression will be ANDed to the ones specified in meta.json -# Example: -# - agents containing 'onetime-agent-' in name: 'name contains "onetime-agent-"' -# - agents with labels ci=true and author=foobar: 'labels.ci = "true" and labels.author = "foobar"' -_def_var TEST_AGENT_FILTER "labels.ci=true and labels.author=$USER" - -# env: YC_LT_TEST_EXTRA_LABELS -# format: list of key-value pairs in format [key=value[,key=value[,...]]] -# Additional (to the ones specified in meta.json) labels with which tests will be created. -_def_var TEST_EXTRA_LABELS "ci=true" - -# env: YC_LT_TEST_EXTRA_DESCRIPTION -# format: string -# Additional (to the one specified in meta.json) description which which tests will be creatd. -_def_var TEST_EXTRA_DESCRIPTION "" - -# ---------------------------------------------------------------------------- # -# Constants customization # -# ---------------------------------------------------------------------------- # - -# env: YC_LT_TEST_CONFIG_MASK -# format: GLOB mask -_def_var TEST_CONFIG_MASK "test-config*.yaml" - -# env: YC_LT_OBJECT_STORAGE_URL -# format: url -_def_var OBJECT_STORAGE_URL "https://storage.yandexcloud.net" - -# env: YC_LT_WEB_CONSOLE_URL -# format: url -_def_var WEB_CONSOLE_URL "https://console.yandex.cloud" diff --git a/performance-test/automation/agent.sh b/performance-test/automation/agent.sh deleted file mode 100755 index d353de40d..000000000 --- a/performance-test/automation/agent.sh +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail - -# shellcheck disable=SC2155 -export _SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) - -# shellcheck source=_functions.sh -source "$_SCRIPT_DIR/_functions.sh" - -# shellcheck source=_variables.sh -source "$_SCRIPT_DIR/_variables.sh" - -# ---------------------------------------------------------------------------- # -# Retrieve arguments from command line # -# ---------------------------------------------------------------------------- # - -_CMD='' - -while [[ $# -gt 0 ]]; do - case "$1" in - create) - _CMD='create' - shift - break - ;; - delete) - _CMD='delete' - shift - break - ;; - -h | --help | *) - echo "Usage: $(basename "$0") subcommand [ARG]..." - echo "" - echo "Subcommands:" - echo " $(basename "$0") create [--count N] [ARG]..." - echo " create specified number of agents" - echo " $(basename "$0") delete [ARG]..." - echo " delete agents" - exit 0 - ;; - esac -done - -if [[ -z "${VAR_FOLDER_ID:-$(yc_ config get folder-id)}" ]]; then - _log "Folder ID must be specified either via YC_LT_FOLDER_ID or via CLI profile." - exit 1 -fi - -if [[ "$_CMD" == 'create' ]]; then - _CNT=$VAR_AGENTS_CNT - while [[ $# -gt 0 ]]; do - case "$1" in - -h | --help) - echo "Usage: $(basename "$0") create [--count N] [ARG]..." - echo "" - echo "Call agent creation subroutine N times and wait until all agents are READY_FOR_TEST" - echo "" - echo "Subroutine help:" - run_script "$_SCRIPT_DIR/_agent_create.sh" --help - exit 0 - ;; - --count) - _CNT="$2" - shift - shift - break - ;; - --) - shift - break - ;; - *) - break - ;; - esac - done - - _log "Compute Agents create request. Number of agents: $_CNT" - _pids=() - for _i in $(seq 1 "$_CNT"); do - _log_stage "[$_i]" - run_script "$_SCRIPT_DIR/_agent_create.sh" "$@" & - _pids+=("$!") - done - - _rc=0 - for _pid in "${_pids[@]}"; do - wait "$_pid" - _rc=$((_rc | $?)) - done - - exit ${_rc} - -elif [[ "$_CMD" == 'delete' ]]; then - while [[ $# -gt 0 ]]; do - case "$1" in - -h | --help) - echo "Usage: $(basename "$0") delete [ARG]..." - echo "" - echo "Call agent deletion subroutine" - echo "" - echo "Subroutine help:" - run_script "$_SCRIPT_DIR/_agent_delete.sh" --help - exit 0 - ;; - --) - shift - break - ;; - *) - break - ;; - esac - done - - _log "Compute Agents delete request." - run_script "$_SCRIPT_DIR/_agent_delete.sh" "$@" - exit $? -fi diff --git a/performance-test/automation/default_check_report.sh b/performance-test/automation/default_check_report.sh deleted file mode 100755 index b3a5cd381..000000000 --- a/performance-test/automation/default_check_report.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash - -_CHECK_JSON_FILE="$1" - -rc=0 - -check_json_val \ - 'report status is READY' \ - '.status' \ - '== "READY"' - -rc=$((rc | $?)) - -check_json_val \ - 'has successfully sent requests' \ - '.overall.net_codes."0" // "-1" | tonumber' \ - '> 0' - -rc=$((rc | $?)) - -check_json_val \ - 'has non-zero response time requests' \ - '.overall.quantiles.q100 // "-1" | tonumber' \ - '> 0' - -rc=$((rc | $?)) - -check_json_val \ - '50th response time percentile is less than 10s' \ - '.overall.quantiles.q50 // "-1" | tonumber' \ - '< 10000' - -rc=$((rc | $?)) - -exit $rc diff --git a/performance-test/automation/default_check_summary.sh b/performance-test/automation/default_check_summary.sh deleted file mode 100755 index 47af45c11..000000000 --- a/performance-test/automation/default_check_summary.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -_CHECK_JSON_FILE="$1" - -rc=0 - -check_json_val \ - 'test status doesnt indicate an error' \ - '.summary.status' \ - '| IN("DONE", "AUTOSTOPPED")' - -rc=$((rc | $?)) - -exit $rc diff --git a/performance-test/automation/s3_upload.sh b/performance-test/automation/s3_upload.sh deleted file mode 100755 index b15c01945..000000000 --- a/performance-test/automation/s3_upload.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail - -# shellcheck disable=SC2155 -export _SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) - -# shellcheck source=_functions.sh -source "$_SCRIPT_DIR/_functions.sh" - -# shellcheck source=_variables.sh -source "$_SCRIPT_DIR/_variables.sh" - -# ---------------------------------------------------------------------------- # -# Retrieve arguments from command line # -# ---------------------------------------------------------------------------- # - -_ARGS=() - - -_file="${1}" -_temp_s3_file="${2}" -var_data_bucket="${3}" - -if ! yc_s3_upload "$_file" "$_temp_s3_file" "$var_data_bucket" >/dev/null; then - _log "- failed to upload $_temp_s3_file" - exit 1 -fi diff --git a/performance-test/automation/test.sh b/performance-test/automation/test.sh deleted file mode 100755 index a26184e0f..000000000 --- a/performance-test/automation/test.sh +++ /dev/null @@ -1,138 +0,0 @@ -#!/usr/bin/env bash - -set -e - -# shellcheck disable=SC2155 -export _SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) - -# shellcheck source=_functions.sh -source "$_SCRIPT_DIR/_functions.sh" - -# shellcheck source=_variables.sh -source "$_SCRIPT_DIR/_variables.sh" - -_DIRS=() -while [[ $# -gt 0 ]]; do - case "$1" in - --help | -h) - echo "Usage: $(basename "$0") TEST_DIR1 [TEST_DIR2]..." - echo "" - echo "Sequentially run and check results of tests defined in directories passed as arguments," - echo "print summary." - echo "" - echo "Specifically, for each provided argument:" - echo "1. call '_test_run.sh TEST_DIR' to run the test (see '_test_run.sh --help')" - echo "2. call '_test_check.sh --id TEST_ID --dir TEST_DIR' to check the results (see '_test_check.sh --help')" - exit 0 - ;; - *) - _DIRS+=("$1") - shift - ;; - esac -done - -assert_installed yc jq curl - -_logv 1 "YC CLI provile: ${VAR_CLI_PROFILE:-"current aka <$(yc_ config profile list | grep ' ACTIVE')>"}" -_logv 1 "" - -_log -f < >(tee /dev/stderr))") - _tests_failed=$((_tests_failed + 1)) - continue - fi - - _test_id= - _log_stage "[RUN]" - _log "Running..." - if _test=$(run_script "$_SCRIPT_DIR/_test_run.sh" "$_test_dir"); then - _test_id=$(jq -r '.id' <<< "$_test") - _logv 1 "ID=$_test_id" - _logv 1 "STATUS=$(jq -r '.summary.status' <<< "$_test")" - _log "FINISHED: $(yc_test_url "$_test_id")/test-report)" - else - _msg="FAILED: error; test=$_test" - _tests_failure_reports+=("$(_log "$_msg" 2> >(tee /dev/stderr))") - _tests_failed=$((_tests_failed + 1)) - continue - fi - - _out_dir="$VAR_OUTPUT_DIR/$_test_id" - mkdir -p "$_out_dir" - yc_lt test get "$_test_id" >"$_out_dir/summary.json" - yc_lt test get-report-table "$_test_id" >"$_out_dir/report.json" - - _log_stage "[CHECK]" - if [[ "${VAR_SKIP_TEST_CHECK:-0}" == 0 ]]; then - _resfile="$_out_dir/check_result.txt" - - _log "Performing checks..." - if run_script "$_SCRIPT_DIR/_test_check.sh" --id "$_test_id" --dir "$_test_dir" -o "$_out_dir" >"$_resfile"; then - _logv 1 -f <"$_resfile" - _log "ALL CHECKS PASSED" - else - _log -f <"$_resfile" - _msg="FAILED: checks did not pass. Result in $_resfile" - _tests_failure_reports+=("$(_log "$_msg" 2> >(tee /dev/stderr))") - _tests_failed=$((_tests_failed + 1)) - fi - else - _log "skipped due to YC_LT_SKIP_TEST_CHECK" - fi - - _log "" -done - -_log_pop_stage -_log_pop_stage -_log_stage "" - -_summary_header="[ OK - $((_tests_total - _tests_failed)) | FAILED - $_tests_failed ]" -_log "==================== $_summary_header ====================" -_log "" -if ((_tests_failed != 0)); then - _log "$_tests_failed out of $_tests_total tests have failed:" - for _msg in "${_tests_failure_reports[@]}"; do - _log "$_msg" - done -fi -_log "" -_log "==================== $_summary_header ====================" - -echo "$_tests_failed" -exit "$_tests_failed"