serverspec 0.6.6 → 0.6.7
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/lib/serverspec/attributes.rb +1 -1
- data/lib/serverspec/commands/base.rb +50 -42
- data/lib/serverspec/commands/darwin.rb +5 -7
- data/lib/serverspec/commands/debian.rb +3 -3
- data/lib/serverspec/commands/gentoo.rb +3 -3
- data/lib/serverspec/commands/linux.rb +4 -6
- data/lib/serverspec/commands/redhat.rb +11 -3
- data/lib/serverspec/commands/solaris.rb +16 -16
- data/lib/serverspec/helper/type.rb +1 -1
- data/lib/serverspec/subject.rb +1 -1
- data/lib/serverspec/type/service.rb +1 -1
- data/lib/serverspec/type/yumrepo.rb +13 -0
- data/lib/serverspec/version.rb +1 -1
- data/lib/serverspec.rb +4 -2
- data/spec/darwin/commands_spec.rb +3 -0
- data/spec/debian/commands_spec.rb +3 -0
- data/spec/debian/file_spec.rb +3 -0
- data/spec/gentoo/commands_spec.rb +3 -0
- data/spec/redhat/commands_spec.rb +13 -0
- data/spec/redhat/file_spec.rb +3 -0
- data/spec/redhat/yumrepo_spec.rb +25 -0
- data/spec/solaris/commands_spec.rb +3 -0
- data/spec/support/shared_commands_examples.rb +1 -1
- data/spec/support/shared_file_examples.rb +36 -0
- metadata +6 -3
@@ -5,24 +5,32 @@ module Serverspec
|
|
5
5
|
class Base
|
6
6
|
class NotImplementedError < Exception; end
|
7
7
|
|
8
|
-
def escape
|
8
|
+
def escape(target)
|
9
9
|
Shellwords.shellescape(target.to_s())
|
10
10
|
end
|
11
11
|
|
12
|
-
def check_enabled
|
12
|
+
def check_enabled(service)
|
13
13
|
raise NotImplementedError.new
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def check_yumrepo(repository)
|
17
|
+
raise NotImplementedError.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_yumrepo_enabled(repository)
|
21
|
+
raise NotImplementedError.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def check_mounted(path)
|
17
25
|
regexp = "on #{path}"
|
18
26
|
"mount | grep -w -- #{escape(regexp)}"
|
19
27
|
end
|
20
28
|
|
21
|
-
def check_routing_table
|
29
|
+
def check_routing_table(destination)
|
22
30
|
"ip route | grep -E '^#{destination} |^default '"
|
23
31
|
end
|
24
32
|
|
25
|
-
def check_reachable
|
33
|
+
def check_reachable(host, port, proto, timeout)
|
26
34
|
if port.nil?
|
27
35
|
"ping -n #{escape(host)} -w #{escape(timeout)} -c 2"
|
28
36
|
else
|
@@ -30,7 +38,7 @@ module Serverspec
|
|
30
38
|
end
|
31
39
|
end
|
32
40
|
|
33
|
-
def check_resolvable
|
41
|
+
def check_resolvable(name, type)
|
34
42
|
if type == "dns"
|
35
43
|
"nslookup -timeout=1 #{escape(name)}"
|
36
44
|
elsif type == "hosts"
|
@@ -40,78 +48,78 @@ module Serverspec
|
|
40
48
|
end
|
41
49
|
end
|
42
50
|
|
43
|
-
def check_file
|
51
|
+
def check_file(file)
|
44
52
|
"test -f #{escape(file)}"
|
45
53
|
end
|
46
54
|
|
47
|
-
def check_socket
|
55
|
+
def check_socket(file)
|
48
56
|
"test -S #{escape(file)}"
|
49
57
|
end
|
50
58
|
|
51
|
-
def check_directory
|
59
|
+
def check_directory(directory)
|
52
60
|
"test -d #{escape(directory)}"
|
53
61
|
end
|
54
62
|
|
55
|
-
def check_user
|
63
|
+
def check_user(user)
|
56
64
|
"id #{escape(user)}"
|
57
65
|
end
|
58
66
|
|
59
|
-
def check_group
|
67
|
+
def check_group(group)
|
60
68
|
"getent group | grep -wq -- #{escape(group)}"
|
61
69
|
end
|
62
70
|
|
63
|
-
def check_installed
|
71
|
+
def check_installed(package)
|
64
72
|
raise NotImplementedError.new
|
65
73
|
end
|
66
74
|
|
67
|
-
def check_listening
|
75
|
+
def check_listening(port)
|
68
76
|
regexp = ":#{port} "
|
69
77
|
"netstat -tunl | grep -- #{escape(regexp)}"
|
70
78
|
end
|
71
79
|
|
72
|
-
def check_running
|
80
|
+
def check_running(service)
|
73
81
|
"service #{escape(service)} status"
|
74
82
|
end
|
75
83
|
|
76
|
-
def check_running_under_supervisor
|
84
|
+
def check_running_under_supervisor(service)
|
77
85
|
"supervisorctl status #{escape(service)}"
|
78
86
|
end
|
79
87
|
|
80
|
-
def check_process
|
88
|
+
def check_process(process)
|
81
89
|
"ps aux | grep -w -- #{escape(process)} | grep -qv grep"
|
82
90
|
end
|
83
91
|
|
84
|
-
def check_file_contain
|
92
|
+
def check_file_contain(file, expected_pattern)
|
85
93
|
"grep -q -- #{escape(expected_pattern)} #{escape(file)}"
|
86
94
|
end
|
87
95
|
|
88
|
-
def check_file_md5checksum
|
96
|
+
def check_file_md5checksum(file, expected)
|
89
97
|
"md5sum #{escape(file)} | grep -iw -- ^#{escape(expected)}"
|
90
98
|
end
|
91
99
|
|
92
|
-
def check_file_contain_within
|
100
|
+
def check_file_contain_within(file, expected_pattern, from=nil, to=nil)
|
93
101
|
from ||= '1'
|
94
102
|
to ||= '$'
|
95
103
|
checker = check_file_contain("-", expected_pattern)
|
96
104
|
"sed -n #{escape(from)},#{escape(to)}p #{escape(file)} | #{checker}"
|
97
105
|
end
|
98
106
|
|
99
|
-
def check_mode
|
107
|
+
def check_mode(file, mode)
|
100
108
|
regexp = "^#{mode}$"
|
101
109
|
"stat -c %a #{escape(file)} | grep -- #{escape(regexp)}"
|
102
110
|
end
|
103
111
|
|
104
|
-
def check_owner
|
112
|
+
def check_owner(file, owner)
|
105
113
|
regexp = "^#{owner}$"
|
106
114
|
"stat -c %U #{escape(file)} | grep -- #{escape(regexp)}"
|
107
115
|
end
|
108
116
|
|
109
|
-
def check_grouped
|
117
|
+
def check_grouped(file, group)
|
110
118
|
regexp = "^#{group}$"
|
111
119
|
"stat -c %G #{escape(file)} | grep -- #{escape(regexp)}"
|
112
120
|
end
|
113
121
|
|
114
|
-
def check_cron_entry
|
122
|
+
def check_cron_entry(user, entry)
|
115
123
|
entry_escaped = entry.gsub(/\*/, '\\*')
|
116
124
|
if user.nil?
|
117
125
|
"crontab -l | grep -- #{escape(entry_escaped)}"
|
@@ -120,11 +128,11 @@ module Serverspec
|
|
120
128
|
end
|
121
129
|
end
|
122
130
|
|
123
|
-
def check_link
|
131
|
+
def check_link(link, target)
|
124
132
|
"stat -c %N #{escape(link)} | grep -- #{escape(target)}"
|
125
133
|
end
|
126
134
|
|
127
|
-
def check_installed_by_gem
|
135
|
+
def check_installed_by_gem(name, version=nil)
|
128
136
|
cmd = "gem list --local | grep -w -- ^#{escape(name)}"
|
129
137
|
if ! version.nil?
|
130
138
|
cmd = "#{cmd} | grep -w -- #{escape(version)}"
|
@@ -132,13 +140,13 @@ module Serverspec
|
|
132
140
|
cmd
|
133
141
|
end
|
134
142
|
|
135
|
-
def check_installed_by_npm
|
143
|
+
def check_installed_by_npm(name, version=nil)
|
136
144
|
cmd = "npm ls #{escape(name)} -g"
|
137
145
|
cmd = "#{cmd} | grep -w -- #{escape(version)}" unless version.nil?
|
138
146
|
cmd
|
139
147
|
end
|
140
148
|
|
141
|
-
def check_installed_by_pecl
|
149
|
+
def check_installed_by_pecl(name, version=nil)
|
142
150
|
cmd = "pecl list | grep -w -- ^#{escape(name)}"
|
143
151
|
if ! version.nil?
|
144
152
|
cmd = "#{cmd} | grep -w -- #{escape(version)}"
|
@@ -146,38 +154,38 @@ module Serverspec
|
|
146
154
|
cmd
|
147
155
|
end
|
148
156
|
|
149
|
-
def check_belonging_group
|
157
|
+
def check_belonging_group(user, group)
|
150
158
|
"id #{escape(user)} | awk '{print $3}' | grep -- #{escape(group)}"
|
151
159
|
end
|
152
160
|
|
153
|
-
def check_gid
|
161
|
+
def check_gid(group, gid)
|
154
162
|
regexp = "^#{group}"
|
155
163
|
"getent group | grep -w -- #{escape(regexp)} | cut -f 3 -d ':' | grep -w -- #{escape(gid)}"
|
156
164
|
end
|
157
165
|
|
158
|
-
def check_uid
|
166
|
+
def check_uid(user, uid)
|
159
167
|
regexp = "^uid=#{uid}("
|
160
168
|
"id #{escape(user)} | grep -- #{escape(regexp)}"
|
161
169
|
end
|
162
170
|
|
163
|
-
def check_login_shell
|
171
|
+
def check_login_shell(user, path_to_shell)
|
164
172
|
"getent passwd #{escape(user)} | cut -f 7 -d ':' | grep -w -- #{escape(path_to_shell)}"
|
165
173
|
end
|
166
174
|
|
167
|
-
def check_home_directory
|
175
|
+
def check_home_directory(user, path_to_home)
|
168
176
|
"getent passwd #{escape(user)} | cut -f 6 -d ':' | grep -w -- #{escape(path_to_home)}"
|
169
177
|
end
|
170
178
|
|
171
|
-
def check_authorized_key
|
179
|
+
def check_authorized_key(user, key)
|
172
180
|
key.sub!(/\s+\S*$/, '') if key.match(/^\S+\s+\S+\s+\S*$/)
|
173
181
|
"grep -w -- #{escape(key)} ~#{escape(user)}/.ssh/authorized_keys"
|
174
182
|
end
|
175
183
|
|
176
|
-
def check_iptables_rule
|
184
|
+
def check_iptables_rule(rule, table=nil, chain=nil)
|
177
185
|
raise NotImplementedError.new
|
178
186
|
end
|
179
187
|
|
180
|
-
def check_zfs
|
188
|
+
def check_zfs(zfs, property=nil, value=nil)
|
181
189
|
raise NotImplementedError.new
|
182
190
|
end
|
183
191
|
|
@@ -185,31 +193,31 @@ module Serverspec
|
|
185
193
|
"stat -c %a #{escape(file)}"
|
186
194
|
end
|
187
195
|
|
188
|
-
def check_ipfilter_rule
|
196
|
+
def check_ipfilter_rule(rule)
|
189
197
|
raise NotImplementedError.new
|
190
198
|
end
|
191
199
|
|
192
|
-
def check_ipnat_rule
|
200
|
+
def check_ipnat_rule(rule)
|
193
201
|
raise NotImplementedError.new
|
194
202
|
end
|
195
203
|
|
196
|
-
def check_svcprop
|
204
|
+
def check_svcprop(svc, property, value)
|
197
205
|
raise NotImplementedError.new
|
198
206
|
end
|
199
207
|
|
200
|
-
def check_svcprops
|
208
|
+
def check_svcprops(svc, property)
|
201
209
|
raise NotImplementedError.new
|
202
210
|
end
|
203
211
|
|
204
|
-
def check_selinux
|
212
|
+
def check_selinux(mode)
|
205
213
|
raise NotImplementedError.new
|
206
214
|
end
|
207
215
|
|
208
|
-
def check_access_by_user
|
216
|
+
def check_access_by_user(file, user, access)
|
209
217
|
raise NotImplementedError.new
|
210
218
|
end
|
211
219
|
|
212
|
-
def check_kernel_module_loaded
|
220
|
+
def check_kernel_module_loaded(name)
|
213
221
|
raise NotImplementedError.new
|
214
222
|
end
|
215
223
|
end
|
@@ -3,23 +3,21 @@ require 'shellwords'
|
|
3
3
|
module Serverspec
|
4
4
|
module Commands
|
5
5
|
class Darwin < Base
|
6
|
-
|
7
|
-
|
8
|
-
def check_file_md5checksum file, expected
|
6
|
+
def check_file_md5checksum(file, expected)
|
9
7
|
"openssl md5 #{escape(file)} | cut -d'=' -f2 | cut -c 2- | grep -E ^#{escape(expected)}$"
|
10
8
|
end
|
11
9
|
|
12
|
-
def check_mode
|
10
|
+
def check_mode(file, mode)
|
13
11
|
regexp = "^#{mode}$"
|
14
12
|
"stat -f%Lp #{escape(file)} | grep -- #{escape(regexp)}"
|
15
13
|
end
|
16
14
|
|
17
|
-
def check_owner
|
15
|
+
def check_owner(file, owner)
|
18
16
|
regexp = "^#{owner}$"
|
19
17
|
"stat -f %Su #{escape(file)} | grep -- #{escape(regexp)}"
|
20
18
|
end
|
21
19
|
|
22
|
-
def check_grouped
|
20
|
+
def check_grouped(file, group)
|
23
21
|
regexp = "^#{group}$"
|
24
22
|
"stat -f %Sg #{escape(file)} | grep -- #{escape(regexp)}"
|
25
23
|
end
|
@@ -28,7 +26,7 @@ module Serverspec
|
|
28
26
|
"stat -f%Lp #{escape(file)}"
|
29
27
|
end
|
30
28
|
|
31
|
-
def check_access_by_user
|
29
|
+
def check_access_by_user(file, user, access)
|
32
30
|
"sudo -u #{user} -s /bin/test -#{access} #{file}"
|
33
31
|
end
|
34
32
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module Serverspec
|
2
2
|
module Commands
|
3
3
|
class Debian < Linux
|
4
|
-
def check_enabled
|
4
|
+
def check_enabled(service)
|
5
5
|
# Until everything uses Upstart, this needs an OR.
|
6
6
|
"ls /etc/rc3.d/ | grep -- #{escape(service)} || grep 'start on' /etc/init/#{escape(service)}.conf"
|
7
7
|
end
|
8
8
|
|
9
|
-
def check_installed
|
9
|
+
def check_installed(package)
|
10
10
|
escaped_package = escape(package)
|
11
11
|
"dpkg -s #{escaped_package} && ! dpkg -s #{escaped_package} | grep -E '^Status: .+ not-installed$'"
|
12
12
|
end
|
13
13
|
|
14
|
-
def check_running
|
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,16 +1,16 @@
|
|
1
1
|
module Serverspec
|
2
2
|
module Commands
|
3
3
|
class Gentoo < Linux
|
4
|
-
def check_enabled
|
4
|
+
def check_enabled(service)
|
5
5
|
regexp = "^\\s*#{service}\\s*|\\s*\\(boot\\|default\\)"
|
6
6
|
"rc-update show | grep -- #{escape(regexp)}"
|
7
7
|
end
|
8
8
|
|
9
|
-
def check_installed
|
9
|
+
def check_installed(package)
|
10
10
|
"eix #{escape(package)} --installed"
|
11
11
|
end
|
12
12
|
|
13
|
-
def check_running
|
13
|
+
def check_running(service)
|
14
14
|
"/etc/init.d/#{escape(service)} status"
|
15
15
|
end
|
16
16
|
end
|
@@ -3,13 +3,11 @@ require 'shellwords'
|
|
3
3
|
module Serverspec
|
4
4
|
module Commands
|
5
5
|
class Linux < Base
|
6
|
-
|
7
|
-
|
8
|
-
def check_access_by_user file, user, access
|
6
|
+
def check_access_by_user(file, user, access)
|
9
7
|
"su -s sh -c \"test -#{access} #{file}\" #{user}"
|
10
8
|
end
|
11
9
|
|
12
|
-
def check_iptables_rule
|
10
|
+
def check_iptables_rule(rule, table=nil, chain=nil)
|
13
11
|
cmd = "iptables"
|
14
12
|
cmd += " -t #{escape(table)}" if table
|
15
13
|
cmd += " -S"
|
@@ -18,11 +16,11 @@ module Serverspec
|
|
18
16
|
cmd
|
19
17
|
end
|
20
18
|
|
21
|
-
def check_selinux
|
19
|
+
def check_selinux(mode)
|
22
20
|
"getenforce | grep -i -- #{escape(mode)} && grep -i -- ^SELINUX=#{escape(mode)}$ /etc/selinux/config"
|
23
21
|
end
|
24
22
|
|
25
|
-
def check_kernel_module_loaded
|
23
|
+
def check_kernel_module_loaded(name)
|
26
24
|
"lsmod | grep ^#{name}"
|
27
25
|
end
|
28
26
|
end
|
@@ -1,16 +1,24 @@
|
|
1
1
|
module Serverspec
|
2
2
|
module Commands
|
3
3
|
class RedHat < Linux
|
4
|
-
def check_access_by_user
|
4
|
+
def check_access_by_user(file, user, access)
|
5
5
|
# Redhat-specific
|
6
6
|
"runuser -s sh -c \"test -#{access} #{file}\" #{user}"
|
7
7
|
end
|
8
8
|
|
9
|
-
def check_enabled
|
9
|
+
def check_enabled(service)
|
10
10
|
"chkconfig --list #{escape(service)} | grep 3:on"
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def check_yumrepo(repository)
|
14
|
+
"yum repolist -C | grep ^#{escape(repository)}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def check_yumrepo_enabled(repository)
|
18
|
+
"yum repolist all -C | grep ^#{escape(repository)} | grep enabled"
|
19
|
+
end
|
20
|
+
|
21
|
+
def check_installed(package)
|
14
22
|
"rpm -q #{escape(package)}"
|
15
23
|
end
|
16
24
|
end
|
@@ -1,24 +1,24 @@
|
|
1
1
|
module Serverspec
|
2
2
|
module Commands
|
3
3
|
class Solaris < Base
|
4
|
-
def check_enabled
|
4
|
+
def check_enabled(service)
|
5
5
|
"svcs -l #{escape(service)} 2> /dev/null | grep 'enabled true'"
|
6
6
|
end
|
7
7
|
|
8
|
-
def check_installed
|
8
|
+
def check_installed(package)
|
9
9
|
"pkg list -H #{escape(package)} 2> /dev/null"
|
10
10
|
end
|
11
11
|
|
12
|
-
def check_listening
|
12
|
+
def check_listening(port)
|
13
13
|
regexp = "\.#{port} "
|
14
14
|
"netstat -an 2> /dev/null | egrep 'LISTEN|Idle' | grep -- #{escape(regexp)}"
|
15
15
|
end
|
16
16
|
|
17
|
-
def check_running
|
17
|
+
def check_running(service)
|
18
18
|
"svcs -l #{escape(service)} status 2> /dev/null |grep 'state online'"
|
19
19
|
end
|
20
20
|
|
21
|
-
def check_cron_entry
|
21
|
+
def check_cron_entry(user, entry)
|
22
22
|
entry_escaped = entry.gsub(/\*/, '\\*')
|
23
23
|
if user.nil?
|
24
24
|
"crontab -l | grep -- #{escape(entry_escaped)}"
|
@@ -27,7 +27,7 @@ module Serverspec
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def check_zfs
|
30
|
+
def check_zfs(zfs, property=nil)
|
31
31
|
if property.nil?
|
32
32
|
"zfs list -H #{escape(zfs)}"
|
33
33
|
else
|
@@ -40,21 +40,21 @@ module Serverspec
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
def check_ipfilter_rule
|
43
|
+
def check_ipfilter_rule(rule)
|
44
44
|
"ipfstat -io 2> /dev/null | grep -- #{escape(rule)}"
|
45
45
|
end
|
46
46
|
|
47
|
-
def check_ipnat_rule
|
47
|
+
def check_ipnat_rule(rule)
|
48
48
|
regexp = "^#{rule}$"
|
49
49
|
"ipnat -l 2> /dev/null | grep -- #{escape(regexp)}"
|
50
50
|
end
|
51
51
|
|
52
|
-
def check_svcprop
|
52
|
+
def check_svcprop(svc, property, value)
|
53
53
|
regexp = "^#{value}$"
|
54
54
|
"svcprop -p #{escape(property)} #{escape(svc)} | grep -- #{escape(regexp)}"
|
55
55
|
end
|
56
56
|
|
57
|
-
def check_svcprops
|
57
|
+
def check_svcprops(svc, property)
|
58
58
|
commands = []
|
59
59
|
property.sort.each do |key, value|
|
60
60
|
regexp = "^#{value}$"
|
@@ -63,31 +63,31 @@ module Serverspec
|
|
63
63
|
commands.join(' && ')
|
64
64
|
end
|
65
65
|
|
66
|
-
def check_file_contain_within
|
66
|
+
def check_file_contain_within(file, expected_pattern, from=nil, to=nil)
|
67
67
|
from ||= '1'
|
68
68
|
to ||= '$'
|
69
69
|
checker = check_file_contain("/dev/stdin", expected_pattern)
|
70
70
|
"sed -n #{escape(from)},#{escape(to)}p #{escape(file)} | #{checker}"
|
71
71
|
end
|
72
72
|
|
73
|
-
def check_belonging_group
|
73
|
+
def check_belonging_group(user, group)
|
74
74
|
"id -Gn #{escape(user)} | grep -- #{escape(group)}"
|
75
75
|
end
|
76
76
|
|
77
|
-
def check_gid
|
77
|
+
def check_gid(group, gid)
|
78
78
|
regexp = "^#{group}:"
|
79
79
|
"getent group | grep -- #{escape(regexp)} | cut -f 3 -d ':' | grep -w -- #{escape(gid)}"
|
80
80
|
end
|
81
81
|
|
82
|
-
def check_home_directory
|
82
|
+
def check_home_directory(user, path_to_home)
|
83
83
|
"getent passwd #{escape(user)} | cut -f 6 -d ':' | grep -w -- #{escape(path_to_home)}"
|
84
84
|
end
|
85
85
|
|
86
|
-
def check_login_shell
|
86
|
+
def check_login_shell(user, path_to_shell)
|
87
87
|
"getent passwd #{escape(user)} | cut -f 7 -d ':' | grep -w -- #{escape(path_to_shell)}"
|
88
88
|
end
|
89
89
|
|
90
|
-
def check_access_by_user
|
90
|
+
def check_access_by_user(file, user, access)
|
91
91
|
# http://docs.oracle.com/cd/E23823_01/html/816-5166/su-1m.html
|
92
92
|
## No need for login shell as it seems that behavior as superuser is favorable for us, but needs
|
93
93
|
## to be better tested under real solaris env
|
@@ -2,7 +2,7 @@ module Serverspec
|
|
2
2
|
module Helper
|
3
3
|
module Type
|
4
4
|
types = %w(
|
5
|
-
base service package port file cron command linux_kernel_parameter iptables host
|
5
|
+
base yumrepo service package port file cron command linux_kernel_parameter iptables host
|
6
6
|
routing_table default_gateway selinux user group zfs ipnat ipfilter kernel_module
|
7
7
|
)
|
8
8
|
|
data/lib/serverspec/subject.rb
CHANGED
data/lib/serverspec/version.rb
CHANGED
data/lib/serverspec.rb
CHANGED
@@ -68,8 +68,9 @@ module RSpec
|
|
68
68
|
exception_class_name = exception_class_name_for(exception)
|
69
69
|
output.puts "#{long_padding}#{failure_color("Failure/Error:")} #{failure_color(read_failed_line(exception, example).strip)}"
|
70
70
|
output.puts "#{long_padding}#{failure_color(exception_class_name)}: #{failure_color(exception.message)}" unless exception_class_name =~ /RSpec/
|
71
|
-
output.puts "#{long_padding} #{failure_color(example.metadata[:command])}"
|
71
|
+
output.puts "#{long_padding} #{failure_color(example.metadata[:command])}" if example.metadata[:command]
|
72
72
|
output.puts "#{long_padding} #{failure_color(example.metadata[:stdout])}" if example.metadata[:stdout] != ''
|
73
|
+
exception.message.to_s.split("\n").each { |line| output.puts "#{long_padding} #{failure_color(line)}" } if exception.message
|
73
74
|
|
74
75
|
if shared_group = find_shared_group(example)
|
75
76
|
dump_shared_failure_info(shared_group)
|
@@ -82,8 +83,9 @@ module RSpec
|
|
82
83
|
exception_class_name = exception_class_name_for(exception)
|
83
84
|
output.puts "#{long_padding}#{failure_color("Failure/Error:")} #{failure_color(read_failed_line(exception, example).strip)}"
|
84
85
|
output.puts "#{long_padding}#{failure_color(exception_class_name)}: #{failure_color(exception.message)}" unless exception_class_name =~ /RSpec/
|
85
|
-
output.puts "#{long_padding} #{failure_color(example.metadata[:command])}"
|
86
|
+
output.puts "#{long_padding} #{failure_color(example.metadata[:command])}" if example.metadata[:command]
|
86
87
|
output.puts "#{long_padding} #{failure_color(example.metadata[:stdout])}" if example.metadata[:stdout] != ''
|
88
|
+
exception.message.to_s.split("\n").each { |line| output.puts "#{long_padding} #{failure_color(line)}" } if exception.message
|
87
89
|
|
88
90
|
if shared_group = find_shared_group(example)
|
89
91
|
dump_shared_failure_info(shared_group)
|
@@ -10,6 +10,9 @@ describe 'Serverspec commands of Darwin family' do
|
|
10
10
|
it_behaves_like 'support command check_installed_by_gem', 'jekyll'
|
11
11
|
it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
|
12
12
|
|
13
|
+
it_behaves_like 'support command check_installed_by_npm', 'hubot'
|
14
|
+
it_behaves_like 'support command check_installed_by_npm with_version', 'hubot', '1.0.2'
|
15
|
+
|
13
16
|
it_behaves_like 'support command check_installed_by_pecl', 'mongo'
|
14
17
|
it_behaves_like 'support command check_installed_by_pecl with_version', 'mongo', '1.4.1'
|
15
18
|
|
@@ -10,6 +10,9 @@ describe 'Serverspec commands of Debian family' do
|
|
10
10
|
it_behaves_like 'support command check_installed_by_gem', 'jekyll'
|
11
11
|
it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
|
12
12
|
|
13
|
+
it_behaves_like 'support command check_installed_by_npm', 'hubot'
|
14
|
+
it_behaves_like 'support command check_installed_by_npm with_version', 'hubot', '1.0.2'
|
15
|
+
|
13
16
|
it_behaves_like 'support command check_installed_by_pecl', 'mongo'
|
14
17
|
it_behaves_like 'support command check_installed_by_pecl with_version', 'mongo', '1.4.1'
|
15
18
|
|
data/spec/debian/file_spec.rb
CHANGED
@@ -4,8 +4,11 @@ include Serverspec::Helper::Debian
|
|
4
4
|
|
5
5
|
describe 'Serverspec file matchers of Debian family' do
|
6
6
|
it_behaves_like 'support file be_file matcher', '/etc/ssh/sshd_config'
|
7
|
+
it_behaves_like 'support file be_a_file matcher', '/etc/ssh/sshd_config'
|
7
8
|
it_behaves_like 'support file be_directory matcher', '/etc/ssh'
|
9
|
+
it_behaves_like 'support file be_a_directory matcher', '/etc/ssh'
|
8
10
|
it_behaves_like 'support file be_socket matcher', '/var/run/unicorn.sock'
|
11
|
+
it_behaves_like 'support file be_a_socket matcher', '/var/run/unicorn.sock'
|
9
12
|
it_behaves_like 'support file contain matcher', '/etc/ssh/sshd_config', 'This is the sshd server system-wide configuration file'
|
10
13
|
it_behaves_like 'support file contain from to matcher', 'Gemfile', 'rspec', /^group :test do/, /^end/
|
11
14
|
it_behaves_like 'support file contain after matcher', 'Gemfile', 'rspec', /^group :test do/
|
@@ -10,6 +10,9 @@ describe 'Serverspec commands of Gentoo family' do
|
|
10
10
|
it_behaves_like 'support command check_installed_by_gem', 'jekyll'
|
11
11
|
it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
|
12
12
|
|
13
|
+
it_behaves_like 'support command check_installed_by_npm', 'hubot'
|
14
|
+
it_behaves_like 'support command check_installed_by_npm with_version', 'hubot', '1.0.2'
|
15
|
+
|
13
16
|
it_behaves_like 'support command check_installed_by_pecl', 'mongo'
|
14
17
|
it_behaves_like 'support command check_installed_by_pecl with_version', 'mongo', '1.4.1'
|
15
18
|
|
@@ -10,6 +10,9 @@ describe 'Serverspec commands of Red Hat' do
|
|
10
10
|
it_behaves_like 'support command check_installed_by_gem', 'jekyll'
|
11
11
|
it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
|
12
12
|
|
13
|
+
it_behaves_like 'support command check_installed_by_npm', 'hubot'
|
14
|
+
it_behaves_like 'support command check_installed_by_npm with_version', 'hubot', '1.0.2'
|
15
|
+
|
13
16
|
it_behaves_like 'support command check_installed_by_pecl', 'mongo'
|
14
17
|
it_behaves_like 'support command check_installed_by_pecl with_version', 'mongo', '1.4.1'
|
15
18
|
|
@@ -63,6 +66,16 @@ describe 'check_enabled' do
|
|
63
66
|
it { should eq 'chkconfig --list httpd | grep 3:on' }
|
64
67
|
end
|
65
68
|
|
69
|
+
describe 'check_yumrepo' do
|
70
|
+
subject { commands.check_yumrepo('epel') }
|
71
|
+
it { should eq 'yum repolist -C | grep ^epel' }
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'check_yumrepo_enabled' do
|
75
|
+
subject { commands.check_yumrepo_enabled('epel') }
|
76
|
+
it { should eq 'yum repolist all -C | grep ^epel | grep enabled' }
|
77
|
+
end
|
78
|
+
|
66
79
|
describe 'check_installed' do
|
67
80
|
subject { commands.check_installed('httpd') }
|
68
81
|
it { should eq 'rpm -q httpd' }
|
data/spec/redhat/file_spec.rb
CHANGED
@@ -4,8 +4,11 @@ include Serverspec::Helper::RedHat
|
|
4
4
|
|
5
5
|
describe 'Serverspec file matchers of Red Hat family' do
|
6
6
|
it_behaves_like 'support file be_file matcher', '/etc/ssh/sshd_config'
|
7
|
+
it_behaves_like 'support file be_a_file matcher', '/etc/ssh/sshd_config'
|
7
8
|
it_behaves_like 'support file be_directory matcher', '/etc/ssh'
|
9
|
+
it_behaves_like 'support file be_a_directory matcher', '/etc/ssh'
|
8
10
|
it_behaves_like 'support file be_socket matcher', '/var/run/unicorn.sock'
|
11
|
+
it_behaves_like 'support file be_a_socket matcher', '/var/run/unicorn.sock'
|
9
12
|
it_behaves_like 'support file contain matcher', '/etc/ssh/sshd_config', 'This is the sshd server system-wide configuration file'
|
10
13
|
it_behaves_like 'support file contain from to matcher', 'Gemfile', 'rspec', /^group :test do/, /^end/
|
11
14
|
it_behaves_like 'support file contain after matcher', 'Gemfile', 'rspec', /^group :test do/
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Serverspec::Helper::RedHat
|
4
|
+
|
5
|
+
describe 'Serverspec yumrepo matchers of Red Hat family' do
|
6
|
+
describe 'exist' do
|
7
|
+
describe yumrepo('epel') do
|
8
|
+
it { should exist }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe yumrepo('invalid-repository') do
|
12
|
+
it { should_not exist }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'be_enabled' do
|
17
|
+
describe yumrepo('epel') do
|
18
|
+
it { should be_enabled }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe yumrepo('invalid-repository') do
|
22
|
+
it { should_not be_enabled }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -10,6 +10,9 @@ describe 'Serverspec commands of Solaris family' do
|
|
10
10
|
it_behaves_like 'support command check_installed_by_gem', 'jekyll'
|
11
11
|
it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
|
12
12
|
|
13
|
+
it_behaves_like 'support command check_installed_by_npm', 'hubot'
|
14
|
+
it_behaves_like 'support command check_installed_by_npm with_version', 'hubot', '1.0.2'
|
15
|
+
|
13
16
|
it_behaves_like 'support command check_installed_by_pecl', 'mongo'
|
14
17
|
it_behaves_like 'support command check_installed_by_pecl with_version', 'mongo', '1.4.1'
|
15
18
|
|
@@ -14,7 +14,7 @@ shared_examples_for 'support command check_installed_by_npm' do |package|
|
|
14
14
|
end
|
15
15
|
|
16
16
|
shared_examples_for 'support command check_installed_by_npm with_version' do |package, version|
|
17
|
-
subject { commands.check_installed_by_npm(package) }
|
17
|
+
subject { commands.check_installed_by_npm(package, version) }
|
18
18
|
it { should eq "npm ls #{package} -g | grep -w -- #{version}" }
|
19
19
|
end
|
20
20
|
|
@@ -10,6 +10,18 @@ shared_examples_for 'support file be_file matcher' do |name|
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
shared_examples_for 'support file be_a_file matcher' do |name|
|
14
|
+
describe 'be_a_file' do
|
15
|
+
describe file(name) do
|
16
|
+
it { should be_a_file }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe file('/etc/invalid_file') do
|
20
|
+
it { should_not be_a_file }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
13
25
|
shared_examples_for 'support file be_directory matcher' do |name|
|
14
26
|
describe 'be_directory' do
|
15
27
|
describe file(name) do
|
@@ -22,6 +34,18 @@ shared_examples_for 'support file be_directory matcher' do |name|
|
|
22
34
|
end
|
23
35
|
end
|
24
36
|
|
37
|
+
shared_examples_for 'support file be_a_directory matcher' do |name|
|
38
|
+
describe 'be_a_directory' do
|
39
|
+
describe file(name) do
|
40
|
+
it { should be_a_directory }
|
41
|
+
end
|
42
|
+
|
43
|
+
describe file('/etc/invalid_directory') do
|
44
|
+
it { should_not be_a_directory }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
25
49
|
shared_examples_for 'support file be_socket matcher' do |name|
|
26
50
|
describe 'be_socket' do
|
27
51
|
describe file(name) do
|
@@ -34,6 +58,18 @@ shared_examples_for 'support file be_socket matcher' do |name|
|
|
34
58
|
end
|
35
59
|
end
|
36
60
|
|
61
|
+
shared_examples_for 'support file be_a_socket matcher' do |name|
|
62
|
+
describe 'be_a_socket' do
|
63
|
+
describe file(name) do
|
64
|
+
it { should be_a_socket }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe file('/etc/invalid_socket') do
|
68
|
+
it { should_not be_a_socket }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
37
73
|
shared_examples_for 'support file contain matcher' do |name, pattern|
|
38
74
|
describe 'contain' do
|
39
75
|
describe file(name) do
|
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.7
|
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-06-
|
12
|
+
date: 2013-06-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-ssh
|
@@ -203,6 +203,7 @@ files:
|
|
203
203
|
- lib/serverspec/type/selinux.rb
|
204
204
|
- lib/serverspec/type/service.rb
|
205
205
|
- lib/serverspec/type/user.rb
|
206
|
+
- lib/serverspec/type/yumrepo.rb
|
206
207
|
- lib/serverspec/type/zfs.rb
|
207
208
|
- lib/serverspec/version.rb
|
208
209
|
- serverspec.gemspec
|
@@ -268,6 +269,7 @@ files:
|
|
268
269
|
- spec/redhat/selinux_spec.rb
|
269
270
|
- spec/redhat/service_spec.rb
|
270
271
|
- spec/redhat/user_spec.rb
|
272
|
+
- spec/redhat/yumrepo_spec.rb
|
271
273
|
- spec/solaris/command_spec.rb
|
272
274
|
- spec/solaris/commands_spec.rb
|
273
275
|
- spec/solaris/cron_spec.rb
|
@@ -322,7 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
322
324
|
version: '0'
|
323
325
|
requirements: []
|
324
326
|
rubyforge_project:
|
325
|
-
rubygems_version: 1.8.
|
327
|
+
rubygems_version: 1.8.25
|
326
328
|
signing_key:
|
327
329
|
specification_version: 3
|
328
330
|
summary: RSpec tests for your servers configured by Puppet, Chef or anything else
|
@@ -389,6 +391,7 @@ test_files:
|
|
389
391
|
- spec/redhat/selinux_spec.rb
|
390
392
|
- spec/redhat/service_spec.rb
|
391
393
|
- spec/redhat/user_spec.rb
|
394
|
+
- spec/redhat/yumrepo_spec.rb
|
392
395
|
- spec/solaris/command_spec.rb
|
393
396
|
- spec/solaris/commands_spec.rb
|
394
397
|
- spec/solaris/cron_spec.rb
|