From 3410a6165af199992c0b06eaf603dd0dde72c4b0 Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Tue, 15 Jan 2019 15:56:21 -0700 Subject: [PATCH] Add distro_python3 option As we add support for python3 on RHEL based systems, we need to add a flag to key off of in the Dockerfiles to swap out the python3 package names. This change adds a distro_python3 configuration option that can be defined to force python3 or python2 package names. If this option is not provided, we set this to True for RHEL 8 based distros and false for other distros. Change-Id: I4028991bad92c0e8e21066cc4173c06ce5eba393 Related-Blueprint: python3-support --- kolla/common/config.py | 4 ++++ kolla/image/build.py | 9 +++++++++ kolla/tests/test_build.py | 20 +++++++++++++++++++ ...ython3-configuration-3ed58b21b0f43246.yaml | 8 ++++++++ 4 files changed, 41 insertions(+) create mode 100644 releasenotes/notes/distro-python3-configuration-3ed58b21b0f43246.yaml diff --git a/kolla/common/config.py b/kolla/common/config.py index 5ba95bd2a6..e1c682b4fe 100755 --- a/kolla/common/config.py +++ b/kolla/common/config.py @@ -266,6 +266,10 @@ _BASE_OPTS = [ cfg.StrOpt('maintainer', default='Kolla Project (https://launchpad.net/kolla)', 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.ListOpt('rpm_setup_config', default=[DELOREAN, DELOREAN_DEPS], help=('Comma separated list of .rpm or .repo file(s) ' 'or URL(s) to install before building containers')), diff --git a/kolla/image/build.py b/kolla/image/build.py index 9ab3f68df1..6cb1cb2da9 100755 --- a/kolla/image/build.py +++ b/kolla/image/build.py @@ -689,6 +689,14 @@ class KollaWorker(object): deb_base = ['ubuntu', 'debian'] deb_type = ['source', 'binary'] + if self.conf.distro_python3 is not None: + self.distro_python3 = self.conf.distro_python3 + elif self.base in rh_base and self.base_tag in ['8']: + # RHEL 8+ is python3 + self.distro_python3 = True + else: + self.distro_python3 = False + if not ((self.base in rh_base and self.install_type in rh_type) or (self.base in deb_base and self.install_type in deb_type)): raise exception.KollaMismatchBaseTypeException( @@ -888,6 +896,7 @@ class KollaWorker(object): 'kolla_version': kolla_version, 'image_name': image_name, 'users': self.get_users(), + 'distro_python3': self.distro_python3, 'rpm_setup': self.rpm_setup, 'build_date': build_date} env = jinja2.Environment( # nosec: not used to render HTML diff --git a/kolla/tests/test_build.py b/kolla/tests/test_build.py index b721bb237e..c6a9530034 100644 --- a/kolla/tests/test_build.py +++ b/kolla/tests/test_build.py @@ -381,6 +381,26 @@ class KollaWorkerTest(base.TestCase): kolla = build.KollaWorker(self.conf) self.assertEqual(2, len(kolla.rpm_setup)) + def test_build_distro_python3(self): + """check distro_python3 conf value is taken""" + self.conf.set_override('distro_python3', True) + kolla = build.KollaWorker(self.conf) + self.assertTrue(kolla.distro_python3) + + def test_build_distro_python3_rhel8(self): + """check distro_python3 true for rhel8""" + self.conf.set_override('base', 'rhel') + self.conf.set_override('base_tag', '8') + kolla = build.KollaWorker(self.conf) + self.assertTrue(kolla.distro_python3) + + def test_build_distro_python3_non_rhel8(self): + """check distro_python3 false for non-rhel8""" + self.conf.set_override('base', 'rhel') + self.conf.set_override('base_tag', '7') + kolla = build.KollaWorker(self.conf) + self.assertFalse(kolla.distro_python3) + def test_pre_defined_exist_profile(self): # default profile include the fake image: image-base self.conf.set_override('profile', ['default']) diff --git a/releasenotes/notes/distro-python3-configuration-3ed58b21b0f43246.yaml b/releasenotes/notes/distro-python3-configuration-3ed58b21b0f43246.yaml new file mode 100644 index 0000000000..40742b7314 --- /dev/null +++ b/releasenotes/notes/distro-python3-configuration-3ed58b21b0f43246.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + Added a `distro_python3` configuration option for the kolla-build.conf + that will switch the package names to assume the python3 name. By default, + this will be True if a RHEL 8 based distro and False for any other distro. + If a value of True or False is provided in the configuration, this will + override the derived value.