From 284f492861835a9616eb53a65a9648e415388cc9 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Mon, 16 Mar 2020 16:18:42 +0000 Subject: [PATCH] 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 --- ansible/roles/baremetal/defaults/main.yml | 12 +++++------- ansible/roles/baremetal/tasks/install.yml | 2 +- ansible/roles/neutron/defaults/main.yml | 12 +----------- tests/templates/globals-default.j2 | 6 ++++++ tools/kolla-ansible | 17 ++++------------- 5 files changed, 17 insertions(+), 32 deletions(-) diff --git a/ansible/roles/baremetal/defaults/main.yml b/ansible/roles/baremetal/defaults/main.yml index 6bd35e2b85..c5e4d5ef23 100644 --- a/ansible/roles/baremetal/defaults/main.yml +++ b/ansible/roles/baremetal/defaults/main.yml @@ -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 diff --git a/ansible/roles/baremetal/tasks/install.yml b/ansible/roles/baremetal/tasks/install.yml index afbd706eac..0d1216215d 100644 --- a/ansible/roles/baremetal/tasks/install.yml +++ b/ansible/roles/baremetal/tasks/install.yml @@ -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) }}" diff --git a/ansible/roles/neutron/defaults/main.yml b/ansible/roles/neutron/defaults/main.yml index c519892f4a..6d64b58063 100644 --- a/ansible/roles/neutron/defaults/main.yml +++ b/ansible/roles/neutron/defaults/main.yml @@ -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 }}" diff --git a/tests/templates/globals-default.j2 b/tests/templates/globals-default.j2 index b95efdb3ff..c28a5a3579 100644 --- a/tests/templates/globals-default.j2 +++ b/tests/templates/globals-default.j2 @@ -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 }}" diff --git a/tools/kolla-ansible b/tools/kolla-ansible index 4322c9cb06..1afc41757c 100755 --- a/tools/kolla-ansible +++ b/tools/kolla-ansible @@ -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"