Browse Source

Make redirect type configurable

This change exposes a redirect type configuration variable so that a
user can specify if they want to use 'temp' or 'permanent' redirects.

This change allows a user to switch to use a 'temp' redirect type
because Mozilla Firefox and Google Chrome cache the responses of '301
Moved Permanently'. Some users have multi tenant environments that have
different URLs for Horizon dashboards (Ubuntu - /horizon, CentOS -
dashboard). '302 Found' is not cacheable response which solves the issue
for multitenant users.

Change-Id: I81694d0ddeebafec7824f5b275d5fb504cd302b1
Closes-Bug: 1385133
Co-Authored-By: Alex Schultz <aschultz@mirantis.com>
tags/7.0.0
Sergii Golovatiuk 4 years ago
parent
commit
8de1b6100b

+ 12
- 0
manifests/init.pp View File

@@ -213,6 +213,16 @@
213 213
 #    (optional) The directory location for the theme (e.g., "static/themes/blue")
214 214
 #    Default to undefined
215 215
 #
216
+#  [*redirect_type*]
217
+#    (optional) What type of redirect to use when redirecting an http request
218
+#    for a user. This should be either 'temp' or 'permanent'. Setting this value
219
+#    to 'permanent' will result in the use of a 301 redirect which may be cached
220
+#    by a user's browser.  Setting this value to 'temp' will result in the use
221
+#    of a 302 redirect which is not cached by browsers and may solve issues if
222
+#    users report errors accessing horizon. Only used if configure_apache is
223
+#    set to true.
224
+#    Defaults to 'permanent'
225
+#
216 226
 # === Examples
217 227
 #
218 228
 #  class { 'horizon':
@@ -266,6 +276,7 @@ class horizon(
266 276
   $tuskar_ui_undercloud_admin_password = undef,
267 277
   $tuskar_ui_deployment_mode           = 'scale',
268 278
   $custom_theme_path                   = undef,
279
+  $redirect_type                       = 'permanent',
269 280
   # DEPRECATED PARAMETERS
270 281
   $can_set_mount_point                 = undef,
271 282
   $vhost_extra_params                  = undef,
@@ -354,6 +365,7 @@ class horizon(
354 365
       horizon_key    => $horizon_key,
355 366
       horizon_ca     => $horizon_ca,
356 367
       extra_params   => $vhost_extra_params,
368
+      redirect_type  => $redirect_type,
357 369
     }
358 370
   }
359 371
 

+ 16
- 1
manifests/wsgi/apache.pp View File

@@ -59,6 +59,16 @@
59 59
 # [*extra_params*]
60 60
 #   (optional) A hash of extra paramaters for apache::wsgi class.
61 61
 #   Defaults to {}
62
+#
63
+# [*redirect_type*]
64
+#   (optional) What type of redirect to use when redirecting an http request
65
+#   for a user. This should be either 'temp' or 'permanent'. Setting this value
66
+#   to 'permanent' will result in the use of a 301 redirect which may be cached
67
+#   by a user's browser.  Setting this value to 'temp' will result in the use
68
+#   of a 302 redirect which is not cached by browsers and may solve issues if
69
+#   users report errors accessing horizon.
70
+#   Defaults to 'permanent'
71
+#
62 72
 class horizon::wsgi::apache (
63 73
   $bind_address        = undef,
64 74
   $fqdn                = undef,
@@ -75,6 +85,7 @@ class horizon::wsgi::apache (
75 85
   $vhost_conf_name     = 'horizon_vhost',
76 86
   $vhost_ssl_conf_name = 'horizon_ssl_vhost',
77 87
   $extra_params        = {},
88
+  $redirect_type       = 'permanent',
78 89
 ) {
79 90
 
80 91
   include ::horizon::params
@@ -132,6 +143,10 @@ class horizon::wsgi::apache (
132 143
     $redirect_url   = $::horizon::params::root_url
133 144
   }
134 145
 
146
+  if !($redirect_type in ['temp', 'permanent']) {
147
+    fail("Invalid redirect type '${redirect_type} provided.")
148
+  }
149
+
135 150
   Package['horizon'] -> Package[$::horizon::params::http_service]
136 151
   File[$::horizon::params::config_file] ~> Service[$::horizon::params::http_service]
137 152
 
@@ -187,7 +202,7 @@ class horizon::wsgi::apache (
187 202
     },
188 203
     wsgi_import_script   => $::horizon::params::django_wsgi,
189 204
     wsgi_process_group   => $::horizon::params::wsgi_group,
190
-    redirectmatch_status => 'permanent',
205
+    redirectmatch_status => $redirect_type,
191 206
   }
192 207
 
193 208
   # Only add the 'ip' element to the $default_vhost_conf hash if it was explicitly

+ 9
- 6
spec/classes/horizon_init_spec.rb View File

@@ -39,10 +39,11 @@ describe 'horizon' do
39 39
 
40 40
       it 'configures apache' do
41 41
         is_expected.to contain_class('horizon::wsgi::apache').with({
42
-          :servername   => 'some.host.tld',
43
-          :listen_ssl   => false,
44
-          :servername   => 'some.host.tld',
45
-          :extra_params => {},
42
+          :servername    => 'some.host.tld',
43
+          :listen_ssl    => false,
44
+          :servername    => 'some.host.tld',
45
+          :extra_params  => {},
46
+          :redirect_type => 'permanent',
46 47
         })
47 48
       end
48 49
 
@@ -193,13 +194,15 @@ describe 'horizon' do
193 194
     context 'with vhost_extra_params' do
194 195
       before do
195 196
         params.merge!({
196
-          :vhost_extra_params   => { 'add_listen' => false },
197
+          :vhost_extra_params => { 'add_listen' => false },
198
+          :redirect_type      => 'temp',
197 199
         })
198 200
       end
199 201
 
200 202
       it 'configures apache' do
201 203
         is_expected.to contain_class('horizon::wsgi::apache').with({
202
-          :extra_params => { 'add_listen' => false },
204
+          :extra_params  => { 'add_listen' => false },
205
+          :redirect_type => 'temp',
203 206
         })
204 207
       end
205 208
     end

+ 3
- 2
spec/classes/horizon_wsgi_apache_spec.rb View File

@@ -57,7 +57,8 @@ describe 'horizon::wsgi::apache' do
57 57
     context 'with overriden parameters' do
58 58
       before do
59 59
         params.merge!({
60
-          :priority => '10',
60
+          :priority      => '10',
61
+          :redirect_type => 'temp',
61 62
         })
62 63
       end
63 64
 
@@ -76,7 +77,7 @@ describe 'horizon::wsgi::apache' do
76 77
           'serveraliases'        => ['*'],
77 78
           'docroot'              => '/var/www/',
78 79
           'ssl'                  => 'false',
79
-          'redirectmatch_status' => 'permanent',
80
+          'redirectmatch_status' => 'temp',
80 81
           'redirectmatch_regexp' => '^/$',
81 82
           'redirectmatch_dest'   => platforms_params[:root_url],
82 83
           'wsgi_script_aliases'  => { platforms_params[:root_url] => '/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi' },

Loading…
Cancel
Save