Skip to content

Commit bd446c7

Browse files
author
OpenShift Bot
authored
Merge pull request #13363 from smarterclayton/extended_test_only
Merged by openshift-bot
2 parents 5516eee + 1806b14 commit bd446c7

22 files changed

+83
-51
lines changed

hack/lib/cleanup.sh

+23
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,30 @@ function os::cleanup::dump_container_logs() {
7676
}
7777
readonly -f os::cleanup::dump_container_logs
7878

79+
# os::cleanup::tmpdir performs cleanup of temp directories as a precondition for running a test. It tries to
80+
# clean up mounts in the temp directories.
81+
#
82+
# Globals:
83+
# - BASETMPDIR
84+
# - USE_SUDO
85+
# Returns:
86+
# None
87+
function os::cleanup::tmpdir() {
88+
# ensure that the directories are clean
89+
if os::util::find::system_binary "findmnt" &>/dev/null; then
90+
for target in $( ${USE_SUDO:+sudo} findmnt --output TARGET --list ); do
91+
if [[ "${target}" == "${BASETMPDIR}"* ]]; then
92+
${USE_SUDO:+sudo} umount "${target}"
93+
fi
94+
done
95+
fi
7996

97+
# delete any sub directory underneath BASETMPDIR
98+
for directory in $( find "${BASETMPDIR}" -d 2 ); do
99+
${USE_SUDO:+sudo} rm -rf "${directory}"
100+
done
101+
}
102+
readonly -f os::cleanup::tmpdir
80103

81104
# os::cleanup::internal::list_k8s_containers returns a space-delimited list of
82105
# docker containers that belonged to k8s.

hack/lib/init.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ os::log::stacktrace::install
5151
# All of our Bash scripts need to have access to the
5252
# binaries that we build so we don't have to find
5353
# them before every invocation.
54-
os::util::environment::update_path_var
54+
os::util::environment::update_path_var
55+
56+
if [[ -z "${OS_TMP_ENV_SET-}" ]]; then
57+
os::util::environment::setup_tmpdir_vars "$( basename "$0" ".sh" )"
58+
fi

hack/lib/log/output.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ readonly -f os::log::debug
8686
# Arguments:
8787
# - all: message to write
8888
function os::log::internal::to_logfile() {
89-
if [[ -n "${LOG_DIR:-}" ]]; then
89+
if [[ -n "${LOG_DIR:-}" && -d "${LOG_DIR-}" ]]; then
9090
echo "$*" >>"${LOG_DIR}/scripts.log"
9191
fi
9292
}

