From b1f986c3492faa2d5386fc7baabbd6d8e370554a Mon Sep 17 00:00:00 2001
From: Vladislav Belogrudov <vladislav.belogrudov@oracle.com>
Date: Wed, 17 Aug 2016 18:07:10 +0300
Subject: [PATCH] Cinder cannot use external non-LVM iSCSI storage

Currently Cinder enables iscsid service only when LVM is choosen as
backend. This fix will allow to specify external iSCSI storage via
configuration add-on and to run iscsid independently of LVM settings.

Change-Id: Iaae0f8025534e5ab1c5f9d5e812a7d41129915ef
Closes-Bug: 1614125
---
 ansible/group_vars/all.yml                 |  2 ++
 ansible/roles/cinder/tasks/start.yml       |  4 ++--
 ansible/roles/iscsi/tasks/start.yml        |  4 +++-
 ansible/roles/nova/tasks/start_compute.yml |  2 +-
 ansible/site.yml                           |  2 +-
 doc/cinder-guide.rst                       | 12 +++++++++++-
 etc/kolla/globals.yml                      |  1 +
 7 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml
index b7b461d2e6..641fa7467c 100644
--- a/ansible/group_vars/all.yml
+++ b/ansible/group_vars/all.yml
@@ -248,6 +248,7 @@ enable_central_logging: "no"
 enable_ceph: "no"
 enable_ceph_rgw: "no"
 enable_cinder: "no"
+enable_cinder_backend_iscsi: "no"
 enable_cinder_backend_lvm: "no"
 enable_cloudkitty: "no"
 enable_congress: "no"
@@ -258,6 +259,7 @@ enable_heat: "yes"
 enable_horizon: "yes"
 enable_influxdb: "no"
 enable_ironic: "no"
+enable_iscsid: "{{ enable_cinder_backend_iscsi | bool or enable_cinder_backend_lvm | bool }}"
 enable_kuryr: "no"
 enable_magnum: "no"
 enable_manila: "no"
diff --git a/ansible/roles/cinder/tasks/start.yml b/ansible/roles/cinder/tasks/start.yml
index 3358503280..1940141c64 100644
--- a/ansible/roles/cinder/tasks/start.yml
+++ b/ansible/roles/cinder/tasks/start.yml
@@ -30,8 +30,8 @@
       - "/etc/localtime:/etc/localtime:ro"
       - "/dev/:/dev/"
       - "/run/:/run/"
-      - "{% if enable_cinder_backend_lvm | bool %}cinder:/var/lib/cinder{% endif %}"
-      - "{% if enable_cinder_backend_lvm | bool %}iscsi_info:/etc/iscsi{% endif %}"
+      - "{% if enable_iscsid | bool %}cinder:/var/lib/cinder{% endif %}"
+      - "{% if enable_iscsid | bool %}iscsi_info:/etc/iscsi{% endif %}"
       - "kolla_logs:/var/log/kolla/"
 
 - name: Starting cinder-volume container
diff --git a/ansible/roles/iscsi/tasks/start.yml b/ansible/roles/iscsi/tasks/start.yml
index 448c6e8c18..887bbed580 100644
--- a/ansible/roles/iscsi/tasks/start.yml
+++ b/ansible/roles/iscsi/tasks/start.yml
@@ -39,4 +39,6 @@
       - "/sys/kernel/config:/configfs"
       - "cinder:/var/lib/cinder"
       - "iscsi_info:/etc/iscsi"
-  when: inventory_hostname in groups['tgtd']
+  when:
+    - inventory_hostname in groups['tgtd']
+    - enable_cinder_backend_lvm | bool
diff --git a/ansible/roles/nova/tasks/start_compute.yml b/ansible/roles/nova/tasks/start_compute.yml
index 7afe664a29..ac8bf97df7 100644
--- a/ansible/roles/nova/tasks/start_compute.yml
+++ b/ansible/roles/nova/tasks/start_compute.yml
@@ -34,7 +34,7 @@
       - "/run:/run"
       - "/dev:/dev"
       - "kolla_logs:/var/log/kolla/"
-      - "{% if enable_cinder_backend_lvm | bool %}iscsi_info:/etc/iscsi{% endif %}"
+      - "{% if enable_iscsid | bool %}iscsi_info:/etc/iscsi{% endif %}"
       - "libvirtd:/var/lib/libvirt"
       - "nova_compute:/var/lib/nova/"
 
diff --git a/ansible/site.yml b/ansible/site.yml
index e2816e4024..48ccef7cb2 100644
--- a/ansible/site.yml
+++ b/ansible/site.yml
@@ -80,7 +80,7 @@
   roles:
     - { role: iscsi,
         tags: iscsi,
-        when: enable_cinder_backend_lvm | bool }
+        when: enable_iscsid | bool }
 
 - hosts:
     - multipathd
diff --git a/doc/cinder-guide.rst b/doc/cinder-guide.rst
index aee91b3319..66ac8b123b 100644
--- a/doc/cinder-guide.rst
+++ b/doc/cinder-guide.rst
@@ -97,7 +97,7 @@ between nova-compute process and the server hosting LVG.
 
 In order to use Cinder's LVM backend, a LVG named ``cinder-volumes`` should
 exist on the server and following parameter must be specified in
-``globals.yml``. ::
+``globals.yml`` ::
 
     enable_cinder_backend_lvm: "yes"
 
@@ -126,3 +126,13 @@ targeted for nova compute role.
     ::
 
       mount -t configfs /etc/rc.local /sys/kernel/config
+
+Cinder backend with external iSCSI storage
+==========================================
+
+In order to use external storage system (like one from EMC or NetApp)
+the following parameter must be specified in ``globals.yml`` ::
+
+    enable_cinder_backend_iscsi: "yes"
+
+Also ``enable_cinder_backend_lvm`` should be set to "no" in this case.
diff --git a/etc/kolla/globals.yml b/etc/kolla/globals.yml
index b007c89e1c..13fcfc26f2 100644
--- a/etc/kolla/globals.yml
+++ b/etc/kolla/globals.yml
@@ -119,6 +119,7 @@ kolla_internal_vip_address: "10.10.10.254"
 #enable_ceph: "no"
 #enable_ceph_rgw: "no"
 #enable_cinder: "no"
+#enable_cinder_backend_iscsi: "no"
 #enable_cinder_backend_lvm: "no"
 #enable_cloudkitty: "no"
 #enable_congress: "no"