Refactoring aodh apache site configuration

The patch changes apache site for aodh to work with regular
template for wsgi.

Change-Id: Ieece100db55fa964c9bddb6a3b665fc63ae0955e
diff --git a/.kitchen.yml b/.kitchen.yml
index 44ccfb7..10dcc1d 100644
--- a/.kitchen.yml
+++ b/.kitchen.yml
@@ -18,6 +18,9 @@
     - name: linux
       repo: git
       source: https://github.com/salt-formulas/salt-formula-linux
+    - name: apache
+      repo: git
+      source: https://github.com/salt-formulas/salt-formula-apache
   state_top:
     base:
       "*":
diff --git a/aodh/server.sls b/aodh/server.sls
index a51abdc..6220c74 100644
--- a/aodh/server.sls
+++ b/aodh/server.sls
@@ -8,6 +8,7 @@
 include:
   - aodh._ssl.mysql
   - aodh._ssl.rabbitmq
+  - apache
 
 aodh_server_packages:
   pkg.installed:
@@ -142,6 +143,26 @@
 # for Newton and newer
 {%- if server.version not in ['mitaka'] %}
 
+{%- if pillar.get('apache', {}).get('server', {}).get('site', {}).aodh is defined %}
+
+apache_enable_aodh_wsgi:
+  apache_site.enabled:
+  - name: wsgi_aodh
+  {%- if grains.get('noservices') %}
+  - onlyif: /bin/false
+  {%- endif %}
+  - require:
+    - pkg: aodh_server_packages
+    - file: aodh_cleanup_configs
+
+aodh_cleanup_configs:
+  file.absent:
+    - names:
+      - '/etc/apache2/sites-available/aodh-api.conf'
+      - '/etc/apache2/sites-enabled/aodh-api.conf'
+
+{%- else %}
+
 aodh_api_apache_config:
   file.managed:
   {%- if server.version == 'newton' %}
@@ -164,6 +185,8 @@
      - target: /etc/apache2/sites-available/aodh-api.conf
      {%- endif %}
 
+{%- endif %}
+
 aodh_apache_restart:
   service.running:
   - enable: true
@@ -173,7 +196,12 @@
   {%- endif %}
   - watch:
     - file: /etc/aodh/aodh.conf
+    {%- if pillar.get('apache', {}).get('server', {}).get('site', {}).aodh is defined %}
+    - apache_enable_aodh_wsgi
+    {%- else %}
     - file: aodh_api_apache_config
+    {%- endif %}
+
 
 {%- if server.message_queue.get('ssl',{}).get('enabled', False) %}
 rabbitmq_ca_aodh_server:
diff --git a/metadata.yml b/metadata.yml
index bac9bbe..e71002b 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,3 +1,6 @@
 name: "aodh"
 version: "2016.4.1"
 source: "https://github.com/tcpcloud/salt-formula-aodh"
+dependencies:
+  - name: apache
+    source: "https://github.com/salt-formulas/salt-formula-apache"
diff --git a/tests/pillar/server_cluster.sls b/tests/pillar/server_cluster.sls
index 5f0cd1b..d49cfd7 100644
--- a/tests/pillar/server_cluster.sls
+++ b/tests/pillar/server_cluster.sls
@@ -44,3 +44,42 @@
       password: test
     notifications:
       store_events: default
+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:
+      aodh:
+        enabled: false
+        available: true
+        type: wsgi
+        name: aodh
+        host:
+          name: 127.0.0.1
+          address: 127.0.0.1
+          port: 8042
+        log:
+          custom:
+            format: >-
+              %v:%p %{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %D %O \"%{Referer}i\" \"%{User-Agent}i\"
+        wsgi:
+          daemon_process: aodh-api
+          processes: ${_param:aodh_api_workers}
+          threads: 1
+          user: aodh
+          group: aodh
+          display_name: '%{GROUP}'
+          script_alias: '/ /usr/share/aodh/app.wsgi'
+          application_group: '%{GLOBAL}'
+          authorization: 'On'
diff --git a/tests/pillar/server_single.sls b/tests/pillar/server_single.sls
index 6fbb80d..a80acbe 100644
--- a/tests/pillar/server_single.sls
+++ b/tests/pillar/server_single.sls
@@ -40,3 +40,18 @@
       password: test
     notifications:
       store_events: default
+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