Deprecate using intree nova placement wsgi template

All openstack services uses 99% persent same wsgi apache config.
This patch adds functionality to configure nova-placement wsgi conf
from apache pillar. To do this on cluster level the following file
should be included:
 - system.apache.server.site.nova-placement

The intree wsgi template will be removed when we switch all model
and cookiecutter to use apache template.

Change-Id: Id6ec48ffa93db572d6a2a8257946a4a1d2fbedb3
diff --git a/.kitchen.yml b/.kitchen.yml
index c8f40b8..f343e41 100644
--- a/.kitchen.yml
+++ b/.kitchen.yml
@@ -21,6 +21,9 @@
     - name: keystone
       repo: git
       source: https://github.com/salt-formulas/salt-formula-keystone
+    - name: apache
+      repo: git
+      source: https://github.com/salt-formulas/salt-formula-apache
   state_top:
     base:
       "*":
@@ -68,4 +71,5 @@
             controller:
               version: <%= ENV['OS_VERSION'] || 'ocata' %>
 
+
 # vim: ft=yaml sw=2 ts=2 sts=2 tw=125
diff --git a/.travis.yml b/.travis.yml
index 1d65abb..50728d0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,11 +18,8 @@
 
 env:
   - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 OS_VERSION=mitaka SUITE=compute-cluster
-  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 OS_VERSION=mitaka SUITE=control-cluster
   - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7 OS_VERSION=mitaka SUITE=compute-cluster
-  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7 OS_VERSION=mitaka SUITE=control-cluster
   - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 OS_VERSION=newton SUITE=compute-cluster
-  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 OS_VERSION=newton SUITE=control-cluster
   - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7 OS_VERSION=newton SUITE=compute-cluster
   - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7 OS_VERSION=newton SUITE=control-cluster
   - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 OS_VERSION=ocata SUITE=compute-cluster
diff --git a/metadata.yml b/metadata.yml
index 0ee34f0..5a279bc 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -4,3 +4,5 @@
 dependencies:
   - name: keystone
     source: "https://github.com/salt-formulas/salt-formula-keystone"
+  - name: apache
+    source: "https://github.com/salt-formulas/salt-formula-apache"
diff --git a/nova/controller.sls b/nova/controller.sls
index 71d8834..49851bf 100644
--- a/nova/controller.sls
+++ b/nova/controller.sls
@@ -315,8 +315,12 @@
   - require:
     - file: nova_placement_service_mask
 
-/etc/apache2/sites-available/nova-placement-api.conf:
+{#- Creation of sites using templates is deprecated, sites should be generated by apache pillar, and enabled by barbican formula #}
+{%- if pillar.get('apache', {}).get('server', {}).get('site', {}).nova_placement is not defined %}
+
+nova_placement_apache_conf_file:
   file.managed:
+  - name: /etc/apache2/sites-available/nova-placement-api.conf
   - source: salt://nova/files/{{ controller.version }}/nova-placement-api.conf
   - template: jinja
   - require:
@@ -324,9 +328,36 @@
     - pkg: nova_placement_package
 
 placement_config:
-  file.symlink:
-     - name: /etc/apache2/sites-enabled/nova-placement-api.conf
-     - target: /etc/apache2/sites-available/nova-placement-api.conf
+  apache_site.enabled:
+    - name: nova-placement-api
+    - require:
+      - nova_placement_apache_conf_file
+
+{%- else %}
+
+include:
+ - apache
+
+nova_cleanup_configs:
+  file.absent:
+    - names:
+      - '/etc/apache2/sites-available/nova-placement-api.conf'
+      - '/etc/apache2/sites-enabled/nova-placement-api.conf'
+
+nova_placement_apache_conf_file:
+  file.exists:
+  - name: /etc/apache2/sites-available/wsgi_nova_placement.conf
+  - require:
+    - pkg: nova_placement_package
+    - nova_cleanup_configs
+
+placement_config:
+  apache_site.enabled:
+    - name: wsgi_nova_placement
+    - require:
+      - nova_placement_apache_conf_file
+
+{%- endif %}
 
 nova_controller_discover_hosts:
   cmd.run:
@@ -400,7 +431,7 @@
   - watch:
     - file: /etc/nova/nova.conf
     - file: /etc/nova/api-paste.ini
-    - file: /etc/apache2/sites-available/nova-placement-api.conf
+    - nova_placement_apache_conf_file
     {%- if controller.database.get('ssl',{}).get('enabled',False)  %}
     - file: mysql_ca_nova_controller
     {% endif %}
diff --git a/tests/pillar/control_cluster.sls b/tests/pillar/control_cluster.sls
index c708f81..f11a947 100644
--- a/tests/pillar/control_cluster.sls
+++ b/tests/pillar/control_cluster.sls
@@ -2,7 +2,7 @@
   controller:
     enabled: true
     networking: default
-    version: liberty
+    version: pike
     vncproxy_url: 127.0.0.1
     vnc_keymap: en-gb
     security_group: false
@@ -75,3 +75,40 @@
       compute: liberty
     barbican:
       enabled: true
+apache:
+  server:
+    enabled: true
+    default_mpm: event
+    mpm:
+      prefork:
+        enabled: true
+        servers:
+          start: 5
+          spare:
+            min: 2
+            max: 10
+        max_requests: 0
+        max_clients: 20
+        limit: 20
+    site:
+      nova_placement:
+        enabled: false
+        available: true
+        type: wsgi
+        name: nova_placement
+        wsgi:
+          daemon_process: nova-placement
+          processes: 5
+          threads: 1
+          user: nova
+          group: nova
+          display_name: '%{GROUP}'
+          script_alias: '/ /usr/bin/nova-placement-api'
+          application_group: '%{GLOBAL}'
+          authorization: 'On'
+        limits:
+          request_body: 114688
+        host:
+          address: 127.0.0.1
+          name: 127.0.0.1
+          port: 8778
diff --git a/tests/pillar/control_single.sls b/tests/pillar/control_single.sls
index da4cd10..3b36463 100644
--- a/tests/pillar/control_single.sls
+++ b/tests/pillar/control_single.sls
@@ -2,7 +2,7 @@
   controller:
     enabled: true
     networking: contrail
-    version: liberty
+    version: pike
     security_group: false
     vncproxy_url: 127.0.0.1
     vnc_keymap: en-gb
@@ -69,3 +69,18 @@
       'context_is_admin': 'role:admin or role:administrator'
       'compute:create': 'rule:admin_or_owner'
       'compute:create:attach_network':
+apache:
+  server:
+    enabled: true
+    default_mpm: event
+    mpm:
+      prefork:
+        enabled: true
+        servers:
+          start: 5
+          spare:
+            min: 2
+            max: 10
+        max_requests: 0
+        max_clients: 20
+        limit: 20