Include ServerAlias in dashboard vhost if set

There are use cases where having ServerAlias in the vhost is preferred. This
includes that option but excludes by default. It's set using an array so you can
set multiple server aliases.

I also added the virtualhost port configurator test for dashboard-http-bind on
port 80 to ensure it works on both ports.

Change-Id: I621cb2a519e92d04d60fd75e727b59250bd72e30
This commit is contained in:
Lance Albertson 2016-08-13 11:45:42 -07:00
parent 796945e658
commit 5fad88d1c0
3 changed files with 23 additions and 0 deletions

View File

@ -51,6 +51,7 @@ default['openstack']['dashboard']['keystone_default_role'] = '_member_'
default['openstack']['dashboard']['keystone_service_chef_role'] = 'keystone'
default['openstack']['dashboard']['server_hostname'] = nil
default['openstack']['dashboard']['server_aliases'] = []
default['openstack']['dashboard']['use_ssl'] = true
# When using a remote certificate and key, the names of the actual installed certificate
# and key in the file system are determined by the following two attributes.

View File

@ -31,6 +31,20 @@ shared_examples 'virtualhost port configurator' do |port_attribute_name, port_at
expect(chef_run).not_to render_file(file.name).with_content(/^#{virtualhost_directive}\s*ServerName$/)
end
end
context 'server_aliases' do
it 'sets the value if the server_aliases is present' do
node.set['openstack']['dashboard']['server_aliases'] = %w(server_aliases_value)
expect(chef_run).to render_file(file.name).with_content(/^#{virtualhost_directive}\s*ServerAlias server_aliases_value$/)
end
it 'sets the value if multiple server_aliases is present' do
node.set['openstack']['dashboard']['server_aliases'] = %w(server_aliases_value1 server_aliases_value2)
expect(chef_run).to render_file(file.name).with_content(/^#{virtualhost_directive}\s*ServerAlias server_aliases_value1 server_aliases_value2$/)
end
it 'does not set the value if the server_aliases is not present' do
node.set['openstack']['dashboard']['server_hostname'] = []
expect(chef_run).not_to render_file(file.name).with_content(/^#{virtualhost_directive}\s*ServerAlias$/)
end
end
end
describe 'openstack-dashboard::apache2-server' do
@ -262,6 +276,8 @@ describe 'openstack-dashboard::apache2-server' do
end
end
it_should_behave_like 'virtualhost port configurator', 'dashboard-http-bind', 80
context 'with use_ssl enabled' do
before do
node.set['openstack']['dashboard']['use_ssl'] = true

View File

@ -8,6 +8,9 @@ NameVirtualHost <%= @http_bind_address %>:<%= @http_bind_port %>
<% if node["openstack"]["dashboard"]["server_hostname"] -%>
ServerName <%= node["openstack"]["dashboard"]["server_hostname"] %>
<% end -%>
<% unless node["openstack"]["dashboard"]["server_aliases"].empty? -%>
ServerAlias <%= node["openstack"]["dashboard"]["server_aliases"].join(" ") %>
<% end -%>
<% if node["openstack"]["dashboard"]["use_ssl"] %>
RewriteEngine On
RewriteCond %{HTTPS} off
@ -27,6 +30,9 @@ NameVirtualHost <%= @https_bind_address %>:<%= @https_bind_port %>
<% if node["openstack"]["dashboard"]["server_hostname"] -%>
ServerName <%= node["openstack"]["dashboard"]["server_hostname"] %>
<% end -%>
<% unless node["openstack"]["dashboard"]["server_aliases"].empty? -%>
ServerAlias <%= node["openstack"]["dashboard"]["server_aliases"].join(" ") %>
<% end -%>
<% end %>
ServerAdmin <%= node["apache"]["contact"] %>
WSGIScriptAlias <%= node["openstack"]["dashboard"]["webroot"] %> <%= node["openstack"]["dashboard"]["wsgi_path"] %>