serverspec 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -189,7 +189,6 @@ module Serverspec
189
189
  'Base'
190
190
  end
191
191
  end
192
-
193
192
  end
194
193
  end
195
194
  end
@@ -196,6 +196,10 @@ module Serverspec
196
196
  def check_access_by_user file, user, access
197
197
  raise NotImplementedError.new
198
198
  end
199
+
200
+ def check_kernel_module_loaded name
201
+ raise NotImplementedError.new
202
+ end
199
203
  end
200
204
  end
201
205
  end
@@ -2,13 +2,19 @@ module Serverspec
2
2
  module Commands
3
3
  class Debian < Linux
4
4
  def check_enabled service
5
- "ls /etc/rc3.d/ | grep -- #{escape(service)}"
5
+ # Until everything uses Upstart, this needs an OR.
6
+ "ls /etc/rc3.d/ | grep -- #{escape(service)} || grep 'start on' /etc/init/#{escape(service)}.conf"
6
7
  end
7
8
 
8
9
  def check_installed package
9
10
  escaped_package = escape(package)
10
11
  "dpkg -s #{escaped_package} && ! dpkg -s #{escaped_package} | grep -E '^Status: .+ not-installed$'"
11
12
  end
13
+
14
+ def check_running service
15
+ # This is compatible with Debian >Jaunty and Ubuntu derivatives
16
+ "service #{escape(service)} status | grep 'running'"
17
+ end
12
18
  end
13
19
  end
14
20
  end
@@ -21,6 +21,10 @@ module Serverspec
21
21
  def check_selinux mode
22
22
  "getenforce | grep -i -- #{escape(mode)} && grep -i -- ^SELINUX=#{escape(mode)}$ /etc/selinux/config"
23
23
  end
24
+
25
+ def check_kernel_module_loaded name
26
+ "lsmod | grep ^#{name}"
27
+ end
24
28
  end
25
29
  end
26
30
  end
@@ -3,7 +3,7 @@ module Serverspec
3
3
  module Type
4
4
  types = %w(
5
5
  base service package port file cron command linux_kernel_parameter iptables host
6
- routing_table default_gateway selinux user group zfs ipnat ipfilter
6
+ routing_table default_gateway selinux user group zfs ipnat ipfilter kernel_module
7
7
  )
8
8
 
9
9
  types.each {|type| require "serverspec/type/#{type}" }
@@ -6,7 +6,9 @@ module Serverspec
6
6
  end
7
7
 
8
8
  def to_s
9
- type = self.class.name.split(':')[-1]
9
+ type = self.class.name.split(':')[-1]
10
+ type.gsub!(/([a-z\d])([A-Z])/, '\1 \2')
11
+ type.capitalize!
10
12
  %Q!#{type} "#{@name}"!
11
13
  end
12
14
  end
@@ -0,0 +1,9 @@
1
+ module Serverspec
2
+ module Type
3
+ class KernelModule < Base
4
+ def loaded?
5
+ backend.check_kernel_module_loaded(@name)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Serverspec
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -52,11 +52,13 @@ describe 'Serverspec commands of Debian family' do
52
52
  it_behaves_like 'support command get_mode'
53
53
 
54
54
  it_behaves_like 'support command check_access_by_user'
55
+
56
+ it_behaves_like 'support command check_kernel_module_loaded', 'lp'
55
57
  end
56
58
 
57
59
  describe 'check_enabled' do
58
60
  subject { commands.check_enabled('httpd') }
59
- it { should eq 'ls /etc/rc3.d/ | grep -- httpd' }
61
+ it { should eq "ls /etc/rc3.d/ | grep -- httpd || grep 'start on' /etc/init/httpd.conf" }
60
62
  end
61
63
 
62
64
  describe 'check_installed' do
@@ -66,5 +68,5 @@ end
66
68
 
67
69
  describe 'check_running' do
68
70
  subject { commands.check_running('httpd') }
69
- it { should eq 'service httpd status' }
71
+ it { should eq "service httpd status | grep 'running'" }
70
72
  end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ include Serverspec::Helper::Debian
4
+
5
+ describe 'Serverspec file matchers of Debian family' do
6
+ it_behaves_like 'support kernel_module be_loaded matcher', 'lp'
7
+ end
@@ -52,6 +52,8 @@ describe 'Serverspec commands of Gentoo family' do
52
52
  it_behaves_like 'support command get_mode'
53
53
 
54
54
  it_behaves_like 'support command check_access_by_user'
55
+
56
+ it_behaves_like 'support command check_kernel_module_loaded', 'lp'
55
57
  end
56
58
 
57
59
  describe 'check_enabled' do
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ include Serverspec::Helper::Gentoo
4
+
5
+ describe 'Serverspec file matchers of Gentoo family' do
6
+ it_behaves_like 'support kernel_module be_loaded matcher', 'lp'
7
+ end
@@ -50,6 +50,8 @@ describe 'Serverspec commands of Red Hat' do
50
50
  it_behaves_like 'support command check_selinux'
51
51
 
52
52
  it_behaves_like 'support command get_mode'
53
+
54
+ it_behaves_like 'support command check_kernel_module_loaded', 'lp'
53
55
  end
54
56
 
