From 239ace0ebf765fe93450faebbc1bf0e6e8997b6f Mon Sep 17 00:00:00 2001
From: Ian Wienand <iwienand@redhat.com>
Date: Thu, 3 Feb 2022 16:38:10 +1100
Subject: [PATCH] ensure-virtualenv: Don't support on CentOS 9-stream

It looks like 9-stream don't want to support virtualenv.  Fail the
ensure-virtualenv role on this platform, and account for this in
testing.

People should use ensure-pip and venv which is portable everywhere.

Change-Id: Ifae93c1eeb96792aa26a624574d595d77cb58c4b
---
 roles/ensure-virtualenv/tasks/RedHat.yaml | 12 ++++++-
 test-playbooks/ensure-pip.yaml            | 38 +++++++++++++----------
 2 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/roles/ensure-virtualenv/tasks/RedHat.yaml b/roles/ensure-virtualenv/tasks/RedHat.yaml
index 98f7a071b..e325bcf0e 100644
--- a/roles/ensure-virtualenv/tasks/RedHat.yaml
+++ b/roles/ensure-virtualenv/tasks/RedHat.yaml
@@ -1,6 +1,16 @@
+# It looks like CentOS 9 has no plans to support this,
+# and we should be using "python3 -m venv". [1]
+#
+# ensure-pip already exports 'ensure_pip_virtualenv_command'
+#
+# [1] https://lists.centos.org/pipermail/centos-devel/2021-August/098470.html
+- name: Fail on CentOS 9
+  fail:
+    msg: 'This element not supported on CentOS >= 9'
+  when: (ansible_facts['distribution'] == 'CentOS' and ansible_facts['distribution_major_version']|int >= 9)
+
 - name: Install virtualenv
   package:
     name:
       - python3-virtualenv
   become: yes
-
diff --git a/test-playbooks/ensure-pip.yaml b/test-playbooks/ensure-pip.yaml
index 2fe57d56a..8a09702af 100644
--- a/test-playbooks/ensure-pip.yaml
+++ b/test-playbooks/ensure-pip.yaml
@@ -36,25 +36,29 @@
         $run_pip wheel --no-deps .
         ls zuul-*.whl || exit 1
 
-    # ensure-virtualenv
-    - name: Include ensure-virtualenv
-      include_role:
-        name: ensure-virtualenv
+    - name: Test virtualenv
+      # NOTE(ianw) 2022-02-03 : not supported on 9-stream, see inline comments
+      when: not (ansible_facts['distribution'] == 'CentOS' and  ansible_facts['distribution_major_version']|int >= 9)
+      block:
+        # ensure-virtualenv
+        - name: Include ensure-virtualenv
+          include_role:
+            name: ensure-virtualenv
 
-    - name: Sanity check virtualenv command works
-      shell: |
-        tmp_venv=$(mktemp -d -t venv-XXXXXXXXXX)
-        trap "rm -rf $tmp_venv" EXIT
-        virtualenv $tmp_venv
-        $tmp_venv/bin/pip install tox
-      failed_when: false
-      register: _virtualenv_sanity
+        - name: Sanity check virtualenv command works
+          shell: |
+            tmp_venv=$(mktemp -d -t venv-XXXXXXXXXX)
+            trap "rm -rf $tmp_venv" EXIT
+            virtualenv $tmp_venv
+            $tmp_venv/bin/pip install tox
+          failed_when: false
+          register: _virtualenv_sanity
 
-    - name: Assert sanity check
-      fail:
-        msg: 'The virtualenv command does not appear to work!'
-      when:
-        - _virtualenv_sanity.rc != 0
+        - name: Assert sanity check
+          fail:
+            msg: 'The virtualenv command does not appear to work!'
+          when:
+            - _virtualenv_sanity.rc != 0
 
 # NOTE(ianw) : this does not play nicely with pip-and-virtualenv which
 # has already installed from source.  We might be able to test this