Skip to content

Commit 7df4f40

Browse files
Fix kolla-ansible to work with pyenv-virtualenv
One of the pyenv-virtualenv-set-up aliases depends on a symlink. It seems pyenv runs the bash script from such a path and it fails because of a failing comparison (VIRTUAL_ENV not detected). The VIRTUAL_ENV is ensured to be fully resolved as well for safety. This requires readlink from GNU coreutils but all supported platforms have it by default. Extra comments included, as well as simplification of directory detection - readlink handles this (not that `bin` itself was ever a symlink...). Closes-Bug: #1903887 Co-Authored-By: Radosław Piliszek <[email protected]> Change-Id: I2fe6eb13ce7be68d346b1b3b7036859f34c896c4 (cherry picked from commit aaab1d1)
1 parent e492b58 commit 7df4f40

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/kolla-ansible

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,24 @@ function check_environment_coherence {
6666

6767
function find_base_dir {
6868
local dir_name
69-
dir_name=$(cd "$(dirname "$0")" &>/dev/null && pwd)
69+
dir_name=$(dirname "$0")
70+
# NOTE(yoctozepto): Fix the case where dir_name is a symlink and VIRTUAL_ENV might not be. This
71+
# happens with pyenv-virtualenv, see https://bugs.launchpad.net/kolla-ansible/+bug/1903887
72+
dir_name=$(readlink -e "$dir_name")
7073
if [ -z "$SNAP" ]; then
7174
if [[ ${dir_name} == "/usr/bin" ]]; then
7275
BASEDIR=/usr/share/kolla-ansible
7376
elif [[ ${dir_name} == "/usr/local/bin" ]]; then
7477
BASEDIR=/usr/local/share/kolla-ansible
75-
elif [[ -n ${VIRTUAL_ENV} ]] && [[ ${dir_name} == "${VIRTUAL_ENV}/bin" ]]; then
78+
elif [[ -n ${VIRTUAL_ENV} ]] && [[ ${dir_name} == "$(readlink -e "${VIRTUAL_ENV}/bin")" ]]; then
7679
if test -f ${VIRTUAL_ENV}/lib/python*/site-packages/kolla-ansible.egg-link; then
7780
# Editable install.
7881
BASEDIR="$(head -n1 ${VIRTUAL_ENV}/lib/python*/site-packages/kolla-ansible.egg-link)"
7982
else
8083
BASEDIR="${VIRTUAL_ENV}/share/kolla-ansible"
8184
fi
8285
else
86+
# Running from sources (repo).
8387
BASEDIR="$(dirname ${dir_name})"
8488
fi
8589
else

0 commit comments

Comments
 (0)