From 420a213ddf23f04504fcdb868966a5fe10046696 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Thu, 30 Jul 2015 09:43:01 -0400 Subject: [PATCH] make package install safer The following makes apt-get install quite a bit safer by retrying the apt-get update should it fail using a common pattern copied from devstack. It also keeps track of whether or not we've run the apt-get update during this run, which means we don't it more than once for no reason. For the specific case of the python yaml module we also check to see if it's installed first (which it often is) to avoid doing network actions when not needed. This should make the Related-Bug: #1400905 show up less often Change-Id: I77159da4e33f4255bd8a5d7d8cd3eaae3a8a59a4 --- devstack-vm-gate.sh | 9 ++++++--- functions.sh | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/devstack-vm-gate.sh b/devstack-vm-gate.sh index 45a3ea60..b8e0819d 100755 --- a/devstack-vm-gate.sh +++ b/devstack-vm-gate.sh @@ -78,10 +78,13 @@ function setup_localrc { else # Install PyYaml for test-matrix.py if uses_debs; then - sudo apt-get update - sudo apt-get --assume-yes install python-yaml + if ! dpkg -s python-yaml > /dev/null; then + apt_get_install python-yaml + fi elif is_fedora; then - sudo yum install -y PyYAML + if ! rpm --quiet -q "PyYAML"; then + sudo yum install -y PyYAML + fi fi MY_ENABLED_SERVICES=`cd $BASE/new/devstack-gate && ./test-matrix.py -b $localrc_branch -f $DEVSTACK_GATE_FEATURE_MATRIX` local original_enabled_services=$MY_ENABLED_SERVICES diff --git a/functions.sh b/functions.sh index d63e34e3..f8f0643b 100644 --- a/functions.sh +++ b/functions.sh @@ -43,6 +43,21 @@ function function_exists { type $1 2>/dev/null | grep -q 'is a function' } +function apt_get_install { + # fetch the updates in a loop to ensure that we're update to + # date. Only do this once per run. Give up to 5 minutes to succeed + # here. + if [[ -z "$APT_UPDATED" ]]; then + if ! timeout 300 sh -c "while ! sudo apt-get update; do sleep 30; done"; then + echo "Failed to update apt repos, we're dead now" + exit 1 + fi + APT_UPDATED=1 + fi + + sudo apt-get --assume-yes install $@ +} + function call_hook_if_defined { local hook_name=$1 local filename=${2-$WORKSPACE/devstack-gate-$hook_name.txt}