diff --git a/manifests/init.pp b/manifests/init.pp index da543e2f..ed8d2864 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -238,6 +238,10 @@ # (optional) The base URL used to contruct horizon web addresses. # Defaults to '/dashboard' or '/horizon' depending OS # +# [*root_path*] +# (optional) The path to the location of static assets. +# Defaults to "${::horizon::params::static_path}/openstack-dashboard" +# # [*session_timeout*] # (optional) The session timeout for horizon in seconds. After this many seconds of inactivity # the user is logged out. @@ -442,6 +446,7 @@ class horizon( $image_backend = {}, $overview_days_range = undef, $root_url = $::horizon::params::root_url, + $root_path = "${::horizon::params::static_path}/openstack-dashboard", $session_timeout = 1800, $timezone = 'UTC', $secure_cookies = false, @@ -539,6 +544,7 @@ settings_local.py and parameter server_aliases for setting ServerAlias directive validate_hash($api_versions) validate_re($password_autocomplete, ['^on$', '^off$']) validate_re($images_panel, ['^legacy$', '^angular$']) + validate_absolute_path($root_path) if $cache_backend =~ /MemcachedCache/ { ensure_resources('package', { 'python-memcache' => @@ -596,7 +602,8 @@ settings_local.py and parameter server_aliases for setting ServerAlias directive horizon_ca => $horizon_ca, extra_params => $vhost_extra_params, redirect_type => $redirect_type, - root_url => $root_url + root_url => $root_url, + root_path => $root_path, } } diff --git a/manifests/wsgi/apache.pp b/manifests/wsgi/apache.pp index 7f2eb747..723b942b 100644 --- a/manifests/wsgi/apache.pp +++ b/manifests/wsgi/apache.pp @@ -79,6 +79,10 @@ # (optional) The base URL used to contruct horizon web addresses. # Defaults to '/dashboard' or '/horizon' depending OS # +# [*root_path*] +# (optional) The path to the location of static assets. +# Defaults to "${::horizon::params::static_path}/openstack-dashboard" +# class horizon::wsgi::apache ( $bind_address = undef, $fqdn = undef, @@ -99,6 +103,7 @@ class horizon::wsgi::apache ( $extra_params = {}, $redirect_type = 'permanent', $root_url = $::horizon::params::root_url, + $root_path = "${::horizon::params::static_path}/openstack-dashboard", ) inherits horizon::params { include ::apache @@ -206,7 +211,7 @@ class horizon::wsgi::apache ( priority => $priority, aliases => [{ alias => "${root_url}/static", - path => "${::horizon::params::static_path}/openstack-dashboard/static", + path => "${root_path}/static", }], port => $http_port, ssl_cert => $horizon_cert, diff --git a/releasenotes/notes/root_path-4dbbddfa82bc6b56.yaml b/releasenotes/notes/root_path-4dbbddfa82bc6b56.yaml new file mode 100644 index 00000000..bd50f52a --- /dev/null +++ b/releasenotes/notes/root_path-4dbbddfa82bc6b56.yaml @@ -0,0 +1,3 @@ +--- +features: + - Allows to specify a custom root_path to static assets. diff --git a/spec/classes/horizon_init_spec.rb b/spec/classes/horizon_init_spec.rb index b0f65c09..52db0f6a 100644 --- a/spec/classes/horizon_init_spec.rb +++ b/spec/classes/horizon_init_spec.rb @@ -285,6 +285,28 @@ describe 'horizon' do end end + context 'with default root_path' do + it 'configures apache' do + is_expected.to contain_class('horizon::wsgi::apache').with({ + :root_path => "#{platforms_params[:root_path]}", + }) + end + end + + context 'with root_path set to /tmp/horizon' do + before do + params.merge!({ + :root_path => '/tmp/horizon', + }) + end + + it 'configures apache' do + is_expected.to contain_class('horizon::wsgi::apache').with({ + :root_path => '/tmp/horizon', + }) + end + end + context 'without apache' do before do params.merge!({ :configure_apache => false }) @@ -538,11 +560,15 @@ describe 'horizon' do when 'Debian' { :config_file => '/etc/openstack-dashboard/local_settings.py', :package_name => 'openstack-dashboard', - :root_url => '/horizon' } + :root_url => '/horizon', + :root_path => '/var/lib/openstack-dashboard', + } when 'RedHat' { :config_file => '/etc/openstack-dashboard/local_settings', :package_name => 'openstack-dashboard', - :root_url => '/dashboard' } + :root_url => '/dashboard', + :root_path => '/usr/share/openstack-dashboard', + } end end diff --git a/spec/classes/horizon_wsgi_apache_spec.rb b/spec/classes/horizon_wsgi_apache_spec.rb index 64700a13..6afc4ef1 100644 --- a/spec/classes/horizon_wsgi_apache_spec.rb +++ b/spec/classes/horizon_wsgi_apache_spec.rb @@ -232,6 +232,26 @@ describe 'horizon::wsgi::apache' do ) end end + + context 'with root_path set to /tmp/horizon' do + before do + params.merge!({ + :root_path => '/tmp/horizon', + }) + end + + 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' => '/tmp/horizon/static'}], + ) + else + is_expected.to contain_apache__vhost('horizon_vhost').with( + 'aliases' => [['alias', '/dashboard/static'], ['path', '/tmp/horizon/static']], + ) + end + end + end end shared_examples_for 'apache for horizon on Debian platforms' do @@ -246,6 +266,26 @@ describe 'horizon::wsgi::apache' do ) end end + + context 'with root_path set to /tmp/horizon' do + before do + params.merge!({ + :root_path => '/tmp/horizon', + }) + end + + 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' => '/tmp/horizon/static'}], + ) + else + is_expected.to contain_apache__vhost('horizon_vhost').with( + 'aliases' => [['alias', '/horizon/static'], ['path', '/tmp/horizon/static']], + ) + end + end + end end