Use git_timed function from devstack in ggp

Gerrit git prep makes a bunch of git calls, sometimes they fail. We
don't like that - so lift the retry-git function from devstack and
re-use it.

Change-Id: I866374e14691dcdffc77e81be049b62e649750a4
This commit is contained in:
Monty Taylor 2015-04-28 08:58:35 -04:00
parent 9450ee37e3
commit c1210ef7f8

@ -3,6 +3,40 @@
GERRIT_SITE=$1
GIT_ORIGIN=$2
# git can sometimes get itself infinitely stuck with transient network
# errors or other issues with the remote end. This wraps git in a
# timeout/retry loop and is intended to watch over non-local git
# processes that might hang. GIT_TIMEOUT, if set, is passed directly
# to timeout(1); otherwise the default value of 0 maintains the status
# quo of waiting forever.
# usage: git_timed <git-command>
function git_timed {
local count=0
local timeout=0
if [[ -n "${GIT_TIMEOUT}" ]]; then
timeout=${GIT_TIMEOUT}
fi
until timeout -s SIGINT ${timeout} git "$@"; do
# 124 is timeout(1)'s special return code when it reached the
# timeout; otherwise assume fatal failure
if [[ $? -ne 124 ]]; then
exitcode=$?
echo $LINENO "git call failed: [git $@]"
exit $exitcode
fi
count=$(($count + 1))
echo "timeout ${count} for git call: [git $@]"
if [ $count -eq 3 ]; then
echo $LINENO "Maximum of 3 git retries reached"
exit 1
fi
sleep 5
done
}
if [ -z "$GERRIT_SITE" ]; then
echo "The gerrit site name (eg 'https://review.openstack.org') must be the first argument."
exit 1
@ -40,18 +74,18 @@ if [[ ! -e .git ]]; then
ls -a
rm -fr .[^.]* *
if [ -d /opt/git/$ZUUL_PROJECT/.git ]; then
git clone file:///opt/git/$ZUUL_PROJECT .
git_timed clone file:///opt/git/$ZUUL_PROJECT .
else
git clone $GIT_ORIGIN/$ZUUL_PROJECT .
git_timed clone $GIT_ORIGIN/$ZUUL_PROJECT .
fi
fi
git remote set-url origin $GIT_ORIGIN/$ZUUL_PROJECT
# attempt to work around bugs 925790 and 1229352
if ! git remote update; then
if ! git_timed remote update; then
echo "The remote update failed, so garbage collecting before trying again."
git gc
git remote update
git_timed remote update
fi
git reset --hard
@ -61,11 +95,11 @@ if ! git clean -x -f -d -q ; then
fi
if echo "$ZUUL_REF" | grep -q ^refs/tags/; then
git fetch --tags $ZUUL_URL/$ZUUL_PROJECT
git_timed fetch --tags $ZUUL_URL/$ZUUL_PROJECT
git checkout $ZUUL_REF
git reset --hard $ZUUL_REF
elif [ -z "$ZUUL_NEWREV" ]; then
git fetch $ZUUL_URL/$ZUUL_PROJECT $ZUUL_REF
git_timed fetch $ZUUL_URL/$ZUUL_PROJECT $ZUUL_REF
git checkout FETCH_HEAD
git reset --hard FETCH_HEAD
else
@ -79,7 +113,7 @@ if ! git clean -x -f -d -q ; then
fi
if [ -f .gitmodules ]; then
git submodule init
git submodule sync
git submodule update --init
git_timed submodule init
git_timed submodule sync
git_timed submodule update --init
fi