serverspec 0.6.13 → 0.6.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,16 +60,16 @@ module Serverspec
60
60
  check_zero(meth, *args)
61
61
  end
62
62
 
63
- def check_running(process, level)
64
- ret = run_command(commands.check_running(process, level))
63
+ def check_running(process)
64
+ ret = run_command(commands.check_running(process))
65
65
  if ret[:exit_status] == 1 || ret[:stdout] =~ /stopped/
66
66
  ret = run_command(commands.check_process(process))
67
67
  end
68
68
  ret[:exit_status] == 0
69
69
  end
70
70
 
71
- def check_running_under_supervisor(process, level)
72
- ret = run_command(commands.check_running_under_supervisor(process, level))
71
+ def check_running_under_supervisor(process)
72
+ ret = run_command(commands.check_running_under_supervisor(process))
73
73
  ret[:exit_status] == 0 && ret[:stdout] =~ /RUNNING/
74
74
  end
75
75
 
@@ -77,11 +77,11 @@ module Serverspec
77
77
  "netstat -tunl | grep -- #{escape(regexp)}"
78
78
  end
79
79
 
80
- def check_running(service, level=3)
80
+ def check_running(service)
81
81
  "service #{escape(service)} status"
82
82
  end
83
83
 
84
- def check_running_under_supervisor(service, level=3)
84
+ def check_running_under_supervisor(service)
85
85
  "supervisorctl status #{escape(service)}"
86
86
  end
87
87
 
@@ -11,7 +11,7 @@ module Serverspec
11
11
  "dpkg -s #{escaped_package} && ! dpkg -s #{escaped_package} | grep -E '^Status: .+ not-installed$'"
12
12
  end
13
13
 
14
- def check_running(service, level=3)
14
+ def check_running(service)
15
15
  # This is compatible with Debian >Jaunty and Ubuntu derivatives
16
16
  "service #{escape(service)} status | grep 'running'"
17
17
  end
@@ -1,7 +1,7 @@
1
1
  module Serverspec
2
2
  module Commands
3
3
  class Gentoo < Linux
4
- def check_enabled(service)
4
+ def check_enabled(service, level=3)
5
5
  regexp = "^\\s*#{service}\\s*|\\s*\\(boot\\|default\\)"
6
6
  "rc-update show | grep -- #{escape(regexp)}"
7
7
  end
@@ -10,7 +10,7 @@ module Serverspec
10
10
  "eix #{escape(package)} --installed"
11
11
  end
12
12
 
13
- def check_running(service, level=3)
13
+ def check_running(service)
14
14
  "/etc/init.d/#{escape(service)} status"
15
15
  end
16
16
  end
@@ -18,7 +18,7 @@ module Serverspec
18
18
  "netstat -an 2> /dev/null | egrep 'LISTEN|Idle' | grep -- #{escape(regexp)}"
19
19
  end
20
20
 
21
- def check_running(service, level=3)
21
+ def check_running(service)
22
22
  "svcs -l #{escape(service)} status 2> /dev/null |grep 'state online'"
23
23
  end
24
24
 
@@ -14,6 +14,7 @@ require 'serverspec/matchers/be_reachable'
14
14
  require 'serverspec/matchers/be_installed'
15
15
 
16
16
  # service
17
+ require 'serverspec/matchers/be_enabled'
17
18
  require 'serverspec/matchers/be_running'
18
19
 
19
20
  # user
@@ -0,0 +1,13 @@
1
+ RSpec::Matchers.define :be_enabled do
2
+ match do |subject|
3
+ if subject.class.name == 'Serverspec::Type::Service'
4
+ subject.enabled?(@level)
5
+ else
6
+ subject.enabled?
7
+ end
8
+ end
9
+
10
+ chain :with_level do |level|
11
+ @level = level
12
+ end
13
+ end
@@ -1,13 +1,9 @@
1
1
  RSpec::Matchers.define :be_running do
2
2
  match do |process|
