serverspec 0.6.13 → 0.6.15
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/serverspec/backend/exec.rb +4 -4
- data/lib/serverspec/commands/base.rb +2 -2
- data/lib/serverspec/commands/debian.rb +1 -1
- data/lib/serverspec/commands/gentoo.rb +2 -2
- data/lib/serverspec/commands/solaris.rb +1 -1
- data/lib/serverspec/matchers.rb +1 -0
- data/lib/serverspec/matchers/be_enabled.rb +13 -0
- data/lib/serverspec/matchers/be_running.rb +1 -5
- data/lib/serverspec/type/service.rb +5 -5
- data/lib/serverspec/version.rb +1 -1
- data/spec/debian/service_spec.rb +1 -0
- data/spec/gentoo/service_spec.rb +3 -2
- data/spec/redhat/commands_spec.rb +5 -0
- data/spec/redhat/service_spec.rb +1 -0
- data/spec/solaris/service_spec.rb +1 -0
- data/spec/support/shared_commands_examples.rb +1 -9
- data/spec/support/shared_service_examples.rb +12 -45
- metadata +2 -1
@@ -60,16 +60,16 @@ module Serverspec
|
|
60
60
|
check_zero(meth, *args)
|
61
61
|
end
|
62
62
|
|
63
|
-
def check_running(process
|
64
|
-
ret = run_command(commands.check_running(process
|
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
|
72
|
-
ret = run_command(commands.check_running_under_supervisor(process
|
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
|
80
|
+
def check_running(service)
|
81
81
|
"service #{escape(service)} status"
|
82
82
|
end
|
83
83
|
|
84
|
-
def check_running_under_supervisor(service
|
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
|
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
|
13
|
+
def check_running(service)
|
14
14
|
"/etc/init.d/#{escape(service)} status"
|
15
15
|
end
|
16
16
|
end
|
data/lib/serverspec/matchers.rb
CHANGED
@@ -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
|
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
|
16
|
+
backend.send(check_method, @name)
|
17
17
|
else
|
18
|
-
backend.check_running(@name
|
18
|
+
backend.check_running(@name)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
data/lib/serverspec/version.rb
CHANGED
data/spec/debian/service_spec.rb
CHANGED
@@ -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'
|
data/spec/gentoo/service_spec.rb
CHANGED
@@ -2,9 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Gentoo
|
4
4
|
|
5
|
-
describe 'Serverspec service matchers of
|
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' }
|
data/spec/redhat/service_spec.rb
CHANGED
@@ -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
|
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.
|
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
|