Fix root_url bug when using a slash
When settings the root_url to a slash the paths in the local_settings.py and apache config will be wrong. This patch fixes that issue. Change-Id: Ib64b22bb88b2827ea4be2eb8356aa404984ee0ba Closes-Bug: 1651720
This commit is contained in:
parent
b0f6bde9a6
commit
32a784c784
@ -141,6 +141,13 @@ class horizon::wsgi::apache (
|
|||||||
require => Package['horizon'],
|
require => Package['horizon'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# NOTE(tobasco): If root_url is set to '/' the paths in the apache
|
||||||
|
# configuration will be wrong (double slashes) so we fix that here.
|
||||||
|
if $root_url == '/' {
|
||||||
|
$root_url_real = ''
|
||||||
|
} else {
|
||||||
|
$root_url_real = $root_url
|
||||||
|
}
|
||||||
|
|
||||||
if $listen_ssl {
|
if $listen_ssl {
|
||||||
include ::apache::mod::ssl
|
include ::apache::mod::ssl
|
||||||
@ -160,7 +167,7 @@ class horizon::wsgi::apache (
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
case $root_url {
|
case $root_url_real {
|
||||||
'': {
|
'': {
|
||||||
$ensure_ssl_vhost = 'absent'
|
$ensure_ssl_vhost = 'absent'
|
||||||
$redirect_match = "^${::horizon::params::root_url}\$"
|
$redirect_match = "^${::horizon::params::root_url}\$"
|
||||||
@ -169,7 +176,7 @@ class horizon::wsgi::apache (
|
|||||||
default: {
|
default: {
|
||||||
$ensure_ssl_vhost = 'absent'
|
$ensure_ssl_vhost = 'absent'
|
||||||
$redirect_match = '^/$'
|
$redirect_match = '^/$'
|
||||||
$redirect_url = $root_url
|
$redirect_url = $root_url_real
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,9 +209,9 @@ class horizon::wsgi::apache (
|
|||||||
require => [ File[$::horizon::params::logdir], Package['horizon'] ],
|
require => [ File[$::horizon::params::logdir], Package['horizon'] ],
|
||||||
}
|
}
|
||||||
|
|
||||||
$script_url = $root_url ? {
|
$script_url = $root_url_real ? {
|
||||||
'' => '/',
|
'' => '/',
|
||||||
default => $root_url,
|
default => $root_url_real,
|
||||||
}
|
}
|
||||||
|
|
||||||
$wsgi_daemon_process_options = merge(
|
$wsgi_daemon_process_options = merge(
|
||||||
@ -226,7 +233,7 @@ class horizon::wsgi::apache (
|
|||||||
error_log_file => 'horizon_error.log',
|
error_log_file => 'horizon_error.log',
|
||||||
priority => $priority,
|
priority => $priority,
|
||||||
aliases => [{
|
aliases => [{
|
||||||
alias => "${root_url}/static",
|
alias => "${root_url_real}/static",
|
||||||
path => "${root_path}/static",
|
path => "${root_path}/static",
|
||||||
}],
|
}],
|
||||||
port => $http_port,
|
port => $http_port,
|
||||||
@ -253,8 +260,8 @@ class horizon::wsgi::apache (
|
|||||||
}
|
}
|
||||||
|
|
||||||
ensure_resource('apache::vhost', $vhost_conf_name, merge ($default_vhost_conf, $extra_params, {
|
ensure_resource('apache::vhost', $vhost_conf_name, merge ($default_vhost_conf, $extra_params, {
|
||||||
redirectmatch_regexp => $root_url ? { '' => undef, '/' => undef, default => $redirect_match },
|
redirectmatch_regexp => $root_url_real ? { '' => undef, '/' => undef, default => $redirect_match },
|
||||||
redirectmatch_dest => $root_url ? { '' => undef, '/' => undef, default => $redirect_url },
|
redirectmatch_dest => $root_url_real ? { '' => undef, '/' => undef, default => $redirect_url },
|
||||||
}))
|
}))
|
||||||
ensure_resource('apache::vhost', $vhost_ssl_conf_name, merge ($default_vhost_conf, $extra_params, {
|
ensure_resource('apache::vhost', $vhost_ssl_conf_name, merge ($default_vhost_conf, $extra_params, {
|
||||||
access_log_file => 'horizon_ssl_access.log',
|
access_log_file => 'horizon_ssl_access.log',
|
||||||
@ -265,8 +272,8 @@ class horizon::wsgi::apache (
|
|||||||
ensure => $ensure_ssl_vhost,
|
ensure => $ensure_ssl_vhost,
|
||||||
wsgi_daemon_process => 'horizon-ssl',
|
wsgi_daemon_process => 'horizon-ssl',
|
||||||
wsgi_process_group => 'horizon-ssl',
|
wsgi_process_group => 'horizon-ssl',
|
||||||
redirectmatch_regexp => $root_url ? { '' => undef, '/' => undef, default => '^/$' },
|
redirectmatch_regexp => $root_url_real ? { '' => undef, '/' => undef, default => '^/$' },
|
||||||
redirectmatch_dest => $root_url ? { '' => undef, '/' => undef, default => $root_url },
|
redirectmatch_dest => $root_url_real ? { '' => undef, '/' => undef, default => $root_url_real },
|
||||||
}))
|
}))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Fixed a bug where passing a '/' as root_url would cause faulty paths in
|
||||||
|
local_settings.py and apache configuration. You can now set it to '/' and
|
||||||
|
the module will fix the correct root url for you.
|
@ -202,9 +202,17 @@ describe 'horizon::wsgi::apache' do
|
|||||||
before do
|
before do
|
||||||
params.merge!({
|
params.merge!({
|
||||||
:root_url => '/',
|
:root_url => '/',
|
||||||
|
:root_path => '/tmp/horizon'
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'configures apache with correct root url' do
|
||||||
|
is_expected.to contain_apache__vhost('horizon_vhost').with(
|
||||||
|
'aliases' => [{'alias' => '/static', 'path' => '/tmp/horizon/static'}],
|
||||||
|
'wsgi_script_aliases' => { '/' => '/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi' },
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
it 'should not configure redirectmatch' do
|
it 'should not configure redirectmatch' do
|
||||||
is_expected.to_not contain_apache__vhost('horizon_vhost').with(
|
is_expected.to_not contain_apache__vhost('horizon_vhost').with(
|
||||||
'redirectmatch_regexp' => '^/$',
|
'redirectmatch_regexp' => '^/$',
|
||||||
|
@ -15,15 +15,25 @@ TEMPLATE_DEBUG = DEBUG
|
|||||||
# should end with a slash.
|
# should end with a slash.
|
||||||
#LOGIN_URL = WEBROOT + 'auth/login/'
|
#LOGIN_URL = WEBROOT + 'auth/login/'
|
||||||
#LOGOUT_URL = WEBROOT + 'auth/logout/'
|
#LOGOUT_URL = WEBROOT + 'auth/logout/'
|
||||||
|
<% if @root_url == '/' %>
|
||||||
|
WEBROOT = '/'
|
||||||
|
LOGIN_URL = '/auth/login/'
|
||||||
|
LOGOUT_URL = '/auth/logout/'
|
||||||
|
<% else %>
|
||||||
WEBROOT = '<%= @root_url %>/'
|
WEBROOT = '<%= @root_url %>/'
|
||||||
LOGIN_URL = '<%= @root_url %>/auth/login/'
|
LOGIN_URL = '<%= @root_url %>/auth/login/'
|
||||||
LOGOUT_URL = '<%= @root_url %>/auth/logout/'
|
LOGOUT_URL = '<%= @root_url %>/auth/logout/'
|
||||||
|
<% end %>
|
||||||
|
|
||||||
# LOGIN_REDIRECT_URL can be used as an alternative for
|
# LOGIN_REDIRECT_URL can be used as an alternative for
|
||||||
# HORIZON_CONFIG.user_home, if user_home is not set.
|
# HORIZON_CONFIG.user_home, if user_home is not set.
|
||||||
# Do not set it to '/home/', as this will cause circular redirect loop
|
# Do not set it to '/home/', as this will cause circular redirect loop
|
||||||
#LOGIN_REDIRECT_URL = WEBROOT
|
#LOGIN_REDIRECT_URL = WEBROOT
|
||||||
|
<% if @root_url == '/' %>
|
||||||
|
LOGIN_REDIRECT_URL = '/'
|
||||||
|
<% else %>
|
||||||
LOGIN_REDIRECT_URL = '<%= @root_url %>/'
|
LOGIN_REDIRECT_URL = '<%= @root_url %>/'
|
||||||
|
<% end %>
|
||||||
|
|
||||||
# Required for Django 1.5.
|
# Required for Django 1.5.
|
||||||
# If horizon is running in production (DEBUG is False), set this
|
# If horizon is running in production (DEBUG is False), set this
|
||||||
|
Loading…
Reference in New Issue
Block a user