Remove support for Python 2 on the host

Drops support for creating Python 2 virtualenvs in bootstrap-servers,
and looking for a python2 interpreter in the kolla-ansible script.

Also forces the use of Python 3 as the remote interpreter in CI on
Debian and Ubuntu hosts, since they typically symlink the unversioned
interpreter to python2.7.

Change-Id: Id0e977de381e7faafed738674a140ba36184727e
Partially-Implements: blueprint drop-py2-support
This commit is contained in:
Mark Goddard 2020-03-16 16:18:42 +00:00
parent f4e20a1f16
commit 284f492861
5 changed files with 17 additions and 32 deletions

View File

@ -49,22 +49,20 @@ easy_install_available: >-
# Version of python used to execute Ansible modules.
host_python_version: "{{ ansible_python.version.major }}.{{ ansible_python.version.minor }}"
host_python_major_version: "{{ ansible_python.version.major }}"
debian_pkg_install:
- "{{ docker_apt_package }}"
- git
- "python{% if host_python_major_version == '3' %}3{% endif %}-setuptools"
- "{% if not easy_install_available %}python{% if host_python_major_version == '3' %}3{% endif %}-pip{% endif %}"
- "{% if virtualenv is not none %}python{% if host_python_major_version == '3' %}3{% endif %}-virtualenv{% endif %}"
- "python3-setuptools"
- "{% if not easy_install_available %}python3-pip{% endif %}"
- "{% if virtualenv is not none %}python3-virtualenv{% endif %}"
- "{% if enable_host_ntp | bool %}ntp{% endif %}"
redhat_pkg_install:
- "{{ docker_yum_package }}"
- git
- "{% if host_python_major_version == '2' %}python-setuptools{% endif %}"
- "{% if not easy_install_available %}python{{ host_python_major_version }}-pip{% endif %}"
- "{% if virtualenv is not none %}python{{ host_python_major_version }}-virtualenv{% endif %}"
- "{% if not easy_install_available %}python3-pip{% endif %}"
- "{% if virtualenv is not none %}python3-virtualenv{% endif %}"
- "{% if enable_host_ntp | bool %}ntp{% endif %}"
- sudo

View File

@ -125,7 +125,7 @@
pip:
# NOTE(hrw) docker 2.4.2 is in kolla-ansible requirements
name: docker>=2.4.2
executable: "{{ virtualenv is none | ternary('pip' ~ host_python_major_version, omit) }}"
executable: "{{ virtualenv is none | ternary('pip3', omit) }}"
virtualenv: "{{ virtualenv is none | ternary(omit, virtualenv) }}"
virtualenv_site_packages: "{{ virtualenv is none | ternary(omit, virtualenv_site_packages) }}"
virtualenv_python: "{{ virtualenv is none | ternary(omit, 'python' ~ host_python_version) }}"

View File

@ -215,17 +215,7 @@ ironic_neutron_agent_image: "{{ docker_registry ~ '/' if docker_registry else ''
ironic_neutron_agent_tag: "{{ neutron_tag }}"
ironic_neutron_agent_image_full: "{{ ironic_neutron_agent_image }}:{{ ironic_neutron_agent_tag }}"
# TODO(wszumski): This is a workaround for: https://bugs.launchpad.net/oslo.rootwrap/+bug/1760471
# and should be removed once we use python 3 for all distibutions.
neutron_agent_dimensions_python2:
# Values taken from TripleO: https://review.opendev.org/#/c/651137/
ulimits:
nofile:
soft: 16384
hard: 16384
neutron_agent_dimensions: >-
{{ default_container_dimensions | combine(neutron_agent_dimensions_python2 if distro_python_version is version('3.0', '<') else {}) }}
neutron_agent_dimensions: "{{ default_container_dimensions }}"
neutron_dhcp_agent_dimensions: "{{ neutron_agent_dimensions }}"
neutron_l3_agent_dimensions: "{{ neutron_agent_dimensions }}"

View File

@ -1,4 +1,10 @@
---
{% if ansible_os_family == 'Debian' %}
# Force the use of python3 on Debian and Ubuntu remote hosts. These distros
# typically have an unversioned Python interpreter which links to python2.7.
ansible_python_interpreter: /usr/bin/python3
{% endif %}
kolla_base_distro: "{{ base_distro }}"
kolla_install_type: "{{ install_type }}"
network_interface: "{{ api_interface_name }}"

View File

@ -15,10 +15,7 @@ function check_ansible_compatibility {
}
function find_base_dir {
# $1: Python interpreter
local python
python=$1
local real_path=$($python -c "import os;print(os.path.realpath('$0'))")
local real_path=$(python3 -c "import os;print(os.path.realpath('$0'))")
local dir_name="$(dirname "$real_path")"
if [ -z "$SNAP" ]; then
if [[ ${dir_name} == "/usr/bin" ]]; then
@ -142,21 +139,15 @@ LONG_OPTS="help,inventory:,playbook:,skip-tags:,tags:,key:,extra:,verbose,config
RAW_ARGS="$*"
ARGS=$(getopt -o "${SHORT_OPTS}" -l "${LONG_OPTS}" --name "$0" -- "$@") || { usage >&2; exit 2; }
# Detect which python interpreter to use.
for python in python3 python2; do
if $python -c 'import kolla_ansible' &>/dev/null; then
PYTHON=$python
break
fi
done
if [[ -z $PYTHON ]]; then
# Check for existence of kolla_ansible module using python3 interpreter.
if ! python3 -c 'import kolla_ansible' &>/dev/null; then
echo "ERROR: kolla_ansible has to be available in the PYTHONPATH (e.g. installed)" >&2
exit 1
fi
eval set -- "$ARGS"
find_base_dir $PYTHON
find_base_dir
INVENTORY="${BASEDIR}/ansible/inventory/all-in-one"
PLAYBOOK="${BASEDIR}/ansible/site.yml"