Ubuntu's apt mirroring mechanism produces inconsistent mirrors pretty
regularly. The devstack-gate apt-get update model seems to have been
more effective getting past this than what we did in devstack. Adopt
that method for our updates.
Change-Id: I97c7896ef38b275aacb4f933fc849acee1bab858
... | ... |
@@ -978,6 +978,34 @@ function _get_package_dir { |
978 | 978 |
echo "$pkg_dir" |
979 | 979 |
} |
980 | 980 |
|
981 |
+# Wrapper for ``apt-get update`` to try multiple times on the update |
|
982 |
+# to address bad package mirrors (which happen all the time). |
|
983 |
+function apt_get_update { |
|
984 |
+ # only do this once per run |
|
985 |
+ if [[ "$REPOS_UPDATED" == "True" && "$RETRY_UPDATE" != "True" ]]; then |
|
986 |
+ return |
|
987 |
+ fi |
|
988 |
+ |
|
989 |
+ # bail if we are offline |
|
990 |
+ [[ "$OFFLINE" = "True" ]] && return |
|
991 |
+ |
|
992 |
+ local sudo="sudo" |
|
993 |
+ [[ "$(id -u)" = "0" ]] && sudo="env" |
|
994 |
+ |
|
995 |
+ # time all the apt operations |
|
996 |
+ time_start "apt-get-update" |
|
997 |
+ |
|
998 |
+ local proxies="http_proxy=${http_proxy:-} https_proxy=${https_proxy:-} no_proxy=${no_proxy:-} " |
|
999 |
+ local update_cmd="$sudo $proxies apt-get update" |
|
1000 |
+ if ! timeout 300 sh -c "while ! $update_cmd; do sleep 30; done"; then |
|
1001 |
+ die $LINENO "Failed to update apt repos, we're dead now" |
|
1002 |
+ fi |
|
1003 |
+ |
|
1004 |
+ REPOS_UPDATED=True |
|
1005 |
+ # stop the clock |
|
1006 |
+ time_stop "apt-get-update" |
|
1007 |
+} |
|
1008 |
+ |
|
981 | 1009 |
# Wrapper for ``apt-get`` to set cache and proxy environment variables |
982 | 1010 |
# Uses globals ``OFFLINE``, ``*_proxy`` |
983 | 1011 |
# apt_get operation package [package ...] |
... | ... |
@@ -1158,16 +1186,7 @@ function update_package_repo { |
1158 | 1158 |
fi |
1159 | 1159 |
|
1160 | 1160 |
if is_ubuntu; then |
1161 |
- local xtrace |
|
1162 |
- xtrace=$(set +o | grep xtrace) |
|
1163 |
- set +o xtrace |
|
1164 |
- if [[ "$REPOS_UPDATED" != "True" || "$RETRY_UPDATE" = "True" ]]; then |
|
1165 |
- # if there are transient errors pulling the updates, that's fine. |
|
1166 |
- # It may be secondary repositories that we don't really care about. |
|
1167 |
- apt_get update || /bin/true |
|
1168 |
- REPOS_UPDATED=True |
|
1169 |
- fi |
|
1170 |
- $xtrace |
|
1161 |
+ apt_get_update |
|
1171 | 1162 |
fi |
1172 | 1163 |
} |
1173 | 1164 |
|