This repository has been archived by the owner on Oct 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathbuild_testcases.sh
executable file
·292 lines (254 loc) · 10.3 KB
/
build_testcases.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/bin/bash
#ARG_POSITIONAL_SINGLE([scenario_home],[The directory of scenario])
#ARG_POSITIONAL_INF([scenarios],[The scenarios to be run])
#ARG_OPTIONAL_SINGLE([target_dir],[o],[The target directory of output, This folder relative to directory of testcase repository.],["testcases"])
#ARG_OPTIONAL_SINGLE([agent_dir],[],[The directory of agent, This folder relative to directory of testcase repository.],["workspace/agent"])
#ARG_OPTIONAL_SINGLE([agent_with_optional_dir],[],[The directory of agent that it contain the optional plugins, This folder relative to directory of testcase repository.],["workspace/agent-with-optional-plugins"])
#ARG_OPTIONAL_SINGLE([collector_image_version],[],[The image version of collector],["6.0.0-2018"])
#ARG_OPTIONAL_SINGLE([skip_single_mode],[],[Skip build the scenario with single mode],[on])
#ARG_OPTIONAL_BOOLEAN([skip_build],[],[Skip build the scenario project],[on])
#DEFINE_SCRIPT_DIR([AGENT_TEST_HOME])
#ARG_HELP([])
#ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.7.1 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
die()
{
local _ret=$2
test -n "$_ret" || _ret=1
test "$_PRINT_HELP" = yes && print_help >&2
echo "$1" >&2
exit ${_ret}
}
begins_with_short_option()
{
local first_option all_short_options='oh'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}
# THE DEFAULTS INITIALIZATION - POSITIONALS
_positionals=()
_arg_scenarios=()
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_target_dir="testcases"
_arg_agent_dir="workspace/agent"
_arg_agent_with_optional_dir="workspace/agent-with-optional-plugins"
_arg_collector_image_version="6.0.0-2018"
_arg_skip_single_mode="on"
_arg_skip_build="on"
print_help()
{
printf 'Usage: %s [-o|--target_dir <arg>] [--agent_dir <arg>] [--agent_with_optional_dir <arg>] [--collector_image_version <arg>] [--skip_single_mode <arg>] [--(no-)skip_build] [-h|--help] <scenario_home> [<scenarios-1>] ... [<scenarios-n>] ...\n' "$0"
printf '\t%s\n' "<scenario_home>: The directory of scenario"
printf '\t%s\n' "<scenarios>: The scenarios to be run"
printf '\t%s\n' "-o, --target_dir: The target directory of output, This folder relative to directory of testcase repository. (default: '"testcases"')"
printf '\t%s\n' "--agent_dir: The directory of agent, This folder relative to directory of testcase repository. (default: '"workspace/agent"')"
printf '\t%s\n' "--agent_with_optional_dir: The directory of agent that it contain the optional plugins, This folder relative to directory of testcase repository. (default: '"workspace/agent-with-optional-plugins"')"
printf '\t%s\n' "--collector_image_version: The image version of collector (default: '"6.0.0-2018"')"
printf '\t%s\n' "--skip_single_mode: Skip build the scenario with single mode (default: 'on')"
printf '\t%s\n' "--skip_build, --no-skip_build: Skip build the scenario project (on by default)"
printf '\t%s\n' "-h, --help: Prints help"
}
parse_commandline()
{
_positionals_count=0
while test $# -gt 0
do
_key="$1"
case "$_key" in
-o|--target_dir)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_target_dir="$2"
shift
;;
--target_dir=*)
_arg_target_dir="${_key##--target_dir=}"
;;
-o*)
_arg_target_dir="${_key##-o}"
;;
--agent_dir)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_agent_dir="$2"
shift
;;
--agent_dir=*)
_arg_agent_dir="${_key##--agent_dir=}"
;;
--agent_with_optional_dir)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_agent_with_optional_dir="$2"
shift
;;
--agent_with_optional_dir=*)
_arg_agent_with_optional_dir="${_key##--agent_with_optional_dir=}"
;;
--collector_image_version)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_collector_image_version="$2"
shift
;;
--collector_image_version=*)
_arg_collector_image_version="${_key##--collector_image_version=}"
;;
--skip_single_mode)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_skip_single_mode="$2"
shift
;;
--skip_single_mode=*)
_arg_skip_single_mode="${_key##--skip_single_mode=}"
;;
--no-skip_build|--skip_build)
_arg_skip_build="on"
test "${1:0:5}" = "--no-" && _arg_skip_build="off"
;;
-h|--help)
print_help
exit 0
;;
-h*)
print_help
exit 0
;;
*)
_last_positional="$1"
_positionals+=("$_last_positional")
_positionals_count=$((_positionals_count + 1))
;;
esac
shift
done
}
handle_passed_args_count()
{
local _required_args_string="'scenario_home'"
test "${_positionals_count}" -ge 1 || _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require at least 1 (namely: $_required_args_string), but got only ${_positionals_count}." 1
}
assign_positional_args()
{
local _positional_name _shift_for=$1
_positional_names="_arg_scenario_home "
_our_args=$((${#_positionals[@]} - 1))
for ((ii = 0; ii < _our_args; ii++))
do
_positional_names="$_positional_names _arg_scenarios[$((ii + 0))]"
done
shift "$_shift_for"
for _positional_name in ${_positional_names}
do
test $# -gt 0 || break
eval "$_positional_name=\${1}" || die "Error during argument parsing, possibly an Argbash bug." 1
shift
done
}
parse_commandline "$@"
handle_passed_args_count
assign_positional_args 1 "${_positionals[@]}"
# OTHER STUFF GENERATED BY Argbash
AGENT_TEST_HOME="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || die "Couldn't determine the script's running directory, which probably matters, bailing out" 2
### END OF CODE GENERATED BY Argbash (sortof) ### ])
# [ <-- needed because of Argbash
#
# declare functions
parse_yaml() {
local yaml_file=$1
local s
local w
local fs
s='[[:space:]]*'
w='[a-zA-Z0-9_.-]*'
fs="$(echo @|tr @ '\034')"
(
sed -ne '/^--/s|--||g; s|\"|\\\"|g; s/\s*$//g;' \
-e "/#.*[\"\']/!s| #.*||g; /^#/s|#.*||g;" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" |
awk -F"$fs" '{
indent = length($1)/2;
if (length($2) == 0) { conj[indent]="+";} else {conj[indent]="";}
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=(\"%s\")\n", vn, $2, conj[indent-1],$3);
}
}' |
sed -e 's/_=/+=/g' \
-e '/\..*=/s|\.|_|' \
-e '/\-.*=/s|\-|_|'
) < "$yaml_file"
}
cleanEnvVariables(){
testcase_support_versions=()
testcase_running_mode=""
testcase_test_framework=""
testcase_request_url=""
}
#declare variables
SCENARIOS_HOME=`cd ${_arg_scenario_home} >/dev/null; pwd`
CASES_HOME=${SCENARIOS_HOME}/${_arg_target_dir}
AGENT_DIR=${SCENARIOS_HOME}/${_arg_agent_dir}
AGENT_WITH_OPTIONAL_PLUGINS_DIR=${SCENARIOS_HOME}/${_arg_agent_with_optional_dir}
AGENT_WITH_BOOTSTRAP_PLUGINS_DIR=${SCENARIOS_HOME}/${_arg_agent_with_bootstrap_dir}
COLLECTOR_IMAGE_VERSION=${_arg_collector_image_version}
ESCAPE_AGENT_DIR=$(echo "$AGENT_DIR" |sed -e 's/\//\\\//g' )
ESCAPE_AGENT_WITH_OPTIONAL_PLUGINS_DIR=$(echo "$AGENT_WITH_OPTIONAL_PLUGINS_DIR" |sed -e 's/\//\\\//g' )
ESCAPE_AGENT_WITH_BOOTSTRAP_PLUGINS_DIR=$(echo "$AGENT_WITH_BOOTSTRAP_PLUGINS_DIR" |sed -e 's/\//\\\//g' )
#
rm -rf ${CASES_HOME} && mkdir -p ${CASES_HOME}
for SCENARIO in ${_arg_scenarios[@]}
do
SCENARIO_HOME=${SCENARIOS_HOME}/${SCENARIO}
SCENARIO_CONFIG_FILE=${SCENARIO_HOME}/testcase.yml
echo "[INFO] start to deploy ${SCENARIO_HOME}"
eval "$(parse_yaml "$SCENARIO_CONFIG_FILE")"
SUPPORT_VERSIONS=${testcase_support_versions[@]}
TEST_FRAMEWORK=${testcase_test_framework}
TEST_CASE_REQUEST_URL=${testcase_request_url}
RUNNING_MODE=${testcase_running_mode}
# skip the running mode is SINGLE
if [ "$RUNNING_MODE" = "SINGLE" ] && [ "${_arg_skip_single_mode}" = "on" ] ; then
echo "[WARNING] ${SCENARIO} running mode: ${RUNNING_MODE}. skip this project"
cleanEnvVariables
continue
fi
AGENT_FILE_PATH="${ESCAPE_AGENT_DIR}"
if [ "$RUNNING_MODE" = "WITH_OPTIONAL" ]; then
AGENT_FILE_PATH="${ESCAPE_AGENT_WITH_OPTIONAL_PLUGINS_DIR}"
elif [ "$RUNNING_MODE" = "WITH_BOOTSTRAP" ]; then
AGENT_FILE_PATH="${ESCAPE_AGENT_WITH_BOOTSTRAP_PLUGINS_DIR}"
elif [[ "$RUNNING_MODE" = "WITH_STANDALONE_OPTIONAL" ]]; then
AGENT_DIR=`cd ${AGENT_WITH_OPTIONAL_PLUGINS_DIR}/.. >/dev/null; pwd`
STANDALONE_OPTIONAL_AGENT_DIR="$AGENT_DIR/${SCENARIO}_AGENT"
cp -r $AGENT_WITH_OPTIONAL_PLUGINS_DIR ${STANDALONE_OPTIONAL_AGENT_DIR}
AGENT_FILE_PATH=$(echo "$STANDALONE_OPTIONAL_AGENT_DIR" |sed -e 's/\//\\\//g' )
fi
cd ${SCENARIO_HOME}
for SUPPORT_VERSION in ${SUPPORT_VERSIONS[@]}
do
if [ "${_arg_skip_build}" = "on" ]; then
echo "[INFO] execute mvn package docker:build -P${SCENARIO}-${SUPPORT_VERSION}"
mvn clean package docker:build -P${SCENARIO}-${SUPPORT_VERSION}
else
echo "[INFO] skip build the case ${SCENARIO} - ${SUPPORT_VERSION}"
fi
TEST_CASE_DIR=$CASES_HOME/$SCENARIO-$SUPPORT_VERSION && mkdir -p $TEST_CASE_DIR
cp $SCENARIO_HOME/config/expectedData.yaml $TEST_CASE_DIR
cp $SCENARIO_HOME/config/docker-compose.yml $TEST_CASE_DIR
eval sed -i '' -e 's/\{CASES_IMAGE_VERSION\}/$SUPPORT_VERSION/' $TEST_CASE_DIR/docker-compose.yml
eval sed -i '' -e 's/\{COLLECTOR_IMAGE_VERSION\}/$COLLECTOR_IMAGE_VERSION/' $TEST_CASE_DIR/docker-compose.yml
eval sed -i -e 's/\{AGENT_FILE_PATH\}/$AGENT_FILE_PATH/' $TEST_CASE_DIR/docker-compose.yml
touch $TEST_CASE_DIR/testcase.desc
echo "case.testFramework=$TEST_FRAMEWORK" >> $TEST_CASE_DIR/testcase.desc
echo "case.testComponents=$SUPPORT_VERSION" >> $TEST_CASE_DIR/testcase.desc
echo "case.request_url=$TEST_CASE_REQUEST_URL" >> $TEST_CASE_DIR/testcase.desc
echo "case.projectName=${TESTCASE_PROJECT}" >> $TEST_CASE_DIR/testcase.desc
cleanEnvVariables
echo "[INFO] build $SCENARIO:$SUPPORT_VERSION success."
done
done
#
# ] <-- needed because of Argbash