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
(cherry picked from commit 88ee8ce4684e13865123636dd5d2baa5d6a44ef7)
| ... | ... |
@@ -982,6 +982,29 @@ function _get_package_dir {
|
| 982 | 982 |
echo "$pkg_dir" |
| 983 | 983 |
} |
| 984 | 984 |
|
| 985 |
+# Wrapper for ``apt-get update`` to try multiple times on the update |
|
| 986 |
+# to address bad package mirrors (which happen all the time). |
|
| 987 |
+function apt_get_update {
|
|
| 988 |
+ # only do this once per run |
|
| 989 |
+ if [[ "$REPOS_UPDATED" == "True" && "$RETRY_UPDATE" != "True" ]]; then |
|
| 990 |
+ return |
|
| 991 |
+ fi |
|
| 992 |
+ |
|
| 993 |
+ # bail if we are offline |
|
| 994 |
+ [[ "$OFFLINE" = "True" ]] && return |
|
| 995 |
+ |
|
| 996 |
+ local sudo="sudo" |
|
| 997 |
+ [[ "$(id -u)" = "0" ]] && sudo="env" |
|
| 998 |
+ |
|
| 999 |
+ local proxies="http_proxy=${http_proxy:-} https_proxy=${https_proxy:-} no_proxy=${no_proxy:-} "
|
|
| 1000 |
+ local update_cmd="$sudo $proxies apt-get update" |
|
| 1001 |
+ if ! timeout 300 sh -c "while ! $update_cmd; do sleep 30; done"; then |
|
| 1002 |
+ die $LINENO "Failed to update apt repos, we're dead now" |
|
| 1003 |
+ fi |
|
| 1004 |
+ |
|
| 1005 |
+ REPOS_UPDATED=True |
|
| 1006 |
+} |
|
| 1007 |
+ |
|
| 985 | 1008 |
# Wrapper for ``apt-get`` to set cache and proxy environment variables |
| 986 | 1009 |
# Uses globals ``OFFLINE``, ``*_proxy`` |
| 987 | 1010 |
# apt_get operation package [package ...] |
| ... | ... |
@@ -1148,15 +1171,7 @@ function update_package_repo {
|
| 1148 | 1148 |
fi |
| 1149 | 1149 |
|
| 1150 | 1150 |
if is_ubuntu; then |
| 1151 |
- local xtrace=$(set +o | grep xtrace) |
|
| 1152 |
- set +o xtrace |
|
| 1153 |
- if [[ "$REPOS_UPDATED" != "True" || "$RETRY_UPDATE" = "True" ]]; then |
|
| 1154 |
- # if there are transient errors pulling the updates, that's fine. |
|
| 1155 |
- # It may be secondary repositories that we don't really care about. |
|
| 1156 |
- apt_get update || /bin/true |
|
| 1157 |
- REPOS_UPDATED=True |
|
| 1158 |
- fi |
|
| 1159 |
- $xtrace |
|
| 1151 |
+ apt_get_update |
|
| 1160 | 1152 |
fi |
| 1161 | 1153 |
} |
| 1162 | 1154 |
|