Browse Source

Add distro_package_manager configuration

Add configuration to allow the switch between dnf/yum or provide an
alternative package manager.

Change-Id: I913769fcf5875a12b4561958cf7c90b74cd116ea
changes/19/639219/16
Alex Schultz 2 years ago
parent
commit
78c819d623
  1. 6
      docker/base/Dockerfile.j2
  2. 12
      docker/base/dnf.conf
  3. 2
      docker/collectd/Dockerfile.j2
  4. 2
      docker/macros.j2
  5. 5
      kolla/common/config.py
  6. 13
      kolla/image/build.py
  7. 46
      kolla/tests/test_build.py
  8. 7
      releasenotes/notes/distro-package-manager-49634f537be63036.yaml

6
docker/base/Dockerfile.j2

@ -39,7 +39,7 @@ RUN CURRENT_DISTRO_RELEASE=$(awk '{match($0, /[0-9]+/,version)}END{print version
echo "Only release '{{ supported_distro_release }}' is supported on {{ base_distro }}"; false; \
fi \
&& cat /tmp/kolla_bashrc >> /etc/bashrc \
&& sed -i 's|^\(override_install_langs=.*\)|# \1|' /etc/yum.conf
&& sed -i 's|^\(override_install_langs=.*\)|# \1|' {% if distro_package_manager == 'dnf' %}/etc/dnf/dnf.conf{% else %}/etc/yum.conf{% endif %}
{% block base_yum_conf %}
@ -52,7 +52,11 @@ RUN CURRENT_DISTRO_RELEASE=$(awk '{match($0, /[0-9]+/,version)}END{print version
RUN echo {{ centos_contentdir }} >> /etc/yum/vars/contentdir
{% endif %}
{% if distro_package_manager == 'dnf' %}
COPY dnf.conf /etc/dnf/dnf.conf
{% else %}
COPY yum.conf /etc/yum.conf
{% endif %}
{% endblock %}

12
docker/base/dnf.conf

@ -0,0 +1,12 @@
[main]
keepcache=0
logfile=/var/log/dnf.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=0
skip_missing_names_on_install=False
clean_requirements_on_remove=True
tsflags=nodocs
install_weak_deps=False

2
docker/collectd/Dockerfile.j2

@ -86,8 +86,10 @@ LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build
{% endif %}
{% endif %}
{% if distro_package_manager == 'yum' %}
# make sure, collectd is pulled from centos-opstools
RUN yum-config-manager --disable epel
{% endif %}
{% endif %}
{{ macros.install_packages(collectd_packages | customizable("packages")) }}

2
docker/macros.j2

@ -1,7 +1,7 @@
{% macro install_packages(packages) -%}
{% if packages is defined and packages|length > 0 -%}
{% if base_package_type == 'rpm' -%}
RUN yum -y install {{ packages | join(' ') }} && yum clean all && rm -rf /var/cache/yum
RUN {{ distro_package_manager }} -y install {{ packages | join(' ') }} && {{ distro_package_manager }} clean all && rm -rf /var/cache/{{ distro_package_manager }}
{%- elif base_package_type == 'deb' -%}
{#-
debian_package_install is a utility method to build up an appropriate

5
kolla/common/config.py

@ -266,6 +266,11 @@ _BASE_OPTS = [
cfg.StrOpt('maintainer',
default='Kolla Project (https://launchpad.net/kolla)',
help='Content of the maintainer label'),
cfg.StrOpt('distro_package_manager', default=None,
help=('Use this parameter to override the default package '
'manager used by kolla. For example, if you want to use '
'yum on a system with dnf, set this to yum which will '
'use yum command in the build process')),
cfg.StrOpt('base_package_type', default=None,
help=('Set the package type of the distro. If not set then '
'the packaging type is set to "rpm" if a RHEL based '

13
kolla/image/build.py

@ -29,6 +29,7 @@ import tempfile
import threading
import time
from distutils.version import LooseVersion
from distutils.version import StrictVersion
import docker
import git
@ -701,6 +702,17 @@ class KollaWorker(object):
# Assume worst
self.conf.distro_python_version = "2.7"
if self.conf.distro_package_manager is not None:
package_manager = self.conf.distro_package_manager
elif self.base in rh_base:
if LooseVersion(self.base_tag) >= LooseVersion('8'):
package_manager = 'dnf'
else:
package_manager = 'yum'
elif self.base in deb_base:
package_manager = 'apt'
self.distro_package_manager = package_manager
# Determine base packaging type for use in Dockerfiles.
if self.conf.base_package_type:
self.base_package_type = self.conf.base_package_type
@ -917,6 +929,7 @@ class KollaWorker(object):
'image_name': image_name,
'users': self.get_users(),
'distro_python_version': self.distro_python_version,
'distro_package_manager': self.distro_package_manager,
'rpm_setup': self.rpm_setup,
'build_date': build_date}
env = jinja2.Environment( # nosec: not used to render HTML

46
kolla/tests/test_build.py

@ -421,6 +421,52 @@ class KollaWorkerTest(base.TestCase):
kolla = build.KollaWorker(self.conf)
self.assertEqual('2.7', kolla.distro_python_version)
def test_build_distro_package_manager(self):
"""check distro_package_manager conf value is taken"""
self.conf.set_override('distro_package_manager', 'foo')
kolla = build.KollaWorker(self.conf)
self.assertEqual('foo', kolla.distro_package_manager)
def test_build_distro_package_manager_rhel8(self):
"""check distro_package_manager dnf for rhel8"""
self.conf.set_override('base', 'rhel')
self.conf.set_override('base_tag', '8')
kolla = build.KollaWorker(self.conf)
self.assertEqual('dnf', kolla.distro_package_manager)
def test_build_distro_package_manager_rhel8_minor(self):
"""check distro_package_manager dnf for rhel8"""
self.conf.set_override('base', 'rhel')
self.conf.set_override('base_tag', '8.1.2')
kolla = build.KollaWorker(self.conf)
self.assertEqual('dnf', kolla.distro_package_manager)
def test_build_distro_package_manager_rhel7(self):
"""check distro_package_manager yum for rhel7"""
self.conf.set_override('base', 'rhel')
self.conf.set_override('base_tag', '7')
kolla = build.KollaWorker(self.conf)
self.assertEqual('yum', kolla.distro_package_manager)
def test_build_distro_package_manager_rhel7_minor(self):
"""check distro_package_manager yum for rhel7"""
self.conf.set_override('base', 'rhel')
self.conf.set_override('base_tag', '7.6.1801')
kolla = build.KollaWorker(self.conf)
self.assertEqual('yum', kolla.distro_package_manager)
def test_build_distro_package_manager_debian(self):
"""check distro_package_manager apt for debian"""
self.conf.set_override('base', 'debian')
kolla = build.KollaWorker(self.conf)
self.assertEqual('apt', kolla.distro_package_manager)
def test_build_distro_package_manager_ubuntu(self):
"""check distro_package_manager apt for ubuntu"""
self.conf.set_override('base', 'ubuntu')
kolla = build.KollaWorker(self.conf)
self.assertEqual('apt', kolla.distro_package_manager)
def test_base_package_type(self):
"""check base_package_type conf value is taken"""
self.conf.set_override('base_package_type', 'pip')

7
releasenotes/notes/distro-package-manager-49634f537be63036.yaml

@ -0,0 +1,7 @@
---
features:
- |
Added `distro_package_manager` configuration that can be used to specify
which package manager commands should be used for a given operating system.
This only works for like type of packaging systems like 'dnf' vs 'yum' for
'rpm' package types.
Loading…
Cancel
Save