3
- process.running?(@under, @level)
3
+ process.running?(@under)
4
4
  end
5
5
 
6
6
  chain :under do |under|
7
7
  @under = under
8
8
  end
9
-
10
- chain :with_level do |level|
11
- @level = level
12
- end
13
9
  end
@@ -1,11 +1,11 @@
1
1
  module Serverspec
2
2
  module Type
3
3
  class Service < Base
4
- def enabled?
5
- backend.check_enabled(@name)
4
+ def enabled?(level=3)
5
+ backend.check_enabled(@name, level)
6
6
  end
7
7
 
8
- def running?(under, level=3)
8
+ def running?(under)
9
9
  if under
10
10
  check_method = "check_running_under_#{under}".to_sym
11
11
 
@@ -13,9 +13,9 @@ module Serverspec
13
13
  raise ArgumentError.new("`be_running` matcher doesn't support #{@under}")
14
14
  end
15
15
 
16
- backend.send(check_method, @name, level)
16
+ backend.send(check_method, @name)
17
17
  else
18
- backend.check_running(@name, level)
18
+ backend.check_running(@name)
19
19
  end
20
20
  end
21
21
 
@@ -1,3 +1,3 @@
1
1
  module Serverspec
2
- VERSION = "0.6.13"
2
+ VERSION = "0.6.15"
3
3
  end
@@ -4,6 +4,7 @@ include Serverspec::Helper::Debian
4
4
 
5
5
  describe 'Serverspec service matchers of Red Hat family' do
6
6
  it_behaves_like 'support service enabled matcher', 'sshd'
7
+ it_behaves_like 'support service enabled with level matcher', 'sshd', 3
7
8
  it_behaves_like 'support service running matcher', 'sshd'
8
9
  it_behaves_like 'support service running under supervisor matcher', 'sshd'
9
10
  it_behaves_like 'support service running under unimplemented matcher', 'sshd'
@@ -2,9 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  include Serverspec::Helper::Gentoo
4
4
 
5
- describe 'Serverspec service matchers of Red Hat family' do
5
+ describe 'Serverspec service matchers of Gentoo family' do
6
+ it_behaves_like 'support service enabled matcher', 'sshd'
7
+ it_behaves_like 'support service enabled with level matcher', 'sshd', 3
6
8
  it_behaves_like 'support service running matcher', 'sshd'
7
9
  it_behaves_like 'support service running under supervisor matcher', 'sshd'
8
10
  it_behaves_like 'support service running under unimplemented matcher', 'sshd'
9
- it_behaves_like 'support service enabled matcher', 'sshd'
10
11
  end
@@ -68,6 +68,11 @@ describe 'check_enabled' do
68
68
  it { should eq 'chkconfig --list httpd | grep 3:on' }
69
69
  end
70
70
 
71
+ describe 'check_enabled with level 4' do
72
+ subject { commands.check_enabled('httpd', 4) }
73
+ it { should eq 'chkconfig --list httpd | grep 4:on' }
74
+ end
75
+
71
76
  describe 'check_yumrepo' do
72
77
  subject { commands.check_yumrepo('epel') }
73
78
  it { should eq 'yum repolist all -C | grep ^epel' }
@@ -4,6 +4,7 @@ include Serverspec::Helper::RedHat
4
4
 
5
5
  describe 'Serverspec service matchers of Red Hat family' do
6
6
  it_behaves_like 'support service enabled matcher', 'sshd'
7
+ it_behaves_like 'support service enabled with level matcher', 'sshd', 3
7
8
  it_behaves_like 'support service running matcher', 'sshd'
8
9
  it_behaves_like 'support service running under supervisor matcher', 'sshd'
9
10
  it_behaves_like 'support service running under unimplemented matcher', 'sshd'
@@ -4,6 +4,7 @@ include Serverspec::Helper::Solaris
4
4
 
5
5
  describe 'Serverspec service matchers of Solaris' do
6
6
  it_behaves_like 'support service enabled matcher', 'sshd'
