From d708e9565881ecf83565112159f5518cf222c976 Mon Sep 17 00:00:00 2001
From: Eduardo Gonzalez <dabarren@gmail.com>
Date: Wed, 7 Jun 2017 14:32:04 +0200
Subject: [PATCH] Migrate cinder-api under apache

Cinder ubuntu binary was already migrated under apache.
This change migrates rest of the distros/install types to
be executed under an apache process.

Change-Id: I8544eec5bfebf771d758f13abf4dfbc802f5d24f
---
 ansible/roles/cinder/handlers/main.yml        |  4 +---
 ansible/roles/cinder/tasks/config.yml         |  2 --
 .../roles/cinder/templates/cinder-api.json.j2 | 19 ++++++++++---------
 .../cinder-api-apache-fc58978df0645b2f.yaml   |  5 +++++
 4 files changed, 16 insertions(+), 14 deletions(-)
 create mode 100644 releasenotes/notes/cinder-api-apache-fc58978df0645b2f.yaml

diff --git a/ansible/roles/cinder/handlers/main.yml b/ansible/roles/cinder/handlers/main.yml
index 7c5c593c8a..485669848e 100644
--- a/ansible/roles/cinder/handlers/main.yml
+++ b/ansible/roles/cinder/handlers/main.yml
@@ -19,11 +19,9 @@
     - service.enabled | bool
     - config_json.changed | bool
       or cinder_conf.changed | bool
+      or wsgi_cinder_api.changed | bool
       or policy_json.changed | bool
       or cinder_api_container.changed | bool
-      or (kolla_base_distro in ['debian', 'ubuntu']
-          and kolla_install_type == 'binary'
-          and wsgi_cinder_api | changed)
 
 - name: Restart cinder-scheduler container
   vars:
diff --git a/ansible/roles/cinder/tasks/config.yml b/ansible/roles/cinder/tasks/config.yml
index 3f808ddde0..9bdc5f2654 100644
--- a/ansible/roles/cinder/tasks/config.yml
+++ b/ansible/roles/cinder/tasks/config.yml
@@ -38,8 +38,6 @@
   when:
     - inventory_hostname in groups[service.group]
     - service.enabled | bool
-    - kolla_base_distro in ['debian', 'ubuntu']
-    - kolla_install_type == 'binary'
   notify:
     - Restart cinder-api container
 
diff --git a/ansible/roles/cinder/templates/cinder-api.json.j2 b/ansible/roles/cinder/templates/cinder-api.json.j2
index 9a38426f41..4b5243fffc 100644
--- a/ansible/roles/cinder/templates/cinder-api.json.j2
+++ b/ansible/roles/cinder/templates/cinder-api.json.j2
@@ -1,6 +1,7 @@
-{% set command = '/usr/sbin/apache2  -DFOREGROUND' if kolla_base_distro in ['ubuntu', 'debian'] and kolla_install_type == 'binary' else 'cinder-api --config-file /etc/cinder/cinder.conf' %}
+{% set cinder_cmd = 'apache2' if kolla_base_distro in ['ubuntu', 'debian'] else 'httpd' %}
+{% set cinder_dir = 'apache2/conf-enabled' if kolla_base_distro in ['ubuntu', 'debian'] else 'httpd/conf.d' %}
 {
-    "command": "{{ command }}",
+    "command": "{{ cinder_cmd }} -DFOREGROUND",
     "config_files": [
         {
             "source": "{{ container_config_directory }}/cinder.conf",
@@ -8,19 +9,19 @@
             "owner": "cinder",
             "perm": "0600"
         },
+        {
+            "source": "{{ container_config_directory }}/cinder-wsgi.conf",
+            "dest": "/etc/{{ cinder_dir }}/cinder-wsgi.conf",
+            "owner": "cinder",
+            "perm": "0600"
+        },
         {
             "source": "{{ container_config_directory }}/policy.json",
             "dest": "/etc/cinder/policy.json",
             "owner": "cinder",
             "perm": "0600",
             "optional": true
-        }{% if kolla_base_distro in ['ubuntu', 'debian'] and kolla_install_type == 'binary' %},
-        {
-            "source": "{{ container_config_directory }}/cinder-wsgi.conf",
-            "dest": "/etc/apache2/conf-enabled/cinder-wsgi.conf",
-            "owner": "cinder",
-            "perm": "0600"
-        }{% endif %}
+        }
     ],
     "permissions": [
         {
diff --git a/releasenotes/notes/cinder-api-apache-fc58978df0645b2f.yaml b/releasenotes/notes/cinder-api-apache-fc58978df0645b2f.yaml
new file mode 100644
index 0000000000..867d31e276
--- /dev/null
+++ b/releasenotes/notes/cinder-api-apache-fc58978df0645b2f.yaml
@@ -0,0 +1,5 @@
+---
+features:
+  - |
+    Cinder-api service has been migrated to run under
+    an apache wsgi process.