Skip to content

Commit

Permalink
define bash function echoerror
Browse files Browse the repository at this point in the history
  • Loading branch information
gargnitingoogle committed Oct 9, 2024
1 parent 9bb8bdf commit 3d1dbd7
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions perfmetrics/scripts/testing_on_gke/examples/run-gke-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fi
# Utilities
function exitWithSuccess() { exit 0; }
function exitWithFailure() { exit 1; }
function echoerror() { >&2 echo "Error: "$@; }

# Default values, to be used for parameters in case user does not specify them.
# GCP related
Expand Down Expand Up @@ -112,11 +113,11 @@ fi
# GCP related
if test -n "${project_id}"; then
if test -z "${project_number}"; then
>&2 echo "Error: project_id was set, but not project_number. Either both should be specified, or neither."
echoerror "project_id was set, but not project_number. Either both should be specified, or neither."
exitWithFailure
fi
elif test -n "${project_number}"; then
>&2 echo "Error: project_number was set, but not project_id. Either both should be specified, or neither."
echoerror "project_number was set, but not project_id. Either both should be specified, or neither."
exitWithFailure
else
export project_id=${DEFAULT_PROJECT_ID}
Expand Down Expand Up @@ -148,7 +149,7 @@ fi

if test -n "${gcsfuse_src_dir}"; then
if ! test -d "${gcsfuse_src_dir}"; then
>&2 echo "Error: gcsfuse_src_dir \"${gcsfuse_src_dir}\" does not exist"
echoerror "gcsfuse_src_dir \"${gcsfuse_src_dir}\" does not exist"
exitWithFailure
fi
export gcsfuse_src_dir="$(realpath "${gcsfuse_src_dir}")"
Expand All @@ -164,7 +165,7 @@ export gke_testing_dir="${gcsfuse_src_dir}"/perfmetrics/scripts/testing_on_gke

if test -n "${csi_src_dir}"; then
if ! test -d "${csi_src_dir}"; then
>&2 echo "Error: csi_src_dir \"${csi_src_dir}\" does not exist"
echoerror "csi_src_dir \"${csi_src_dir}\" does not exist"
exitWithFailure
fi
export csi_src_dir="$(realpath "${csi_src_dir}")"
Expand All @@ -173,20 +174,20 @@ else
fi

# GCSFuse configuration related - deprecated. Will cause error.
test -z "${gcsfuse_mount_options}" || (>&2 echo "Error: gcsfuse_mount_options set by user is a deprecated option. Please set gcsfuseMountOptions in workload objects in workload configuration file in its place." && exitWithFailure )
test -z "${gcsfuse_mount_options}" || (echoerror "gcsfuse_mount_options set by user is a deprecated option. Please set gcsfuseMountOptions in workload objects in workload configuration file in its place." && exitWithFailure )
# Test runtime configuration
test -n "${pod_wait_time_in_seconds}" || export pod_wait_time_in_seconds="${DEFAULT_POD_WAIT_TIME_IN_SECONDS}"
test -n "${pod_timeout_in_seconds}" || export pod_timeout_in_seconds="${DEFAULT_POD_TIMEOUT_IN_SECONDS}"
test -n "${instance_id}" || export instance_id="${DEFAULT_INSTANCE_ID}"

if [[ ${pod_timeout_in_seconds} -le ${pod_wait_time_in_seconds} ]]; then
>&2 echo "Error: pod_timeout_in_seconds (${pod_timeout_in_seconds}) <= pod_wait_time_in_seconds (${pod_wait_time_in_seconds})"
echoerror "pod_timeout_in_seconds (${pod_timeout_in_seconds}) <= pod_wait_time_in_seconds (${pod_wait_time_in_seconds})"
exitWithFailure
fi

if test -n "${workload_config}"; then
if ! test -f "${workload_config}"; then
>&2 echo "Error: workload_config \"${workload_config}\" does not exist"
echoerror "workload_config \"${workload_config}\" does not exist"
exitWithFailure
fi
export workload_config="$(realpath "${workload_config}")"
Expand All @@ -196,7 +197,7 @@ fi