hack/lib/util/docs.sh

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function generate_manual_pages() {
1111
local skipprefix="${3:-}"
1212

1313
os::util::environment::setup_tmpdir_vars generate/manuals
14+
os::cleanup::tmpdir
1415

1516
# We do this in a tmpdir in case the dest has other non-autogenned files
1617
# We don't want to include them in the list of gen'd files
@@ -50,6 +51,7 @@ function generate_documentation() {
5051
local skipprefix="${1:-}"
5152

5253
os::util::environment::setup_tmpdir_vars generate/docs
54+
os::cleanup::tmpdir
5355

5456
# We do this in a tmpdir in case the dest has other non-autogenned files
5557
# We don't want to include them in the list of gen'd files

hack/lib/util/environment.sh

+3-22
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ readonly -f os::util::environment::setup_time_vars
8686
# - export USE_IMAGES
8787
# - export TAG
8888
function os::util::environment::setup_all_server_vars() {
89-
local subtempdir=$1
90-
91-
os::util::environment::setup_tmpdir_vars "${subtempdir}"
9289
os::util::environment::setup_kubelet_vars
9390
os::util::environment::setup_etcd_vars
9491
os::util::environment::setup_server_vars
@@ -123,9 +120,6 @@ readonly -f os::util::environment::update_path_var
123120
#
124121
# Globals:
125122
# - TMPDIR
126-
# - LOG_DIR
127-
# - ARTIFACT_DIR
128-
# - USE_SUDO
129123
# Arguments:
130124
# - 1: the path under the root temporary directory for OpenShift where these subdirectories should be made
131125
# Returns:
@@ -135,6 +129,7 @@ readonly -f os::util::environment::update_path_var
135129
# - export ARTIFACT_DIR
136130
# - export FAKE_HOME_DIR
137131
# - export HOME
132+
# - export OS_TMP_ENV_SET
138133
function os::util::environment::setup_tmpdir_vars() {
139134
local sub_dir=$1
140135

@@ -146,26 +141,12 @@ function os::util::environment::setup_tmpdir_vars() {
146141
export VOLUME_DIR
147142
ARTIFACT_DIR="${ARTIFACT_DIR:-${BASETMPDIR}/artifacts}"
148143
export ARTIFACT_DIR
149-
150-
# change the location of $HOME so no one does anything naughty
151144
FAKE_HOME_DIR="${BASETMPDIR}/openshift.local.home"
152145
export FAKE_HOME_DIR
153-
HOME="${FAKE_HOME_DIR}"
154-
export HOME
155146

156-
# ensure that the directories are clean
157-
if os::util::find::system_binary "findmnt" &>/dev/null; then
158-
for target in $( ${USE_SUDO:+sudo} findmnt --output TARGET --list ); do
159-
if [[ "${target}" == "${BASETMPDIR}"* ]]; then
160-
${USE_SUDO:+sudo} umount "${target}"
161-
fi
162-
done
163-
fi
147+
mkdir -p "${LOG_DIR}" "${VOLUME_DIR}" "${ARTIFACT_DIR}" "${FAKE_HOME_DIR}"
164148

165-
for directory in "${BASETMPDIR}" "${LOG_DIR}" "${VOLUME_DIR}" "${ARTIFACT_DIR}" "${HOME}"; do
166-
${USE_SUDO:+sudo} rm -rf "${directory}"
167-
mkdir -p "${directory}"
168-
done
149+
export OS_TMP_ENV_SET="${sub_dir}"
169150
}
170151
readonly -f os::util::environment::setup_tmpdir_vars
171152

hack/test-cmd.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ export ETCD_HOST=${ETCD_HOST:-127.0.0.1}
7272
export ETCD_PORT=${ETCD_PORT:-24001}
7373
export ETCD_PEER_PORT=${ETCD_PEER_PORT:-27001}
7474

75-
os::util::environment::setup_all_server_vars "test-cmd/"
75+
os::cleanup::tmpdir
76+
os::util::environment::setup_all_server_vars
77+
export HOME="${FAKE_HOME_DIR}"
7678

7779
# Allow setting $JUNIT_REPORT to toggle output behavior
7880
if [[ -n "${JUNIT_REPORT:-}" ]]; then

hack/test-end-to-end-docker.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ os::log::info "Starting containerized end-to-end test"
1010
unset KUBECONFIG
1111

1212
os::util::environment::use_sudo
13-
os::util::environment::setup_all_server_vars "test-end-to-end-docker/"
13+
os::cleanup::tmpdir
14+
os::util::environment::setup_all_server_vars
15+
export HOME="${FAKE_HOME_DIR}"
1416

1517
# Allow setting $JUNIT_REPORT to toggle output behavior
1618
if [[ -n "${JUNIT_REPORT:-}" ]]; then

hack/test-end-to-end.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ trap "cleanup" EXIT
4444

4545
# Start All-in-one server and wait for health
4646
os::util::environment::use_sudo
47-
os::util::environment::setup_all_server_vars "test-end-to-end/"
47+
os::cleanup::tmpdir
48+
os::util::environment::setup_all_server_vars
4849

4950
# Allow setting $JUNIT_REPORT to toggle output behavior
5051
if [[ -n "${JUNIT_REPORT:-}" ]]; then

hack/test-go.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ trap exit_trap EXIT
3939
start_time=$(date +%s)
4040
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
4141
os::build::setup_env
42-
os::util::environment::setup_tmpdir_vars "test-go"
42+
os::cleanup::tmpdir
4343

4444
# Internalize environment variables we consume and default if they're not set
4545
dry_run="${DRY_RUN:-}"

hack/test-integration.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ os::build::setup_env
66

77
export API_SCHEME="http"
88
export API_BIND_HOST="127.0.0.1"
9-
os::util::environment::setup_all_server_vars "test-integration/"
9+
os::cleanup::tmpdir
10+
os::util::environment::setup_all_server_vars
1011

1112
function cleanup() {
1213
out=$?

hack/test-lib.sh

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ trap exit_trap EXIT
2020

2121
start_time=$(date +%s)
2222
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
23-
os::util::environment::setup_tmpdir_vars "test-lib"
2423

2524
cd "${OS_ROOT}"
2625

hack/test-util.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
44
trap os::test::junit::reconcile_output EXIT
55

6-
os::util::environment::setup_all_server_vars "test-os-cmd/"
6+
os::cleanup::tmpdir
7+
os::util::environment::setup_all_server_vars
8+
export HOME="${FAKE_HOME_DIR}"
79
export JUNIT_REPORT_OUTPUT="${LOG_DIR}/raw_test_output.log"
810

911
# set verbosity so we can see that command output renders correctly

hack/update-generated-swagger-spec.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export API_BIND_HOST=127.0.0.1
2727
export API_PORT=38443
2828
export ETCD_PORT=34001
2929
export ETCD_PEER_PORT=37001
30-
os::util::environment::setup_all_server_vars "generate-swagger-spec/"
30+
os::cleanup::tmpdir
31+
os::util::environment::setup_all_server_vars
3132
os::start::configure_server
3233

3334
SWAGGER_SPEC_REL_DIR="${1:-}"

hack/util.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ function cleanup_openshift() {
4646
# really have it smack people in their logs. This is a severe correctness problem
4747
grep -a5 "CACHE.*ALTERED" ${LOG_DIR}/openshift.log
4848

49-
os::cleanup::dump_etcd
5049
os::cleanup::dump_container_logs
5150

5251
if [[ -z "${SKIP_TEARDOWN-}" ]]; then
52+
os::cleanup::dump_etcd
5353
os::log::info "Tearing down test"
5454
kill_all_processes
5555

test/extended/alternate_certs.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# This scripts starts the OpenShift server with custom TLS certs, and verifies generated kubeconfig files can be used to talk to it.
44
source "$(dirname "${BASH_SOURCE}")/../../hack/lib/init.sh"
55

6-
os::util::environment::setup_all_server_vars "test-extended-alternate-certs/"
6+
os::cleanup::tmpdir
7+
os::util::environment::setup_all_server_vars
78

89
export EXTENDED_TEST_PATH="${OS_ROOT}/test/extended"
910

test/extended/alternate_launches.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
source "$(dirname "${BASH_SOURCE}")/../../hack/lib/init.sh"
77

88
os::util::environment::use_sudo
9-
os::util::environment::setup_all_server_vars "test-extended-alternate-launches/"
9+
os::cleanup::tmpdir
10+
os::util::environment::setup_all_server_vars
1011

1112
export EXTENDED_TEST_PATH="${OS_ROOT}/test/extended"
1213

test/extended/cmd.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ trap "cleanup" EXIT
2727
os::log::info "Starting server"
2828

2929
os::util::environment::use_sudo
30-
os::util::environment::setup_all_server_vars "test-extended/cmd/"
30+
os::cleanup::tmpdir
31+
os::util::environment::setup_all_server_vars
3132

3233
os::log::system::start
3334

test/extended/gssapi.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ os::build::setup_env
1212

1313
os::util::environment::use_sudo
1414
os::util::environment::setup_time_vars
15-
os::util::environment::setup_all_server_vars "${test_name}"
15+
os::cleanup::tmpdir
16+
os::util::environment::setup_all_server_vars
1617

1718
os::log::system::start
1819

test/extended/ldap_groups.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ os::log::info "Starting server"
2626

2727
os::util::ensure::iptables_privileges_exist
2828
os::util::environment::use_sudo
29-
os::util::environment::setup_all_server_vars "test-extended/ldap_groups/"
29+
os::cleanup::tmpdir
30+
os::util::environment::setup_all_server_vars
3031

3132
os::log::system::start
3233

test/extended/networking.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ else
316316
"${OPENSHIFT_CLUSTER_ID}-node-2"
317317
)
318318

319-
os::util::environment::setup_tmpdir_vars "test-extended/networking"
319+
os::cleanup::tmpdir
320320

321321
# Allow setting $JUNIT_REPORT to toggle output behavior
322322
if [[ -n "${JUNIT_REPORT:-}" ]]; then

test/extended/setup.sh

+20-11
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ function os::test::extended::setup () {
3434
export KUBE_REPO_ROOT="${OS_ROOT}/vendor/k8s.io/kubernetes"
3535

3636
os::util::environment::setup_time_vars
37-
os::util::environment::use_sudo
38-
os::util::environment::setup_all_server_vars "test-extended/core"
39-
40-
os::util::ensure::iptables_privileges_exist
4137

4238
# Allow setting $JUNIT_REPORT to toggle output behavior
4339
if [[ -n "${JUNIT_REPORT:-}" ]]; then
@@ -46,6 +42,22 @@ function os::test::extended::setup () {
4642
export TEST_REPORT_DIR="${ARTIFACT_DIR}"
4743
fi
4844

45+
# TODO: we shouldn't have to do this much work just to get tests to run against a real
46+
# cluster, until then
47+
if [[ -n "${TEST_ONLY-}" ]]; then
48+
function cleanup() {
49+
out=$?
50+
os::test::junit::generate_oscmd_report
51+
os::log::info "Exiting"
52+
return $out
53+
}
54+
trap "exit" INT TERM
55+
trap "cleanup" EXIT
56+
57+
os::log::info "Not starting server"
58+
return 0
59+
fi
60+
4961
function cleanup() {
5062
out=$?
5163
cleanup_openshift
@@ -59,13 +71,10 @@ function os::test::extended::setup () {
5971
trap "exit" INT TERM
6072
trap "cleanup" EXIT
6173

62-
# allow setup to be skipped
63-
if [[ -n "${TEST_ONLY+x}" ]]; then
64-
export SKIP_TEARDOWN='true'
65-
# be sure to set VOLUME_DIR if you are running with TEST_ONLY
66-
os::log::info "Not starting server, VOLUME_DIR=${VOLUME_DIR:-}"
67-
return 0
68-
fi
74+
os::util::environment::use_sudo
75+
os::cleanup::tmpdir
76+
os::util::environment::setup_all_server_vars
77+
os::util::ensure::iptables_privileges_exist
6978

7079
os::log::info "Starting server"
7180

test/extended/testdata/gssapi/scripts/test-wrapper.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ source hack/lib/init.sh
99

1010
export TEST_NAME="test-extended/gssapiproxy-tests/$(uname -n)-${CLIENT}-${SERVER}"
1111
os::util::environment::setup_time_vars
12-
os::util::environment::setup_tmpdir_vars "${TEST_NAME}"
12+
os::cleanup::tmpdir
1313
export JUNIT_REPORT_OUTPUT="${LOG_DIR}/raw_test_output.log"
1414

1515
# use a subshell and `if` statement to prevent `exit` calls from killing this script

0 commit comments

Comments
 (0)