55
57
  describe 'check_enabled' do
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ include Serverspec::Helper::RedHat
4
+
5
+ describe 'Serverspec file matchers of Red Hat family' do
6
+ it_behaves_like 'support kernel_module be_loaded matcher', 'lp'
7
+ end
@@ -250,3 +250,8 @@ shared_examples_for 'support command check_access_by_user' do
250
250
  it { should eq 'su -s sh -c "test -x /tmp/somethingx" dummyuser3' }
251
251
  end
252
252
  end
253
+
254
+ shared_examples_for 'support command check_kernel_module_loaded' do |name|
255
+ subject { commands.check_kernel_module_loaded(name) }
256
+ it { should eq "lsmod | grep ^#{name}" }
257
+ end
@@ -0,0 +1,11 @@
1
+ shared_examples_for 'support kernel_module be_loaded matcher' do |name|
2
+ describe 'be_loaded' do
3
+ describe kernel_module(name) do
4
+ it { should be_loaded }
5
+ end
6
+
7
+ describe kernel_module('invalid-module') do
8
+ it { should_not be_loaded }
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -196,6 +196,7 @@ files:
196
196
  - lib/serverspec/type/ipfilter.rb
197
197
  - lib/serverspec/type/ipnat.rb
198
198
  - lib/serverspec/type/iptables.rb
199
+ - lib/serverspec/type/kernel_module.rb
199
200
  - lib/serverspec/type/linux_kernel_parameter.rb
200
201
  - lib/serverspec/type/package.rb
201
202
  - lib/serverspec/type/port.rb
@@ -228,6 +229,7 @@ files:
228
229
  - spec/debian/group_spec.rb
229
230
  - spec/debian/host_spec.rb
230
231
  - spec/debian/iptables_spec.rb
232
+ - spec/debian/kernel_module_spec.rb
231
233
  - spec/debian/linux_kernel_parameter_spec.rb
232
234
  - spec/debian/package_spec.rb
233
235
  - spec/debian/port_spec.rb
@@ -243,6 +245,7 @@ files:
243
245
  - spec/gentoo/group_spec.rb
244
246
  - spec/gentoo/host_spec.rb
245
247
  - spec/gentoo/iptables_spec.rb
248
+ - spec/gentoo/kernel_module_spec.rb
246
249
  - spec/gentoo/linux_kernel_parameter_spec.rb
247
250
  - spec/gentoo/package_spec.rb
248
251
  - spec/gentoo/port_spec.rb
@@ -258,6 +261,7 @@ files:
258
261
  - spec/redhat/group_spec.rb
259
262
  - spec/redhat/host_spec.rb
260
263
  - spec/redhat/iptables_spec.rb
264
+ - spec/redhat/kernel_module_spec.rb
261
265
  - spec/redhat/linux_kernel_parameter_spec.rb
262
266
  - spec/redhat/package_spec.rb
263
267
  - spec/redhat/port_spec.rb
@@ -290,6 +294,7 @@ files:
290
294
  - spec/support/shared_group_examples.rb
291
295
  - spec/support/shared_host_examples.rb
292
296
  - spec/support/shared_iptables_examples.rb
297
+ - spec/support/shared_kernel_module_examples.rb
293
298
  - spec/support/shared_linux_kernel_parameter_examples.rb
294
299
  - spec/support/shared_package_examples.rb
295
300
  - spec/support/shared_port_examples.rb
@@ -345,6 +350,7 @@ test_files:
345
350
  - spec/debian/group_spec.rb
346
351
  - spec/debian/host_spec.rb
347
352
  - spec/debian/iptables_spec.rb
353
+ - spec/debian/kernel_module_spec.rb
348
354
  - spec/debian/linux_kernel_parameter_spec.rb
349
355
  - spec/debian/package_spec.rb
350
356
  - spec/debian/port_spec.rb
@@ -360,6 +366,7 @@ test_files:
360
366
  - spec/gentoo/group_spec.rb
361
367
  - spec/gentoo/host_spec.rb
362
368
  - spec/gentoo/iptables_spec.rb
369
+ - spec/gentoo/kernel_module_spec.rb
363
370
  - spec/gentoo/linux_kernel_parameter_spec.rb
364
371
  - spec/gentoo/package_spec.rb
365
372
  - spec/gentoo/port_spec.rb
@@ -375,6 +382,7 @@ test_files:
375
382
  - spec/redhat/group_spec.rb
376
383
  - spec/redhat/host_spec.rb
377
384
  - spec/redhat/iptables_spec.rb
385
+ - spec/redhat/kernel_module_spec.rb
378
386
  - spec/redhat/linux_kernel_parameter_spec.rb
379
387
  - spec/redhat/package_spec.rb
380
388
  - spec/redhat/port_spec.rb
@@ -407,6 +415,7 @@ test_files:
407
415
  - spec/support/shared_group_examples.rb
408
416
  - spec/support/shared_host_examples.rb
409
417
  - spec/support/shared_iptables_examples.rb
418
+ - spec/support/shared_kernel_module_examples.rb
410
419
  - spec/support/shared_linux_kernel_parameter_examples.rb
411
420
  - spec/support/shared_package_examples.rb
412
421
  - spec/support/shared_port_examples.rb