if test -n "${output_dir}"; then
if ! test -d "${output_dir}"; then
>&2 echo "Error: output_dir \"${output_dir}\" does not exist"
echoerror "output_dir \"${output_dir}\" does not exist"
exitWithFailure
fi
export output_dir="$(realpath "${output_dir}")"
Expand Down Expand Up @@ -308,8 +309,8 @@ function installDependencies() {
which jq || sudo apt-get install -y jq
# Ensure sudoless docker is installed.
if ! docker ps 1>/dev/null ; then
>&2 echo "Error: sudoless docker is not installed on this machine ($(hostname)). Please install sudoless-docker using the following commands and re-run this script ($0)"
>&2 echo "sudo addgroup docker && sudo usermod -aG docker $USER && newgrp docker"
echoerror "sudoless docker is not installed on this machine ($(hostname)). Please install sudoless-docker using the following commands and re-run this script ($0)"
echoerror "sudo addgroup docker && sudo usermod -aG docker $USER && newgrp docker"
return 1
fi
# Install python modules for gsheet.
Expand Down Expand Up @@ -343,19 +344,19 @@ function validateMachineConfig() {
case "${machine_type}" in
"n2-standard-96")
if [ ${num_ssd} -ne 0 -a ${num_ssd} -ne 16 -a ${num_ssd} -ne 24 ]; then
>&2 echo "Error: Unsupported num-ssd "${num_ssd}" with given machine-type "${machine_type}". It should be 0, 16 or 24"
echoerror "Unsupported num-ssd "${num_ssd}" with given machine-type "${machine_type}". It should be 0, 16 or 24"
return 1
fi
;;
"n2-standard-48")
if [ ${num_ssd} -ne 0 -a ${num_ssd} -ne 8 -a ${num_ssd} -ne 16 -a ${num_ssd} -ne 24 ]; then
>&2 echo "Error: Unsupported num-ssd "${num_ssd}" with given machine-type "${machine_type}". It should be 0, 8, 16 or 24"
echoerror "Unsupported num-ssd "${num_ssd}" with given machine-type "${machine_type}". It should be 0, 8, 16 or 24"
return 1
fi
;;
"n2-standard-32")
if [ ${num_ssd} -ne 0 -a ${num_ssd} -ne 4 -a ${num_ssd} -ne 8 -a ${num_ssd} -ne 16 -a ${num_ssd} -ne 24 ]; then
>&2 echo "Error: Unsupported num-ssd "${num_ssd}" with given machine-type "${machine_type}". It should be 0, 4, 8, 16 or 24"
echoerror "Unsupported num-ssd "${num_ssd}" with given machine-type "${machine_type}". It should be 0, 4, 8, 16 or 24"
return 1
fi
;;
Expand Down Expand Up @@ -511,7 +512,7 @@ function ensureGcsfuseCode() {
cd ${gcsfuse_src_dir} && git fetch --all && git reset --hard origin/${gcsfuse_branch} && cd -
fi
test -d "${gke_testing_dir}" || (>&2 echo "Error: ${gke_testing_dir} does not exist" && exitWithFailure )
test -d "${gke_testing_dir}" || (echoerror "${gke_testing_dir} does not exist" && exitWithFailure )
}
function ensureGcsFuseCsiDriverCode() {
Expand All @@ -535,7 +536,7 @@ function createCustomCsiDriverIfNeeded() {
package_bucket=${package_bucket/google/}
fi
if [[ ${#package_bucket} -gt 63 ]] ; then
>&2 echo "Error: package_bucket \"${package_bucket}\" is too long (should be <= 63)"
echoerror "package_bucket \"${package_bucket}\" is too long (should be <= 63)"
return 1
fi
# If package_bucket does not already exist, create it.
Expand Down Expand Up @@ -610,7 +611,7 @@ function waitTillAllPodsComplete() {
cur_epoch=$(date +%s)
time_till_timeout=$((start_epoch+pod_timeout_in_seconds-cur_epoch))
if [[ ${time_till_timeout} -lt 0 ]]; then
>&2 printf "\nError: Pod-run timed out!\n\n"
echoerror printf "\nPod-run timed out!\n\n"
printf "Clearing all pods created in this run...\n"
deleteAllPods
exitWithFailure
Expand Down

0 comments on commit 3d1dbd7

Please sign in to comment.