File: ceilometer_agent_polling_spec.rb

package info (click to toggle)
puppet-module-ceilometer 27.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,264 kB
  • sloc: ruby: 1,888; python: 33; makefile: 11; sh: 10
file content (417 lines) | stat: -rw-r--r-- 14,976 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
require 'spec_helper'

describe 'ceilometer::agent::polling' do

  let :pre_condition do
    "include nova
    include nova::compute
    class { 'ceilometer': telemetry_secret => 's3cr3t' }"
  end

  let :params do
    {}
  end

  shared_examples 'ceilometer::agent::polling' do
    context 'with default params' do
      it { should contain_class('ceilometer::deps') }
      it { should contain_class('ceilometer::params') }

      it {
        if platform_params[:libvirt_group]
          should contain_user('ceilometer').with_groups(['nova', "#{platform_params[:libvirt_group]}"])
        else
          should contain_user('ceilometer').with_groups(['nova'])
        end
      }

      it { should contain_user('ceilometer').with(
        :ensure  => 'present',
        :name    => 'ceilometer',
        :gid     => 'ceilometer',
        :groups  => platform_params[:ceilometer_groups],
        :require => 'Anchor[ceilometer::install::end]',
      ) }

      it { should contain_package('nova-common').with(
       :before => /User\[ceilometer\]/
      )}

      it {
        should contain_ceilometer_config('compute/instance_discovery_method').with_value('<SERVICE DEFAULT>')
        should contain_ceilometer_config('compute/resource_update_interval').with_value('<SERVICE DEFAULT>')
        should contain_ceilometer_config('compute/resource_cache_expiry').with_value('<SERVICE DEFAULT>')
      }

      it 'shoud install the polling package' do
        should contain_package('ceilometer-polling').with(
          :ensure => 'present',
          :name   => platform_params[:agent_polling_package_name],
          :tag    => ['openstack', 'ceilometer-package'],
        )
        should_not contain_package('ceilometer-central')
        should_not contain_package('ceilometer-compute')
        should_not contain_package('ceilometer-ipmi')
      end

      it { should contain_ceilometer_config('DEFAULT/polling_namespaces').with_value('central,compute,ipmi') }

      it 'should enable the polling service' do
        should contain_service('ceilometer-polling').with(
          :ensure     => 'running',
          :name       => platform_params[:agent_polling_service_name],
          :enable     => true,
          :hasstatus  => true,
          :hasrestart => true,
          :tag        => 'ceilometer-service',
        )
        should_not contain_service('ceilometer-central')
        should_not contain_service('ceilometer-compute')
        should_not contain_service('ceilometer-ipmi')
      end

      it { should contain_ceilometer_config('polling/batch_size').with_value('<SERVICE DEFAULT>') }
      it { should_not contain_file('polling') }
      it { should contain_ceilometer_config('polling/identity_name_discovery').with_value('<SERVICE DEFAULT>') }
      it { should contain_ceilometer_config('polling/ignore_disabled_projects').with_value('<SERVICE DEFAULT>') }
      it { should contain_ceilometer_config('polling/enable_notifications').with_value('<SERVICE DEFAULT>') }
      it { should contain_ceilometer_config('polling/enable_prometheus_exporter').with_value('<SERVICE DEFAULT>') }
      it { should contain_ceilometer_config('polling/prometheus_listen_addresses').with_value('<SERVICE DEFAULT>') }
      it { should contain_ceilometer_config('polling/prometheus_tls_enable').with_value('<SERVICE DEFAULT>') }
      it { should contain_ceilometer_config('polling/prometheus_tls_certfile').with_value('<SERVICE DEFAULT>') }
      it { should contain_ceilometer_config('polling/prometheus_tls_keyfile').with_value('<SERVICE DEFAULT>') }
      it { should contain_ceilometer_config('polling/pollsters_definitions_dirs').with_value('<SERVICE DEFAULT>') }
      it { should contain_ceilometer_config('polling/cfg_file').with_value('<SERVICE DEFAULT>') }
    end

    context 'when setting package_ensure' do
      before do
        params.merge!( :package_ensure => 'latest' )
      end

      it { should contain_package('ceilometer-polling').with(
        :ensure => 'latest',
      )}
    end

    context 'when compute parameters set' do
      before do
        params.merge!(
          :instance_discovery_method => 'naive',
          :resource_update_interval  => 0,
          :resource_cache_expiry     => 3600,
        )
      end

      it {
        should contain_ceilometer_config('compute/instance_discovery_method').with_value('naive')
        should contain_ceilometer_config('compute/resource_update_interval').with_value(0)
        should contain_ceilometer_config('compute/resource_cache_expiry').with_value(3600)
      }
    end

    context 'when common parameters are set' do
      before do
        params.merge!(
          :identity_name_discovery     => true,
          :ignore_disabled_projects    => false,
          :enable_notifications        => true,
          :enable_prometheus_exporter  => false,
          :prometheus_listen_addresses => ['127.0.0.1:9101'],
          :prometheus_tls_enable       => false,
          :prometheus_tls_certfile     => 'certfile',
          :prometheus_tls_keyfile      => 'keyfile',
          :pollsters_definitions_dirs  => ['/etc/ceilometer/pollsters.d', '/etc/ceilometer/mypollsters.d']
        )
      end

      it {
        should contain_ceilometer_config('polling/identity_name_discovery').with_value(true)
        should contain_ceilometer_config('polling/ignore_disabled_projects').with_value(false)
        should contain_ceilometer_config('polling/enable_notifications').with_value(true)
        should contain_ceilometer_config('polling/enable_prometheus_exporter').with_value(false)
        should contain_ceilometer_config('polling/prometheus_listen_addresses').with_value('127.0.0.1:9101')
        should contain_ceilometer_config('polling/prometheus_tls_enable').with_value(false)
        should contain_ceilometer_config('polling/prometheus_tls_certfile').with_value('certfile')
        should contain_ceilometer_config('polling/prometheus_tls_keyfile').with_value('keyfile')
        should contain_ceilometer_config('polling/pollsters_definitions_dirs').with_value(
          '/etc/ceilometer/pollsters.d,/etc/ceilometer/mypollsters.d')
      }
    end

    context 'with compute namespace disabled' do
      before do
        params.merge!(
          :compute_namespace => false
        )
      end

      it {
        should contain_ceilometer_config('DEFAULT/polling_namespaces').with_value('central,ipmi')
        should contain_ceilometer_config('compute/instance_discovery_method').with_ensure('absent')
        should contain_ceilometer_config('compute/resource_update_interval').with_ensure('absent')
        should contain_ceilometer_config('compute/resource_cache_expiry').with_ensure('absent')
      }
    end

    context 'with central namespace disabled' do
      before do
        params.merge!(
          :central_namespace => false,
        )
      end

      it {
        should contain_ceilometer_config('DEFAULT/polling_namespaces').with_value('compute,ipmi')
       }
    end

    context 'with central and ipmi polling namespaces disabled' do
      before do
        params.merge!(
          :central_namespace => false,
          :ipmi_namespace    => false
        )
      end

      it { should contain_ceilometer_config('DEFAULT/polling_namespaces').with_value('compute') }
    end

    context 'with all namespaces disabled' do
      before do
        params.merge!(
          :compute_namespace => false,
          :central_namespace => false,
          :ipmi_namespace    => false
        )
      end

      it { should contain_ceilometer_config('DEFAULT/polling_namespaces').with_ensure('absent') }
    end

    context 'with service disabled' do
      before do
        params.merge!( :enabled => false )
      end

      it { should contain_service('ceilometer-polling').with(
        :ensure     => 'stopped',
        :name       => platform_params[:agent_polling_service_name],
        :enable     => false,
        :hasstatus  => true,
        :hasrestart => true,
        :tag        => 'ceilometer-service',
      )}
    end

    context 'with service unmanaged' do
      before do
        params.merge!( :manage_service => false )
      end

      it { should_not contain_service('ceilometer-polling') }
    end

    context 'with polling management enabled and default meters' do
      before do
        params.merge!( :manage_polling => true )
     end

      it { should contain_file('polling').with(
        :ensure  => 'file',
        :path    => '/etc/ceilometer/polling.yaml',
        :content => '---
sources:
    - name: some_pollsters
      interval: 300
      meters:
        - cpu
        - memory.usage
        - network.incoming.bytes
        - network.incoming.packets
        - network.outgoing.bytes
        - network.outgoing.packets
        - disk.device.read.bytes
        - disk.device.read.requests
        - disk.device.write.bytes
        - disk.device.write.requests
        - volume.size
        - volume.snapshot.size
        - volume.backup.size
',
        :tag     => 'ceilometer-yamls',
      )}
      it { should contain_ceilometer_config('polling/cfg_file').with_value('/etc/ceilometer/polling.yaml') }
    end

    context 'with polling and basic custom settings' do
      before do
        params.merge!({
          :manage_polling   => true,
          :polling_interval => 30,
          :polling_meters   => ['meter1', 'meter2']
        })
      end

      it { should contain_file('polling').with(
        :ensure  => 'file',
        :path    => '/etc/ceilometer/polling.yaml',
        :content => '---
sources:
    - name: some_pollsters
      interval: 30
      meters:
        - meter1
        - meter2
',
        :tag     => 'ceilometer-yamls',
      )}
      it { should contain_ceilometer_config('polling/cfg_file').with_value('/etc/ceilometer/polling.yaml') }
    end

    context 'with polling and custom config' do
      before do
        params.merge!( :manage_polling => true,
                       :polling_config => {
          'sources' => [
            'name'     => 'my_pollsters',
            'interval' => 60,
            'meters'   => [
              'meterfoo',
              'meterbar',
            ],
          ],
        } )
      end

      it { should contain_file('polling').with(
        :ensure  => 'file',
        :path    => '/etc/ceilometer/polling.yaml',
        :content => '---
sources:
- name: my_pollsters
  interval: 60
  meters:
  - meterfoo
  - meterbar
',
      )}
      it { should contain_ceilometer_config('polling/cfg_file').with_value('/etc/ceilometer/polling.yaml') }
    end

    context 'with polling management disabled' do
      before do
        params.merge!( :manage_polling => false )
      end

      it { should_not contain_file('polling') }
      it { should contain_ceilometer_config('polling/cfg_file').with_value('<SERVICE DEFAULT>') }
    end

    context 'when batch_size is set' do
      before do
        params.merge!( :batch_size => 50 )
      end

      it { should contain_ceilometer_config('polling/batch_size').with_value(50) }
    end

    context 'with separate agents' do
      before do
        params.merge!( :separate_services => true )
      end

      it 'should install the agent packages' do
        should_not contain_package('ceilometer-polling')
        should contain_package('ceilometer-central').with(
          :ensure => 'present',
          :name   => platform_params[:agent_central_package_name],
          :tag    => ['openstack', 'ceilometer-package'],
        )
        should contain_package('ceilometer-compute').with(
          :ensure => 'present',
          :name   => platform_params[:agent_compute_package_name],
          :tag    => ['openstack', 'ceilometer-package'],
        )
        should contain_package('ceilometer-ipmi').with(
          :ensure => 'present',
          :name   => platform_params[:agent_ipmi_package_name],
          :tag    => ['openstack', 'ceilometer-package'],
        )
      end

      it { should contain_ceilometer_config('DEFAULT/polling_namespaces').with_ensure('absent') }

      it 'should enable the agent services' do
        should_not contain_service('ceilometer-polling')
        should contain_service('ceilometer-central').with(
          :ensure     => 'running',
          :name       => platform_params[:agent_central_service_name],
          :enable     => true,
          :hasstatus  => true,
          :hasrestart => true,
          :tag        => 'ceilometer-service',
        )
        should contain_service('ceilometer-compute').with(
          :ensure     => 'running',
          :name       => platform_params[:agent_compute_service_name],
          :enable     => true,
          :hasstatus  => true,
          :hasrestart => true,
          :tag        => 'ceilometer-service',
        )
        should contain_service('ceilometer-ipmi').with(
          :ensure     => 'running',
          :name       => platform_params[:agent_ipmi_service_name],
          :enable     => true,
          :hasstatus  => true,
          :hasrestart => true,
          :tag        => 'ceilometer-service',
        )
      end
    end
  end

  on_supported_os({
    :supported_os => OSDefaults.get_supported_os
  }).each do |os,facts|
    context "on #{os}" do
      let (:facts) do
        facts.merge!(OSDefaults.get_facts())
      end

      let :platform_params do
        case facts[:os]['family']
        when 'Debian'
            {
              :agent_polling_package_name => 'ceilometer-polling',
              :agent_polling_service_name => 'ceilometer-polling',
              :agent_central_package_name => 'ceilometer-agent-central',
              :agent_central_service_name => 'ceilometer-agent-central',
              :agent_compute_package_name => 'ceilometer-agent-compute',
              :agent_compute_service_name => 'ceilometer-agent-compute',
              :agent_ipmi_package_name    => 'ceilometer-agent-ipmi',
              :agent_ipmi_service_name    => 'ceilometer-agent-ipmi',
              :libvirt_group              => 'libvirt',
              :ceilometer_groups          => ['nova', 'libvirt'],
            }
        when 'RedHat'
            {
              :agent_polling_package_name => 'openstack-ceilometer-polling',
              :agent_polling_service_name => 'openstack-ceilometer-polling',
              :agent_central_package_name => 'openstack-ceilometer-central',
              :agent_central_service_name => 'openstack-ceilometer-central',
              :agent_compute_package_name => 'openstack-ceilometer-compute',
              :agent_compute_service_name => 'openstack-ceilometer-compute',
              :agent_ipmi_package_name    => 'openstack-ceilometer-ipmi',
              :agent_ipmi_service_name    => 'openstack-ceilometer-ipmi',
              :ceilometer_groups          => ['nova'],
            }
        end
      end

      it_behaves_like 'ceilometer::agent::polling'
    end
  end

end