forked from yandex/pandora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_test_run.sh
executable file
·194 lines (152 loc) · 6.49 KB
/
_test_run.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/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"