replace 'distro_python3' variable with 'distro_python_version'

RHEL7 derived distros use Python 2.7
RHEL8 uses Python 3.6
Ubuntu 18.04 uses Python 3.6, but we haven't enabled it yet.
Debian:buster uses Python 3.7, but we haven't enabled it yet.

We have several places in code where "/lib/pythonX.Y/site-packages"
is used so we need to know value of X.Y rather than py2/py3 switch.

How to check for Python 2:

{% if distro_python_version == '2.7' %}

Breaks: Iad6b70b433a0dd1b0f8ae6790fd280594517661a
Change-Id: Ie24f109af19ae0438c21e0d43cb3cc947812b4ce
This commit is contained in:
Marcin Juszkiewicz 2019-03-08 13:19:03 +01:00
parent 8ae32bb172
commit 8df6eb0118
10 changed files with 66 additions and 31 deletions

View File

@ -17,7 +17,8 @@ LABEL kolla_version="{{ kolla_version }}"
ENV KOLLA_BASE_DISTRO={{ base_distro }} \ ENV KOLLA_BASE_DISTRO={{ base_distro }} \
KOLLA_INSTALL_TYPE={{ install_type }} \ KOLLA_INSTALL_TYPE={{ install_type }} \
KOLLA_INSTALL_METATYPE={{ install_metatype }} KOLLA_INSTALL_METATYPE={{ install_metatype }} \
KOLLA_DISTRO_PYTHON_VERSION={{ distro_python_version }}
#### Customize PS1 to be used with bash shell #### Customize PS1 to be used with bash shell
COPY kolla_bashrc /tmp/ COPY kolla_bashrc /tmp/

View File

