Skip to content

Commit d99463e

Browse files
committed
yugabyte#9334: Fix provider creation in yugabundle by using correct version of python
Summary: Our jenkins workers currently have python3.7 symlinked to `python`, so python3.7 is also used when packaging the yugabundle tarball. However, the yugabundle installation is meant for centos7, which installs python3.6 by default, so errors will arise because `ybops` will be looking for python3.7 modules rather than python3.6. This diff fixes that by prioritizing `python3.6` over other python3 versions. Test Plan: Run jenkins with simpleops (https://jenkins.dev.yugabyte.com/job/dev-itest-pipeline/181) Tested universe creation + backup on custom yugabundle Reviewers: arnav, muthu, sanketh Reviewed By: sanketh Subscribers: jenkins-bot, yugaware Differential Revision: https://phabricator.dev.yugabyte.com/D12351
1 parent e3b6f61 commit d99463e

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

managed/devops/ansible_requirements.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
- name: ansible-sshd
1212
scm: git
13-
src: https://github.com/WesleyW/ansible-sshd.git
13+
src: https://github.com/YugaByte/ansible-sshd.git
1414
version: master-yb
1515

1616
- name: ansible-prometheus

managed/devops/bin/common.sh

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ set_python_executable() {
5454
executables=( "${PYTHON2_EXECUTABLES[@]}" )
5555
fi
5656

57+
for py_executable in "${executables[@]}"; do
58+
if which "$py_executable" > /dev/null 2>&1; then
59+
PYTHON_EXECUTABLE="$py_executable"
60+
return
61+
fi
62+
done
63+
5764
if which python > /dev/null 2>&1; then
5865
if python -c 'import sys; sys.exit(1) if sys.version_info[0] != 2 else sys.exit(0)'; then
5966
if [[ "$YB_MANAGED_DEVOPS_USE_PYTHON3" == "0" ]]; then
@@ -66,21 +73,15 @@ set_python_executable() {
6673
fi
6774
fi
6875

69-
for py_executable in "${executables[@]}"; do
70-
if which "$py_executable" > /dev/null 2>&1; then
71-
PYTHON_EXECUTABLE="$py_executable"
72-
return
73-
fi
74-
done
75-
76-
fatal "Failed to find python executable."
76+
echo "Failed to find python executable."
77+
exit 1
7778
}
7879

7980
# -------------------------------------------------------------------------------------------------
8081
# Constants
8182
# -------------------------------------------------------------------------------------------------
8283
readonly PYTHON2_EXECUTABLES=('python2' 'python2.7')
83-
readonly PYTHON3_EXECUTABLES=('python3' 'python3.6' 'python3.7' 'python3.8')
84+
readonly PYTHON3_EXECUTABLES=('python3.6' 'python3' 'python3.7' 'python3.8')
8485
PYTHON_EXECUTABLE=""
8586

8687
readonly YB_MANAGED_DEVOPS_USE_PYTHON3=${YB_MANAGED_DEVOPS_USE_PYTHON3:-1}
@@ -269,6 +270,7 @@ deactivate_virtualenv() {
269270

270271
unset VIRTUAL_ENV
271272
unset PYTHONPATH
273+
set_python_executable
272274
fi
273275
}
274276

@@ -280,6 +282,7 @@ activate_virtualenv() {
280282
if [[ -d "$YB_INSTALLED_MODULES_DIR" ]]; then
281283
export PYTHONPATH="${YB_INSTALLED_MODULES_DIR}:${MANAGED_PYTHONPATH_ORIGINAL}"
282284
export PATH="${YB_INSTALLED_MODULES_DIR}/bin:${MANAGED_PATH_ORIGINAL}"
285+
export SITE_PACKAGES="$YB_INSTALLED_MODULES_DIR"
283286
return
284287
fi
285288

@@ -290,7 +293,6 @@ activate_virtualenv() {
290293
if [[ ! -d $virtualenv_dir ]]; then
291294
# We need to be using system python to install the virtualenv module or create a new virtualenv.
292295
deactivate_virtualenv
293-
set_python_executable
294296
if [[ $YB_MANAGED_DEVOPS_USE_PYTHON3 == "0" ]]; then
295297
pip_install "virtualenv<20"
296298
fi
@@ -316,6 +318,9 @@ activate_virtualenv() {
316318
set +u
317319
. "$virtualenv_dir"/bin/activate
318320
set -u
321+
export SITE_PACKAGES=$(python -c "import sysconfig; print(sysconfig.get_path('purelib'))")
322+
PYTHON_EXECUTABLE="python"
323+
log "Using virtualenv python executable now."
319324

320325
# We unset the pythonpath to make sure we aren't looking at the global pythonpath.
321326
unset PYTHONPATH
@@ -345,7 +350,7 @@ create_pymodules_package() {
345350
# Change shebangs to be path-independent.
346351
current_py_exec=$(which $PYTHON_EXECUTABLE)
347352
LC_ALL=C find "$YB_PYTHON_MODULES_DIR"/bin ! -name '*.pyc' -type f -exec sed -i.yb_tmp \
348-
-e "1s|${current_py_exec}|/usr/bin/env python|" {} \; -exec rm {}.yb_tmp \;
353+
-e "1s|${current_py_exec}|/usr/bin/env ${PYTHON_EXECUTABLE}|" {} \; -exec rm {}.yb_tmp \;
349354
tar -C $(dirname "$YB_PYTHON_MODULES_DIR") -czvf "$YB_PYTHON_MODULES_PACKAGE" \
350355
$(basename "$YB_PYTHON_MODULES_DIR")
351356
rm -rf "$YB_PYTHON_MODULES_DIR"

managed/devops/opscli/ybops/cloud/common/ansible.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ def run(self, filename, extra_vars=dict(), host_info={}, print_output=True):
121121
"-e", "ansible_python_interpreter='/usr/bin/env python'"
122122
])
123123

124-
os.environ['SITE_PACKAGES'] = sysconfig.get_path('purelib')
125-
126124
# Setup the full list of extra-vars needed for ansible plays.
127125
process_args.extend(["--extra-vars", json.dumps(playbook_args)])
128126
env = os.environ.copy()

0 commit comments

Comments
 (0)