From 3c78c29e94443ca2c169c6c2d065a2e57d3023b5 Mon Sep 17 00:00:00 2001
From: Dmitry Tantsur <dtantsur@protonmail.com>
Date: Wed, 27 Nov 2019 19:29:47 +0100
Subject: [PATCH] Replace CentOS 7 images with CentOS 8

CentOS 7 uses Python 2. Although it's possible to install Python 3
on it, it not trivial with DIB. We should rather switch to
a distribution where Python 3 is the default version.

As a nice side effect, the CentOS 8 images seem smaller.

The CentOS 7 job definitions are kept around since they're used
on stable/train.

Change-Id: I6b23da21eab19c69f7b070adff76b35e1752bf8d
---
 .zuul.yaml                                    | 19 ++++++++++++++-----
 doc/source/admin/dib.rst                      |  7 ++++---
 .../notes/centos8-46a95956fd871c90.yaml       | 11 +++++++++++
 roles/ipa-build-dib-image/defaults/main.yaml  |  3 ++-
 roles/ipa-build-dib-image/tasks/main.yaml     | 16 +++++++++++++++-
 5 files changed, 46 insertions(+), 10 deletions(-)
 create mode 100644 releasenotes/notes/centos8-46a95956fd871c90.yaml

diff --git a/.zuul.yaml b/.zuul.yaml
index d1c8224..5c546c0 100644
--- a/.zuul.yaml
+++ b/.zuul.yaml
@@ -29,6 +29,17 @@
       image_type: 'dib'
       image_distro: 'centos7'
 
+- job:
+    name: ironic-python-agent-build-image-dib-centos8
+    parent: ironic-python-agent-build-image-base
+    required-projects:
+      # NOTE(dtantsur): used for bindep only
+      - openstack/diskimage-builder
+    vars:
+      image_type: 'dib'
+      image_distro: 'centos-minimal'
+      image_release: 8
+
 - job:
     name: ironic-python-agent-check-image-base
     parent: base
@@ -122,9 +133,7 @@
         - ipa-tempest-wholedisk-bios-ipmi-direct-tinyipa-src
         - ipa-tempest-wholedisk-bios-ipmi-iscsi-tinyipa-src
         - ironic-python-agent-check-image-tinyipa
-        - ironic-python-agent-check-image-dib-centos7
-        - ironic-python-agent-check-image-dib-centos8:
-            voting: false
+        - ironic-python-agent-check-image-dib-centos8
         - ironic-python-agent-check-image-dib-fedora:
             voting: false
         - ironic-python-agent-check-image-dib-ubuntu:
@@ -144,9 +153,9 @@
         - ipa-tempest-wholedisk-bios-ipmi-direct-tinyipa-src
         - ipa-tempest-wholedisk-bios-ipmi-iscsi-tinyipa-src
         - ironic-python-agent-check-image-tinyipa
-        - ironic-python-agent-check-image-dib-centos7
+        - ironic-python-agent-check-image-dib-centos8
     post:
       jobs:
         - publish-openstack-python-branch-tarball
         - ironic-python-agent-build-image-tinyipa
-        - ironic-python-agent-build-image-dib-centos7
+        - ironic-python-agent-build-image-dib-centos8
diff --git a/doc/source/admin/dib.rst b/doc/source/admin/dib.rst
index 890e7e6..3dae528 100644
--- a/doc/source/admin/dib.rst
+++ b/doc/source/admin/dib.rst
@@ -20,13 +20,13 @@ You can add other diskimage-builder_ elements via the ``-e`` flag:
 
 .. code-block:: shell
 
-    ironic-python-agent-builder -e <extra-element> centos7
+    ironic-python-agent-builder -e <extra-element> --release 8 centos-minimal
 
 You can specify the base name of the target images:
 
 .. code-block:: shell
 
-    ironic-python-agent-builder -o my-ipa centos7
+    ironic-python-agent-builder -o my-ipa --release 8 centos-minimal
 
 You can specify the arch of the target image by setting ``ARCH`` environment
 variable (default is amd64):
@@ -65,8 +65,9 @@ for example:
 
 .. code-block:: shell
 
+    export DIB_RELEASE=8
     disk-image-create -o ironic-python-agent \
-        ironic-python-agent-ramdisk centos7 dhcp-all-interfaces
+        ironic-python-agent-ramdisk centos-minimal
 
 To use a specific branch of ironic-python-agent, use:
 
diff --git a/releasenotes/notes/centos8-46a95956fd871c90.yaml b/releasenotes/notes/centos8-46a95956fd871c90.yaml
new file mode 100644
index 0000000..4e96ecb
--- /dev/null
+++ b/releasenotes/notes/centos8-46a95956fd871c90.yaml
@@ -0,0 +1,11 @@
+---
+deprecations:
+  - |
+    Building images for CentOS 7 and other distribution releases that default
+    to Python 2 is deprecated.
+other:
+  - |
+    Since ironic-python-agent has removed support for Python 2, CentOS 8 images
+    are now built and published on https://tarballs.openstack.org instead of
+    CentOS 7 ones. The CentOS 7 images should not be used for Ussuri and later
+    releases.
diff --git a/roles/ipa-build-dib-image/defaults/main.yaml b/roles/ipa-build-dib-image/defaults/main.yaml
index 870561e..ff495bb 100644
--- a/roles/ipa-build-dib-image/defaults/main.yaml
+++ b/roles/ipa-build-dib-image/defaults/main.yaml
@@ -1,5 +1,6 @@
-image_distro: centos7
+image_distro: centos-minimal
 image_release:
+image_target_name:
 ipa_branch_path: '{{ zuul.branch | replace("/", "-") }}'
 ipa_source_path: '{{ ansible_user_dir }}/src/opendev.org/openstack/ironic-python-agent'
 requirements_path: '{{ ansible_user_dir }}/src/opendev.org/openstack/requirements'
diff --git a/roles/ipa-build-dib-image/tasks/main.yaml b/roles/ipa-build-dib-image/tasks/main.yaml
index 830e2d7..bcda54f 100644
--- a/roles/ipa-build-dib-image/tasks/main.yaml
+++ b/roles/ipa-build-dib-image/tasks/main.yaml
@@ -1,6 +1,20 @@
+- name: Default to CentOS 8
+  set_fact:
+    image_release: 8
+  when:
+    - image_distro == "centos-minimal"
+    - not image_release
+
+- name: Generate a nice target name for CentOS
+  set_fact:
+    image_target_name: centos{{ image_release }}
+  when:
+    - image_distro == "centos-minimal"
+    - not image_target_name
+
 - name: Generate image name
   set_fact:
-    image_name: ipa-{{ image_distro }}-{{ ipa_branch_path }}
+    image_name: ipa-{{ image_target_name | default(image_distro, true) }}-{{ ipa_branch_path }}
 
 - name: Build a DIB image
   command: |