From 42ed4ec7362b559e2c292b036765d696bfbd3716 Mon Sep 17 00:00:00 2001 From: Javier Pena 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 --- manifests/wsgi/apache.pp | 4 ++-- spec/classes/horizon_init_spec.rb | 12 ++++++++++++ spec/classes/horizon_wsgi_apache_spec.rb | 30 ++++++++++++++++++++++++++---- templates/local_settings.py.erb | 4 ++++ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/manifests/wsgi/apache.pp b/manifests/wsgi/apache.pp index 797fe91..b4f9e63 100644 --- a/manifests/wsgi/apache.pp +++ b/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/spec/classes/horizon_init_spec.rb b/spec/classes/horizon_init_spec.rb index 4e18df8..e22d4bf 100644 --- a/spec/classes/horizon_init_spec.rb +++ b/spec/classes/horizon_init_spec.rb @@ -299,6 +299,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 @@ -316,5 +322,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/spec/classes/horizon_wsgi_apache_spec.rb b/spec/classes/horizon_wsgi_apache_spec.rb index 90ba623..467a426 100644 --- a/spec/classes/horizon_wsgi_apache_spec.rb +++ b/spec/classes/horizon_wsgi_apache_spec.rb @@ -40,7 +40,7 @@ describe 'horizon::wsgi::apache' do 'access_log_file' => 'horizon_access.log', 'error_log_file' => 'horizon_error.log', 'priority' => '15', - 'serveraliases' => '*', + 'serveraliases' => ['*'], 'docroot' => '/var/www/', 'ssl' => 'false', 'redirectmatch_status' => 'permanent', @@ -73,7 +73,7 @@ describe 'horizon::wsgi::apache' do 'access_log_file' => 'horizon_access.log', 'error_log_file' => 'horizon_error.log', 'priority' => params[:priority], - 'serveraliases' => '*', + 'serveraliases' => ['*'], 'docroot' => '/var/www/', 'ssl' => 'false', 'redirectmatch_status' => 'permanent', @@ -107,7 +107,7 @@ describe 'horizon::wsgi::apache' do 'access_log_file' => 'horizon_ssl_access.log', 'error_log_file' => 'horizon_ssl_error.log', 'priority' => '15', - 'serveraliases' => '*', + 'serveraliases' => ['*'], 'docroot' => '/var/www/', 'ssl' => 'true', 'ssl_cert' => '/etc/pki/tls/certs/httpd.crt', @@ -126,7 +126,7 @@ describe 'horizon::wsgi::apache' do 'access_log_file' => 'horizon_access.log', 'error_log_file' => 'horizon_error.log', 'priority' => '15', - 'serveraliases' => '*', + 'serveraliases' => ['*'], 'docroot' => '/var/www/', 'ssl' => 'false', 'redirectmatch_status' => 'permanent', @@ -203,6 +203,17 @@ 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 + if (Gem::Version.new(Puppet.version) >= Gem::Version.new('4.0')) + is_expected.to contain_apache__vhost('horizon_vhost').with( + 'aliases' => [{'alias' => '/dashboard/static', 'path' => '/usr/share/openstack-dashboard/static'}], + ) + else + is_expected.to contain_apache__vhost('horizon_vhost').with( + 'aliases' => [['alias', '/dashboard/static'], ['path', '/usr/share/openstack-dashboard/static']], + ) + end + end end context 'on Debian platforms' do @@ -226,5 +237,16 @@ describe 'horizon::wsgi::apache' do end it_behaves_like 'apache for horizon' + it 'configures webroot alias' do + if (Gem::Version.new(Puppet.version) >= Gem::Version.new('4.0')) + is_expected.to contain_apache__vhost('horizon_vhost').with( + 'aliases' => [{'alias' => '/horizon/static', 'path' => '/usr/share/openstack-dashboard/static'}], + ) + else + is_expected.to contain_apache__vhost('horizon_vhost').with( + 'aliases' => [['alias', '/horizon/static'], ['path', '/usr/share/openstack-dashboard/static']], + ) + end + end end end diff --git a/templates/local_settings.py.erb b/templates/local_settings.py.erb index 944c00e..00b15e5 100644 --- a/templates/local_settings.py.erb +++ b/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. -- 1.9.1