diff --git a/manifests/wsgi/apache.pp b/manifests/wsgi/apache.pp index 0a87b8c8..7f6d5748 100644 --- a/manifests/wsgi/apache.pp +++ b/manifests/wsgi/apache.pp @@ -141,6 +141,13 @@ class horizon::wsgi::apache ( 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 { include ::apache::mod::ssl @@ -160,7 +167,7 @@ class horizon::wsgi::apache ( } } else { - case $root_url { + case $root_url_real { '': { $ensure_ssl_vhost = 'absent' $redirect_match = "^${::horizon::params::root_url}\$" @@ -169,7 +176,7 @@ class horizon::wsgi::apache ( default: { $ensure_ssl_vhost = 'absent' $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'] ], } - $script_url = $root_url ? { + $script_url = $root_url_real ? { '' => '/', - default => $root_url, + default => $root_url_real, } $wsgi_daemon_process_options = merge( @@ -226,7 +233,7 @@ class horizon::wsgi::apache ( error_log_file => 'horizon_error.log', priority => $priority, aliases => [{ - alias => "${root_url}/static", + alias => "${root_url_real}/static", path => "${root_path}/static", }], port => $http_port, @@ -253,8 +260,8 @@ class horizon::wsgi::apache ( } ensure_resource('apache::vhost', $vhost_conf_name, merge ($default_vhost_conf, $extra_params, { - redirectmatch_regexp => $root_url ? { '' => undef, '/' => undef, default => $redirect_match }, - redirectmatch_dest => $root_url ? { '' => undef, '/' => undef, default => $redirect_url }, + redirectmatch_regexp => $root_url_real ? { '' => undef, '/' => undef, default => $redirect_match }, + redirectmatch_dest => $root_url_real ? { '' => undef, '/' => undef, default => $redirect_url }, })) ensure_resource('apache::vhost', $vhost_ssl_conf_name, merge ($default_vhost_conf, $extra_params, { access_log_file => 'horizon_ssl_access.log', @@ -265,8 +272,8 @@ class horizon::wsgi::apache ( ensure => $ensure_ssl_vhost, wsgi_daemon_process => 'horizon-ssl', wsgi_process_group => 'horizon-ssl', - redirectmatch_regexp => $root_url ? { '' => undef, '/' => undef, default => '^/$' }, - redirectmatch_dest => $root_url ? { '' => undef, '/' => undef, default => $root_url }, + redirectmatch_regexp => $root_url_real ? { '' => undef, '/' => undef, default => '^/$' }, + redirectmatch_dest => $root_url_real ? { '' => undef, '/' => undef, default => $root_url_real }, })) } diff --git a/releasenotes/notes/horizon-fix-invalid-root-url-0c8e54a5c6de2f5e.yaml b/releasenotes/notes/horizon-fix-invalid-root-url-0c8e54a5c6de2f5e.yaml new file mode 100644 index 00000000..7d634de1 --- /dev/null +++ b/releasenotes/notes/horizon-fix-invalid-root-url-0c8e54a5c6de2f5e.yaml @@ -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. diff --git a/spec/classes/horizon_wsgi_apache_spec.rb b/spec/classes/horizon_wsgi_apache_spec.rb index 83b61f03..23d59351 100644 --- a/spec/classes/horizon_wsgi_apache_spec.rb +++ b/spec/classes/horizon_wsgi_apache_spec.rb @@ -202,9 +202,17 @@ describe 'horizon::wsgi::apache' do before do params.merge!({ :root_url => '/', + :root_path => '/tmp/horizon' }) 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 is_expected.to_not contain_apache__vhost('horizon_vhost').with( 'redirectmatch_regexp' => '^/$', diff --git a/templates/local_settings.py.erb b/templates/local_settings.py.erb index cb0a4f0e..893229b6 100644 --- a/templates/local_settings.py.erb +++ b/templates/local_settings.py.erb @@ -15,15 +15,25 @@ TEMPLATE_DEBUG = DEBUG # should end with a slash. #LOGIN_URL = WEBROOT + 'auth/login/' #LOGOUT_URL = WEBROOT + 'auth/logout/' +<% if @root_url == '/' %> +WEBROOT = '/' +LOGIN_URL = '/auth/login/' +LOGOUT_URL = '/auth/logout/' +<% else %> WEBROOT = '<%= @root_url %>/' LOGIN_URL = '<%= @root_url %>/auth/login/' LOGOUT_URL = '<%= @root_url %>/auth/logout/' +<% end %> # LOGIN_REDIRECT_URL can be used as an alternative for # HORIZON_CONFIG.user_home, if user_home is not set. # Do not set it to '/home/', as this will cause circular redirect loop #LOGIN_REDIRECT_URL = WEBROOT +<% if @root_url == '/' %> +LOGIN_REDIRECT_URL = '/' +<% else %> LOGIN_REDIRECT_URL = '<%= @root_url %>/' +<% end %> # Required for Django 1.5. # If horizon is running in production (DEBUG is False), set this