Merge pull request #1289 from Random-Liu/ignore-permission-denied
Ignore temporary permission denied error.
This commit is contained in:
commit
f7f64fdefd
@ -29,6 +29,7 @@ CLEANUP="${CLEANUP:-"true"}"
|
|||||||
root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/../..
|
root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/../..
|
||||||
script_path="${root}/test/windows"
|
script_path="${root}/test/windows"
|
||||||
node_name="windows-cri-$(cat /proc/sys/kernel/random/uuid)"
|
node_name="windows-cri-$(cat /proc/sys/kernel/random/uuid)"
|
||||||
|
tempdir="$(mktemp -d)"
|
||||||
|
|
||||||
# log logs the test logs.
|
# log logs the test logs.
|
||||||
function log() {
|
function log() {
|
||||||
@ -36,22 +37,43 @@ function log() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
|
rm -rf "$tempdir"
|
||||||
if [[ "$CLEANUP" == "true" ]]; then
|
if [[ "$CLEANUP" == "true" ]]; then
|
||||||
log "Delete the test instance"
|
log "Delete the test instance"
|
||||||
gcloud compute instances delete -q "${node_name}"
|
gcloud compute instances delete -q "${node_name}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function retry() {
|
function retry_anyway() {
|
||||||
local -r MAX_ATTEMPTS=$1
|
retry_on_error 36 5 "" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
function retry_on_permission_error() {
|
||||||
|
retry_on_error 12 5 "Permission denied" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
function retry_on_error() {
|
||||||
|
local -r MAX_ATTEMPTS="$1"
|
||||||
|
local -r SLEEP_PERIOD="$2"
|
||||||
|
local -r ON_ERROR="$3"
|
||||||
|
shift 3
|
||||||
local attempts=1
|
local attempts=1
|
||||||
shift
|
local -r stderr="$(mktemp -p "$tempdir")"
|
||||||
until "$@" || (( attempts == MAX_ATTEMPTS ))
|
until "$@" 2>"$stderr"; do
|
||||||
do
|
cat "$stderr"
|
||||||
log "$* failed, retry in 1 second..."
|
|
||||||
(( attempts++ ))
|
(( attempts++ ))
|
||||||
sleep 1
|
if [[ -n "$ON_ERROR" ]] && (! grep "$ON_ERROR" "$stderr" > /dev/null); then
|
||||||
|
log "$* failed with unexpected error!"
|
||||||
|
exit 1
|
||||||
|
elif (( attempts > MAX_ATTEMPTS )); then
|
||||||
|
log "$* failed, $MAX_ATTEMPTS retry exceeded!"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
log "$* failed, retry in ${SLEEP_PERIOD} second..."
|
||||||
|
fi
|
||||||
|
sleep "${SLEEP_PERIOD}"
|
||||||
done
|
done
|
||||||
|
rm "$stderr"
|
||||||
}
|
}
|
||||||
|
|
||||||
gcloud config set compute/zone "${ZONE}"
|
gcloud config set compute/zone "${ZONE}"
|
||||||
@ -64,32 +86,32 @@ gcloud compute instances create "${node_name}" --machine-type=n1-standard-2 \
|
|||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
log "Wait for ssh to be ready"
|
log "Wait for ssh to be ready"
|
||||||
retry 180 gcloud compute ssh "${node_name}" --command="echo ssh ready"
|
retry_anyway gcloud compute ssh "${node_name}" --command="echo ssh ready"
|
||||||
|
|
||||||
log "Setup test environment in the test instance"
|
log "Setup test environment in the test instance"
|
||||||
retry 5 gcloud compute scp "${script_path}/setup-vm.ps1" "${node_name}":"C:/setup-vm.ps1"
|
retry_on_permission_error gcloud compute scp "${script_path}/setup-vm.ps1" "${node_name}":"C:/setup-vm.ps1"
|
||||||
gcloud compute ssh "${node_name}" --command="powershell /c C:/setup-vm.ps1"
|
retry_on_permission_error gcloud compute ssh "${node_name}" --command="powershell /c C:/setup-vm.ps1"
|
||||||
|
|
||||||
log "Reboot the test instance to refresh environment variables"
|
log "Reboot the test instance to refresh environment variables"
|
||||||
gcloud compute ssh "${node_name}" --command="powershell /c Restart-Computer"
|
retry_on_permission_error gcloud compute ssh "${node_name}" --command="powershell /c Restart-Computer"
|
||||||
|
|
||||||
log "Wait for ssh to be ready"
|
log "Wait for ssh to be ready"
|
||||||
retry 180 gcloud compute ssh "${node_name}" --command="echo ssh ready"
|
retry_anyway gcloud compute ssh "${node_name}" --command="echo ssh ready"
|
||||||
|
|
||||||
log "Run test on the test instance"
|
log "Run test on the test instance"
|
||||||
cri_tar="/tmp/cri.tar.gz"
|
cri_tar="/tmp/cri.tar.gz"
|
||||||
tar -zcf "${cri_tar}" -C "${root}" . --owner=0 --group=0
|
tar -zcf "${cri_tar}" -C "${root}" . --owner=0 --group=0
|
||||||
retry 5 gcloud compute scp "${script_path}/test.sh" "${node_name}":"C:/test.sh"
|
retry_on_permission_error gcloud compute scp "${script_path}/test.sh" "${node_name}":"C:/test.sh"
|
||||||
retry 5 gcloud compute scp "${cri_tar}" "${node_name}":"C:/cri.tar.gz"
|
retry_on_permission_error gcloud compute scp "${cri_tar}" "${node_name}":"C:/cri.tar.gz"
|
||||||
rm "${cri_tar}"
|
rm "${cri_tar}"
|
||||||
# git-bash doesn't return test exit code, the command should
|
# git-bash doesn't return test exit code, the command should
|
||||||
# succeed. We'll collect test exit code from _artifacts/.
|
# succeed. We'll collect test exit code from _artifacts/.
|
||||||
gcloud compute ssh "${node_name}" --command='powershell /c "Start-Process -FilePath \"C:\Program Files\Git\git-bash.exe\" -ArgumentList \"-elc\",\"`\"/c/test.sh &> /c/test.log`\"\" -Wait"'
|
retry_on_permission_error gcloud compute ssh "${node_name}" --command='powershell /c "Start-Process -FilePath \"C:\Program Files\Git\git-bash.exe\" -ArgumentList \"-elc\",\"`\"/c/test.sh &> /c/test.log`\"\" -Wait"'
|
||||||
|
|
||||||
log "Collect test logs"
|
log "Collect test logs"
|
||||||
mkdir -p "${ARTIFACTS}"
|
mkdir -p "${ARTIFACTS}"
|
||||||
retry 5 gcloud compute scp "${node_name}":"C:/test.log" "${ARTIFACTS}"
|
retry_on_permission_error gcloud compute scp "${node_name}":"C:/test.log" "${ARTIFACTS}"
|
||||||
retry 5 gcloud compute scp --recurse "${node_name}":"C:/_artifacts/*" "${ARTIFACTS}"
|
retry_on_permission_error gcloud compute scp --recurse "${node_name}":"C:/_artifacts/*" "${ARTIFACTS}"
|
||||||
|
|
||||||
log "Test output:"
|
log "Test output:"
|
||||||
cat "${ARTIFACTS}/test.log"
|
cat "${ARTIFACTS}/test.log"
|
||||||
|
Loading…
Reference in New Issue
Block a user