Skip to content

Commit fbcf7c0

Browse files
committed
[2.5.3][Platform]: Revert python packaging changes made for python3.
Summary: Revert the python3 prioritization packaging changes. 2.5.3 will use python2 and later versions will move towards python3. Test Plan: bin/install_python_requirements.sh --create_package bin/install_python_requirements.sh --use_package --- Reviewers: daniel, sanketh Reviewed By: sanketh Subscribers: jenkins-bot, yugaware Differential Revision: https://phabricator.dev.yugabyte.com/D10908
1 parent 677f7f1 commit fbcf7c0

File tree

11 files changed

+160
-235
lines changed

11 files changed

+160
-235
lines changed

managed/devops/bin/common.sh

Lines changed: 64 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -47,120 +47,20 @@ regex_from_list() {
4747
echo "^($regex)$"
4848
}
4949

50-
# This just logs to stderr.
51-
log() {
52-
BEGIN_COLOR='\033[0;32m'
53-
END_COLOR='\033[0m'
54-
GREEN='\033[0;32m'
55-
RED='\033[0;31m'
56-
57-
case ${_log_level:-info} in
58-
error)
59-
BEGIN_COLOR='\033[0;31m'
60-
shift
61-
;;
62-
warn)
63-
BEGIN_COLOR='\033[0;33m'
64-
shift
65-
;;
66-
esac
67-
echo -e "${BEGIN_COLOR}[$( get_timestamp ) \
68-
${BASH_SOURCE[1]##*/}:${BASH_LINENO[0]} ${FUNCNAME[1]}]${END_COLOR}" $* >&2
69-
}
70-
71-
fatal() {
72-
log "$@"
73-
exit 1
74-
}
75-
76-
get_timestamp() {
77-
date +%Y-%m-%d_%H_%M_%S
78-
}
79-
80-
check_python_executables() {
81-
executables=("$@")
82-
for py_executable in "${executables[@]}"; do
83-
if which "$py_executable" > /dev/null 2>&1; then
84-
PYTHON_EXECUTABLE="$py_executable"
85-
return 0
86-
fi
87-
done
88-
return 1
89-
}
90-
91-
set_python_vars() {
92-
# Prioritize python3 over python2.
93-
if [ -z "$YB_MANAGED_DEVOPS_USE_PYTHON3" ]; then
94-
if check_python_executables "${PYTHON3_EXECUTABLES[@]}"; then
95-
YB_MANAGED_DEVOPS_USE_PYTHON3="1"
96-
elif check_python_executables "${PYTHON2_EXECUTABLES[@]}"; then
97-
YB_MANAGED_DEVOPS_USE_PYTHON3="0"
98-
fi
99-
100-
if [ -z "$PYTHON_EXECUTABLE" ]; then
101-
if which python > /dev/null 2>&1; then
102-
PYTHON_EXECUTABLE="python"
103-
if python -c 'import sys; sys.exit(1) if sys.version_info[0] != 2 else sys.exit(0)'; then
104-
YB_MANAGED_DEVOPS_USE_PYTHON3="0"
105-
else
106-
YB_MANAGED_DEVOPS_USE_PYTHON3="1"
107-
fi
108-
fi
109-
fi
110-
else
111-
if which python > /dev/null 2>&1; then
112-
if python -c 'import sys; sys.exit(1) if sys.version_info[0] != 2 else sys.exit(0)'; then
113-
if [[ "$YB_MANAGED_DEVOPS_USE_PYTHON3" == "0" ]]; then
114-
PYTHON_EXECUTABLE="python"
115-
fi
116-
elif [[ "$YB_MANAGED_DEVOPS_USE_PYTHON3" == "1" ]]; then
117-
PYTHON_EXECUTABLE="python"
118-
fi
119-
fi
120-
121-
if [ -z "$PYTHON_EXECUTABLE" ]; then
122-
POSSIBLE_EXECUTABLES="$PYTHON3_EXECUTABLES"
123-
if [[ "$YB_MANAGED_DEVOPS_USE_PYTHON3" == "0" ]]; then
124-
POSSIBLE_EXECUTABLES="$PYTHON2_EXECUTABLES"
125-
fi
126-
check_python_executables "${POSSIBLE_EXECUTABLES[@]}"
127-
fi
128-
fi
129-
130-
if [[ $YB_MANAGED_DEVOPS_USE_PYTHON3 != "0" &&
131-
$YB_MANAGED_DEVOPS_USE_PYTHON3 != "1" ]]; then
132-
fatal "Invalid value of YB_MANAGED_DEVOPS_USE_PYTHON3: $YB_MANAGED_DEVOPS_USE_PYTHON3," \
133-
"expected 0 or 1"
134-
fi
135-
if [ -z "$PYTHON_EXECUTABLE" ]; then
136-
fatal "Failed to find python executable."
137-
fi
138-
139-
if [[ $YB_MANAGED_DEVOPS_USE_PYTHON3 == "1" ]]; then
140-
YB_VIRTUALENV_BASENAME=venv
141-
REQUIREMENTS_FILE_NAME="$yb_devops_home/python3_requirements.txt"
142-
FROZEN_REQUIREMENTS_FILE="$yb_devops_home/python3_requirements_frozen.txt"
143-
YB_PYTHON_MODULES_DIR="$yb_devops_home/python3_modules"
144-
YB_PYTHON_MODULES_PACKAGE="$yb_devops_home/python3_modules.tar.gz"
145-
YB_INSTALLED_MODULES_DIR="$yb_devops_home/python3_installed_modules"
146-
else
147-
YB_VIRTUALENV_BASENAME=python_virtual_env
148-
REQUIREMENTS_FILE_NAME="$yb_devops_home/python_requirements.txt"
149-
FROZEN_REQUIREMENTS_FILE="$yb_devops_home/python_requirements_frozen.txt"
150-
YB_PYTHON_MODULES_DIR="$yb_devops_home/python2_modules"
151-
YB_PYTHON_MODULES_PACKAGE="$yb_devops_home/python2_modules.tar.gz"
152-
YB_INSTALLED_MODULES_DIR="$yb_devops_home/python2_installed_modules"
153-
fi
154-
}
155-
15650
# -------------------------------------------------------------------------------------------------
15751
# Constants
15852
# -------------------------------------------------------------------------------------------------
159-
readonly PYTHON2_EXECUTABLES=('python2' 'python2.7')
160-
readonly PYTHON3_EXECUTABLES=('python3' 'python3.6' 'python3.7' 'python3.8')
161-
PYTHON_EXECUTABLE=""
162-
USER_INPUT_MANAGED_DEVOPS_USE_PYTHON3=${YB_MANAGED_DEVOPS_USE_PYTHON3:-""}
163-
YB_MANAGED_DEVOPS_USE_PYTHON3=""
53+
DEFAULT_USE_PY3_VALUE="1"
54+
if python -c 'import sys; sys.exit(1) if sys.version_info[0] != 2 else sys.exit(0)'; then
55+
DEFAULT_USE_PY3_VALUE="0"
56+
fi
57+
58+
readonly YB_MANAGED_DEVOPS_USE_PYTHON3=${YB_MANAGED_DEVOPS_USE_PYTHON3:-$DEFAULT_USE_PY3_VALUE}
59+
if [[ $YB_MANAGED_DEVOPS_USE_PYTHON3 != "0" &&
60+
$YB_MANAGED_DEVOPS_USE_PYTHON3 != "1" ]]; then
61+
fatal "Invalid value of YB_MANAGED_DEVOPS_USE_PYTHON3: $YB_MANAGED_DEVOPS_USE_PYTHON3," \
62+
"expected 0 or 1"
63+
fi
16464

