File: init_spec.rb

package info (click to toggle)
puppet-module-deric-zookeeper 0.8.4-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 392 kB
  • sloc: ruby: 1,734; sh: 224; makefile: 10
file content (368 lines) | stat: -rw-r--r-- 10,375 bytes parent folder | download | duplicates (3)
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
require 'spec_helper'

describe 'zookeeper', :type => :class do
  let(:facts) do
  {
    :operatingsystem           => 'Debian',
    :osfamily                  => 'Debian',
    :lsbdistcodename           => 'wheezy',
    :operatingsystemmajrelease => '7',
    :ipaddress                 => '192.168.1.1',
    :puppetversion             => Puppet.version,
  }
  end

  it { is_expected.to contain_class('zookeeper::config') }
  it { is_expected.to contain_class('zookeeper::install') }
  it { is_expected.to contain_class('zookeeper::service') }
  it { is_expected.to compile.with_all_deps }
  it { is_expected.to contain_service('zookeeper') }
  it { is_expected.to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/myid]') }
  it { is_expected.to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/zoo.cfg]') }
  it { is_expected.to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/environment]') }
  it { is_expected.to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/log4j.properties]') }

  context 'skip service restart' do
    let(:params) do
      {
        :restart_on_change => false,
      }
    end

    it { is_expected.to contain_service('zookeeper') }
    it { is_expected.not_to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/myid]') }
    it { is_expected.not_to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/zoo.cfg]') }
    it { is_expected.not_to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/environment]') }
    it { is_expected.not_to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/log4j.properties]') }
  end

  context 'allow installing multiple packages' do
    let(:user) { 'zookeeper' }
    let(:group) { 'zookeeper' }

    let(:params) do
      {
        :packages => [ 'zookeeper', 'zookeeper-bin' ],
      }
    end

    it { is_expected.to compile.with_all_deps }
    it { is_expected.to contain_package('zookeeper').with({:ensure => 'present'}) }
    it { is_expected.to contain_package('zookeeper-bin').with({:ensure => 'present'}) }
    it { is_expected.to contain_service('zookeeper').with({:ensure => 'running'}) }
    # datastore exec is not included by default
    it { is_expected.not_to contain_exec('initialize_datastore') }

    it { is_expected.to contain_user('zookeeper').with({:ensure => 'present'}) }
    it { is_expected.to contain_group('zookeeper').with({:ensure => 'present'}) }
  end

  context 'Cloudera packaging' do
    let(:user) { 'zookeeper' }
    let(:group) { 'zookeeper' }

    let(:params) do
      {
      :packages             => ['zookeeper','zookeeper-server'],
      :service_name         => 'zookeeper-server',
      :initialize_datastore => true
    }
    end

    it { should contain_package('zookeeper').with({:ensure => 'present'}) }
    it { should contain_package('zookeeper-server').with({:ensure => 'present'}) }
    it { should contain_service('zookeeper-server').with({:ensure => 'running'}) }
    it { should contain_exec('initialize_datastore') }
  end

  context 'setting minSessionTimeout' do
    let(:params) do
      {
      :min_session_timeout => 3000
    }
    end

    it do
      should contain_file(
        '/etc/zookeeper/conf/zoo.cfg'
      ).with_content(/minSessionTimeout=3000/)
    end
  end

  context 'setting maxSessionTimeout' do
    let(:params) do
      {
      :max_session_timeout => 60000
    }
    end

    it do
      should contain_file(
        '/etc/zookeeper/conf/zoo.cfg'
      ).with_content(/maxSessionTimeout=60000/)
    end
  end

  context 'disable service management' do
    let(:user) { 'zookeeper' }
    let(:group) { 'zookeeper' }

    let(:params) do
      {
      :manage_service => false,
    }
    end

    it { should contain_package('zookeeper').with({:ensure => 'present'}) }
    it { should_not contain_service('zookeeper').with({:ensure => 'running'}) }
    it { should_not contain_class('zookeeper::service') }
  end

  context 'use Cloudera RPM repo' do
    let(:facts) do
      {
      :ipaddress => '192.168.1.1',
      :osfamily => 'RedHat',
      :operatingsystemmajrelease => '7',
      :hardwaremodel => 'x86_64',
      :puppetversion => Puppet.version,
    }
    end

    let(:params) do
      {
      :repo => 'cloudera',
      :cdhver => '5',
    }
    end

    it { should contain_class('zookeeper::install::repo') }
    it { should contain_yumrepo('cloudera-cdh5') }

    context 'custom RPM repo' do
      let(:params) do
        {
        :repo => {
          'name'  => 'myrepo',
          'url'   => 'http://repo.url',
          'descr' => 'custom repo',
        },
        :cdhver => '5',
      }
      end
      it { should contain_yumrepo('myrepo').with({:baseurl => 'http://repo.url'}) }
    end
  end

  context 'service provider' do
    let(:user) { 'zookeeper' }
    let(:group) { 'zookeeper' }

    # provider is detected based on facts
    context 'do not set provider by default' do
      it { is_expected.to contain_package('zookeeper').with({:ensure => 'present'}) }
      it do
        is_expected.to contain_service('zookeeper').with({
        :ensure => 'running',
        :provider => 'init',
      })
      end
    end

    context 'autodetect provider on RedHat 7' do
      let(:facts) do
        {
        :ipaddress => '192.168.1.1',
        :osfamily => 'RedHat',
        :operatingsystemmajrelease => '7',
        :puppetversion => Puppet.version,
      }
      end
      it { should contain_package('zookeeper').with({:ensure => 'present'}) }
      it { should contain_package('zookeeper-server').with({:ensure => 'present'}) }
      it do
        should contain_service('zookeeper-server').with({
        :ensure => 'running',
        :provider => 'systemd',
      })
      end
    end

    it { should contain_class('zookeeper::service') }
  end

  context 'allow passing specific version' do
    let(:facts) do
    {
      :ipaddress => '192.168.1.1',
      :osfamily => 'Debian',
      :operatingsystem => 'Ubuntu',
      :operatingsystemmajrelease => '14.04',
      :lsbdistcodename => 'trusty',
      :puppetversion => Puppet.version,
    }
    end

    let(:version) {'3.4.5+dfsg-1'}

    let(:params) do
      {
      :ensure => version,
    }
    end

    it { is_expected.to contain_package('zookeeper').with({:ensure => version}) }
    it { is_expected.to contain_package('zookeeperd').with({:ensure => version}) }

    it { is_expected.to contain_user('zookeeper').with({:ensure => 'present'}) }
  end

  context 'upstart is used on Ubuntu' do
    let(:facts) do
      {
      :ipaddress => '192.168.1.1',
      :osfamily => 'Debian',
      :operatingsystem => 'Ubuntu',
      :operatingsystemmajrelease => '14.04',
      :lsbdistcodename => 'trusty',
      :puppetversion => Puppet.version,
    }
    end

    let(:params) do
      {
    }
    end

    it { should contain_package('zookeeper').with({:ensure => 'present'}) }
    it { should contain_package('zookeeperd').with({:ensure => 'present'}) }
    it do
      should contain_service('zookeeper').with({
      :ensure => 'running',
      :provider => 'upstart',
    })
    end
  end

  context 'set pid file for init provider' do
    let(:user) { 'zookeeper' }
    let(:group) { 'zookeeper' }

    let(:facts) do
      {
      :ipaddress => '192.168.1.1',
      :osfamily => 'RedHat',
      :operatingsystemmajrelease => '6',
      :puppetversion => Puppet.version,
    }
    end

    let(:params) do
      {
      :zoo_dir             => '/usr/lib/zookeeper',
      :log_dir             => '/var/log/zookeeper',
      :manage_service      => true,
      :manage_service_file => true,
      :service_provider    => 'init',
    }
    end

    it do
      is_expected.to contain_file(
        '/etc/zookeeper/conf/log4j.properties'
      ).with_content(/zookeeper.log.dir=\/var\/log\/zookeeper/)
    end

    context 'set service provider' do
      it { is_expected.to contain_package('zookeeper').with({:ensure => 'present'}) }
      it do
        is_expected.to contain_service('zookeeper-server').with({
        :ensure => 'running',
        :provider => 'init',
      })
      end
    end

    it do
      is_expected.to contain_file(
        '/etc/init.d/zookeeper-server'
      ).with_content(/pidfile=\/var\/run\/zookeeper.pid/)
    end
  end

  context 'create env file' do
    let(:user) { 'zookeeper' }
    let(:group) { 'zookeeper' }

    context 'on RedHat' do
      let(:facts) do
        {
        :ipaddress => '192.168.1.1',
        :osfamily => 'RedHat',
        :operatingsystemmajrelease => '6',
        :puppetversion => Puppet.version,
      }
      end

      it do
        is_expected.to contain_file(
          '/etc/zookeeper/conf/java.env'
        )
      end
    end

    context 'on Debian' do
      let(:facts) do
        {
        :ipaddress => '192.168.1.1',
        :osfamily => 'Debian',
        :operatingsystem => 'Debian',
        :lsbdistcodename => 'jessie',
        :operatingsystemmajrelease => '8',
        :puppetversion => Puppet.version,
      }
      end

      it do
        is_expected.to contain_file(
          '/etc/zookeeper/conf/environment'
        )
      end
    end

  end

  context 'managed by exhibitor' do
    let(:params) do
      {
        :service_provider => 'exhibitor',
        :service_name => 'zookeeper',
        :cfg_dir => '/opt/zookeeper/conf',
      }
    end

    it { is_expected.not_to contain_class('zookeeper::service') }
    it { is_expected.not_to contain_service('zookeeper') }
    it { is_expected.not_to contain_file('/opt/zookeeper/conf/zoo.cfg') }
    it { is_expected.not_to contain_file('/opt/zookeeper/conf/myid') }
  end

  context 'install from archive' do
    let(:params) do
      {
        install_method: 'archive',
        archive_version: '3.4.9',
      }
    end

    it { is_expected.to compile.with_all_deps }
    it { is_expected.to contain_class('Zookeeper::Install::Archive') }

    it { is_expected.not_to contain_package('zookeeper').with({:ensure => 'present'}) }
    it { is_expected.to contain_service('zookeeper').with({:ensure => 'running'}) }

    it { is_expected.to contain_user('zookeeper').with({:ensure => 'present'}) }
    it { is_expected.to contain_group('zookeeper').with({:ensure => 'present'}) }

  end
end