]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/horizon/spec/classes/horizon_wsgi_apache_spec.rb
try again, with puppetforge modules, correctly included now
[dsa-puppet.git] / 3rdparty / modules / horizon / spec / classes / horizon_wsgi_apache_spec.rb
1 require 'spec_helper'
2
3 describe 'horizon::wsgi::apache' do
4
5   let :params do
6     { :fqdn           => '*',
7       :servername     => 'some.host.tld',
8       :wsgi_processes => '3',
9       :wsgi_threads   => '10',
10     }
11   end
12
13   let :pre_condition do
14     "include apache\n" +
15     "class { 'horizon': secret_key => 's3cr3t', configure_apache => false }"
16   end
17
18   let :fixtures_path do
19     File.expand_path(File.join(__FILE__, '..', '..', 'fixtures'))
20   end
21
22   let :facts do
23     { :concat_basedir => '/var/lib/puppet/concat',
24       :fqdn           => 'some.host.tld'
25     }
26   end
27
28   shared_examples 'apache for horizon' do
29
30     context 'with default parameters' do
31       it 'configures apache' do
32         should contain_class('horizon::params')
33         should contain_class('apache')
34         should contain_class('apache::mod::wsgi')
35         should contain_service('httpd').with_name(platforms_params[:http_service])
36         should contain_file(platforms_params[:httpd_config_file])
37         should contain_package('horizon').with_ensure('present')
38         should contain_apache__vhost('horizon_vhost').with(
39           'servername'           => 'some.host.tld',
40           'access_log_file'      => 'horizon_access.log',
41           'error_log_file'       => 'horizon_error.log',
42           'priority'             => '15',
43           'serveraliases'        => '*',
44           'docroot'              => '/var/www/',
45           'ssl'                  => 'false',
46           'redirectmatch_status' => 'permanent',
47           'redirectmatch_regexp' => '^/$',
48           'redirectmatch_dest'   => platforms_params[:root_url],
49           'wsgi_script_aliases'  => { platforms_params[:root_url] => '/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi' },
50           'wsgi_process_group'   => platforms_params[:wsgi_group],
51           'wsgi_daemon_process'  => platforms_params[:wsgi_group],
52           'wsgi_daemon_process_options' => { 'processes' => params[:wsgi_processes], 'threads' => params[:wsgi_threads], 'user' => platforms_params[:unix_user], 'group' => platforms_params[:unix_group] }
53          )
54       end
55     end
56
57     context 'with overriden parameters' do
58       before do
59         params.merge!({
60           :priority => '10',
61         })
62       end
63
64       it 'configures apache' do
65         should contain_class('horizon::params')
66         should contain_class('apache')
67         should contain_class('apache::mod::wsgi')
68         should contain_service('httpd').with_name(platforms_params[:http_service])
69         should contain_file(platforms_params[:httpd_config_file])
70         should contain_package('horizon').with_ensure('present')
71         should contain_apache__vhost('horizon_vhost').with(
72           'servername'           => 'some.host.tld',
73           'access_log_file'      => 'horizon_access.log',
74           'error_log_file'       => 'horizon_error.log',
75           'priority'             => params[:priority],
76           'serveraliases'        => '*',
77           'docroot'              => '/var/www/',
78           'ssl'                  => 'false',
79           'redirectmatch_status' => 'permanent',
80           'redirectmatch_regexp' => '^/$',
81           'redirectmatch_dest'   => platforms_params[:root_url],
82           'wsgi_script_aliases'  => { platforms_params[:root_url] => '/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi' },
83           'wsgi_process_group'   => platforms_params[:wsgi_group],
84           'wsgi_daemon_process'  => platforms_params[:wsgi_group],
85           'wsgi_daemon_process_options' => { 'processes' => params[:wsgi_processes], 'threads' => params[:wsgi_threads], 'user' => platforms_params[:unix_user], 'group' => platforms_params[:unix_group] }
86          )
87       end
88     end
89
90     context 'with ssl enabled' do
91       before do
92         params.merge!({
93           :listen_ssl   => true,
94           :ssl_redirect => true,
95           :horizon_cert => '/etc/pki/tls/certs/httpd.crt',
96           :horizon_key  => '/etc/pki/tls/private/httpd.key',
97           :horizon_ca   => '/etc/pki/tls/certs/ca.crt',
98         })
99       end
100
101       context 'with required parameters' do
102         it 'configures apache for SSL' do
103           should contain_class('apache::mod::ssl')
104         end
105         it { should contain_apache__vhost('horizon_ssl_vhost').with(
106           'servername'             => 'some.host.tld',
107           'access_log_file'        => 'horizon_ssl_access.log',
108           'error_log_file'         => 'horizon_ssl_error.log',
109           'priority'               => '15',
110           'serveraliases'          => '*',
111           'docroot'                => '/var/www/',
112           'ssl'                    => 'true',
113           'ssl_cert'               => '/etc/pki/tls/certs/httpd.crt',
114           'ssl_key'                => '/etc/pki/tls/private/httpd.key',
115           'ssl_ca'                 => '/etc/pki/tls/certs/ca.crt',
116           'redirectmatch_status'   => 'permanent',
117           'redirectmatch_regexp'   => '^/$',
118           'redirectmatch_dest'     => platforms_params[:root_url],
119           'wsgi_process_group'     => 'horizon-ssl',
120           'wsgi_daemon_process'    => 'horizon-ssl',
121           'wsgi_script_aliases'    => { platforms_params[:root_url] => '/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi' }
122         )}
123
124         it { should contain_apache__vhost('horizon_vhost').with(
125           'servername'           => 'some.host.tld',
126           'access_log_file'      => 'horizon_access.log',
127           'error_log_file'       => 'horizon_error.log',
128           'priority'             => '15',
129           'serveraliases'        => '*',
130           'docroot'              => '/var/www/',
131           'ssl'                  => 'false',
132           'redirectmatch_status' => 'permanent',
133           'redirectmatch_regexp' => '(.*)',
134           'redirectmatch_dest'   => 'https://some.host.tld',
135           'wsgi_process_group'   => platforms_params[:wsgi_group],
136           'wsgi_daemon_process'  => platforms_params[:wsgi_group],
137           'wsgi_script_aliases'  => { platforms_params[:root_url] => '/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi' }
138         )}
139       end
140
141       context 'without required parameters' do
142
143         context 'without horizon_ca parameter' do
144           before { params.delete(:horizon_ca) }
145           it_raises 'a Puppet::Error', /The horizon_ca parameter is required when listen_ssl is true/
146         end
147
148         context 'without horizon_cert parameter' do
149           before { params.delete(:horizon_cert) }
150           it_raises 'a Puppet::Error', /The horizon_cert parameter is required when listen_ssl is true/
151         end
152
153         context 'without horizon_key parameter' do
154           before { params.delete(:horizon_key) }
155           it_raises 'a Puppet::Error', /The horizon_key parameter is required when listen_ssl is true/
156         end
157       end
158
159       context 'with extra parameters' do
160         before do
161           params.merge!({
162             :extra_params  => {
163               'add_listen' => false,
164               'docroot' => '/tmp'
165             },
166           })
167         end
168
169         it 'configures apache' do
170           should contain_apache__vhost('horizon_vhost').with(
171             'add_listen' => false,
172             'docroot'    => '/tmp'
173           )
174         end
175
176       end
177
178
179     end
180   end
181
182   context 'on RedHat platforms' do
183     before do
184       facts.merge!({
185         :osfamily               => 'RedHat',
186         :operatingsystemrelease => '6.0'
187       })
188     end
189
190     let :platforms_params do
191       { :http_service      => 'httpd',
192         :httpd_config_file => '/etc/httpd/conf.d/openstack-dashboard.conf',
193         :root_url          => '/dashboard',
194         :apache_user       => 'apache',
195         :apache_group      => 'apache',
196         :wsgi_user         => 'dashboard',
197         :wsgi_group        => 'dashboard',
198         :unix_user         => 'apache',
199         :unix_group        => 'apache' }
200     end
201
202     it_behaves_like 'apache for horizon'
203     it {
204       should contain_class('apache::mod::wsgi').with(:wsgi_socket_prefix => '/var/run/wsgi')
205     }
206   end
207
208   context 'on Debian platforms' do
209     before do
210       facts.merge!({
211         :osfamily               => 'Debian',
212         :operatingsystemrelease => '6.0'
213       })
214     end
215
216     let :platforms_params do
217       { :http_service      => 'apache2',
218         :httpd_config_file => '/etc/apache2/conf-available/openstack-dashboard.conf',
219         :root_url          => '/horizon',
220         :apache_user       => 'www-data',
221         :apache_group      => 'www-data',
222         :wsgi_user         => 'horizon',
223         :wsgi_group        => 'horizon',
224         :unix_user         => 'horizon',
225         :unix_group        => 'horizon' }
226     end
227
228     it_behaves_like 'apache for horizon'
229   end
230 end