16565
readonly yb_script_name=${0##*/}
16666
readonly yb_script_name_no_extension=${yb_script_name%.sh}
@@ -189,12 +89,22 @@ set +u
18989
readonly MANAGED_PYTHONPATH_ORIGINAL="${PYTHONPATH:-}"
19090
set -u
19191

192-
YB_VIRTUALENV_BASENAME=venv
193-
REQUIREMENTS_FILE_NAME="$yb_devops_home/python3_requirements.txt"
194-
FROZEN_REQUIREMENTS_FILE="$yb_devops_home/python3_requirements_frozen.txt"
195-
YB_PYTHON_MODULES_DIR="$yb_devops_home/python3_modules"
196-
YB_PYTHON_MODULES_PACKAGE="$yb_devops_home/python3_modules.tar.gz"
197-
YB_INSTALLED_MODULES_DIR="$yb_devops_home/python3_installed_modules"
92+
# Basename (i.e. name excluding the directory path) of our virtualenv.
93+
if [[ $YB_MANAGED_DEVOPS_USE_PYTHON3 == "1" ]]; then
94+
readonly YB_VIRTUALENV_BASENAME=venv
95+
readonly REQUIREMENTS_FILE_NAME="$yb_devops_home/python3_requirements.txt"
96+
readonly FROZEN_REQUIREMENTS_FILE="$yb_devops_home/python3_requirements_frozen.txt"
97+
readonly YB_PYTHON_MODULES_DIR="$yb_devops_home/python3_modules"
98+
readonly YB_PYTHON_MODULES_PACKAGE="$yb_devops_home/python3_modules.tar.gz"
99+
readonly YB_INSTALLED_MODULES_DIR="$yb_devops_home/python3_installed_modules"
100+
else
101+
readonly YB_VIRTUALENV_BASENAME=python_virtual_env
102+
readonly REQUIREMENTS_FILE_NAME="$yb_devops_home/python_requirements.txt"
103+
readonly FROZEN_REQUIREMENTS_FILE="$yb_devops_home/python_requirements_frozen.txt"
104+
readonly YB_PYTHON_MODULES_DIR="$yb_devops_home/python2_modules"
105+
readonly YB_PYTHON_MODULES_PACKAGE="$yb_devops_home/python2_modules.tar.gz"
106+
readonly YB_INSTALLED_MODULES_DIR="$yb_devops_home/python2_installed_modules"
107+
fi
198108

199109
readonly YBOPS_TOP_LEVEL_DIR_BASENAME=opscli
200110
readonly YBOPS_PACKAGE_NAME=ybops
@@ -217,6 +127,35 @@ log_error() {
217127
log "$@"
218128
}
219129

130+
# This just logs to stderr.
131+
log() {
132+
BEGIN_COLOR='\033[0;32m'
133+
END_COLOR='\033[0m'
134+
GREEN='\033[0;32m'
135+
RED='\033[0;31m'
136+
137+
case ${_log_level:-info} in
138+
error)
139+
BEGIN_COLOR='\033[0;31m'
140+
shift
141+
;;
142+
warn)
143+
BEGIN_COLOR='\033[0;33m'
144+
shift
145+
;;
146+
esac
147+
echo -e "${BEGIN_COLOR}[$( get_timestamp ) ${BASH_SOURCE[1]##*/}:${BASH_LINENO[0]} ${FUNCNAME[1]}]${END_COLOR}" $* >&2
148+
}
149+
150+
fatal() {
151+
log "$@"
152+
exit 1
153+
}
154+
155+
get_timestamp() {
156+
date +%Y-%m-%d_%H_%M_%S
157+
}
158+
220159
ensure_log_dir_defined() {
221160
if [[ -z ${log_dir:-} ]]; then
222161
fatal "log_dir is not set"
@@ -268,7 +207,7 @@ deactivate_virtualenv() {
268207
return
269208
fi
270209

271-
if [[ -d "$YB_INSTALLED_MODULES_DIR" ]]; then
210+
if [[ -f "$YB_INSTALLED_MODULES_DIR" ]]; then
272211
export PYTHONPATH=$MANAGED_PYTHONPATH_ORIGINAL
273212
return
274213
fi
@@ -306,7 +245,7 @@ activate_virtualenv() {
306245
return
307246
fi
308247

309-
if [[ -d "$YB_INSTALLED_MODULES_DIR" ]]; then
248+
if [[ -f "$YB_INSTALLED_MODULES_DIR" ]]; then
310249
export PYTHONPATH="${YB_INSTALLED_MODULES_DIR}:${MANAGED_PYTHONPATH_ORIGINAL}"
311250
return
312251
fi
@@ -318,10 +257,6 @@ activate_virtualenv() {
318257
if [[ ! -d $virtualenv_dir ]]; then
319258
# We need to be using system python to install the virtualenv module or create a new virtualenv.
320259
deactivate_virtualenv
321-
# Reset python variables after deactivating virtualenv
322-
PYTHON_EXECUTABLE=""
323-
YB_MANAGED_DEVOPS_USE_PYTHON3=$USER_INPUT_MANAGED_DEVOPS_USE_PYTHON3
324-
set_python_vars
325260

326261
if [[ $YB_MANAGED_DEVOPS_USE_PYTHON3 == "0" ]]; then
327262
pip_install "virtualenv<20"
@@ -331,10 +266,10 @@ activate_virtualenv() {
331266
set -x
332267
cd "${virtualenv_dir%/*}"
333268
if [[ $YB_MANAGED_DEVOPS_USE_PYTHON3 == "1" ]]; then
334-
"$PYTHON_EXECUTABLE" -m venv "$YB_VIRTUALENV_BASENAME"
269+
python3 -m venv "$YB_VIRTUALENV_BASENAME"
335270
else
336271
# Assuming that the default python binary is pointing to Python 2.7.
337-
"$PYTHON_EXECUTABLE" -m virtualenv --no-setuptools "$YB_VIRTUALENV_BASENAME"
272+
python -m virtualenv --no-setuptools "$YB_VIRTUALENV_BASENAME"
338273
fi
339274
)
340275
elif "$is_linux"; then
@@ -431,9 +366,9 @@ verbose_mkdir_p() {
431366

432367
run_pip() {
433368
if [[ $YB_MANAGED_DEVOPS_USE_PYTHON3 == "1" ]]; then
434-
"$PYTHON_EXECUTABLE" -m pip "$@"
369+
pip3 "$@"
435370
else
436-
"$PYTHON_EXECUTABLE" "$(which pip)" "$@"
371+
python "$(which pip)" "$@"
437372
fi
438373
}
439374

@@ -531,7 +466,8 @@ install_ybops_package() {
531466
fi
532467
(
533468
cd "$yb_devops_home/$YBOPS_TOP_LEVEL_DIR_BASENAME"
534-
"$PYTHON_EXECUTABLE" setup.py install $user_flag
469+
log "Using python: $( which python )"
470+
python setup.py install $user_flag
535471
rm -rf build dist "$YBOPS_PACKAGE_NAME.egg-info"
536472
)
537473
virtualenv_aware_log "Installed the ybops package"
@@ -576,7 +512,6 @@ detect_os() {
576512
# Initialization
577513
# -------------------------------------------------------------------------------------------------
578514

579-
set_python_vars
580515
detect_os
581516

582517
#

managed/devops/bin/ybcloud.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ set -e
1212
. "${BASH_SOURCE%/*}"/common.sh
1313

1414
activate_virtualenv
15+
cd "$yb_devops_home"
1516

16-
if [[ -d "$YB_INSTALLED_MODULES_DIR" ]]; then
17-
"$PYTHON_EXECUTABLE" "$yb_devops_home"/opscli/ybops/scripts/ybcloud.py "$@"
18-
else
19-
"$PYTHON_EXECUTABLE" "$(which ybcloud.py)" "$@"
20-
fi
17+
python "$(which ybcloud.py)" "$@"

managed/devops/opscli/ybops/cloud/aws/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def __init__(self, metadata, host_vpc_id, host_vpc_region):
210210
self._validate_cidr_overlap()
211211

212212
def _validate_cidr_overlap(self):
213-
region_networks = [ip_network(cidr) for cidr in self.region_cidrs.values()]
213+
region_networks = [ip_network(cidr.decode('utf-8')) for cidr in self.region_cidrs.values()]
214214
all_networks = region_networks
215215
for i in range(len(all_networks)):
216216
for j in range(i + 1, len(all_networks)):

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def run(self, filename, extra_vars=dict(), host_info={}, print_output=True):
126126
p = subprocess.Popen(process_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
127127
stdout, stderr = p.communicate()
128128
if print_output:
129-
print(stdout.decode('utf-8'))
129+
print(stdout)
130130
EXCEPTION_MSG_FORMAT = ("Playbook run of {} against {} with args {} " +
131131
"failed with return code {} and error '{}'")
132132
if p.returncode != 0:

managed/devops/opscli/ybops/cloud/gcp/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _query_endpoint(endpoint):
108108
try:
109109
url = "{}/{}".format(GcpMetadata.METADATA_URL_BASE, endpoint)
110110
req = requests.get(url, headers=GcpMetadata.CUSTOM_HEADERS, timeout=2)
111-
return req.content.decode('utf-8') if req.status_code == requests.codes.ok else None
111+
return req.content if req.status_code == requests.codes.ok else None
112112
except requests.exceptions.ConnectionError as e:
113113
return None
114114

managed/devops/opscli/ybops/utils/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,9 @@ def format_rsa_key(key, public_key):
448448
key (str): Encoded key in OpenSSH or PEM format based on the flag (public key or not).
449449
"""
450450
if public_key:
451-
return key.publickey().exportKey("OpenSSH").decode('utf-8')
451+
return str(key.publickey().exportKey("OpenSSH"))
452452
else:
453-
return key.exportKey("PEM").decode('utf-8')
453+
return str(key.exportKey("PEM"))
454454

455455

456456
def validated_key_file(key_file):
@@ -602,7 +602,7 @@ def validate_cron_status(host_name, port, username, ssh_key_file):
602602

603603
_, stdout, stderr = ssh_client.exec_command("crontab -l")
604604
cronjobs = ["clean_cores.sh", "zip_purge_yb_logs.sh", "yb-server-ctl.sh tserver"]
605-
stdout = stdout.read().decode('utf-8')
605+
stdout = stdout.read()
606606
return len(stderr.readlines()) == 0 and all(c in stdout for c in cronjobs)
607607
except (paramiko.ssh_exception.NoValidConnectionsError,
608608
paramiko.ssh_exception.AuthenticationException,

managed/devops/python3_requirements.txt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@
1919
# TODO: see if we can move to using Pundler (https://github.com/Deepwalker/pundler) instead.
2020

2121
ansible==2.5.4
22-
ansible-vault==2.1.0
22+
ansible-vault==1.0.4
2323
apache-libcloud>=1.2.1
2424
auth0-python==3.0.0
25+
awscli==1.11.1
2526
azure-common==1.1.25
2627
azure-mgmt-compute==12.1.0
27-
azure-mgmt-privatedns==0.1.0
2828
azure-mgmt-network==10.2.0
2929
azure-mgmt-resource==10.0.0
30-
boto==2.49.0
31-
boto3==1.17.22
32-
botocore==1.20.22
33-
cryptography==3.3.2
30+
azure-mgmt-nspkg==3.0.2
31+
boto>=2.42.0
32+
boto3>=1.4.0
33+
botocore>=1.4.59
3434
distro==1.5.0
35+
docker-compose==1.9.0
3536
docker-py==1.7.0
37+
enum34==1.1.6
3638
fabric==2.2.1
37-
google-api-python-client==1.10.0
38-
google-api-core==1.22.0
39-
google-auth==1.19.2
39+
google-api-python-client
4040
graphviz
4141
jmespath==0.9.0
4242
ipaddress==1.0.22
@@ -47,7 +47,6 @@ pycryptodome==3.6.1
4747
python-dateutil==2.5.3
4848
python-dotenv==0.6.4
4949
PyYAML==3.13
50-
s3transfer>=0.3.0,<0.4.0
5150
six==1.10.0
5251
slackclient
5352
stormssh

0 commit comments

Comments
 (0)