@ -74,7 +74,7 @@ RUN echo > /etc/apache2/ports.conf \
&& cp /usr/share/openstack-dashboard/openstack_dashboard/conf/*.json /etc/openstack-dashboard \ && cp /usr/share/openstack-dashboard/openstack_dashboard/conf/*.json /etc/openstack-dashboard \
&& cp /usr/share/openstack-dashboard/manage.py /usr/bin/manage.py \ && cp /usr/share/openstack-dashboard/manage.py /usr/bin/manage.py \
&& rm /etc/apache2/conf-enabled/openstack-dashboard.conf \ && rm /etc/apache2/conf-enabled/openstack-dashboard.conf \
&& for locale in /usr/lib/python2.7/site-packages/*/locale; do \ && for locale in /usr/lib/python{{distro_python_version}}/site-packages/*/locale; do \
(cd ${locale%/*} && /usr/bin/python /usr/bin/manage.py compilemessages) \ (cd ${locale%/*} && /usr/bin/python /usr/bin/manage.py compilemessages) \
done done
{% endblock %} {% endblock %}
@ -136,10 +136,10 @@ RUN ln -s horizon-source/* horizon \
&& if [ "$(ls /plugins)" ]; then \ && if [ "$(ls /plugins)" ]; then \
{{ macros.install_pip(horizon_plugins_pip_packages) }}; \ {{ macros.install_pip(horizon_plugins_pip_packages) }}; \
fi \ fi \
&& for locale in /var/lib/kolla/venv/lib/python2.7/site-packages/*/locale; do \ && for locale in /var/lib/kolla/venv/lib/python{{distro_python_version}}/site-packages/*/locale; do \
(cd ${locale%/*} && /var/lib/kolla/venv/bin/python /var/lib/kolla/venv/bin/manage.py compilemessages) \ (cd ${locale%/*} && /var/lib/kolla/venv/bin/python /var/lib/kolla/venv/bin/manage.py compilemessages) \
done \ done \
&& chown -R horizon: /etc/openstack-dashboard /var/lib/kolla/venv/lib/python2.7/site-packages/static && chown -R horizon: /etc/openstack-dashboard /var/lib/kolla/venv/lib/python{{distro_python_version}}/site-packages/static
{% endif %} {% endif %}

View File

@ -5,9 +5,9 @@ set -o errexit
FORCE_GENERATE="${FORCE_GENERATE}" FORCE_GENERATE="${FORCE_GENERATE}"
if [[ ${KOLLA_INSTALL_TYPE} == "binary" ]]; then if [[ ${KOLLA_INSTALL_TYPE} == "binary" ]]; then
SITE_PACKAGES="/usr/lib/python2.7/site-packages" SITE_PACKAGES="/usr/lib/python${KOLLA_DISTRO_PYTHON_VERSION}/site-packages"
elif [[ ${KOLLA_INSTALL_TYPE} == "source" ]]; then elif [[ ${KOLLA_INSTALL_TYPE} == "source" ]]; then
SITE_PACKAGES="/var/lib/kolla/venv/lib/python2.7/site-packages" SITE_PACKAGES="/var/lib/kolla/venv/lib/python${KOLLA_DISTRO_PYTHON_VERSION}/site-packages"
fi fi
if [[ ${KOLLA_INSTALL_TYPE} == "source" ]] && [[ ! -f ${SITE_PACKAGES}/openstack_dashboard/local/local_settings.py ]]; then if [[ ${KOLLA_INSTALL_TYPE} == "source" ]] && [[ ! -f ${SITE_PACKAGES}/openstack_dashboard/local/local_settings.py ]]; then

View File

@ -4,7 +4,7 @@ LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build
{% block kolla_toolbox_header %}{% endblock %} {% block kolla_toolbox_header %}{% endblock %}
{% set virtualenv_path='/opt/ansible' %} {% set virtualenv_path='/opt/ansible' %}
{% set os_client_config= virtualenv_path + '/lib/python2.7/site-packages/os_client_config/defaults.json' %} {% set os_client_config= virtualenv_path + '/lib/python' + distro_python_version + '/site-packages/os_client_config/defaults.json' %}
{% import "macros.j2" as macros with context %} {% import "macros.j2" as macros with context %}

View File

@ -22,8 +22,13 @@
{%- endmacro %} {%- endmacro %}
{% macro get_pip() %} {% macro get_pip() %}
{% if distro_python_version == '2.7' %}
{% set python='python' %}
{% else %}
{% set python='python3' %}
{% endif %}
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \ RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \
&& python get-pip.py \ && {{python}} get-pip.py \
&& rm get-pip.py && rm get-pip.py
{% endmacro %} {% endmacro %}

View File

@ -211,11 +211,9 @@ ENV DEBIAN_FRONTEND noninteractive
'debtcollector', 'debtcollector',
'decorator', 'decorator',
'elasticsearch', 'elasticsearch',
'enum34',
'eventlet', 'eventlet',
'fasteners', 'fasteners',
'funcsigs', 'funcsigs',
'functools32',
'futures', 'futures',
'futurist', 'futurist',
'gnocchiclient', 'gnocchiclient',
@ -297,6 +295,14 @@ ENV DEBIAN_FRONTEND noninteractive
] ]
%} %}
{% if distro_python_version == '2.7' %}
{% set openstack_base_pip_packages = openstack_base_pip_packages + [
'enum34',
'functools32'
]
%}
{% endif %}
ADD openstack-base-archive /openstack-base-source ADD openstack-base-archive /openstack-base-source
RUN ln -s openstack-base-source/* /requirements \ RUN ln -s openstack-base-source/* /requirements \
&& mkdir -p /var/lib/kolla \ && mkdir -p /var/lib/kolla \

View File

@ -266,10 +266,6 @@ _BASE_OPTS = [
cfg.StrOpt('maintainer', cfg.StrOpt('maintainer',
default='Kolla Project (https://launchpad.net/kolla)', default='Kolla Project (https://launchpad.net/kolla)',
help='Content of the maintainer label'), help='Content of the maintainer label'),
cfg.BoolOpt('distro_python3', default=None,
help=('Enable this to force python3 packaging names. By '
'default this will try and determine the value of this '
'based on the base_distro and base_distro_tag.')),
cfg.StrOpt('base_package_type', default=None, cfg.StrOpt('base_package_type', default=None,
help=('Set the package type of the distro. If not set then ' help=('Set the package type of the distro. If not set then '
'the packaging type is set to "rpm" if a RHEL based ' 'the packaging type is set to "rpm" if a RHEL based '

View File

@ -693,13 +693,13 @@ class KollaWorker(object):
deb_base = ['ubuntu', 'debian'] deb_base = ['ubuntu', 'debian']
deb_type = ['source', 'binary'] deb_type = ['source', 'binary']
if self.conf.distro_python3 is not None: if self.base in rh_base and self.base_tag.startswith('7'):
self.distro_python3 = self.conf.distro_python3 self.conf.distro_python_version = "2.7"
elif self.base in rh_base and self.base_tag in ['8']: elif self.base in rh_base and self.base_tag.startswith('8'):
# RHEL 8+ is python3 self.conf.distro_python_version = "3.6"
self.distro_python3 = True
else: else:
self.distro_python3 = False # Assume worst
self.conf.distro_python_version = "2.7"
# Determine base packaging type for use in Dockerfiles. # Determine base packaging type for use in Dockerfiles.
if self.conf.base_package_type: if self.conf.base_package_type:
@ -738,6 +738,7 @@ class KollaWorker(object):
self.image_statuses_unmatched = dict() self.image_statuses_unmatched = dict()
self.image_statuses_skipped = dict() self.image_statuses_skipped = dict()
self.maintainer = conf.maintainer self.maintainer = conf.maintainer
self.distro_python_version = conf.distro_python_version
docker_kwargs = docker.utils.kwargs_from_env() docker_kwargs = docker.utils.kwargs_from_env()
try: try:
@ -915,7 +916,7 @@ class KollaWorker(object):
'kolla_version': kolla_version, 'kolla_version': kolla_version,
'image_name': image_name, 'image_name': image_name,
'users': self.get_users(), 'users': self.get_users(),
'distro_python3': self.distro_python3, 'distro_python_version': self.distro_python_version,
'rpm_setup': self.rpm_setup, 'rpm_setup': self.rpm_setup,
'build_date': build_date} 'build_date': build_date}
env = jinja2.Environment( # nosec: not used to render HTML env = jinja2.Environment( # nosec: not used to render HTML

View File

@ -381,25 +381,45 @@ class KollaWorkerTest(base.TestCase):
kolla = build.KollaWorker(self.conf) kolla = build.KollaWorker(self.conf)
self.assertEqual(2, len(kolla.rpm_setup)) self.assertEqual(2, len(kolla.rpm_setup))
def test_build_distro_python3(self): def test_build_distro_python_version_debian(self):
"""check distro_python3 conf value is taken""" """check distro_python_version for Debian"""
self.conf.set_override('distro_python3', True) self.conf.set_override('base', 'debian')
kolla = build.KollaWorker(self.conf) kolla = build.KollaWorker(self.conf)
self.assertTrue(kolla.distro_python3) self.assertEqual('2.7', kolla.distro_python_version)
def test_build_distro_python3_rhel8(self): def test_build_distro_python_version_rhel80(self):
"""check distro_python3 true for rhel8""" """check distro_python_version for RHEL8.0"""
self.conf.set_override('base', 'rhel')
self.conf.set_override('base_tag', '8.0')
kolla = build.KollaWorker(self.conf)
self.assertEqual('3.6', kolla.distro_python_version)
def test_build_distro_python_version_rhel8(self):
"""check distro_python_version for RHEL8"""
self.conf.set_override('base', 'rhel') self.conf.set_override('base', 'rhel')
self.conf.set_override('base_tag', '8') self.conf.set_override('base_tag', '8')
kolla = build.KollaWorker(self.conf) kolla = build.KollaWorker(self.conf)
self.assertTrue(kolla.distro_python3) self.assertEqual('3.6', kolla.distro_python_version)
def test_build_distro_python3_non_rhel8(self): def test_build_distro_python_version_ubuntu(self):
"""check distro_python3 false for non-rhel8""" """check distro_python_version for Ubuntu"""
self.conf.set_override('base', 'ubuntu')
kolla = build.KollaWorker(self.conf)
self.assertEqual('2.7', kolla.distro_python_version)
def test_build_distro_python_version_centos7(self):
"""check distro_python_version for CentOS 7.6.1810"""
self.conf.set_override('base', 'centos')
self.conf.set_override('base_tag', '7.6.1810')
kolla = build.KollaWorker(self.conf)
self.assertEqual('2.7', kolla.distro_python_version)
def test_build_distro_python_version_rhel7(self):
"""check distro_python_version for RHEL7"""
self.conf.set_override('base', 'rhel') self.conf.set_override('base', 'rhel')
self.conf.set_override('base_tag', '7') self.conf.set_override('base_tag', '7')
kolla = build.KollaWorker(self.conf) kolla = build.KollaWorker(self.conf)
self.assertFalse(kolla.distro_python3) self.assertEqual('2.7', kolla.distro_python_version)
def test_base_package_type(self): def test_base_package_type(self):
"""check base_package_type conf value is taken""" """check base_package_type conf value is taken"""

View File

@ -0,0 +1,6 @@
---
features:
- |
New variable 'distro_python_version' to store version of Python used in
distribution used as a base. Can be used to handle py2/py3 checks and to
find 'site-packages' directory.