serverspec 0.6.16 → 0.6.17
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.
- 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
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Serverspec [](http://badge.fury.io/rb/serverspec) [](http://badge.fury.io/rb/serverspec) [](http://travis-ci.org/serverspec/serverspec)
|
2
2
|
|
3
3
|
RSpec tests for your servers configured by Puppet, Chef or anything else
|
4
4
|
|
@@ -73,6 +73,22 @@ module Serverspec
|
|
73
73
|
ret[:exit_status] == 0 && ret[:stdout] =~ /RUNNING/
|
74
74
|
end
|
75
75
|
|
76
|
+
def check_running_under_upstart(process)
|
77
|
+
ret = run_command(commands.check_running_under_upstart(process))
|
78
|
+
ret[:exit_status] == 0 && ret[:stdout] =~ /running/
|
79
|
+
end
|
80
|
+
|
81
|
+
def check_monitored_by_monit(process)
|
82
|
+
ret = run_command(commands.check_monitored_by_monit(process))
|
83
|
+
return false unless ret[:stdout] != nil && ret[:exit_status] == 0
|
84
|
+
|
85
|
+
retlines = ret[:stdout].split(/[\r\n]+/).map(&:strip)
|
86
|
+
proc_index = retlines.index("Process '#{process}'")
|
87
|
+
return false unless proc_index
|
88
|
+
|
89
|
+
retlines[proc_index+2].match(/\Amonitoring status\s+monitored\Z/) != nil
|
90
|
+
end
|
91
|
+
|
76
92
|
def check_readable(file, by_whom)
|
77
93
|
mode = sprintf('%04s',run_command(commands.get_mode(file))[:stdout].strip)
|
78
94
|
mode = mode.split('')
|
@@ -68,7 +68,7 @@ module Serverspec
|
|
68
68
|
"getent group | grep -wq -- #{escape(group)}"
|
69
69
|
end
|
70
70
|
|
71
|
-
def check_installed(package)
|
71
|
+
def check_installed(package, version=nil)
|
72
72
|
raise NotImplementedError.new
|
73
73
|
end
|
74
74
|
|
@@ -85,6 +85,14 @@ module Serverspec
|
|
85
85
|
"supervisorctl status #{escape(service)}"
|
86
86
|
end
|
87
87
|
|
88
|
+
def check_running_under_upstart(service)
|
89
|
+
"initctl status #{escape(service)}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def check_monitored_by_monit(service)
|
93
|
+
"monit status"
|
94
|
+
end
|
95
|
+
|
88
96
|
def check_process(process)
|
89
97
|
"ps aux | grep -w -- #{escape(process)} | grep -qv grep"
|
90
98
|
end
|
@@ -10,7 +10,7 @@ module Serverspec
|
|
10
10
|
check_method = "check_running_under_#{under}".to_sym
|
11
11
|
|
12
12
|
unless backend.respond_to?(check_method)
|
13
|
-
raise ArgumentError.new("`be_running` matcher doesn't support #{
|
13
|
+
raise ArgumentError.new("`be_running` matcher doesn't support #{under}")
|
14
14
|
end
|
15
15
|
|
16
16
|
backend.send(check_method, @name)
|
@@ -19,6 +19,14 @@ module Serverspec
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
def monitored_by?(monitor)
|
23
|
+
check_method = "check_monitored_by_#{monitor}".to_sym
|
24
|
+
unless monitor && backend.respond_to?(check_method)
|
25
|
+
raise ArgumentError.new("`be_monitored_by` matcher doesn't support #{monitor}")
|
26
|
+
end
|
27
|
+
backend.send(check_method, @name)
|
28
|
+
end
|
29
|
+
|
22
30
|
def has_property?(property)
|
23
31
|
backend.check_svcprops(@name, property)
|
24
32
|
end
|
data/lib/serverspec/version.rb
CHANGED
@@ -5,29 +5,33 @@ include Serverspec::Helper::Base
|
|
5
5
|
include Serverspec::Helper::Exec
|
6
6
|
|
7
7
|
describe 'configurations are not set' do
|
8
|
-
context
|
9
|
-
|
8
|
+
context file('/etc/passwd') do
|
9
|
+
it { should be_file }
|
10
|
+
its(:command) { should eq 'test -f /etc/passwd' }
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
14
|
describe 'path is set' do
|
14
15
|
let(:path) { '/sbin:/usr/sbin' }
|
15
|
-
context
|
16
|
-
|
16
|
+
context file('/etc/passwd') do
|
17
|
+
it { should be_file }
|
18
|
+
its(:command) { should eq 'env PATH=/sbin:/usr/sbin:$PATH test -f /etc/passwd' }
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
22
|
describe 'pre_command is set' do
|
21
23
|
let(:pre_command) { 'source ~/.zshrc' }
|
22
|
-
context
|
23
|
-
|
24
|
+
context file('/etc/passwd') do
|
25
|
+
it { should be_file }
|
26
|
+
its(:command) { should eq 'source ~/.zshrc && test -f /etc/passwd' }
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
30
|
describe 'path and pre_command are set' do
|
28
31
|
let(:path) { '/sbin:/usr/sbin' }
|
29
32
|
let(:pre_command) { 'source ~/.zshrc' }
|
30
|
-
context
|
31
|
-
|
33
|
+
context file('/etc/passwd') do
|
34
|
+
it { should be_file }
|
35
|
+
its(:command) { should eq 'env PATH=/sbin:/usr/sbin:$PATH source ~/.zshrc && env PATH=/sbin:/usr/sbin:$PATH test -f /etc/passwd' }
|
32
36
|
end
|
33
37
|
end
|
@@ -14,8 +14,9 @@ describe 'configurations are not set' do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
context
|
18
|
-
|
17
|
+
context file('/etc/passwd') do
|
18
|
+
it { should be_file }
|
19
|
+
its(:command) { should eq 'test -f /etc/passwd' }
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -28,8 +29,9 @@ describe 'path is set' do
|
|
28
29
|
end
|
29
30
|
|
30
31
|
let(:path) { '/sbin:/usr/sbin' }
|
31
|
-
context
|
32
|
-
|
32
|
+
context file('/etc/passwd') do
|
33
|
+
it { should be_file }
|
34
|
+
its(:command) { should eq 'env PATH=/sbin:/usr/sbin:$PATH test -f /etc/passwd' }
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
@@ -42,8 +44,9 @@ describe 'pre_command is set and user is root' do
|
|
42
44
|
end
|
43
45
|
|
44
46
|
let(:pre_command) { 'source ~/.zshrc' }
|
45
|
-
context
|
46
|
-
|
47
|
+
context file('/etc/passwd') do
|
48
|
+
it { should be_file }
|
49
|
+
its(:command) { should eq 'source ~/.zshrc && test -f /etc/passwd' }
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
@@ -56,8 +59,9 @@ describe 'pre_command is set and user is non-root' do
|
|
56
59
|
end
|
57
60
|
|
58
61
|
let(:pre_command) { 'source ~/.zshrc' }
|
59
|
-
context
|
60
|
-
|
62
|
+
context file('/etc/passwd') do
|
63
|
+
it { should be_file }
|
64
|
+
its(:command) { should eq 'sudo source ~/.zshrc && sudo test -f /etc/passwd' }
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
@@ -69,8 +73,9 @@ describe 'pre_command is not set and user is non-root' do
|
|
69
73
|
end
|
70
74
|
end
|
71
75
|
|
72
|
-
context
|
73
|
-
|
76
|
+
context file('/etc/passwd') do
|
77
|
+
it { should be_file }
|
78
|
+
its(:command) { should eq 'sudo test -f /etc/passwd' }
|
74
79
|
end
|
75
80
|
end
|
76
81
|
|
@@ -85,8 +90,9 @@ describe 'path pre_command and set and user is non-root' do
|
|
85
90
|
|
86
91
|
let(:path) { '/sbin:/usr/sbin' }
|
87
92
|
let(:pre_command) { 'source ~/.zshrc' }
|
88
|
-
context
|
89
|
-
|
93
|
+
context file('/etc/passwd') do
|
94
|
+
it { should be_file }
|
95
|
+
its(:command) { should eq 'sudo env PATH=/sbin:/usr/sbin:$PATH source ~/.zshrc && sudo env PATH=/sbin:/usr/sbin:$PATH test -f /etc/passwd' }
|
90
96
|
end
|
91
97
|
end
|
92
98
|
|
@@ -100,7 +106,8 @@ describe 'path pre_command and set and user is non-root' do
|
|
100
106
|
|
101
107
|
let(:path) { '/sbin:/usr/sbin' }
|
102
108
|
let(:pre_command) { 'source ~/.zshrc' }
|
103
|
-
context
|
104
|
-
|
109
|
+
context file('/etc/passwd') do
|
110
|
+
it { should be_file }
|
111
|
+
its(:command) { should eq 'env PATH=/sbin:/usr/sbin:$PATH source ~/.zshrc && env PATH=/sbin:/usr/sbin:$PATH test -f /etc/passwd' }
|
105
112
|
end
|
106
113
|
end
|
data/spec/darwin/command_spec.rb
CHANGED
@@ -2,12 +2,47 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Darwin
|
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,23 +18,16 @@ describe 'Serverspec commands of Darwin 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_reachable'
|
23
|
-
it_behaves_like 'support command check_resolvable'
|
24
|
-
|
25
21
|
it_behaves_like 'support command check_user', 'root'
|
26
22
|
it_behaves_like 'support command check_user', 'wheel'
|
27
23
|
|
28
|
-
it_behaves_like 'support command check_listening', 80
|
29
|
-
|
30
24
|
it_behaves_like 'support command check_running_under_supervisor', 'httpd'
|
25
|
+
it_behaves_like 'support command check_monitored_by_monit', 'unicorn'
|
31
26
|
it_behaves_like 'support command check_process', 'httpd'
|
32
27
|
|
33
28
|
it_behaves_like 'support command check_file_contain', '/etc/passwd', 'root'
|
34
29
|
it_behaves_like 'support command check_file_contain_within'
|
35
30
|
|
36
|
-
it_behaves_like 'support command check_cron_entry'
|
37
|
-
|
38
31
|
it_behaves_like 'support command check_link', '/etc/system-release', '/etc/darwin-release'
|
39
32
|
|
40
33
|
it_behaves_like 'support command check_belonging_group', 'root', 'wheel'
|
data/spec/darwin/cron_spec.rb
CHANGED
@@ -2,7 +2,20 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Darwin
|
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 -u root -l | 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::Darwin
|
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/darwin/host_spec.rb
CHANGED
@@ -2,11 +2,57 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Darwin
|
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 -w 5 -c 2" }
|
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 -w 1 -c 2" }
|
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 127.0.0.1 22 -w 1" }
|
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 127.0.0.1 53 -w 1" }
|
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/darwin/port_spec.rb
CHANGED
@@ -2,6 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Darwin
|
4
4
|
|
5
|
-
describe
|
6
|
-
|
5
|
+
describe port(80) do
|
6
|
+
it { should be_listening }
|
7
|
+
its(:command) { should eq 'netstat -tunl | 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::Darwin
|
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
|
data/spec/darwin/service_spec.rb
CHANGED
@@ -6,4 +6,6 @@ describe 'Serverspec service matchers of Darwin family' do
|
|
6
6
|
it_behaves_like 'support service running matcher', 'sshd'
|
7
7
|
it_behaves_like 'support service running under supervisor matcher', 'sshd'
|
8
8
|
it_behaves_like 'support service running under unimplemented matcher', 'sshd'
|
9
|
+
it_behaves_like 'support service monitored by monit matcher', 'unicorn'
|
10
|
+
it_behaves_like 'support service monitored by unimplemented matcher', 'unicorn'
|
9
11
|
end
|
data/spec/debian/command_spec.rb
CHANGED
@@ -2,12 +2,47 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Serverspec::Helper::Debian
|
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,18 +18,17 @@ describe 'Serverspec commands of Debian 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_reachable'
|
23
|
-
it_behaves_like 'support command check_resolvable'
|
24
|
-
|
25
21
|
it_behaves_like 'support command check_user', 'root'
|
26
22
|
it_behaves_like 'support command check_user', 'wheel'
|
27
23
|
|
28
|
-
it_behaves_like 'support command check_listening', 80
|
29
|
-
|
30
24
|
it_behaves_like 'support command check_file_md5checksum', '/etc/passewd', '96c8c50f81a29965f7af6de371ab4250'
|
31
25
|
|
32
26
|
it_behaves_like 'support command check_running_under_supervisor', 'httpd'
|
27
|
+
|
28
|
+
it_behaves_like 'support command check_running_under_upstart', 'monit'
|
29
|
+
|
30
|
+
it_behaves_like 'support command check_monitored_by_monit', 'unicorn'
|
31
|
+
|
33
32
|
it_behaves_like 'support command check_process', 'httpd'
|
34
33
|
|
35
34
|
it_behaves_like 'support command check_file_contain', '/etc/passwd', 'root'
|
@@ -39,8 +38,6 @@ describe 'Serverspec commands of Debian family' do
|
|
39
38
|
it_behaves_like 'support command check_owner', '/etc/sudoers', 'root'
|
40
39
|
it_behaves_like 'support command check_grouped', '/etc/sudoers', 'wheel'
|
41
40
|
|
42
|
-
it_behaves_like 'support command check_cron_entry'
|
43
|
-
|
44
41
|
it_behaves_like 'support command check_link', '/etc/system-release', '/etc/redhat-release'
|
45
42
|
|
46
43
|
it_behaves_like 'support command check_belonging_group', 'root', 'wheel'
|
@@ -53,7 +50,6 @@ describe 'Serverspec commands of Debian family' do
|
|
53
50
|
|
54
51
|
it_behaves_like 'support command check_authorized_key'
|
55
52
|
|
56
|
-
it_behaves_like 'support command check_iptables'
|
57
53
|
it_behaves_like 'support command check_selinux'
|
58
54
|
|
59
55
|
it_behaves_like 'support command get_mode'
|
@@ -61,8 +57,6 @@ describe 'Serverspec commands of Debian family' do
|
|
61
57
|
it_behaves_like 'support command check_access_by_user'
|
62
58
|
|
63
59
|
it_behaves_like 'support command check_kernel_module_loaded', 'lp'
|
64
|
-
|
65
|
-
it_behaves_like 'support command get_interface_speed_of', 'eth0'
|
66
60
|
end
|
67
61
|
|
68
62
|
describe 'check_enabled' do
|