7
+ it_behaves_like 'support service enabled with level matcher', 'sshd', 3
7
8
  it_behaves_like 'support service running matcher', 'sshd'
8
9
  it_behaves_like 'support service running under supervisor matcher', 'sshd'
9
10
  it_behaves_like 'support service running under unimplemented matcher', 'sshd'
@@ -104,15 +104,7 @@ shared_examples_for 'support command check_file_md5checksum' do |file, md5sum|
104
104
  end
105
105
 
106
106
  shared_examples_for 'support command check_running_under_supervisor' do |service|
107
- subject { commands.check_running_under_supervisor(service, 3) }
108
- it { should eq "supervisorctl status #{service}" }
109
- end
110
-
111
- shared_examples_for 'support command check_running_under_supervisor_with_level' do |service|
112
- subject { commands.check_running_under_supervisor(service, 3) }
113
- it { should eq "supervisorctl status #{service}" }
114
-
115
- subject { commands.check_running_under_supervisor(service, 3) }
107
+ subject { commands.check_running_under_supervisor(service) }
116
108
  it { should eq "supervisorctl status #{service}" }
117
109
  end
118
110
 
@@ -10,6 +10,18 @@ shared_examples_for 'support service enabled matcher' do |valid_service|
10
10
  end
11
11
  end
12
12
 
13
+ shared_examples_for 'support service enabled with level matcher' do |valid_service, level|
14
+ describe 'be_enabled' do
15
+ describe service(valid_service) do
16
+ it { should be_enabled.with_level(level) }
17
+ end
18
+
19
+ describe service('invalid-service') do
20
+ it { should_not be_enabled.with_level(level) }
21
+ end
22
+ end
23
+ end
24
+
13
25
  shared_examples_for 'support service running matcher' do |valid_service|
14
26
  describe 'be_running' do
15
27
  describe service(valid_service) do
@@ -56,48 +68,3 @@ shared_examples_for 'support service running under unimplemented matcher' do |va
56
68
  end
57
69
  end
58
70
  end
59
-
60
- shared_examples_for 'support service running with runlevel' do |valid_service|
61
- describe 'be_running.with_level(3)' do
62
- describe service(valid_service) do
63
- before :all do
64
- RSpec.configure do |c|
65
- c.stdout = "#{valid_service} RUNNING\r\n"
66
- end
67
- end
68
-
69
- it { should be_running.with_level(3) }
70
- it { should_not be_running.with_level(5) }
71
- end
72
-
73
- describe service(valid_service) do
74
- before :all do
75
- RSpec.configure do |c|
76
- c.stdout = "#{valid_service} STOPPED\r\n"
77
- end
78
- end
79
-
80
- it { should_not be_running.with_level(3) }
81
- end
82
-
83
- describe service('invalid-daemon') do
84
- it { should_not be_running.with_level(3) }
85
- end
86
- end
87
- end
88
-
89
- shared_examples_for 'support service running under supervisor matcher with runlevel' do |valid_service|
90
- describe 'be_running.under("supervisor").with_level(3)' do
91
- describe service(valid_service) do
92
- before :all do
93
- RSpec.configure do |c|
94
- c.stdout = "#{valid_service} RUNNING\r\n"
95
- end
96
- end
97
-
98
- it { should be_running.under('supervisor').with_level(3) }
99
- it { should_not be_running.under('supervisor').with_level(5) }
100
- end
101
-
102
- end
103
- 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.13
4
+ version: 0.6.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -167,6 +167,7 @@ files:
167
167
  - lib/serverspec/helper/ssh.rb
168
168
  - lib/serverspec/helper/type.rb
169
169
  - lib/serverspec/matchers.rb
170
+ - lib/serverspec/matchers/be_enabled.rb
170
171
  - lib/serverspec/matchers/be_executable.rb
171
172
  - lib/serverspec/matchers/be_installed.rb
172
173
  - lib/serverspec/matchers/be_mounted.rb