serverspec 0.6.16 → 0.6.17
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/serverspec/backend/exec.rb +16 -0
- data/lib/serverspec/commands/base.rb +9 -1
- data/lib/serverspec/helper/configuration.rb +1 -0
- data/lib/serverspec/type/service.rb +9 -1
- data/lib/serverspec/version.rb +1 -1
- data/spec/backend/exec/configuration_spec.rb +12 -8
- data/spec/backend/ssh/configuration_spec.rb +21 -14
- data/spec/darwin/command_spec.rb +41 -6
- data/spec/darwin/commands_spec.rb +1 -8
- data/spec/darwin/cron_spec.rb +16 -3
- data/spec/darwin/default_gateway_spec.rb +11 -2
- data/spec/darwin/host_spec.rb +52 -6
- data/spec/darwin/port_spec.rb +7 -2
- data/spec/darwin/routing_table_spec.rb +115 -2
- data/spec/darwin/service_spec.rb +2 -0
- data/spec/debian/command_spec.rb +41 -6
- data/spec/debian/commands_spec.rb +5 -11
- data/spec/debian/cron_spec.rb +16 -3
- data/spec/debian/default_gateway_spec.rb +11 -2
- data/spec/debian/host_spec.rb +52 -6
- data/spec/debian/interface_spec.rb +9 -2
- data/spec/debian/iptables_spec.rb +16 -3
- data/spec/debian/linux_kernel_parameter_spec.rb +31 -4
- data/spec/debian/port_spec.rb +7 -2
- data/spec/debian/routing_table_spec.rb +115 -2
- data/spec/debian/service_spec.rb +3 -0
- data/spec/gentoo/command_spec.rb +41 -6
- data/spec/gentoo/commands_spec.rb +1 -11
- data/spec/gentoo/cron_spec.rb +16 -3
- data/spec/gentoo/default_gateway_spec.rb +11 -2
- data/spec/gentoo/host_spec.rb +52 -6
- data/spec/gentoo/interface_spec.rb +9 -2
- data/spec/gentoo/iptables_spec.rb +16 -3
- data/spec/gentoo/linux_kernel_parameter_spec.rb +31 -4
- data/spec/gentoo/port_spec.rb +7 -2
- data/spec/gentoo/routing_table_spec.rb +120 -0
- data/spec/gentoo/service_spec.rb +2 -0
- data/spec/redhat/command_spec.rb +41 -6
- data/spec/redhat/commands_spec.rb +5 -11
- data/spec/redhat/cron_spec.rb +16 -3
- data/spec/redhat/default_gateway_spec.rb +11 -2
- data/spec/redhat/host_spec.rb +52 -6
- data/spec/redhat/interface_spec.rb +9 -2
- data/spec/redhat/iptables_spec.rb +16 -3
- data/spec/redhat/linux_kernel_parameter_spec.rb +31 -4
- data/spec/redhat/port_spec.rb +7 -2
- data/spec/redhat/routing_table_spec.rb +115 -2
- data/spec/redhat/service_spec.rb +3 -0
- data/spec/smartos/commands_spec.rb +1 -30
- data/spec/solaris/command_spec.rb +41 -6
- data/spec/solaris/commands_spec.rb +1 -35
- data/spec/solaris/cron_spec.rb +16 -3
- data/spec/solaris/default_gateway_spec.rb +11 -2
- data/spec/solaris/host_spec.rb +52 -6
- data/spec/solaris/port_spec.rb +7 -2
- data/spec/solaris/routing_table_spec.rb +115 -2
- data/spec/solaris/service_spec.rb +2 -0
- data/spec/spec_helper.rb +36 -2
- data/spec/support/shared_commands_examples.rb +11 -69
- data/spec/support/shared_service_examples.rb +48 -0
- metadata +4 -20
- data/spec/support/shared_command_examples.rb +0 -77
- data/spec/support/shared_cron_examples.rb +0 -23
- data/spec/support/shared_default_gateway_examples.rb +0 -13
- data/spec/support/shared_host_examples.rb +0 -53
- data/spec/support/shared_interface_examples.rb +0 -12
- data/spec/support/shared_iptables_examples.rb +0 -23
- data/spec/support/shared_linux_kernel_parameter_examples.rb +0 -41
- data/spec/support/shared_port_examples.rb +0 -11
- data/spec/support/shared_routing_table_examples.rb +0 -118
@@ -2,12 +2,47 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Solaris
|
4
4
|
|
5
|
-
describe '
|
6
|
-
|
7
|
-
|
5
|
+
describe command('cat /etc/resolv.conf') do
|
6
|
+
let(:stdout) { "nameserver 127.0.0.1\r\n" }
|
7
|
+
it { should return_stdout("nameserver 127.0.0.1") }
|
8
|
+
its(:command) { should eq 'cat /etc/resolv.conf' }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'complete matching of stdout' do
|
12
|
+
context command('cat /etc/resolv.conf') do
|
13
|
+
let(:stdout) { "foocontent-should-be-includedbar\r\n" }
|
14
|
+
it { should_not return_stdout('content-should-be-included') }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'regexp matching of stdout' do
|
19
|
+
context command('cat /etc/resolv.conf') do
|
20
|
+
let(:stdout) { "nameserver 127.0.0.1\r\n" }
|
21
|
+
it { should return_stdout(/127\.0\.0\.1/) }
|
22
|
+
end
|
23
|
+
end
|
8
24
|
|
9
|
-
|
10
|
-
|
25
|
+
describe command('cat /etc/resolv.conf') do
|
26
|
+
let(:stdout) { "No such file or directory\r\n" }
|
27
|
+
it { should return_stderr("No such file or directory") }
|
28
|
+
its(:command) { should eq 'cat /etc/resolv.conf' }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'complete matching of stderr' do
|
32
|
+
context command('cat /etc/resolv.conf') do
|
33
|
+
let(:stdout) { "No such file or directory\r\n" }
|
34
|
+
it { should_not return_stdout('file') }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'regexp matching of stderr' do
|
39
|
+
context command('cat /etc/resolv.conf') do
|
40
|
+
let(:stdout) { "No such file or directory\r\n" }
|
41
|
+
it { should return_stderr(/file/) }
|
42
|
+
end
|
43
|
+
end
|
11
44
|
|
12
|
-
|
45
|
+
describe command('cat /etc/resolv.conf') do
|
46
|
+
it { should return_exit_status 0 }
|
47
|
+
its(:command) { should eq 'cat /etc/resolv.conf' }
|
13
48
|
end
|
@@ -18,15 +18,13 @@ describe 'Serverspec commands of Solaris family' do
|
|
18
18
|
|
19
19
|
it_behaves_like 'support command check_mounted', '/'
|
20
20
|
|
21
|
-
it_behaves_like 'support command check_routing_table', '192.168.100.1/24'
|
22
|
-
it_behaves_like 'support command check_resolvable'
|
23
|
-
|
24
21
|
it_behaves_like 'support command check_user', 'root'
|
25
22
|
it_behaves_like 'support command check_user', 'wheel'
|
26
23
|
|
27
24
|
it_behaves_like 'support command check_file_md5checksum', '/etc/passewd', '96c8c50f81a29965f7af6de371ab4250'
|
28
25
|
|
29
26
|
it_behaves_like 'support command check_running_under_supervisor', 'httpd'
|
27
|
+
it_behaves_like 'support command check_monitored_by_monit', 'unicorn'
|
30
28
|
it_behaves_like 'support command check_process', 'httpd'
|
31
29
|
|
32
30
|
it_behaves_like 'support command check_file_contain', '/etc/passwd', 'root'
|
@@ -84,28 +82,11 @@ describe 'check_file_contain_within' do
|
|
84
82
|
end
|
85
83
|
end
|
86
84
|
|
87
|
-
describe 'check_listening' do
|
88
|
-
subject { commands.check_listening(80) }
|
89
|
-
it { should eq "netstat -an 2> /dev/null | egrep 'LISTEN|Idle' | grep -- .80\\ " }
|
90
|
-
end
|
91
|
-
|
92
85
|
describe 'check_running' do
|
93
86
|
subject { commands.check_running('httpd') }
|
94
87
|
it { should eq "svcs -l httpd status 2> /dev/null |grep -wx '^state.*online$'" }
|
95
88
|
end
|
96
89
|
|
97
|
-
describe 'check_cron_entry' do
|
98
|
-
context 'specify root user' do
|
99
|
-
subject { commands.check_cron_entry('root', '* * * * * /usr/local/bin/batch.sh') }
|
100
|
-
it { should eq 'crontab -l root | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'no specified user' do
|
104
|
-
subject { commands.check_cron_entry(nil, '* * * * * /usr/local/bin/batch.sh') }
|
105
|
-
it { should eq 'crontab -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
90
|
describe 'check_belonging_group' do
|
110
91
|
subject { commands.check_belonging_group('root', 'wheel') }
|
111
92
|
it { should eq "id -Gn root | grep -- wheel" }
|
@@ -174,18 +155,3 @@ describe 'check_access_by_user' do
|
|
174
155
|
it { should eq 'su dummyuser3 -c "test -x /tmp/somethingx"' }
|
175
156
|
end
|
176
157
|
end
|
177
|
-
|
178
|
-
describe 'check_reachable' do
|
179
|
-
context "connect with name from /etc/services to localhost" do
|
180
|
-
subject { commands.check_reachable('localhost', 'ssh', 'tcp', 1) }
|
181
|
-
it { should eq "nc -vvvvzt -w 1 localhost ssh" }
|
182
|
-
end
|
183
|
-
context "connect with ip and port 11111 and timeout of 5" do
|
184
|
-
subject { commands.check_reachable('127.0.0.1', '11111', 'udp', 5) }
|
185
|
-
it { should eq "nc -vvvvzu -w 5 127.0.0.1 11111" }
|
186
|
-
end
|
187
|
-
context "do a ping" do
|
188
|
-
subject { commands.check_reachable('127.0.0.1', nil, 'icmp', 1) }
|
189
|
-
it { should eq "ping -n 127.0.0.1 1" }
|
190
|
-
end
|
191
|
-
end
|
data/spec/solaris/cron_spec.rb
CHANGED
@@ -2,7 +2,20 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Solaris
|
4
4
|
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
5
|
+
describe cron do
|
6
|
+
it { should have_entry '* * * * * /usr/local/bin/batch.sh' }
|
7
|
+
its(:command) { should eq 'crontab -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe cron do
|
11
|
+
it { should_not have_entry 'invalid entry' }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe cron do
|
15
|
+
it { should have_entry('* * * * * /usr/local/bin/batch.sh').with_user('root') }
|
16
|
+
its(:command) { should eq 'crontab -l root | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe cron do
|
20
|
+
it { should_not have_entry('* * * * * /usr/local/bin/batch.sh').with_user('invalid-user') }
|
8
21
|
end
|
@@ -2,6 +2,15 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Solaris
|
4
4
|
|
5
|
-
describe
|
6
|
-
|
5
|
+
describe default_gateway do
|
6
|
+
let(:stdout) { "default via 192.168.1.1 dev eth1 \r\n" }
|
7
|
+
|
8
|
+
its(:ipaddress) { should eq '192.168.1.1' }
|
9
|
+
its(:command) { should eq "ip route | grep -E '^default |^default '" }
|
10
|
+
|
11
|
+
its(:interface) { should eq 'eth1' }
|
12
|
+
its(:command) { should eq "ip route | grep -E '^default |^default '" }
|
13
|
+
|
14
|
+
its(:ipaddress) { should_not eq '192.168.1.2' }
|
15
|
+
its(:interface) { should_not eq 'eth0' }
|
7
16
|
end
|
data/spec/solaris/host_spec.rb
CHANGED
@@ -2,11 +2,57 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Solaris
|
4
4
|
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
5
|
+
describe host('127.0.0.1') do
|
6
|
+
it { should be_resolvable }
|
7
|
+
its(:command) { should eq "getent hosts 127.0.0.1" }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe host('invalid-name') do
|
11
|
+
it { should_not be_resolvable }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe host('127.0.0.1') do
|
15
|
+
it { should be_resolvable.by('hosts') }
|
16
|
+
its(:command) { should eq "grep -w -- 127.0.0.1 /etc/hosts" }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe host('invalid-name') do
|
20
|
+
it { should_not be_resolvable.by('hosts') }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe host('127.0.0.1') do
|
24
|
+
it { should be_resolvable.by('dns') }
|
25
|
+
its(:command) { should eq "nslookup -timeout=1 127.0.0.1" }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe host('invalid-name') do
|
29
|
+
it { should_not be_resolvable.by('dns') }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe host('127.0.0.1') do
|
33
|
+
it { should be_reachable }
|
34
|
+
its(:command) { should eq "ping -n 127.0.0.1 5" }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe host('invalid-host') do
|
38
|
+
it { should_not be_reachable }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe host('127.0.0.1') do
|
42
|
+
it { should be_reachable.with(:proto => "icmp", :timeout=> 1) }
|
43
|
+
its(:command) { should eq "ping -n 127.0.0.1 1" }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe host('127.0.0.1') do
|
47
|
+
it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) }
|
48
|
+
its(:command) { should eq "nc -vvvvzt -w 1 127.0.0.1 22" }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe host('127.0.0.1') do
|
52
|
+
it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) }
|
53
|
+
its(:command) { should eq "nc -vvvvzu -w 1 127.0.0.1 53" }
|
54
|
+
end
|
8
55
|
|
9
|
-
|
10
|
-
|
11
|
-
it_behaves_like 'support host be_resolvable by matcher', 'localhost', 'dns'
|
56
|
+
describe host('invalid-host') do
|
57
|
+
it { should_not be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) }
|
12
58
|
end
|
data/spec/solaris/port_spec.rb
CHANGED
@@ -2,6 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Solaris
|
4
4
|
|
5
|
-
describe
|
6
|
-
|
5
|
+
describe port(80) do
|
6
|
+
it { should be_listening }
|
7
|
+
its(:command) { should eq %q!netstat -an 2> /dev/null | egrep 'LISTEN|Idle' | grep -- .80\\ ! }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe port('invalid') do
|
11
|
+
it { should_not be_listening }
|
7
12
|
end
|
@@ -2,6 +2,119 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Solaris
|
4
4
|
|
5
|
-
describe
|
6
|
-
|
5
|
+
describe routing_table do
|
6
|
+
let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" }
|
7
|
+
it { should have_entry( :destination => '192.168.100.0/24' ) }
|
8
|
+
its(:command) { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe routing_table do
|
12
|
+
let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" }
|
13
|
+
it { should_not have_entry( :destination => '192.168.100.100/24' ) }
|
14
|
+
its(:command) { should eq "ip route | grep -E '^192.168.100.100/24 |^default '" }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe routing_table do
|
18
|
+
let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" }
|
19
|
+
it do
|
20
|
+
should have_entry(
|
21
|
+
:destination => '192.168.100.0/24',
|
22
|
+
:gateway => '192.168.100.1'
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it do
|
27
|
+
should have_entry(
|
28
|
+
:destination => '192.168.100.0/24',
|
29
|
+
:gateway => '192.168.100.1',
|
30
|
+
:interface => 'eth1'
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
it do
|
35
|
+
should_not have_entry(
|
36
|
+
:gateway => '192.168.100.1',
|
37
|
+
:interface => 'eth1'
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
it do
|
42
|
+
should_not have_entry(
|
43
|
+
:destination => '192.168.100.0/32',
|
44
|
+
:gateway => '192.168.100.1',
|
45
|
+
:interface => 'eth1'
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe routing_table do
|
51
|
+
let(:stdout) { "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n" }
|
52
|
+
it { should have_entry( :destination => '192.168.200.0/24' ) }
|
53
|
+
it { should_not have_entry( :destination => '192.168.200.200/24' ) }
|
54
|
+
|
55
|
+
it do
|
56
|
+
should have_entry(
|
57
|
+
:destination => '192.168.200.0/24',
|
58
|
+
:gateway => '192.168.200.1'
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
it do
|
63
|
+
should have_entry(
|
64
|
+
:destination => '192.168.200.0/24',
|
65
|
+
:gateway => '192.168.200.1',
|
66
|
+
:interface => 'eth0'
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
it do
|
71
|
+
should_not have_entry(
|
72
|
+
:gateway => '192.168.200.1',
|
73
|
+
:interface => 'eth0'
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
it do
|
78
|
+
should_not have_entry(
|
79
|
+
:destination => '192.168.200.0/32',
|
80
|
+
:gateway => '192.168.200.1',
|
81
|
+
:interface => 'eth0'
|
82
|
+
)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe routing_table do
|
87
|
+
let(:stdout) { "default via 10.0.2.2 dev eth0 \r\n" }
|
88
|
+
it { should have_entry( :destination => 'default' ) }
|
89
|
+
it { should_not have_entry( :destination => 'defaulth' ) }
|
90
|
+
|
91
|
+
it do
|
92
|
+
should have_entry(
|
93
|
+
:destination => 'default',
|
94
|
+
:gateway => '10.0.2.2'
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
it do
|
99
|
+
should have_entry(
|
100
|
+
:destination => 'default',
|
101
|
+
:gateway => '10.0.2.2',
|
102
|
+
:interface => 'eth0'
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
it do
|
107
|
+
should_not have_entry(
|
108
|
+
:gateway => '10.0.2.2',
|
109
|
+
:interface => 'eth0'
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
it do
|
114
|
+
should_not have_entry(
|
115
|
+
:destination => 'default',
|
116
|
+
:gateway => '10.0.2.1',
|
117
|
+
:interface => 'eth0'
|
118
|
+
)
|
119
|
+
end
|
7
120
|
end
|
@@ -8,4 +8,6 @@ describe 'Serverspec service matchers of Solaris' do
|
|
8
8
|
it_behaves_like 'support service running matcher', 'sshd'
|
9
9
|
it_behaves_like 'support service running under supervisor matcher', 'sshd'
|
10
10
|
it_behaves_like 'support service running under unimplemented matcher', 'sshd'
|
11
|
+
it_behaves_like 'support service monitored by monit matcher', 'unicorn'
|
12
|
+
it_behaves_like 'support service monitored by unimplemented matcher', 'unicorn'
|
11
13
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,6 +11,38 @@ module Serverspec
|
|
11
11
|
module Backend
|
12
12
|
class Exec
|
13
13
|
def run_command(cmd)
|
14
|
+
cmd = build_command(cmd)
|
15
|
+
cmd = add_pre_command(cmd)
|
16
|
+
if @example
|
17
|
+
@example.metadata[:subject].set_command(cmd)
|
18
|
+
end
|
19
|
+
|
20
|
+
if cmd =~ /invalid/
|
21
|
+
{
|
22
|
+
:stdout => ::Serverspec.configuration.stdout,
|
23
|
+
:stderr => ::Serverspec.configuration.stderr,
|
24
|
+
:exit_status => 1,
|
25
|
+
:exit_signal => nil
|
26
|
+
}
|
27
|
+
else
|
28
|
+
{
|
29
|
+
:stdout => ::Serverspec.configuration.stdout,
|
30
|
+
:stderr => ::Serverspec.configuration.stderr,
|
31
|
+
:exit_status => 0,
|
32
|
+
:exit_signal => nil
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Ssh
|
39
|
+
def run_command(cmd)
|
40
|
+
cmd = build_command(cmd)
|
41
|
+
cmd = add_pre_command(cmd)
|
42
|
+
if @example
|
43
|
+
@example.metadata[:subject].set_command(cmd)
|
44
|
+
end
|
45
|
+
|
14
46
|
if cmd =~ /invalid/
|
15
47
|
{
|
16
48
|
:stdout => ::Serverspec.configuration.stdout,
|
@@ -32,9 +64,11 @@ module Serverspec
|
|
32
64
|
|
33
65
|
module Type
|
34
66
|
class Base
|
67
|
+
def set_command(command)
|
68
|
+
@command = command
|
69
|
+
end
|
35
70
|
def command
|
36
|
-
|
37
|
-
backend.add_pre_command(cmd)
|
71
|
+
@command
|
38
72
|
end
|
39
73
|
end
|
40
74
|
end
|
@@ -48,41 +48,6 @@ shared_examples_for 'support command check_mounted' do |path|
|
|
48
48
|
it { should eq "mount | grep -w -- on\\ #{path}" }
|
49
49
|
end
|
50
50
|
|
51
|
-
shared_examples_for 'support command check_routing_table' do |dest|
|
52
|
-
subject { commands.check_routing_table(dest) }
|
53
|
-
it { should eq "ip route | grep -E '^#{dest} |^default '" }
|
54
|
-
end
|
55
|
-
|
56
|
-
shared_examples_for 'support command check_reachable' do
|
57
|
-
context "connect with name from /etc/services to localhost" do
|
58
|
-
subject { commands.check_reachable('localhost', 'ssh', 'tcp', 1) }
|
59
|
-
it { should eq "nc -vvvvzt localhost ssh -w 1" }
|
60
|
-
end
|
61
|
-
context "connect with ip and port 11111 and timeout of 5" do
|
62
|
-
subject { commands.check_reachable('127.0.0.1', '11111', 'udp', 5) }
|
63
|
-
it { should eq "nc -vvvvzu 127.0.0.1 11111 -w 5" }
|
64
|
-
end
|
65
|
-
context "do a ping" do
|
66
|
-
subject { commands.check_reachable('127.0.0.1', nil, 'icmp', 1) }
|
67
|
-
it { should eq "ping -n 127.0.0.1 -w 1 -c 2" }
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
shared_examples_for 'support command check_resolvable' do
|
72
|
-
context "resolve localhost by hosts" do
|
73
|
-
subject { commands.check_resolvable('localhost', 'hosts') }
|
74
|
-
it { should eq "grep -w -- localhost /etc/hosts" }
|
75
|
-
end
|
76
|
-
context "resolve localhost by dns" do
|
77
|
-
subject { commands.check_resolvable('localhost', 'dns') }
|
78
|
-
it { should eq "nslookup -timeout=1 localhost" }
|
79
|
-
end
|
80
|
-
context "resolve localhost with default settings" do
|
81
|
-
subject { commands.check_resolvable('localhost',nil) }
|
82
|
-
it { should eq 'getent hosts localhost' }
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
51
|
shared_examples_for 'support command check_user' do |user|
|
87
52
|
subject { commands.check_user(user) }
|
88
53
|
it { should eq "id #{user}" }
|
@@ -93,11 +58,6 @@ shared_examples_for 'support command check_group' do |group|
|
|
93
58
|
it { should eq "getent group | grep -wq -- #{group}" }
|
94
59
|
end
|
95
60
|
|
96
|
-
shared_examples_for 'support command check_listening' do |port|
|
97
|
-
subject { commands.check_listening(port) }
|
98
|
-
it { should eq "netstat -tunl | grep -- :#{port}\\ " }
|
99
|
-
end
|
100
|
-
|
101
61
|
shared_examples_for 'support command check_file_md5checksum' do |file, md5sum|
|
102
62
|
subject { commands.check_file_md5checksum(file, md5sum) }
|
103
63
|
it { should eq "md5sum #{file} | grep -iw -- ^#{md5sum}" }
|
@@ -108,6 +68,17 @@ shared_examples_for 'support command check_running_under_supervisor' do |service
|
|
108
68
|
it { should eq "supervisorctl status #{service}" }
|
109
69
|
end
|
110
70
|
|
71
|
+
|
72
|
+
shared_examples_for 'support command check_running_under_upstart' do |service|
|
73
|
+
subject { commands.check_running_under_upstart(service) }
|
74
|
+
it { should eq "initctl status #{service}" }
|
75
|
+
end
|
76
|
+
|
77
|
+
shared_examples_for 'support command check_monitored_by_monit' do |service|
|
78
|
+
subject { commands.check_monitored_by_monit(service) }
|
79
|
+
it { should eq "monit status" }
|
80
|
+
end
|
81
|
+
|
111
82
|
shared_examples_for 'support command check_process' do |process|
|
112
83
|
subject { commands.check_process(process) }
|
113
84
|
it { should eq "ps aux | grep -w -- #{process} | grep -qv grep" }
|
@@ -155,18 +126,6 @@ shared_examples_for 'support command check_grouped' do |file, group|
|
|
155
126
|
it { should eq "stat -c %G #{file} | grep -- \\^#{group}\\$" }
|
156
127
|
end
|
157
128
|
|
158
|
-
shared_examples_for 'support command check_cron_entry' do
|
159
|
-
context 'specify root user' do
|
160
|
-
subject { commands.check_cron_entry('root', '* * * * * /usr/local/bin/batch.sh') }
|
161
|
-
it { should eq 'crontab -u root -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
162
|
-
end
|
163
|
-
|
164
|
-
context 'no specified user' do
|
165
|
-
subject { commands.check_cron_entry(nil, '* * * * * /usr/local/bin/batch.sh') }
|
166
|
-
it { should eq 'crontab -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
129
|
shared_examples_for 'support command check_link' do |link, target|
|
171
130
|
subject { commands.check_link(link, target) }
|
172
131
|
it { should eq "stat -c %N #{link} | grep -- #{target}" }
|
@@ -215,18 +174,6 @@ shared_examples_for 'support command check_authorized_key' do
|
|
215
174
|
end
|
216
175
|
end
|
217
176
|
|
218
|
-
shared_examples_for 'support command check_iptables' do
|
219
|
-
context 'check a rule without a table and a chain' do
|
220
|
-
subject { commands.check_iptables_rule('-P INPUT ACCEPT') }
|
221
|
-
it { should eq "iptables -S | grep -- -P\\ INPUT\\ ACCEPT" }
|
222
|
-
end
|
223
|
-
|
224
|
-
context 'chack a rule with a table and a chain' do
|
225
|
-
subject { commands.check_iptables_rule('-P INPUT ACCEPT', 'mangle', 'INPUT') }
|
226
|
-
it { should eq "iptables -t mangle -S INPUT | grep -- -P\\ INPUT\\ ACCEPT" }
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
177
|
shared_examples_for 'support command check_selinux' do
|
231
178
|
context 'enforcing' do
|
232
179
|
subject { commands.check_selinux('enforcing') }
|
@@ -270,8 +217,3 @@ shared_examples_for 'support command check_kernel_module_loaded' do |name|
|
|
270
217
|
subject { commands.check_kernel_module_loaded(name) }
|
271
218
|
it { should eq "lsmod | grep ^#{name}" }
|
272
219
|
end
|
273
|
-
|
274
|
-
shared_examples_for 'support command get_interface_speed_of' do |name|
|
275
|
-
subject { commands.get_interface_speed_of(name) }
|
276
|
-
it { should eq "ethtool eth0 | grep Speed | gawk '{print gensub(/Speed: ([0-9]+)Mb\\/s/,\"\\\\1\",\"\")}'" }
|
277
|
-
end
|
@@ -57,6 +57,24 @@ shared_examples_for 'support service running under supervisor matcher' do |valid
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
shared_examples_for 'support service running under upstart matcher' do |valid_service|
|
61
|
+
describe 'be_running.under("upstart")' do
|
62
|
+
describe service(valid_service) do
|
63
|
+
let(:stdout) { "#{valid_service} running\r\n" }
|
64
|
+
it { should be_running.under('upstart') }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe service(valid_service) do
|
68
|
+
let(:stdout) { "#{valid_service} waiting\r\n" }
|
69
|
+
it { should_not be_running.under('upstart') }
|
70
|
+
end
|
71
|
+
|
72
|
+
describe service('invalid-daemon') do
|
73
|
+
it { should_not be_running.under('upstart') }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
60
78
|
shared_examples_for 'support service running under unimplemented matcher' do |valid_service|
|
61
79
|
describe 'be_running.under("not implemented")' do
|
62
80
|
describe service(valid_service) do
|
@@ -68,3 +86,33 @@ shared_examples_for 'support service running under unimplemented matcher' do |va
|
|
68
86
|
end
|
69
87
|
end
|
70
88
|
end
|
89
|
+
|
90
|
+
shared_examples_for 'support service monitored by monit matcher' do |valid_service|
|
91
|
+
describe 'be_monitored_by("monit")' do
|
92
|
+
describe service(valid_service) do
|
93
|
+
let(:stdout) { "Process '#{valid_service}'\r\n status running\r\n monitoring status monitored" }
|
94
|
+
it { should be_monitored_by('monit') }
|
95
|
+
end
|
96
|
+
|
97
|
+
describe service(valid_service) do
|
98
|
+
let(:stdout) { "Process '#{valid_service}'\r\n status not monitored\r\n monitoring status not monitored" }
|
99
|
+
it { should_not be_monitored_by('monit') }
|
100
|
+
end
|
101
|
+
|
102
|
+
describe service('invalid-daemon') do
|
103
|
+
it { should_not be_monitored_by('monit') }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
shared_examples_for 'support service monitored by unimplemented matcher' do |valid_service|
|
109
|
+
describe 'be_monitored_by("not implemented")' do
|
110
|
+
describe service(valid_service) do
|
111
|
+
it {
|
112
|
+
expect {
|
113
|
+
should be_monitored_by('not implemented')
|
114
|
+
}.to raise_error(ArgumentError, %r/\A`be_monitored_by` matcher doesn\'t support/)
|
115
|
+
}
|
116
|
+
end
|
117
|
+
end
|
118
|
+
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.17
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-ssh
|
@@ -255,6 +255,7 @@ files:
|
|
255
255
|
- spec/gentoo/linux_kernel_parameter_spec.rb
|
256
256
|
- spec/gentoo/package_spec.rb
|
257
257
|
- spec/gentoo/port_spec.rb
|
258
|
+
- spec/gentoo/routing_table_spec.rb
|
258
259
|
- spec/gentoo/selinux_spec.rb
|
259
260
|
- spec/gentoo/service_spec.rb
|
260
261
|
- spec/gentoo/user_spec.rb
|
@@ -295,20 +296,11 @@ files:
|
|
295
296
|
- spec/solaris/user_spec.rb
|
296
297
|
- spec/solaris/zfs_spec.rb
|
297
298
|
- spec/spec_helper.rb
|
298
|
-
- spec/support/shared_command_examples.rb
|
299
299
|
- spec/support/shared_commands_examples.rb
|
300
|
-
- spec/support/shared_cron_examples.rb
|
301
|
-
- spec/support/shared_default_gateway_examples.rb
|
302
300
|
- spec/support/shared_file_examples.rb
|
303
301
|
- spec/support/shared_group_examples.rb
|
304
|
-
- spec/support/shared_host_examples.rb
|
305
|
-
- spec/support/shared_interface_examples.rb
|
306
|
-
- spec/support/shared_iptables_examples.rb
|
307
302
|
- spec/support/shared_kernel_module_examples.rb
|
308
|
-
- spec/support/shared_linux_kernel_parameter_examples.rb
|
309
303
|
- spec/support/shared_package_examples.rb
|
310
|
-
- spec/support/shared_port_examples.rb
|
311
|
-
- spec/support/shared_routing_table_examples.rb
|
312
304
|
- spec/support/shared_selinux_examples.rb
|
313
305
|
- spec/support/shared_service_examples.rb
|
314
306
|
- spec/support/shared_user_examples.rb
|
@@ -382,6 +374,7 @@ test_files:
|
|
382
374
|
- spec/gentoo/linux_kernel_parameter_spec.rb
|
383
375
|
- spec/gentoo/package_spec.rb
|
384
376
|
- spec/gentoo/port_spec.rb
|
377
|
+
- spec/gentoo/routing_table_spec.rb
|
385
378
|
- spec/gentoo/selinux_spec.rb
|
386
379
|
- spec/gentoo/service_spec.rb
|
387
380
|
- spec/gentoo/user_spec.rb
|
@@ -422,20 +415,11 @@ test_files:
|
|
422
415
|
- spec/solaris/user_spec.rb
|
423
416
|
- spec/solaris/zfs_spec.rb
|
424
417
|
- spec/spec_helper.rb
|
425
|
-
- spec/support/shared_command_examples.rb
|
426
418
|
- spec/support/shared_commands_examples.rb
|
427
|
-
- spec/support/shared_cron_examples.rb
|
428
|
-
- spec/support/shared_default_gateway_examples.rb
|
429
419
|
- spec/support/shared_file_examples.rb
|
430
420
|
- spec/support/shared_group_examples.rb
|
431
|
-
- spec/support/shared_host_examples.rb
|
432
|
-
- spec/support/shared_interface_examples.rb
|
433
|
-
- spec/support/shared_iptables_examples.rb
|
434
421
|
- spec/support/shared_kernel_module_examples.rb
|
435
|
-
- spec/support/shared_linux_kernel_parameter_examples.rb
|
436
422
|
- spec/support/shared_package_examples.rb
|
437
|
-
- spec/support/shared_port_examples.rb
|
438
|
-
- spec/support/shared_routing_table_examples.rb
|
439
423
|
- spec/support/shared_selinux_examples.rb
|
440
424
|
- spec/support/shared_service_examples.rb
|
441
425
|
- spec/support/shared_user_examples.rb
|