@@ -70,6 +70,8 @@ main() {
7070
7171 read_config
7272
73+ parse_host_map || true
74+
7375 count_expected_tests
7476
7577 verbose " ${CONFIG} "
@@ -83,6 +85,34 @@ main() {
8385 iterate_host
8486}
8587
88+ get_host_filename () {
89+ local HOST=" ${1:- } "
90+ get_host " ${HOST} " | base64
91+ }
92+
93+ get_host () {
94+ local HOST=" ${1:- } "
95+
96+ if [[ ! " ${HOST} " =~ - ]]; then
97+ local HOST_CACHE_KEY=" HOST_MAP_${HOST// ./ _} "
98+ # attempt to detect invalid cache keys :/
99+ if [[ " ${! HOST_CACHE_KEY:- } " != " " ]]; then
100+ echo " ${! HOST_CACHE_KEY} (${HOST} )"
101+ return 0
102+ fi
103+ fi
104+
105+ echo " ${HOST} "
106+ }
107+
108+ # todo(ajm) unsafe
109+ parse_host_map () {
110+ local HOST_ALIAS_MAP=$( jqc " ${CONFIG} " -r \
111+ " .alias? | to_entries? | map(\" export HOST_MAP_\(.key)='\(.value|tostring)'\" ) | .[]? | sub(\"\\ \.\" ; \" _\" ; \" g\" ) " )
112+ verbose " ${HOST_ALIAS_MAP} "
113+ source /dev/stdin < <( echo " ${HOST_ALIAS_MAP} " ) || true
114+ }
115+
86116count_expected_tests () {
87117 EXPECTED_TESTS=$( jqc " ${CONFIG} " ' [(.host, .k8s.deployment) | keys? | .[]? ] | length' )
88118 info " ${EXPECTED_TESTS} tests expected"
@@ -180,7 +210,7 @@ _iterate_k8s_worker() {
180210 --env TEST_YAML=$( echo " ${TEST_DATA} " | to_yaml | base64 -w0) \
181211 --env DEBUG=" ${DEBUG} " \
182212 \
183- | tee " ${TEMP_DIR} /${HOST} " > /dev/null; then
213+ | tee " ${TEMP_DIR} /$( get_host_filename $ {HOST}) " > /dev/null; then
184214
185215 warning " ${HOST} fail"
186216 else
@@ -202,10 +232,12 @@ configure_parallel() {
202232
203233 parallel --no-notice --record-env
204234 export -f _iterate_k8s_worker _iterate_host_worker jqc success \
205- info debug verbose error warning ssh_to_node log_message_prefix is_gke to_yaml wait_safe
235+ info debug verbose error warning ssh_to_node log_message_prefix \
236+ is_gke to_yaml wait_safe get_host get_host_filename
206237
207238 export CONFIG TEMP_DIR THIS_SCRIPT DIR NETASSERT_IMAGE_NAME \
208- DEBUG IS_OFFLINE CONTAINER_BASE_NAME SSH_DEFAULT_OPTIONS SSH_USER SSH_USER_OPTIONS YJ
239+ DEBUG IS_OFFLINE CONTAINER_BASE_NAME SSH_DEFAULT_OPTIONS \
240+ SSH_USER SSH_USER_OPTIONS YJ
209241}
210242
211243iterate_host () {
@@ -250,24 +282,24 @@ _iterate_host_worker() {
250282 if [[ -f /opt/ssh_config ]]; then
251283 CONFIG_FILE_FLAG=" -F /opt/ssh_config"
252284 fi
253- info " Iterating instance targets: $( echo ${HOSTS} | tr ' ' ' ,' ) "
285+ verbose " Iterating instance targets: $( echo ${HOSTS} | tr ' ' ' ,' ) "
254286
255287
256288 local CONNECTION=" ssh -tt ${SSH_DEFAULT_OPTIONS} ${SSH_USER_OPTIONS} ${CONFIG_FILE_FLAG} "
257289
258290 if [[ " ${IS_OFFLINE:- } " != 1 ]]; then
259291 for HOST in ${HOSTS} ; do
260292 if [[ " ${HOST} " == ' localhost' ]]; then
261- (info " $( hostname) : pulling image locally" && docker pull " ${NETASSERT_IMAGE_NAME} " ) &
293+ (info " $( get_host " $( hostname) " ) : pulling image locally" && docker pull " ${NETASSERT_IMAGE_NAME} " ) &
262294 PIDS+=" $! "
263295
264296 else
265- local LOG_MESSAGE=$( info " ${HOST} : pulling image remotely" )
297+ local LOG_MESSAGE=$( info " $( get_host " $ {HOST}" ) : pulling image remotely" )
266298
267299 ${CONNECTION} ${HOST} \
268300 -- \
269301 bash -c " echo ${LOG_MESSAGE} && docker pull ${NETASSERT_IMAGE_NAME} " 2>&1 \
270- | tee -a " ${TEMP_DIR} /${HOST} " &
302+ | tee -a " ${TEMP_DIR} /$( get_host_filename " $ {HOST}" ) " &
271303 PIDS+=" $! "
272304 fi
273305 done
@@ -285,7 +317,7 @@ _iterate_host_worker() {
285317
286318 if [[ " ${HOST} " == ' localhost' ]]; then
287319
288- info " ${HOST} : local test start"
320+ info " $( get_host " $ {HOST}" ) : local test start"
289321
290322 if ! \
291323 docker run -t \
@@ -295,15 +327,15 @@ _iterate_host_worker() {
295327 --env DEBUG=" ${DEBUG} " \
296328 " ${NETASSERT_IMAGE_NAME} " \
297329 npm test -s \
298- | tee -a " ${TEMP_DIR} /${HOST} " > /dev/null; then
330+ | tee -a " ${TEMP_DIR} /$( get_host_filename " $ {HOST}" ) " > /dev/null; then
299331
300- warning " ${HOST} : test fail"
332+ warning " $( get_host " $ {HOST}" ) : test fail"
301333 else
302- success " ${HOST} : test pass"
334+ success " $( get_host " $ {HOST}" ) : test pass"
303335 fi
304336 else
305337
306- info " ${HOST} : remote test start"
338+ info " $( get_host " $ {HOST}" ) : remote test start"
307339
308340 if ! \
309341 ${CONNECTION} ${HOST} \
@@ -319,11 +351,11 @@ _iterate_host_worker() {
319351 " ${NETASSERT_IMAGE_NAME} " \
320352 npm test -s \
321353 " \
322- | tee -a " ${TEMP_DIR} /${HOST} " > /dev/null; then
354+ | tee -a " ${TEMP_DIR} /$( get_host_filename " $ {HOST}" ) " > /dev/null; then
323355
324- warning " ${HOST} : test fail"
356+ warning " $( get_host " $ {HOST}" ) : test fail"
325357 else
326- success " ${HOST} : test pass"
358+ success " $( get_host " $ {HOST}" ) : test pass"
327359 fi
328360 fi
329361 done <<< " ${HOSTS}"
@@ -367,7 +399,7 @@ ssh_to_node() {
367399 CONNECTION=" ssh -tt ${SSH_DEFAULT_OPTIONS} ${SSH_USER_OPTIONS} ${HOST} -- "
368400 fi
369401
370- info " Connecting to ${HOST} ..."
402+ info " Connecting to $( get_host " $ {HOST}" ) ..."
371403
372404 local PULL_COMMAND=" "
373405 if [[ " ${IS_OFFLINE:- } " != 1 ]]; then
@@ -405,8 +437,15 @@ present_results() {
405437 local OUTPUT_FAIL_HR=$( printf " %s\n" " ${COLOUR_RED} $( hr) ${COLOUR_RESET} " )
406438 local OUTPUT_PASS_HR=$( printf " %s\n" " ${COLOUR_GREEN} $( hr) ${COLOUR_RESET} " )
407439
408- for RESULT in $( find ${TEMP_DIR} / -type f) ; do
440+ # todo(ajm) write aliases into test results at runtime
441+ while read ALIAS; do
442+ sed " s=${ALIAS} =g" -i " ${TEMP_DIR} /" *
443+ done < <( jqc " ${CONFIG} " -r \
444+ " .alias? | to_entries? | map(\" \(.key)=\(.value|tostring) (\(.key))\" ) | .[]? " )
445+
446+ while read RESULT; do
409447 local TEST_NAME=" ${RESULT/ ${TEMP_DIR} \/ / } "
448+ TEST_NAME=$( base64 -d <<< " ${TEST_NAME}" )
410449 RESULT_COUNT=$(( RESULT_COUNT + 1 ))
411450 local TAP_RESULT=$(
412451 if ! cat " ${RESULT} " | grep -E ' ^TAP version [0-9]+' -A 9999; then
@@ -432,7 +471,7 @@ present_results() {
432471 echo " ${OUTPUT_PASS_HR} "
433472 echo)
434473 fi
435- done
474+ done < <( find ${TEMP_DIR} / -type f )
436475
437476 local OUTPUT_RESULT=$(
438477 if [[ " ${TEST_FAILURES} " -gt 0 ]]; then
@@ -510,8 +549,8 @@ check_dependencies() {
510549}
511550
512551handle_arguments () {
513- parse_arguments " $@ "
514- validate_arguments " $@ "
552+ parse_arguments " ${ @ } "
553+ validate_arguments " ${ @ } "
515554}
516555
517556parse_arguments () {
0 commit comments