8181# LB_TYPE Load balancer type. Can be 'TRAEFIK', 'VOYAGER', or 'APACHE'.
8282# Default is 'TRAEFIK'.
8383#
84- # VERBOSE Set to 'true' to echo verbose output to stdout.
84+ # VERBOSE Set to 'true' to echo verbose tracing to stdout.
8585# Default is 'false'.
8686#
87+ # DEBUG_OUT Set to 'tee' to echo various command output to stdout that
88+ # is normally only stored in files. Set to 'cat' to echo such
89+ # commands via 'cat' instead of 'tee'. Set to 'file' to
90+ # only put the output in files. Default is 'file'.
91+ #
8792# QUICKTEST When set to "true", limits testing to a subset of
8893# of the tests.
8994#
@@ -217,7 +222,7 @@ function renewLease {
217222 if [ ! " $LEASE_ID " = " " ]; then
218223 # RESULT_DIR may not have been created yet, so use /tmp
219224 local outfile=/tmp/acc_test_renew_lease.out
220- $SCRIPTPATH /lease.sh -r " $LEASE_ID " 2>&1 | tee $outfile
225+ $SCRIPTPATH /lease.sh -r " $LEASE_ID " 2>&1 | opt_tee $outfile
221226 if [ $? -ne 0 ]; then
222227 trace " Lease renew error:"
223228 echo " " >> $outfile
@@ -370,6 +375,24 @@ function trace {
370375 echo " [` date ' +%m-%d-%YT%H:%M:%S' ` ] [secs=$SECONDS ] [test=$TEST_ID ] [fn=${FUNCNAME[1]} ]: " " $@ "
371376}
372377
378+ #
379+ # opt_tee <filename>
380+ # Use this function in place of 'tee' for most use cases.
381+ # See the description of 'DEBUG_OUT' above for information about this function
382+ #
383+ function opt_tee {
384+ local filename=" ${1?} "
385+ if [ " $DEBUG_OUT " = " tee" ]; then
386+ tee $filename
387+ elif [ " $DEBUG_OUT " = " cat" ]; then
388+ cat > $filename
389+ cat $filename
390+ else
391+ cat > $filename
392+ fi
393+ echo " [` date ' +%m-%d-%YT%H:%M:%S' ` ] [secs=$SECONDS ] [test=$TEST_ID ] [fn=${FUNCNAME[1]} ]: Output from last command is in " " $1 "
394+ }
395+
373396#
374397# state_dump <dir-suffix>
375398# - called at the end of a run, and from fail
@@ -388,6 +411,7 @@ function state_dump {
388411 local PROJECT_ROOT=" ` cat /tmp/test_suite.project_root` "
389412 local SCRIPTPATH=" $PROJECT_ROOT /src/integration-tests/bash"
390413 local LEASE_ID=" ` cat /tmp/test_suite.lease_id` "
414+ local DEBUG_OUT=" ` cat /tmp/test_suite.debug_out` "
391415
392416 if [ ! -d " $RESULT_DIR " ]; then
393417 trace State dump exiting early. RESULT_DIR \" $RESULT_DIR \" does not exist or is not a directory.
@@ -409,8 +433,8 @@ function state_dump {
409433 # get domains is in its own command since this can fail if domain CRD undefined
410434
411435 trace Dumping kubectl gets to kgetmany.out and kgetdomains.out in ${DUMP_DIR}
412- kubectl get all,crd,cm,pv,pvc,ns,roles,rolebindings,clusterroles,clusterrolebindings,secrets --show-labels=true --all-namespaces=true 2>&1 | tee ${DUMP_DIR} /kgetmany.out
413- kubectl get domains --show-labels=true --all-namespaces=true 2>&1 | tee ${DUMP_DIR} /kgetdomains.out
436+ kubectl get all,crd,cm,pv,pvc,ns,roles,rolebindings,clusterroles,clusterrolebindings,secrets --show-labels=true --all-namespaces=true 2>&1 | opt_tee ${DUMP_DIR} /kgetmany.out
437+ kubectl get domains --show-labels=true --all-namespaces=true 2>&1 | opt_tee ${DUMP_DIR} /kgetdomains.out
414438
415439 # Get all pod logs and redirect/copy to files
416440
@@ -428,15 +452,15 @@ function state_dump {
428452 for pod in $pods ; do
429453 local logfile=${DUMP_DIR} /pod-log.${namespace} .${pod}
430454 local descfile=${DUMP_DIR} /pod-describe.${namespace} .${pod}
431- kubectl log $pod -n $namespace 2>&1 | tee $logfile
432- kubectl describe pod $pod -n $namespace 2>&1 | tee $descfile
455+ kubectl log $pod -n $namespace 2>&1 | opt_tee $logfile
456+ kubectl describe pod $pod -n $namespace 2>&1 | opt_tee $descfile
433457 done
434458 done
435459
436460 # use a job to archive PV, /scratch mounts to PV_ROOT in the K8S cluster
437461 trace " Archiving pv directory using a kubernetes job. Look for it on k8s cluster in $PV_ROOT /acceptance_test_pv_archive"
438462 local outfile=${DUMP_DIR} /archive_pv_job.out
439- $SCRIPTPATH /job.sh " /scripts/archive.sh /scratch/acceptance_test_pv /scratch/acceptance_test_pv_archive" 2>&1 | tee ${outfile}
463+ $SCRIPTPATH /job.sh " /scripts/archive.sh /scratch/acceptance_test_pv /scratch/acceptance_test_pv_archive" 2>&1 | opt_tee ${outfile}
440464 if [ " $? " = " 0" ]; then
441465 trace Job complete.
442466 else
@@ -445,12 +469,12 @@ function state_dump {
445469
446470 if [ ! " $LEASE_ID " = " " ]; then
447471 # release the lease if we own it
448- ${SCRIPTPATH} /lease.sh -d " $LEASE_ID " 2>&1 | tee ${RESULT_DIR} /release_lease.out
472+ ${SCRIPTPATH} /lease.sh -d " $LEASE_ID " 2>&1 | opt_tee ${RESULT_DIR} /release_lease.out
449473 if [ " $? " = " 0" ]; then
450474 trace Lease released.
451475 else
452476 trace Lease could not be released:
453- cat /tmp /release_lease.out
477+ cat /${RESULT_DIR} /release_lease.out
454478 fi
455479 fi
456480
@@ -498,6 +522,7 @@ function ctrl_c() {
498522 declare_new_test_from_trap 1 run_aborted_with_ctrl_c
499523 # disable the trap:
500524 trap - INT
525+ set -o pipefail
501526 fail " Trapped CTRL-C"
502527}
503528
@@ -683,7 +708,7 @@ function deploy_operator {
683708
684709 local outfile=" ${TMP_DIR} /create-weblogic-operator.sh.out"
685710 trace " Run the script to deploy the weblogic operator, see \" $outfile \" for tracking."
686- sh $PROJECT_ROOT /kubernetes/create-weblogic-operator.sh -i $inputs -o $USER_PROJECTS_DIR 2>&1 | tee ${outfile}
711+ sh $PROJECT_ROOT /kubernetes/create-weblogic-operator.sh -i $inputs -o $USER_PROJECTS_DIR 2>&1 | opt_tee ${outfile}
687712 if [ " $? " = " 0" ]; then
688713 # Prepend "+" to detailed debugging to make it easy to filter out
689714 cat ${outfile} | sed ' s/^/+/g'
@@ -917,7 +942,7 @@ function run_create_domain_job {
917942
918943 # Note that the job.sh job mounts PV_ROOT to /scratch and runs as UID 1000,
919944 # so PV_ROOT must already exist and have 777 or UID=1000 permissions.
920- $SCRIPTPATH /job.sh " mkdir -p /scratch/acceptance_test_pv/$DOMAIN_STORAGE_DIR " 2>&1 | tee ${outfile}
945+ $SCRIPTPATH /job.sh " mkdir -p /scratch/acceptance_test_pv/$DOMAIN_STORAGE_DIR " 2>&1 | opt_tee ${outfile}
921946 if [ " $? " = " 0" ]; then
922947 cat ${outfile} | sed ' s/^/+/g'
923948 trace Job complete. Directory created on k8s cluster.
@@ -929,7 +954,7 @@ function run_create_domain_job {
929954 local outfile=" ${tmp_dir} /create-weblogic-domain.sh.out"
930955 trace " Run the script to create the domain, see \" $outfile \" for tracing."
931956
932- sh $PROJECT_ROOT /kubernetes/create-weblogic-domain.sh -i $inputs -o $USER_PROJECTS_DIR 2>&1 | tee ${outfile}
957+ sh $PROJECT_ROOT /kubernetes/create-weblogic-domain.sh -i $inputs -o $USER_PROJECTS_DIR 2>&1 | opt_tee ${outfile}
933958
934959 if [ " $? " = " 0" ]; then
935960 cat ${outfile} | sed ' s/^/+/g'
@@ -1670,14 +1695,14 @@ function test_mvn_integration_local {
16701695 [ " $? " = " 0" ] || fail " Error: Could not find mvn in path."
16711696
16721697 local mstart=` date +%s`
1673- mvn -P integration-tests clean install 2>&1 | tee $RESULT_DIR /mvn.out
1698+ mvn -P integration-tests clean install 2>&1 | opt_tee $RESULT_DIR /mvn.out
16741699 local mend=` date +%s`
16751700 local msecs=$(( mend- mstart))
16761701 trace " mvn complete, runtime $msecs seconds"
16771702
16781703 confirm_mvn_build $RESULT_DIR /mvn.out
16791704
1680- docker build -t " ${IMAGE_NAME_OPERATOR} :${IMAGE_TAG_OPERATOR} " --no-cache=true . 2>&1 | tee $RESULT_DIR /docker_build_tag.out
1705+ docker build -t " ${IMAGE_NAME_OPERATOR} :${IMAGE_TAG_OPERATOR} " --no-cache=true . 2>&1 | opt_tee $RESULT_DIR /docker_build_tag.out
16811706 [ " $? " = " 0" ] || fail " Error: Failed to docker tag operator image, see $RESULT_DIR /docker_build_tag.out" .
16821707
16831708 declare_test_pass
@@ -1689,7 +1714,7 @@ function test_mvn_integration_wercker {
16891714 trace " Running mvn -P integration-tests install. Output in $RESULT_DIR /mvn.out"
16901715
16911716 local mstart=` date +%s`
1692- mvn -P integration-tests install 2>&1 | tee $RESULT_DIR /mvn.out
1717+ mvn -P integration-tests install 2>&1 | opt_tee $RESULT_DIR /mvn.out
16931718 local mend=` date +%s`
16941719 local msecs=$(( mend- mstart))
16951720 trace " mvn complete, runtime $msecs seconds"
@@ -1810,7 +1835,7 @@ function run_wlst_script {
18101835
18111836 cat << EOF > $TMP_DIR /empty.py
18121837EOF
1813- java weblogic.WLST $TMP_DIR /empty.py 2>&1 | tee $TMP_DIR /empty.py.out
1838+ java weblogic.WLST $TMP_DIR /empty.py 2>&1 | opt_tee $TMP_DIR /empty.py.out
18141839 if [ " $? " = " 0" ]; then
18151840 # We're running WLST locally. No need to do anything fancy.
18161841 local mycommand=" java weblogic.WLST ${pyfile_lcl} ${username} ${password} ${t3url_lcl} "
@@ -1876,7 +1901,7 @@ EOF
18761901 local maxwaitsecs=180
18771902 local failedonce=" false"
18781903 while : ; do
1879- eval " $mycommand " " $@ " 2>&1 | tee ${pyfile_lcl} .out
1904+ eval " $mycommand " " $@ " 2>&1 | opt_tee ${pyfile_lcl} .out
18801905 local result=" $? "
18811906
18821907 # '+' marks verbose tracing
@@ -2594,6 +2619,7 @@ function test_suite_init {
25942619 PV_ROOT \
25952620 LB_TYPE \
25962621 VERBOSE \
2622+ DEBUG_OUT \
25972623 QUICKTEST \
25982624 NODEPORT_HOST \
25992625 JVM_ARGS \
@@ -2627,10 +2653,14 @@ function test_suite_init {
26272653
26282654 export LEASE_ID=" ${LEASE_ID} "
26292655
2630- if [ -z " $LB_TYPE " ]; then
2656+ if [ -z " $LB_TYPE " ]; then
26312657 export LB_TYPE=TRAEFIK
26322658 fi
26332659
2660+ if [ -z " $DEBUG_OUT " ; then
2661+ export DEBUG_OUT= " false"
2662+ fi
2663+
26342664 # The following customizable exports are currently only customized by WERCKER
26352665 export IMAGE_TAG_OPERATOR= ${IMAGE_TAG_OPERATOR:- `echo " test_${BRANCH_NAME} " | sed " s#/#_#g" `}
26362666 export IMAGE_NAME_OPERATOR= ${IMAGE_NAME_OPERATOR:- wlsldi-v2.docker.oraclecorp.com/ weblogic-operator}
@@ -2646,6 +2676,7 @@ function test_suite_init {
26462676 PV_ROOT \
26472677 LB_TYPE \
26482678 VERBOSE \
2679+ DEBUG_OUT \
26492680 QUICKTEST \
26502681 NODEPORT_HOST \
26512682 JVM_ARGS \
@@ -2681,6 +2712,7 @@ function test_suite_init {
26812712 echo " ${PV_ROOT} " > /tmp/test_suite.pv_root
26822713 echo " ${PROJECT_ROOT} " > /tmp/test_suite.project_root
26832714 echo " ${LEASE_ID} " > /tmp/test_suite.lease_id
2715+ echo " ${DEBUG_OUT} " > /tmp/test_suite.debug_out
26842716
26852717 # Declare we're in a test. We did not declare at the start
26862718 # of the function to ensure that any env vars that might
@@ -2901,6 +2933,15 @@ function test_suite {
29012933
29022934# entry point
29032935
2936+ # "set -o pipefail" ensures that "$?" reflects the first failure in a pipe
2937+ # instead of the status of the last command in the pipe.
2938+ # For example, this script:
2939+ # ls missing-file | tee /tmp/ls.out
2940+ # echo $?
2941+ # Will echo "0" by default, and echo "2" with "set -o pipefile"
2942+
2943+ set -o pipefail
2944+
29042945if [ " $WERCKER " = " true" -o " $JENKINS " = " true" ]; then
29052946 if [ " ${VERBOSE:- false} " = " true" ]; then
29062947 test_suite 2>&1
0 commit comments