try again, with puppetforge modules, correctly included now
[mirror/dsa-puppet.git] / 3rdparty / modules / cinder / spec / classes / cinder_api_spec.rb
1 require 'spec_helper'
2
3 describe 'cinder::api' do
4
5   let :req_params do
6     {:keystone_password => 'foo'}
7   end
8   let :facts do
9     {:osfamily       => 'Debian',
10      :processorcount => 8 }
11   end
12
13   describe 'with only required params' do
14     let :params do
15       req_params
16     end
17
18     it { should contain_service('cinder-api').with(
19       'hasstatus' => true,
20       'ensure' => 'running'
21     )}
22
23     it 'should configure cinder api correctly' do
24       should contain_cinder_config('DEFAULT/auth_strategy').with(
25        :value => 'keystone'
26       )
27       should contain_cinder_config('DEFAULT/osapi_volume_listen').with(
28        :value => '0.0.0.0'
29       )
30       should contain_cinder_config('DEFAULT/osapi_volume_workers').with(
31        :value => '8'
32       )
33       should contain_cinder_config('DEFAULT/default_volume_type').with(
34        :ensure => 'absent'
35       )
36       should contain_cinder_api_paste_ini('filter:authtoken/service_protocol').with(
37         :value => 'http'
38       )
39       should contain_cinder_api_paste_ini('filter:authtoken/service_host').with(
40         :value => 'localhost'
41       )
42       should contain_cinder_api_paste_ini('filter:authtoken/service_port').with(
43         :value => '5000'
44       )
45       should contain_cinder_api_paste_ini('filter:authtoken/auth_protocol').with(
46         :value => 'http'
47       )
48       should contain_cinder_api_paste_ini('filter:authtoken/auth_host').with(
49         :value => 'localhost'
50       )
51       should contain_cinder_api_paste_ini('filter:authtoken/auth_port').with(
52         :value => '35357'
53       )
54       should contain_cinder_api_paste_ini('filter:authtoken/auth_admin_prefix').with(
55         :ensure => 'absent'
56       )
57       should contain_cinder_api_paste_ini('filter:authtoken/admin_tenant_name').with(
58         :value => 'services'
59       )
60       should contain_cinder_api_paste_ini('filter:authtoken/admin_user').with(
61         :value => 'cinder'
62       )
63       should contain_cinder_api_paste_ini('filter:authtoken/admin_password').with(
64         :value  => 'foo',
65         :secret => true
66       )
67
68       should contain_cinder_api_paste_ini('filter:authtoken/auth_uri').with(
69         :value => 'http://localhost:5000/'
70       )
71
72       should_not contain_cinder_config('DEFAULT/os_region_name')
73     end
74   end
75
76   describe 'with a custom region for nova' do
77     let :params do
78       req_params.merge({'os_region_name' => 'MyRegion'})
79     end
80     it 'should configure the region for nova' do
81       should contain_cinder_config('DEFAULT/os_region_name').with(
82         :value => 'MyRegion'
83       )
84     end
85   end
86
87   describe 'with a default volume type' do
88     let :params do
89       req_params.merge({'default_volume_type' => 'foo'})
90     end
91     it 'should configure the default volume type for cinder' do
92       should contain_cinder_config('DEFAULT/default_volume_type').with(
93         :value => 'foo'
94       )
95     end
96   end
97
98   describe 'with custom auth_uri' do
99     let :params do
100       req_params.merge({'keystone_auth_uri' => 'http://foo.bar:8080/v2.0/'})
101     end
102     it 'should configure cinder auth_uri correctly' do
103       should contain_cinder_api_paste_ini('filter:authtoken/auth_uri').with(
104         :value => 'http://foo.bar:8080/v2.0/'
105       )
106     end
107   end
108
109   describe 'with only required params' do
110     let :params do
111       req_params.merge({'bind_host' => '192.168.1.3'})
112     end
113     it 'should configure cinder api correctly' do
114       should contain_cinder_config('DEFAULT/osapi_volume_listen').with(
115        :value => '192.168.1.3'
116       )
117     end
118   end
119
120   [ '/keystone', '/keystone/admin', '' ].each do |keystone_auth_admin_prefix|
121     describe "with keystone_auth_admin_prefix containing incorrect value #{keystone_auth_admin_prefix}" do
122       let :params do
123         {
124           :keystone_auth_admin_prefix => keystone_auth_admin_prefix,
125           :keystone_password    => 'dummy'
126         }
127       end
128
129       it { should contain_cinder_api_paste_ini('filter:authtoken/auth_admin_prefix').with(
130         :value => keystone_auth_admin_prefix
131       )}
132     end
133   end
134
135   [
136     '/keystone/',
137     'keystone/',
138     'keystone',
139     '/keystone/admin/',
140     'keystone/admin/',
141     'keystone/admin'
142   ].each do |keystone_auth_admin_prefix|
143     describe "with keystone_auth_admin_prefix containing incorrect value #{keystone_auth_admin_prefix}" do
144       let :params do
145         {
146           :keystone_auth_admin_prefix => keystone_auth_admin_prefix,
147           :keystone_password    => 'dummy'
148         }
149       end
150
151       it { expect { should contain_cinder_api_paste_ini('filter:authtoken/auth_admin_prefix') }.to \
152         raise_error(Puppet::Error, /validate_re\(\): "#{keystone_auth_admin_prefix}" does not match/) }
153     end
154   end
155
156   describe 'with enabled false' do
157     let :params do
158       req_params.merge({'enabled' => false})
159     end
160     it 'should stop the service' do
161       should contain_service('cinder-api').with_ensure('stopped')
162     end
163     it 'should contain db_sync exec' do
164       should_not contain_exec('cinder-manage db_sync')
165     end
166   end
167
168   describe 'with manage_service false' do
169     let :params do
170       req_params.merge({'manage_service' => false})
171     end
172     it 'should not change the state of the service' do
173       should contain_service('cinder-api').without_ensure
174     end
175   end
176
177   describe 'with ratelimits' do
178     let :params do
179       req_params.merge({ :ratelimits => '(GET, "*", .*, 100, MINUTE);(POST, "*", .*, 200, MINUTE)' })
180     end
181
182     it { should contain_cinder_api_paste_ini('filter:ratelimit/limits').with(
183       :value => '(GET, "*", .*, 100, MINUTE);(POST, "*", .*, 200, MINUTE)'
184     )}
185   end
186
187   describe 'while validating the service with default command' do
188     let :params do
189       req_params.merge({
190         :validate => true,
191       })
192     end
193     it { should contain_exec('execute cinder-api validation').with(
194       :path        => '/usr/bin:/bin:/usr/sbin:/sbin',
195       :provider    => 'shell',
196       :tries       => '10',
197       :try_sleep   => '2',
198       :command     => 'cinder --os-auth-url http://localhost:5000/ --os-tenant-name services --os-username cinder --os-password foo list',
199     )}
200
201     it { should contain_anchor('create cinder-api anchor').with(
202       :require => 'Exec[execute cinder-api validation]',
203     )}
204   end
205
206   describe 'while validating the service with custom command' do
207     let :params do
208       req_params.merge({
209         :validate            => true,
210         :validation_options  => { 'cinder-api' => { 'command' => 'my-script' } }
211       })
212     end
213     it { should contain_exec('execute cinder-api validation').with(
214       :path        => '/usr/bin:/bin:/usr/sbin:/sbin',
215       :provider    => 'shell',
216       :tries       => '10',
217       :try_sleep   => '2',
218       :command     => 'my-script',
219     )}
220
221     it { should contain_anchor('create cinder-api anchor').with(
222       :require => 'Exec[execute cinder-api validation]',
223     )}
224   end
225
226 end