93d08a5afe81c0d7c60a4f28fc2db1cccb491c2b
[mirror/dsa-puppet.git] / 3rdparty / modules / horizon / spec / classes / horizon_init_spec.rb
1 require 'spec_helper'
2
3 describe 'horizon' do
4
5   let :params do
6     { 'secret_key' => 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0',
7       'fqdn'       => '*' }
8   end
9
10   let :pre_condition do
11     'include apache'
12   end
13
14   let :fixtures_path do
15     File.expand_path(File.join(__FILE__, '..', '..', 'fixtures'))
16   end
17
18   let :facts do
19     { :concat_basedir => '/var/lib/puppet/concat',
20       :fqdn           => 'some.host.tld'
21     }
22   end
23
24   shared_examples 'horizon' do
25
26     context 'with default parameters' do
27       it {
28           should contain_package('python-lesscpy').with_ensure('present')
29           should contain_package('horizon').with_ensure('present')
30       }
31       it { should contain_exec('refresh_horizon_django_cache').with({
32           :command     => '/usr/share/openstack-dashboard/manage.py compress',
33           :refreshonly => true,
34       })}
35       it { should contain_file(platforms_params[:config_file]).that_notifies('Exec[refresh_horizon_django_cache]') }
36
37       it 'configures apache' do
38         should contain_class('horizon::wsgi::apache').with({
39           :servername   => 'some.host.tld',
40           :listen_ssl   => false,
41           :servername   => 'some.host.tld',
42           :extra_params => {},
43         })
44       end
45
46       it 'generates local_settings.py' do
47         verify_contents(subject, platforms_params[:config_file], [
48           'DEBUG = False',
49           "ALLOWED_HOSTS = ['*', ]",
50           "SECRET_KEY = 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0'",
51           'OPENSTACK_KEYSTONE_URL = "http://127.0.0.1:5000/v2.0"',
52           'OPENSTACK_KEYSTONE_DEFAULT_ROLE = "_member_"',
53           "    'can_set_mount_point': True,",
54           "    'can_set_password': False,",
55           "    'enable_lb': False,",
56           "    'enable_firewall': False,",
57           "    'enable_quotas': True,",
58           "    'enable_security_group': True,",
59           "    'enable_vpn': False,",
60           'API_RESULT_LIMIT = 1000',
61           "LOGIN_URL = '#{platforms_params[:root_url]}/auth/login/'",
62           "LOGOUT_URL = '#{platforms_params[:root_url]}/auth/logout/'",
63           "LOGIN_REDIRECT_URL = '#{platforms_params[:root_url]}'",
64           'COMPRESS_OFFLINE = True',
65           "FILE_UPLOAD_TEMP_DIR = '/tmp'"
66         ])
67
68         # From internals of verify_contents, get the contents to check for absence of a line
69         content = subject.resource('file', platforms_params[:config_file]).send(:parameters)[:content]
70
71         # With default options, should _not_ have a line to configure SESSION_ENGINE
72         content.should_not match(/^SESSION_ENGINE/)
73       end
74
75       it { should_not contain_file(params[:file_upload_temp_dir]) }
76     end
77
78     context 'with overridden parameters' do
79       before do
80         params.merge!({
81           :cache_server_ip         => '10.0.0.1',
82           :django_session_engine   => 'django.contrib.sessions.backends.cache',
83           :keystone_default_role   => 'SwiftOperator',
84           :keystone_url            => 'https://keystone.example.com:4682',
85           :openstack_endpoint_type => 'internalURL',
86           :secondary_endpoint_type => 'ANY-VALUE',
87           :django_debug            => true,
88           :api_result_limit        => 4682,
89           :compress_offline        => false,
90           :hypervisor_options      => {'can_set_mount_point' => false, 'can_set_password' => true },
91           :cinder_options          => {'enable_backup' => true },
92           :neutron_options         => {'enable_lb' => true, 'enable_firewall' => true, 'enable_quotas' => false, 'enable_security_group' => false, 'enable_vpn' => true, 'profile_support' => 'cisco' },
93           :file_upload_temp_dir    => '/var/spool/horizon',
94           :secure_cookies          => true
95         })
96       end
97
98       it 'generates local_settings.py' do
99         verify_contents(subject, platforms_params[:config_file], [
100           'DEBUG = True',
101           "ALLOWED_HOSTS = ['*', ]",
102           'CSRF_COOKIE_SECURE = True',
103           'SESSION_COOKIE_SECURE = True',
104           "SECRET_KEY = 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0'",
105           "        'LOCATION': '10.0.0.1:11211',",
106           'SESSION_ENGINE = "django.contrib.sessions.backends.cache"',
107           'OPENSTACK_KEYSTONE_URL = "https://keystone.example.com:4682"',
108           'OPENSTACK_KEYSTONE_DEFAULT_ROLE = "SwiftOperator"',
109           "    'can_set_mount_point': False,",
110           "    'can_set_password': True,",
111           "    'enable_backup': True,",
112           "    'enable_lb': True,",
113           "    'enable_firewall': True,",
114           "    'enable_quotas': False,",
115           "    'enable_security_group': False,",
116           "    'enable_vpn': True,",
117           "    'profile_support': 'cisco',",
118           'OPENSTACK_ENDPOINT_TYPE = "internalURL"',
119           'SECONDARY_ENDPOINT_TYPE = "ANY-VALUE"',
120           'API_RESULT_LIMIT = 4682',
121           'COMPRESS_OFFLINE = False',
122           "FILE_UPLOAD_TEMP_DIR = '/var/spool/horizon'"
123         ])
124       end
125
126       it { should_not contain_file(platforms_params[:config_file]).that_notifies('Exec[refresh_horizon_django_cache]') }
127
128       it { should contain_file(params[:file_upload_temp_dir]) }
129     end
130
131     context 'with overridden parameters and cache_server_ip array' do
132       before do
133         params.merge!({
134           :cache_server_ip => ['10.0.0.1','10.0.0.2'],
135         })
136       end
137
138       it 'generates local_settings.py' do
139         verify_contents(subject, platforms_params[:config_file], [
140           "        'LOCATION': [ '10.0.0.1:11211','10.0.0.2:11211', ],",
141         ])
142       end
143
144       it { should contain_exec('refresh_horizon_django_cache') }
145     end
146
147     context 'with deprecated parameters' do
148       before do
149         params.merge!({
150           :keystone_host       => 'keystone.example.com',
151           :keystone_port       => 4682,
152           :keystone_scheme     => 'https',
153           :can_set_mount_point => true,
154         })
155       end
156
157       it 'generates local_settings.py' do
158         verify_contents(subject, platforms_params[:config_file], [
159           'OPENSTACK_KEYSTONE_URL = "https://keystone.example.com:4682/v2.0"',
160           "    'can_set_mount_point': True,"
161         ])
162       end
163     end
164
165     context 'with vhost_extra_params' do
166       before do
167         params.merge!({
168           :vhost_extra_params   => { 'add_listen' => false },
169         })
170       end
171
172       it 'configures apache' do
173         should contain_class('horizon::wsgi::apache').with({
174           :extra_params => { 'add_listen' => false },
175         })
176       end
177     end
178
179
180     context 'with ssl enabled' do
181       before do
182         params.merge!({
183           :listen_ssl   => true,
184           :servername   => 'some.host.tld',
185           :horizon_cert => '/etc/pki/tls/certs/httpd.crt',
186           :horizon_key  => '/etc/pki/tls/private/httpd.key',
187           :horizon_ca   => '/etc/pki/tls/certs/ca.crt',
188         })
189       end
190
191       it 'configures apache' do
192         should contain_class('horizon::wsgi::apache').with({
193           :bind_address => nil,
194           :listen_ssl   => true,
195           :horizon_cert => '/etc/pki/tls/certs/httpd.crt',
196           :horizon_key  => '/etc/pki/tls/private/httpd.key',
197           :horizon_ca   => '/etc/pki/tls/certs/ca.crt',
198         })
199       end
200     end
201
202     context 'without apache' do
203       before do
204         params.merge!({ :configure_apache => false })
205       end
206
207       it 'does not configure apache' do
208         should_not contain_class('horizon::wsgi::apache')
209       end
210     end
211
212     context 'with available_regions parameter' do
213       before do
214         params.merge!({
215           :available_regions => [
216             ['http://region-1.example.com:5000/v2.0', 'Region-1'],
217             ['http://region-2.example.com:5000/v2.0', 'Region-2']
218           ]
219         })
220       end
221
222       it 'AVAILABLE_REGIONS is configured' do
223         verify_contents(subject, platforms_params[:config_file], [
224           "AVAILABLE_REGIONS = [",
225           "    ('http://region-1.example.com:5000/v2.0', 'Region-1'),",
226           "    ('http://region-2.example.com:5000/v2.0', 'Region-2'),",
227           "]"
228         ])
229       end
230     end
231
232     context 'with policy parameters' do
233       before do
234         params.merge!({
235           :policy_files_path => '/opt/openstack-dashboard',
236           :policy_files      => {
237             'compute'  => 'nova_policy.json',
238             'identity' => 'keystone_policy.json',
239             'network'  => 'neutron_policy.json',
240           }
241         })
242       end
243
244       it 'POLICY_FILES_PATH and POLICY_FILES are configured' do
245         verify_contents(subject, platforms_params[:config_file], [
246           "POLICY_FILES_PATH = '/opt/openstack-dashboard'",
247           "POLICY_FILES = {",
248           "    'compute': 'nova_policy.json',",
249           "    'identity': 'keystone_policy.json',",
250           "    'network': 'neutron_policy.json',",
251           "} # POLICY_FILES"
252         ])
253       end
254     end
255
256     context 'with overriding local_settings_template' do
257       before do
258         params.merge!({
259           :django_debug            => 'True',
260           :help_url                => 'https://docs.openstack.org',
261           :local_settings_template => fixtures_path + '/override_local_settings.py.erb'
262         })
263       end
264
265       it 'uses the custom local_settings.py template' do
266         verify_contents(subject, platforms_params[:config_file], [
267           '# Custom local_settings.py',
268           'DEBUG = True',
269           "HORIZON_CONFIG = {",
270           "    'dashboards': ('project', 'admin', 'settings',),",
271           "    'default_dashboard': 'project',",
272           "    'user_home': 'openstack_dashboard.views.get_user_home',",
273           "    'ajax_queue_limit': 10,",
274           "    'auto_fade_alerts': {",
275           "        'delay': 3000,",
276           "        'fade_duration': 1500,",
277           "        'types': ['alert-success', 'alert-info']",
278           "    },",
279           "    'help_url': \"https://docs.openstack.org\",",
280           "    'exceptions': {'recoverable': exceptions.RECOVERABLE,",
281           "                   'not_found': exceptions.NOT_FOUND,",
282           "                   'unauthorized': exceptions.UNAUTHORIZED},",
283           "}",
284         ])
285       end
286     end
287
288     context 'with /var/tmp as upload temp dir' do
289       before do
290         params.merge!({
291           :file_upload_temp_dir => '/var/tmp'
292         })
293       end
294
295       it { should_not contain_file(params[:file_upload_temp_dir]) }
296     end
297   end
298
299   context 'on RedHat platforms' do
300     before do
301       facts.merge!({
302         :osfamily               => 'RedHat',
303         :operatingsystemrelease => '6.0'
304       })
305     end
306
307     let :platforms_params do
308       { :config_file       => '/etc/openstack-dashboard/local_settings',
309         :package_name      => 'openstack-dashboard',
310         :root_url          => '/dashboard' }
311     end
312
313     it_behaves_like 'horizon'
314   end
315
316   context 'on Debian platforms' do
317     before do
318       facts.merge!({
319         :osfamily               => 'Debian',
320         :operatingsystemrelease => '6.0'
321       })
322     end
323
324     let :platforms_params do
325       { :config_file       => '/etc/openstack-dashboard/local_settings.py',
326         :package_name      => 'openstack-dashboard-apache',
327         :root_url          => '/horizon' }
328     end
329
330     it_behaves_like 'horizon'
331   end
332 end