Blob Blame History Raw
From cac261b36225b1f77a84911a4e4963ea9da12499 Mon Sep 17 00:00:00 2001
From: Javier Pena <jpena@redhat.com>
Date: Tue, 14 Apr 2015 15:47:55 +0200
Subject: [PATCH] Add support for WEBROOT in local_settings

Starting in Kilo, a new WEBROOT setting has been added in file
local_settings (see
http://docs.openstack.org/developer/horizon/topics/settings.html).
This requires changes in the Apache vhost configuration, too.

Change-Id: Ibbeec600502964b51c0c725c35d2afd6fd7bd9e9
---
 horizon/manifests/wsgi/apache.pp                 |  4 ++--
 horizon/spec/classes/horizon_init_spec.rb        | 14 +++++++++++++-
 horizon/spec/classes/horizon_wsgi_apache_spec.rb | 10 ++++++++++
 horizon/templates/local_settings.py.erb          |  4 ++++
 4 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/horizon/manifests/wsgi/apache.pp b/horizon/manifests/wsgi/apache.pp
index 797fe91..b4f9e63 100644
--- a/horizon/manifests/wsgi/apache.pp
+++ b/horizon/manifests/wsgi/apache.pp
@@ -170,8 +170,8 @@ class horizon::wsgi::apache (
     error_log_file              => 'horizon_error.log',
     priority                    => $priority,
     aliases                     => [{
-      alias => '/static',
-      path => '/usr/share/openstack-dashboard/static',
+      alias => "${$::horizon::params::root_url}/static",
+      path  => '/usr/share/openstack-dashboard/static',
     }],
     port                        => 80,
     ssl_cert                    => $horizon_cert,
diff --git a/horizon/spec/classes/horizon_init_spec.rb b/horizon/spec/classes/horizon_init_spec.rb
index c0b1861..5d7229d 100644
--- a/horizon/spec/classes/horizon_init_spec.rb
+++ b/horizon/spec/classes/horizon_init_spec.rb
@@ -97,7 +97,7 @@ describe 'horizon' do
           :neutron_options         => {'enable_lb' => true, 'enable_firewall' => true, 'enable_quotas' => false, 'enable_security_group' => false, 'enable_vpn' => true,
                                        'enable_distributed_router' => false, 'enable_ha_router' => false, 'profile_support' => 'cisco', },
           :file_upload_temp_dir    => '/var/spool/horizon',
-          :secure_cookies          => true
+          :secure_cookies          => true,
         })
       end
 
@@ -327,6 +327,12 @@ describe 'horizon' do
     end
 
     it_behaves_like 'horizon'
+
+    it 'sets WEBROOT in local_settings.py' do
+      verify_concat_fragment_contents(catalogue, 'local_settings.py', [
+        "WEBROOT = '/dashboard/'",
+      ])
+    end
   end
 
   context 'on Debian platforms' do
@@ -344,5 +350,11 @@ describe 'horizon' do
     end
 
     it_behaves_like 'horizon'
+
+    it 'sets WEBROOT in local_settings.py' do
+      verify_concat_fragment_contents(catalogue, 'local_settings.py', [
+        "WEBROOT = '/horizon/'",
+      ])
+    end
   end
 end
diff --git a/horizon/spec/classes/horizon_wsgi_apache_spec.rb b/horizon/spec/classes/horizon_wsgi_apache_spec.rb
index a69048e..daea11e 100644
--- a/horizon/spec/classes/horizon_wsgi_apache_spec.rb
+++ b/horizon/spec/classes/horizon_wsgi_apache_spec.rb
@@ -203,6 +203,11 @@ describe 'horizon::wsgi::apache' do
     it {
       is_expected.to contain_class('apache::mod::wsgi').with(:wsgi_socket_prefix => '/var/run/wsgi')
     }
+    it 'configures webroot alias' do
+      is_expected.to contain_apache__vhost('horizon_vhost').with(
+        'aliases' => [['alias', '/dashboard/static'], ['path', '/usr/share/openstack-dashboard/static']],
+      )
+    end
   end
 
   context 'on Debian platforms' do
@@ -226,5 +231,10 @@ describe 'horizon::wsgi::apache' do
     end
 
     it_behaves_like 'apache for horizon'
+    it 'configures webroot alias' do
+      is_expected.to contain_apache__vhost('horizon_vhost').with(
+        'aliases' => [['alias', '/horizon/static'], ['path', '/usr/share/openstack-dashboard/static']],
+      )
+    end
   end
 end
diff --git a/horizon/templates/local_settings.py.erb b/horizon/templates/local_settings.py.erb
index b8237ca..6f2ece4 100644
--- a/horizon/templates/local_settings.py.erb
+++ b/horizon/templates/local_settings.py.erb
@@ -7,6 +7,10 @@ from openstack_dashboard import exceptions
 DEBUG = <%= @django_debug.to_s.capitalize %>
 TEMPLATE_DEBUG = DEBUG
 
+# WEBROOT is the location relative to Webserver root
+# should end with a slash.
+WEBROOT = '<%= scope.lookupvar("horizon::params::root_url") %>/'
+
 # Required for Django 1.5.
 # If horizon is running in production (DEBUG is False), set this
 # with the list of host/domain names that the application can serve.