81
81
# LB_TYPE Load balancer type. Can be 'TRAEFIK', 'VOYAGER', or 'APACHE'.
82
82
# Default is 'TRAEFIK'.
83
83
#
84
- # VERBOSE Set to 'true' to echo verbose output to stdout.
84
+ # VERBOSE Set to 'true' to echo verbose tracing to stdout.
85
85
# Default is 'false'.
86
86
#
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
+ #
87
92
# QUICKTEST When set to "true", limits testing to a subset of
88
93
# of the tests.
89
94
#
@@ -217,7 +222,7 @@ function renewLease {
217
222
if [ ! " $LEASE_ID " = " " ]; then
218
223
# RESULT_DIR may not have been created yet, so use /tmp
219
224
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
221
226
if [ $? -ne 0 ]; then
222
227
trace " Lease renew error:"
223
228
echo " " >> $outfile
@@ -370,6 +375,24 @@ function trace {
370
375
echo " [` date ' +%m-%d-%YT%H:%M:%S' ` ] [secs=$SECONDS ] [test=$TEST_ID ] [fn=${FUNCNAME[1]} ]: " " $@ "
371
376
}
372
377
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
+
373
396
#
374
397
# state_dump <dir-suffix>
375
398
# - called at the end of a run, and from fail
@@ -388,6 +411,7 @@ function state_dump {
388
411
local PROJECT_ROOT=" ` cat /tmp/test_suite.project_root` "
389
412
local SCRIPTPATH=" $PROJECT_ROOT /src/integration-tests/bash"
390
413
local LEASE_ID=" ` cat /tmp/test_suite.lease_id` "
414
+ local DEBUG_OUT=" ` cat /tmp/test_suite.debug_out` "
391
415
392
416
if [ ! -d " $RESULT_DIR " ]; then
393
417
trace State dump exiting early. RESULT_DIR \" $RESULT_DIR \" does not exist or is not a directory.
@@ -409,8 +433,8 @@ function state_dump {
409
433
# get domains is in its own command since this can fail if domain CRD undefined
410
434
411
435
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
414
438
415
439
# Get all pod logs and redirect/copy to files
416
440
@@ -428,15 +452,15 @@ function state_dump {
428
452
for pod in $pods ; do
429
453
local logfile=${DUMP_DIR} /pod-log.${namespace} .${pod}
430
454
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
433
457
done
434
458
done
435
459
436
460
# use a job to archive PV, /scratch mounts to PV_ROOT in the K8S cluster
437
461
trace " Archiving pv directory using a kubernetes job. Look for it on k8s cluster in $PV_ROOT /acceptance_test_pv_archive"
438
462
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}
440
464
if [ " $? " = " 0" ]; then
441
465
trace Job complete.
442
466
else
@@ -445,12 +469,12 @@ function state_dump {
445
469
446
470
if [ ! " $LEASE_ID " = " " ]; then
447
471
# 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
449
473
if [ " $? " = " 0" ]; then
450
474
trace Lease released.
451
475
else
452
476
trace Lease could not be released:
453
- cat /tmp /release_lease.out
477
+ cat /${RESULT_DIR} /release_lease.out
454
478
fi
455
479
fi
456
480
@@ -498,6 +522,7 @@ function ctrl_c() {
498
522
declare_new_test_from_trap 1 run_aborted_with_ctrl_c
499
523
# disable the trap:
500
524
trap - INT
525
+ set -o pipefail
501
526
fail " Trapped CTRL-C"
502
527
}
503
528
@@ -683,7 +708,7 @@ function deploy_operator {
683
708
684
709
local outfile=" ${TMP_DIR} /create-weblogic-operator.sh.out"
685
710
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}
687
712
if [ " $? " = " 0" ]; then
688
713
# Prepend "+" to detailed debugging to make it easy to filter out
689
714
cat ${outfile} | sed ' s/^/+/g'
@@ -917,7 +942,7 @@ function run_create_domain_job {
917
942
918
943
# Note that the job.sh job mounts PV_ROOT to /scratch and runs as UID 1000,
919
944
# 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}
921
946
if [ " $? " = " 0" ]; then
922
947
cat ${outfile} | sed ' s/^/+/g'
923
948
trace Job complete. Directory created on k8s cluster.
@@ -929,7 +954,7 @@ function run_create_domain_job {
929
954
local outfile=" ${tmp_dir} /create-weblogic-domain.sh.out"
930
955
trace " Run the script to create the domain, see \" $outfile \" for tracing."
931
956
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}
933
958
934
959
if [ " $? " = " 0" ]; then
935
960
cat ${outfile} | sed ' s/^/+/g'
@@ -1670,14 +1695,14 @@ function test_mvn_integration_local {
1670
1695
[ " $? " = " 0" ] || fail " Error: Could not find mvn in path."
1671
1696
1672
1697
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
1674
1699
local mend=` date +%s`
1675
1700
local msecs=$(( mend- mstart))
1676
1701
trace " mvn complete, runtime $msecs seconds"
1677
1702
1678
1703
confirm_mvn_build $RESULT_DIR /mvn.out
1679
1704
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
1681
1706
[ " $? " = " 0" ] || fail " Error: Failed to docker tag operator image, see $RESULT_DIR /docker_build_tag.out" .
1682
1707
1683
1708
declare_test_pass
@@ -1689,7 +1714,7 @@ function test_mvn_integration_wercker {
1689
1714
trace " Running mvn -P integration-tests install. Output in $RESULT_DIR /mvn.out"
1690
1715
1691
1716
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
1693
1718
local mend=` date +%s`
1694
1719
local msecs=$(( mend- mstart))
1695
1720
trace " mvn complete, runtime $msecs seconds"
@@ -1810,7 +1835,7 @@ function run_wlst_script {
1810
1835
1811
1836
cat << EOF > $TMP_DIR /empty.py
1812
1837
EOF
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
1814
1839
if [ " $? " = " 0" ]; then
1815
1840
# We're running WLST locally. No need to do anything fancy.
1816
1841
local mycommand=" java weblogic.WLST ${pyfile_lcl} ${username} ${password} ${t3url_lcl} "
@@ -1876,7 +1901,7 @@ EOF
1876
1901
local maxwaitsecs=180
1877
1902
local failedonce=" false"
1878
1903
while : ; do
1879
- eval " $mycommand " " $@ " 2>&1 | tee ${pyfile_lcl} .out
1904
+ eval " $mycommand " " $@ " 2>&1 | opt_tee ${pyfile_lcl} .out
1880
1905
local result=" $? "
1881
1906
1882
1907
# '+' marks verbose tracing
@@ -2594,6 +2619,7 @@ function test_suite_init {
2594
2619
PV_ROOT \
2595
2620
LB_TYPE \
2596
2621
VERBOSE \
2622
+ DEBUG_OUT \
2597
2623
QUICKTEST \
2598
2624
NODEPORT_HOST \
2599
2625
JVM_ARGS \
@@ -2627,10 +2653,14 @@ function test_suite_init {
2627
2653
2628
2654
export LEASE_ID=" ${LEASE_ID} "
2629
2655
2630
- if [ -z " $LB_TYPE " ]; then
2656
+ if [ -z " $LB_TYPE " ]; then
2631
2657
export LB_TYPE=TRAEFIK
2632
2658
fi
2633
2659
2660
+ if [ -z " $DEBUG_OUT " ; then
2661
+ export DEBUG_OUT= " false"
2662
+ fi
2663
+
2634
2664
# The following customizable exports are currently only customized by WERCKER
2635
2665
export IMAGE_TAG_OPERATOR= ${IMAGE_TAG_OPERATOR:- `echo " test_${BRANCH_NAME} " | sed " s#/#_#g" `}
2636
2666
export IMAGE_NAME_OPERATOR= ${IMAGE_NAME_OPERATOR:- wlsldi-v2.docker.oraclecorp.com/ weblogic-operator}
@@ -2646,6 +2676,7 @@ function test_suite_init {
2646
2676
PV_ROOT \
2647
2677
LB_TYPE \
2648
2678
VERBOSE \
2679
+ DEBUG_OUT \
2649
2680
QUICKTEST \
2650
2681
NODEPORT_HOST \
2651
2682
JVM_ARGS \
@@ -2681,6 +2712,7 @@ function test_suite_init {
2681
2712
echo " ${PV_ROOT} " > /tmp/test_suite.pv_root
2682
2713
echo " ${PROJECT_ROOT} " > /tmp/test_suite.project_root
2683
2714
echo " ${LEASE_ID} " > /tmp/test_suite.lease_id
2715
+ echo " ${DEBUG_OUT} " > /tmp/test_suite.debug_out
2684
2716
2685
2717
# Declare we're in a test. We did not declare at the start
2686
2718
# of the function to ensure that any env vars that might
@@ -2901,6 +2933,15 @@ function test_suite {
2901
2933
2902
2934
# entry point
2903
2935
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
+
2904
2945
if [ " $WERCKER " = " true" -o " $JENKINS " = " true" ]; then
2905
2946
if [ " ${VERBOSE:- false} " = " true" ]; then
2906
2947
test_suite 2>&1
0 commit comments