Making root_url configurable

This commit will make universal modifications to the way the "root_url"
  parameter is set so that a person can modify it.  Adjusts tests
  accordingly and improves on beaker success scenario.

  This needs to occur to allow people the ability to serve horizon from the
  root of a vhost.

Change-Id: If43ea694b2601c55a4b07c1cd5fc411abbaaaa2d
This commit is contained in:
Cody Herriges 2016-01-15 15:32:17 -08:00
parent 1c51079068
commit 64f5872e5f
6 changed files with 80 additions and 24 deletions

View File

@ -256,6 +256,10 @@
# of data fetched by default when rendering the Overview panel.
# Defaults to undef.
#
# [*root_url*]
# (optional) The base URL used to contruct horizon web addresses.
# Defaults to '/dashboard' or '/horizon' depending OS
#
# [*session_timeout*]
# (optional) The session timeout for horizon in seconds. After this many seconds of inactivity
# the user is logged out.
@ -321,15 +325,14 @@ class horizon(
$keystone_default_domain = undef,
$image_backend = {},
$overview_days_range = undef,
$root_url = $::horizon::params::root_url,
$session_timeout = 1800,
# DEPRECATED PARAMETERS
$can_set_mount_point = undef,
$vhost_extra_params = undef,
$secure_cookies = false,
$django_session_engine = undef,
) {
include ::horizon::params
) inherits ::horizon::params {
$hypervisor_defaults = {
'can_set_mount_point' => true,
@ -412,6 +415,7 @@ class horizon(
horizon_ca => $horizon_ca,
extra_params => $vhost_extra_params,
redirect_type => $redirect_type,
root_url => $root_url
}
}

View File

@ -75,6 +75,10 @@
# users report errors accessing horizon.
# Defaults to 'permanent'
#
# [*root_url*]
# (optional) The base URL used to contruct horizon web addresses.
# Defaults to '/dashboard' or '/horizon' depending OS
#
class horizon::wsgi::apache (
$bind_address = undef,
$fqdn = undef,
@ -94,9 +98,9 @@ class horizon::wsgi::apache (
$vhost_ssl_conf_name = 'horizon_ssl_vhost',
$extra_params = {},
$redirect_type = 'permanent',
) {
$root_url = $::horizon::params::root_url,
) inherits horizon::params {
include ::horizon::params
include ::apache
if $fqdn {
@ -146,9 +150,18 @@ class horizon::wsgi::apache (
}
} else {
$ensure_ssl_vhost = 'absent'
$redirect_match = '^/$'
$redirect_url = $::horizon::params::root_url
case $root_url {
'': {
$ensure_ssl_vhost = 'absent'
$redirect_match = "^${::horizon::params::root_url}\$"
$redirect_url = '/'
}
default: {
$ensure_ssl_vhost = 'absent'
$redirect_match = '^/$'
$redirect_url = $root_url
}
}
}
if !($redirect_type in ['temp', 'permanent']) {
@ -185,6 +198,11 @@ class horizon::wsgi::apache (
require => [ File[$::horizon::params::logdir], Package['horizon'] ],
}
$script_url = $root_url ? {
'' => '/',
default => $root_url,
}
$default_vhost_conf_no_ip = {
servername => $servername,
serveraliases => os_any2array($final_server_aliases),
@ -193,14 +211,14 @@ class horizon::wsgi::apache (
error_log_file => 'horizon_error.log',
priority => $priority,
aliases => [{
alias => "${$::horizon::params::root_url}/static",
alias => "${root_url}/static",
path => '/usr/share/openstack-dashboard/static',
}],
port => $http_port,
ssl_cert => $horizon_cert,
ssl_key => $horizon_key,
ssl_ca => $horizon_ca,
wsgi_script_aliases => hash([$::horizon::params::root_url, $::horizon::params::django_wsgi]),
wsgi_script_aliases => hash([$script_url, $::horizon::params::django_wsgi]),
wsgi_daemon_process => $::horizon::params::wsgi_group,
wsgi_daemon_process_options => {
processes => $wsgi_processes,
@ -237,7 +255,7 @@ class horizon::wsgi::apache (
wsgi_daemon_process => 'horizon-ssl',
wsgi_process_group => 'horizon-ssl',
redirectmatch_regexp => '^/$',
redirectmatch_dest => $::horizon::params::root_url,
redirectmatch_dest => $root_url,
}))
}

View File

@ -14,7 +14,8 @@ describe 'horizon class' do
# need to disable offline compression due to
# https://bugs.launchpad.net/ubuntu/+source/horizon/+bug/1424042
compress_offline => false,
allowed_hosts => 'localhost',
allowed_hosts => [$::fqdn, 'localhost'],
server_aliases => [$::fqdn, 'localhost'],
}
EOS
@ -25,15 +26,49 @@ describe 'horizon class' do
# basic test for now, to make sure Apache serve /horizon dashboard
if os[:family] == 'Debian'
describe command('curl --connect-timeout 5 -sL -w "%{http_code} %{url_effective}\n" http://localhost/horizon/ -o /dev/null') do
it { is_expected.to return_exit_status 0 }
it 'executes curl and returns 200' do
shell('curl --connect-timeout 5 -sL -w "%{http_code} %{url_effective}\n" http://localhost/horizon -o /dev/null', :acceptable_exit_codes => [0]) do |r|
expect(r.stdout).to match(/^200/)
end
end
elsif os[:family] == 'RedHat'
describe command('curl --connect-timeout 5 -sL -w "%{http_code} %{url_effective}\n" http://localhost/dashboard/ -o /dev/null') do
it { is_expected.to return_exit_status 0 }
it 'executes curl and returns 200' do
shell('curl --connect-timeout 5 -sL -w "%{http_code} %{url_effective}\n" http://localhost/dashboard -o /dev/null', :acceptable_exit_codes => [0]) do |r|
expect(r.stdout).to match(/^200/)
end
end
end
end
context 'parameters with modified root' do
it 'should work with no errors' do
pp= <<-EOS
include ::openstack_integration
include ::openstack_integration::repos
class { '::horizon':
secret_key => 'big_secret',
# need to disable offline compression due to
# https://bugs.launchpad.net/ubuntu/+source/horizon/+bug/1424042
compress_offline => false,
allowed_hosts => [$::fqdn, 'localhost'],
server_aliases => [$::fqdn, 'localhost'],
root_url => '',
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
# basic test for now, to make sure Apache serve /horizon dashboard
it 'executes curl and returns 200' do
shell('curl --connect-timeout 5 -sL -w "%{http_code} %{url_effective}\n" http://localhost -o /dev/null', :acceptable_exit_codes => [0]) do |r|
expect(r.stdout).to match(/^200/)
end
end
end
end

View File

@ -56,7 +56,7 @@ describe 'horizon' do
'DEBUG = False',
"LOGIN_URL = '#{platforms_params[:root_url]}/auth/login/'",
"LOGOUT_URL = '#{platforms_params[:root_url]}/auth/logout/'",
"LOGIN_REDIRECT_URL = '#{platforms_params[:root_url]}'",
"LOGIN_REDIRECT_URL = '#{platforms_params[:root_url]}/'",
"ALLOWED_HOSTS = ['*', ]",
" 'identity': 3,",
"SECRET_KEY = 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0'",

View File

@ -122,7 +122,7 @@ describe 'horizon::wsgi::apache' do
'redirectmatch_dest' => platforms_params[:root_url],
'wsgi_process_group' => 'horizon-ssl',
'wsgi_daemon_process' => 'horizon-ssl',
'wsgi_script_aliases' => { platforms_params[:root_url] => '/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi' }
'wsgi_script_aliases' => { platforms_params[:root_url] => '/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi' },
)}
it { is_expected.to contain_apache__vhost('horizon_vhost').with(
@ -139,7 +139,7 @@ describe 'horizon::wsgi::apache' do
'redirectmatch_dest' => 'https://some.host.tld',
'wsgi_process_group' => platforms_params[:wsgi_group],
'wsgi_daemon_process' => platforms_params[:wsgi_group],
'wsgi_script_aliases' => { platforms_params[:root_url] => '/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi' }
'wsgi_script_aliases' => { platforms_params[:root_url] => '/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi' },
)}
end

View File

@ -13,18 +13,17 @@ TEMPLATE_DEBUG = DEBUG
# WEBROOT is the location relative to Webserver root
# should end with a slash.
#WEBROOT = '/'
#LOGIN_URL = WEBROOT + 'auth/login/'
#LOGOUT_URL = WEBROOT + 'auth/logout/'
WEBROOT = '<%= scope.lookupvar("horizon::params::root_url") %>/'
LOGIN_URL = '<%= scope.lookupvar("horizon::params::root_url") %>/auth/login/'
LOGOUT_URL = '<%= scope.lookupvar("horizon::params::root_url") %>/auth/logout/'
WEBROOT = '<%= @root_url %>/'
LOGIN_URL = '<%= @root_url %>/auth/login/'
LOGOUT_URL = '<%= @root_url %>/auth/logout/'
# 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
LOGIN_REDIRECT_URL = '<%= scope.lookupvar("horizon::params::root_url") %>'
LOGIN_REDIRECT_URL = '<%= @root_url %>/'
# Required for Django 1.5.
# If horizon is running in production (DEBUG is False), set this