Skip to content

Commit

Permalink
Revert "Implemented a single-directive library import for Origin Bash…
Browse files Browse the repository at this point in the history
… scripts"
  • Loading branch information
smarterclayton committed May 11, 2016
1 parent dc84964 commit a8b60df
Show file tree
Hide file tree
Showing 87 changed files with 269 additions and 307 deletions.
8 changes: 4 additions & 4 deletions contrib/vagrant/provision-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ set -o pipefail
# Set a useful format for xtrace output
# export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'

OS_ROOT=$(
ORIGIN_ROOT=$(
unset CDPATH
origin_root=$(dirname "${BASH_SOURCE}")/../..
cd "${origin_root}"
pwd
)
source "${OS_ROOT}/hack/lib/init.sh"
source ${OS_ROOT}/contrib/vagrant/provision-util.sh
source ${ORIGIN_ROOT}/hack/common.sh
source ${ORIGIN_ROOT}/contrib/vagrant/provision-util.sh

# Passed as arguments to provisioning script
MASTER_IP=${1:-""}
Expand All @@ -26,7 +26,7 @@ INSTANCE_PREFIX=${4:-${OPENSHIFT_INSTANCE_PREFIX:-openshift}}
FIXUP_NET_UDEV=false
NETWORK_PLUGIN=${OPENSHIFT_NETWORK_PLUGIN:-""}
NODE_INDEX=0
CONFIG_ROOT=${OS_ROOT}
CONFIG_ROOT=${ORIGIN_ROOT}
SKIP_BUILD=${OPENSHIFT_SKIP_BUILD:-false}

# Parse optional arguments
Expand Down
3 changes: 2 additions & 1 deletion hack/build-assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ set -o pipefail

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
source "${OS_ROOT}/hack/common.sh"
source "${OS_ROOT}/hack/util.sh"
os::log::install_errexit

pushd "${OS_ROOT}/assets" > /dev/null
Expand Down
3 changes: 2 additions & 1 deletion hack/build-base-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ set -o pipefail

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
source "${OS_ROOT}/hack/common.sh"
source "${OS_ROOT}/hack/util.sh"
os::log::install_errexit

# Go to the top of the tree.
Expand Down
3 changes: 2 additions & 1 deletion hack/build-cross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ set -o pipefail

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
source "${OS_ROOT}/hack/common.sh"
source "${OS_ROOT}/hack/util.sh"
os::log::install_errexit

platforms=( "${OS_CROSS_COMPILE_PLATFORMS[@]}" )
Expand Down
3 changes: 2 additions & 1 deletion hack/build-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ set -o pipefail

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
source "${OS_ROOT}/hack/common.sh"
source "${OS_ROOT}/hack/util.sh"
os::log::install_errexit

# only works on Linux for now, all other platforms must build binaries themselves
Expand Down
3 changes: 2 additions & 1 deletion hack/build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ set -o pipefail

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
source "${OS_ROOT}/hack/common.sh"
source "${OS_ROOT}/hack/util.sh"
source "${OS_ROOT}/contrib/node/install-sdn.sh"
os::log::install_errexit

Expand Down
2 changes: 1 addition & 1 deletion hack/build-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function absolute_path() {

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
source "${OS_ROOT}/hack/text.sh"
origin_path="src/github.com/openshift/origin"

# TODO: Remove this check and fix the docker command instead after the
Expand Down
3 changes: 2 additions & 1 deletion hack/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ set -o pipefail

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
source "${OS_ROOT}/hack/common.sh"
source "${OS_ROOT}/hack/util.sh"
os::log::install_errexit

# Go to the top of the tree.
Expand Down
3 changes: 2 additions & 1 deletion hack/cherry-pick.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ set -o nounset
set -o pipefail

OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
source "${OS_ROOT}/hack/common.sh"
source "${OS_ROOT}/hack/util.sh"
os::log::install_errexit

# Go to the top of the tree.
Expand Down
2 changes: 1 addition & 1 deletion hack/clean-assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/lib/init.sh"
source "${OS_ROOT}/hack/common.sh"

pushd ${OS_ROOT}/assets > /dev/null
echo "Cleaning up bower_components, node_modules, and dist directories..."
Expand Down
37 changes: 7 additions & 30 deletions hack/cmd_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
# This utility file contains functions that wrap commands to be tested. All wrapper functions run commands
# in a sub-shell and redirect all output. Tests in test-cmd *must* use these functions for testing.

# We assume ${OS_ROOT} is set
source "${OS_ROOT}/hack/text.sh"
source "${OS_ROOT}/hack/util.sh"
source "${OS_ROOT}/hack/lib/test/junit.sh"

# expect_success runs the cmd and expects an exit code of 0
function os::cmd::expect_success() {
if [[ $# -ne 1 ]]; then echo "os::cmd::expect_success expects only one argument, got $#"; exit 1; fi
local cmd=$1

os::cmd::internal::expect_exit_code_run_grep "${cmd}"
}
readonly -f os::cmd::expect_success

# expect_failure runs the cmd and expects a non-zero exit code
function os::cmd::expect_failure() {
Expand All @@ -18,7 +22,6 @@ function os::cmd::expect_failure() {

os::cmd::internal::expect_exit_code_run_grep "${cmd}" "os::cmd::internal::failure_func"
}
readonly -f os::cmd::expect_failure

# expect_success_and_text runs the cmd and expects an exit code of 0
# as well as running a grep test to find the given string in the output
Expand All @@ -29,7 +32,6 @@ function os::cmd::expect_success_and_text() {

os::cmd::internal::expect_exit_code_run_grep "${cmd}" "os::cmd::internal::success_func" "${expected_text}"
}
readonly -f os::cmd::expect_success_and_text

# expect_failure_and_text runs the cmd and expects a non-zero exit code
# as well as running a grep test to find the given string in the output
Expand All @@ -40,7 +42,6 @@ function os::cmd::expect_failure_and_text() {

os::cmd::internal::expect_exit_code_run_grep "${cmd}" "os::cmd::internal::failure_func" "${expected_text}"
}
readonly -f os::cmd::expect_failure_and_text

# expect_success_and_not_text runs the cmd and expects an exit code of 0
# as well as running a grep test to ensure the given string is not in the output
Expand All @@ -51,7 +52,6 @@ function os::cmd::expect_success_and_not_text() {

os::cmd::internal::expect_exit_code_run_grep "${cmd}" "os::cmd::internal::success_func" "${expected_text}" "os::cmd::internal::failure_func"
}
readonly -f os::cmd::expect_success_and_not_text

# expect_failure_and_not_text runs the cmd and expects a non-zero exit code
# as well as running a grep test to ensure the given string is not in the output
Expand All @@ -62,7 +62,6 @@ function os::cmd::expect_failure_and_not_text() {

os::cmd::internal::expect_exit_code_run_grep "${cmd}" "os::cmd::internal::failure_func" "${expected_text}" "os::cmd::internal::failure_func"
}
readonly -f os::cmd::expect_failure_and_not_text

# expect_code runs the cmd and expects a given exit code
function os::cmd::expect_code() {
Expand All @@ -72,7 +71,6 @@ function os::cmd::expect_code() {

os::cmd::internal::expect_exit_code_run_grep "${cmd}" "os::cmd::internal::specific_code_func ${expected_cmd_code}"
}
readonly -f os::cmd::expect_code

# expect_code_and_text runs the cmd and expects the given exit code
# as well as running a grep test to find the given string in the output
Expand All @@ -84,7 +82,6 @@ function os::cmd::expect_code_and_text() {

os::cmd::internal::expect_exit_code_run_grep "${cmd}" "os::cmd::internal::specific_code_func ${expected_cmd_code}" "${expected_text}"
}
readonly -f os::cmd::expect_code_and_text

# expect_code_and_not_text runs the cmd and expects the given exit code
# as well as running a grep test to ensure the given string is not in the output
Expand All @@ -96,7 +93,6 @@ function os::cmd::expect_code_and_not_text() {

os::cmd::internal::expect_exit_code_run_grep "${cmd}" "os::cmd::internal::specific_code_func ${expected_cmd_code}" "${expected_text}" "os::cmd::internal::failure_func"
}
readonly -f os::cmd::expect_code_and_not_text

millisecond=1
second=$(( 1000 * millisecond ))
Expand All @@ -113,7 +109,6 @@ function os::cmd::try_until_success() {

os::cmd::internal::run_until_exit_code "${cmd}" "os::cmd::internal::success_func" "${duration}" "${interval}"
}
readonly -f os::cmd::try_until_success

# os::cmd::try_until_failure runs the cmd until either the command fails or times out
# the default time-out for os::cmd::try_until_failure is 60 seconds.
Expand All @@ -125,7 +120,6 @@ function os::cmd::try_until_failure() {

os::cmd::internal::run_until_exit_code "${cmd}" "os::cmd::internal::failure_func" "${duration}" "${interval}"
}
readonly -f os::cmd::try_until_failure

# os::cmd::try_until_text runs the cmd until either the command outputs the desired text or times out
# the default time-out for os::cmd::try_until_text is 60 seconds.
Expand All @@ -138,7 +132,6 @@ function os::cmd::try_until_text() {

os::cmd::internal::run_until_text "${cmd}" "${text}" "${duration}" "${interval}"
}
readonly -f os::cmd::try_until_text

# Functions in the os::cmd::internal namespace are discouraged from being used outside of os::cmd

Expand Down Expand Up @@ -230,15 +223,14 @@ function os::cmd::internal::expect_exit_code_run_grep() {
( IFS=$'\n'; echo "${junit_log[*]}" >> "${JUNIT_REPORT_OUTPUT:-/dev/null}" )
os::test::junit::declare_test_end
return "${return_code}"

}
readonly -f os::cmd::internal::expect_exit_code_run_grep

# os::cmd::internal::init_tempdir initializes the temporary directory
function os::cmd::internal::init_tempdir() {
mkdir -p "${os_cmd_internal_tmpdir}"
rm -f "${os_cmd_internal_tmpdir}"/tmp_std{out,err}.log
}
readonly -f os::cmd::internal::init_tempdir

# os::cmd::internal::describe_call determines the file:line of the latest function call made
# from outside of this file in the call stack, and the name of the function being called from
Expand Down Expand Up @@ -268,7 +260,6 @@ function os::cmd::internal::describe_call() {

echo "${full_name}"
}
readonly -f os::cmd::internal::describe_call

# os::cmd::internal::determine_caller determines the file relative to the OpenShift Origin root directory
# and line number of the function call to the outer os::cmd wrapper function
Expand All @@ -293,7 +284,6 @@ function os::cmd::internal::determine_caller() {
local caller_line="${BASH_LINENO[${call_depth}-1]}"
echo "${caller_file}:${caller_line}"
}
readonly -f os::cmd::internal::determine_caller

# os::cmd::internal::describe_expectation describes a command return code evaluation function
function os::cmd::internal::describe_expectation() {
Expand All @@ -310,7 +300,6 @@ function os::cmd::internal::describe_expectation() {
echo "any result"
esac
}
readonly -f os::cmd::internal::describe_expectation

# os::cmd::internal::seconds_since_epoch returns the number of seconds elapsed since the epoch
# with milli-second precision
Expand All @@ -323,7 +312,6 @@ function os::cmd::internal::seconds_since_epoch() {
fi
echo $(bc <<< "scale=3; ${ns}/1000000000")
}
readonly -f os::cmd::internal::seconds_since_epoch

# os::cmd::internal::run_collecting_output runs the command given, piping stdout and stderr into
# the given files, and returning the exit code of the command
Expand All @@ -336,7 +324,6 @@ function os::cmd::internal::run_collecting_output() {

return "${result}"
}
readonly -f os::cmd::internal::run_collecting_output

# os::cmd::internal::success_func determines if the input exit code denotes success
# this function returns 0 for false and 1 for true to be compatible with arithmetic tests
Expand All @@ -347,7 +334,6 @@ function os::cmd::internal::success_func() {
[[ "${exit_code}" -ne "0" ]]
return $?
}
readonly -f os::cmd::internal::success_func

# os::cmd::internal::failure_func determines if the input exit code denotes failure
# this function returns 0 for false and 1 for true to be compatible with arithmetic tests
Expand All @@ -358,7 +344,6 @@ function os::cmd::internal::failure_func() {
[[ "${exit_code}" -eq "0" ]]
return $?
}
readonly -f os::cmd::internal::failure_func

# os::cmd::internal::specific_code_func determines if the input exit code matches the given code
# this function returns 0 for false and 1 for true to be compatible with arithmetic tests
Expand All @@ -370,13 +355,11 @@ function os::cmd::internal::specific_code_func() {
[[ "${exit_code}" -ne "${expected_code}" ]]
return $?
}
readonly -f os::cmd::internal::specific_code_func

# os::cmd::internal::get_results prints the stderr and stdout files
function os::cmd::internal::get_results() {
cat "${os_cmd_internal_tmpout}" "${os_cmd_internal_tmperr}"
}
readonly -f os::cmd::internal::get_results

# os::cmd::internal::get_try_until_results returns a concise view of the stdout and stderr output files
# using a timeline format, where consecutive output lines that are the same are condensed into one line
Expand All @@ -396,22 +379,19 @@ function os::cmd::internal::print_try_until_results() {
echo "There was no error output from the command."
fi
}
readonly -f os::cmd::internal::print_try_until_results

# os::cmd::internal::mark_attempt marks the end of an attempt in the stdout and stderr log files
# this is used to make the try_until_* output more concise
function os::cmd::internal::mark_attempt() {
echo -e '\x1e' >> "${os_cmd_internal_tmpout}" | tee "${os_cmd_internal_tmperr}"
}
readonly -f os::cmd::internal::mark_attempt

# os::cmd::internal::compress_output compresses an output file into timeline representation
function os::cmd::internal::compress_output() {
local logfile=$1

awk -f ${OS_ROOT}/hack/compress.awk $logfile
}
readonly -f os::cmd::internal::compress_output

# os::cmd::internal::print_results pretty-prints the stderr and stdout files
function os::cmd::internal::print_results() {
Expand All @@ -429,7 +409,6 @@ function os::cmd::internal::print_results() {
echo "There was no error output from the command."
fi
}
readonly -f os::cmd::internal::print_results

# os::cmd::internal::assemble_causes determines from the two input booleans which part of the test
# failed and generates a nice delimited list of failure causes
Expand All @@ -448,7 +427,7 @@ function os::cmd::internal::assemble_causes() {
local list=$(printf '; %s' "${causes[@]}")
echo "${list:2}"
}
readonly -f os::cmd::internal::assemble_causes


# os::cmd::internal::run_until_exit_code runs the provided command until the exit code test given
# succeeds or the timeout given runs out. Output from the command to be tested is suppressed unless
Expand Down Expand Up @@ -530,7 +509,6 @@ function os::cmd::internal::run_until_exit_code() {
os::test::junit::declare_test_end
return "${return_code}"
}
readonly -f os::cmd::internal::run_until_exit_code

# os::cmd::internal::run_until_text runs the provided command until the command output contains the
# given text or the timeout given runs out. Output from the command to be tested is suppressed unless
Expand Down Expand Up @@ -615,4 +593,3 @@ function os::cmd::internal::run_until_text() {
os::test::junit::declare_test_end
return "${return_code}"
}
readonly -f os::cmd::internal::run_until_text
Loading

0 comments on commit a8b60df

Please sign in to comment.