From 350bb171ef6abe8412f93fc0c9a9e28ac5eaff1d Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Thu, 17 Jan 2019 12:19:55 +0000
Subject: [PATCH] Configure Cinder to use lioadm on CentOS/RHEL 8

In CentOS/RHEL 8 there is no scsi-target-utils package, nor is it
available in EPEL. It is removed from kolla in [1]. In RHEL 7 and beyond
the LIO kernel subsystem can be used instead of the tgtd daemon.

This change removes support for the SCSI target daemon on CentOS/RHEL 8.
The 'tgtd' image is no longer available for CentOS/RHEL 8.

[1] https://review.openstack.org/#/c/613815/5

Change-Id: I718fc16cde2dd177b2a1c2f79b932426034897fe
Related: blueprint centos-rhel-8
---
 ansible/group_vars/all.yml                             |  2 +-
 ansible/roles/iscsi/tasks/precheck.yml                 |  9 +++++++++
 .../notes/centos8-cinder-lio-3fb17ce5c88abbf1.yaml     |  6 ++++++
 tests/run.yml                                          |  1 +
 tools/setup_gate.sh                                    | 10 ++++++++--
 5 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 releasenotes/notes/centos8-cinder-lio-3fb17ce5c88abbf1.yaml

diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml
index 20673f14e1..c64817376c 100644
--- a/ansible/group_vars/all.yml
+++ b/ansible/group_vars/all.yml
@@ -852,7 +852,7 @@ gnocchi_metric_datadir_volume: "gnocchi"
 cinder_backend_ceph: "{{ enable_ceph }}"
 cinder_backend_vmwarevc_vmdk: "no"
 cinder_volume_group: "cinder-volumes"
-cinder_target_helper: "tgtadm"
+cinder_target_helper: "{{ 'lioadm' if ansible_os_family == 'RedHat' and ansible_distribution_major_version is version_compare('8', '>=') else 'tgtadm' }}"
 # Valid options are [ '', redis, etcd ]
 cinder_coordination_backend: "{{ 'redis' if enable_redis|bool else 'etcd' if enable_etcd|bool else '' }}"
 
diff --git a/ansible/roles/iscsi/tasks/precheck.yml b/ansible/roles/iscsi/tasks/precheck.yml
index f3c0b2f097..fed4e3a34b 100644
--- a/ansible/roles/iscsi/tasks/precheck.yml
+++ b/ansible/roles/iscsi/tasks/precheck.yml
@@ -17,3 +17,12 @@
     - container_facts['iscsid'] is not defined
     - inventory_hostname in groups[iscsi_services.iscsid.group]
     - iscsi_services.iscsid.enabled | bool
+
+- name: Check supported platforms for tgtd
+  fail:
+    msg:
+      The SCSI target daemon tgtd is not supported on CentOS/RHEL 8 and later
+  when:
+    - ansible_os_family == 'RedHat'
+    - ansible_distribution_major_version is version_compare('8', '>=')
+    - enable_tgtd | bool
diff --git a/releasenotes/notes/centos8-cinder-lio-3fb17ce5c88abbf1.yaml b/releasenotes/notes/centos8-cinder-lio-3fb17ce5c88abbf1.yaml
new file mode 100644
index 0000000000..5a6877a42d
--- /dev/null
+++ b/releasenotes/notes/centos8-cinder-lio-3fb17ce5c88abbf1.yaml
@@ -0,0 +1,6 @@
+---
+upgrade:
+  - |
+    Support for the SCSI target daemon (``tgtd``) has been removed for
+    CentOS/RHEL 8. The default value of ``cinder_target_helper`` is now
+    ``lioadm`` on CentOS/RHEL 8, but remains as ``tgtadm`` on other platforms.
diff --git a/tests/run.yml b/tests/run.yml
index b77eeb5205..48e1af570f 100644
--- a/tests/run.yml
+++ b/tests/run.yml
@@ -234,6 +234,7 @@
         chdir: "{{ kolla_ansible_src_dir }}"
       environment:
         BASE_DISTRO: "{{ base_distro }}"
+        BASE_DISTRO_MAJOR_VERSION: "{{ ansible_distribution_major_version }}"
         INSTALL_TYPE: "{{ install_type }}"
         BUILD_IMAGE: "{{ need_build_image }}"
         TAG: "{{ build_image_tag }}"
diff --git a/tools/setup_gate.sh b/tools/setup_gate.sh
index 46b41cda6d..2d2e00f956 100755
--- a/tools/setup_gate.sh
+++ b/tools/setup_gate.sh
@@ -40,11 +40,17 @@ function setup_config {
     fi
 
     if [[ $SCENARIO == "cinder-lvm" ]]; then
-        GATE_IMAGES+=",cinder,iscsid,tgtd"
+        GATE_IMAGES+=",cinder,iscsid"
+        if [[ $BASE_DISTRO != "centos" ]] || [[ $BASE_DISTRO_MAJOR_VERSION -eq 7 ]]; then
+            GATE_IMAGES+=",tgtd"
+        fi
     fi
 
     if [[ $SCENARIO == "zun" ]]; then
-        GATE_IMAGES+=",zun,kuryr,etcd,cinder,iscsid,tgtd"
+        GATE_IMAGES+=",zun,kuryr,etcd,cinder,iscsid"
+        if [[ $BASE_DISTRO != "centos" ]] || [[ $BASE_DISTRO_MAJOR_VERSION -eq 7 ]]; then
+            GATE_IMAGES+=",tgtd"
+        fi
     fi
 
     if [[ $SCENARIO == "scenario_nfv" ]]; then