Skip to content

Instantly share code, notes, and snippets.

@cloudnull
Last active August 3, 2021 14:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudnull/cb87440c8221104ed2b857e67289905f to your computer and use it in GitHub Desktop.
Save cloudnull/cb87440c8221104ed2b857e67289905f to your computer and use it in GitHub Desktop.
upgrade venvs on compute
#!/usr/bin/env bash
# When upgrading from 16.04 to 18.04 a lot of new packages get installed and a lot of old packages get removed.
# The upgrade process can break things we rely on within the virtual environments we run openstack services within.
# This script will correct issues in the venvs by fixing broken symlinks to system libraries we require.
for venv in $(find /openstack/venvs/* -maxdepth 0 -type d); do
# Update the venvs in place with the new system python
virtualenv --no-wheel --no-pip --no-setuptools --always-copy --python=/usr/bin/python "${venv}"
# Correct SSL links
ln -sf /usr/lib/python2.7/lib-dynload/_ssl.x86_64-linux-gnu.so "${venv}/local/lib/python2.7/lib-dynload/_ssl.x86_64-linux-gnu.so"
ln -sf /usr/lib/python2.7/lib-dynload/_ssl.x86_64-linux-gnu.so "${venv}/lib/python2.7/lib-dynload/_ssl.x86_64-linux-gnu.so"
# Find broken links
for broken_link in $(find "${venv}" -type l ! -exec test -e {} \; -print); do
LOCAL_LIB=$(find /usr -name "$(basename -s .so ${broken_link}).x86_64-linux-gnu.so" -print -quit)
if [[ -z "${LOCAL_LIB}" ]]; then
echo "a broken link has been found within a venv and can not be automatically fixed"
echo "BROKEN LINK: ${broken_link}"
else
ln -sf "${LOCAL_LIB}" "${broken_link}"
fi
done
done
@NewJorg
Copy link

NewJorg commented Aug 3, 2021

When you change the line 22 this script works very well else it would overwrite the files in /usr with a symbolic link to a broken symbolic link in the venv.

ln -sf "${LOCAL_LIB}" "${broken_link}"

@cloudnull
Copy link
Author

When you change the line 22 this script works very well else it would overwrite the files in /usr with a symbolic link to a broken symbolic link in the venv.

ln -sf "${LOCAL_LIB}" "${broken_link}"

👍 fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment