serverspec 0.1.7 → 0.2.1
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 +15 -2
- data/lib/serverspec/backend/exec.rb +99 -0
- data/lib/serverspec/backend/puppet.rb +108 -0
- data/lib/serverspec/backend/ssh.rb +47 -0
- data/lib/serverspec/backend.rb +2 -0
- data/lib/serverspec/commands/base.rb +1 -1
- data/lib/serverspec/helper/debian.rb +9 -0
- data/lib/serverspec/helper/exec.rb +9 -0
- data/lib/serverspec/helper/gentoo.rb +9 -0
- data/lib/serverspec/helper/obsoleted.rb +62 -0
- data/lib/serverspec/helper/puppet.rb +9 -0
- data/lib/serverspec/helper/redhat.rb +9 -0
- data/lib/serverspec/helper/solaris.rb +9 -0
- data/lib/serverspec/helper/ssh.rb +10 -0
- data/lib/serverspec/helper.rb +13 -77
- data/lib/serverspec/matchers/be_directory.rb +1 -2
- data/lib/serverspec/matchers/be_enabled.rb +1 -2
- data/lib/serverspec/matchers/be_file.rb +1 -2
- data/lib/serverspec/matchers/be_group.rb +1 -2
- data/lib/serverspec/matchers/be_grouped_into.rb +1 -2
- data/lib/serverspec/matchers/be_installed.rb +1 -2
- data/lib/serverspec/matchers/be_installed_by_gem.rb +1 -6
- data/lib/serverspec/matchers/be_linked_to.rb +1 -2
- data/lib/serverspec/matchers/be_listening.rb +1 -2
- data/lib/serverspec/matchers/be_mode.rb +1 -2
- data/lib/serverspec/matchers/be_owned_by.rb +1 -2
- data/lib/serverspec/matchers/be_running.rb +1 -5
- data/lib/serverspec/matchers/be_user.rb +1 -2
- data/lib/serverspec/matchers/belong_to_group.rb +1 -2
- data/lib/serverspec/matchers/contain.rb +3 -3
- data/lib/serverspec/matchers/get_stdout.rb +1 -1
- data/lib/serverspec/matchers/have_cron_entry.rb +1 -2
- data/lib/serverspec/matchers/have_iptables_rule.rb +1 -2
- data/lib/serverspec/setup.rb +13 -6
- data/lib/serverspec/version.rb +1 -1
- data/lib/serverspec.rb +6 -5
- data/spec/debian/commands_spec.rb +2 -2
- data/spec/gentoo/commands_spec.rb +2 -2
- data/spec/redhat/commands_spec.rb +2 -2
- data/spec/solaris/commads_spec.rb +2 -2
- data/spec/spec_helper.rb +8 -6
- metadata +99 -77
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
RSpec tests for your servers provisioned by Puppet, Chef or anything else
|
4
4
|
|
5
|
+
You can see the details of serverspec on [serverspec.org](http://serverspec.org/).
|
6
|
+
|
5
7
|
----
|
6
8
|
|
7
9
|
## Installation
|
@@ -24,6 +26,13 @@ Or install it yourself as:
|
|
24
26
|
|
25
27
|
```
|
26
28
|
$ serverspec-init
|
29
|
+
Select a backend type:
|
30
|
+
|
31
|
+
1) SSH
|
32
|
+
2) Exec (local)
|
33
|
+
|
34
|
+
Select number: 1
|
35
|
+
|
27
36
|
Input target host name: www.example.jp
|
28
37
|
|
29
38
|
Select OS type of target host:
|
@@ -92,7 +101,7 @@ Finished in 0.99715 seconds
|
|
92
101
|
|
93
102
|
Serverspec is supporting Red Hat based OS, Debian based OS, Gentoo and Solaris now.
|
94
103
|
|
95
|
-
If your target host's OS is Debian, you should include Serverspec::
|
104
|
+
If your target host's OS is Debian, you should include `Serverspec::Helper::Debian` like this.
|
96
105
|
|
97
106
|
```ruby
|
98
107
|
require 'serverspec'
|
@@ -100,8 +109,12 @@ require 'pathname'
|
|
100
109
|
require 'net/ssh'
|
101
110
|
|
102
111
|
RSpec.configure do |c|
|
112
|
+
# Include backend helper
|
113
|
+
c.include(Serverspec::Helper::Ssh)
|
103
114
|
# Include OS helper
|
104
|
-
c.include(Serverspec::
|
115
|
+
c.include(Serverspec::Helper::Debian)
|
116
|
+
# Add SSH before hook in case you use the SSH backend
|
117
|
+
# (not required for the Exec backend)
|
105
118
|
c.before do
|
106
119
|
host = File.basename(Pathname.new(example.metadata[:location]).dirname)
|
107
120
|
if c.host != host
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Serverspec
|
2
|
+
module Backend
|
3
|
+
class Exec
|
4
|
+
def initialize(commands)
|
5
|
+
@commands ||= commands
|
6
|
+
end
|
7
|
+
|
8
|
+
def commands
|
9
|
+
@commands
|
10
|
+
end
|
11
|
+
|
12
|
+
def do_check(cmd, opts={})
|
13
|
+
stdout = `#{cmd} 2>&1`
|
14
|
+
# In ruby 1.9, it is possible to use Open3.capture3, but not in 1.8
|
15
|
+
#stdout, stderr, status = Open3.capture3(cmd)
|
16
|
+
{ :stdout => stdout, :stderr => nil,
|
17
|
+
:exit_code => $?, :exit_signal => nil }
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_zero(cmd, *args)
|
21
|
+
ret = do_check(commands.send(cmd, *args))
|
22
|
+
ret[:exit_code] == 0
|
23
|
+
end
|
24
|
+
|
25
|
+
def check_directory(directory)
|
26
|
+
check_zero(:check_directory, directory)
|
27
|
+
end
|
28
|
+
|
29
|
+
def check_enabled(service)
|
30
|
+
check_zero(:check_enabled, service)
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_file(file)
|
34
|
+
check_zero(:check_file, file)
|
35
|
+
end
|
36
|
+
|
37
|
+
def check_group(group)
|
38
|
+
check_zero(:check_group, group)
|
39
|
+
end
|
40
|
+
|
41
|
+
def check_grouped(file, group)
|
42
|
+
check_zero(:check_grouped, file, group)
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_installed(package)
|
46
|
+
check_zero(:check_installed, package)
|
47
|
+
end
|
48
|
+
|
49
|
+
def check_installed_by_gem(package, version)
|
50
|
+
ret = do_check(commands.check_installed_by_gem(package))
|
51
|
+
res = ret[:exit_code] == 0
|
52
|
+
if res && version
|
53
|
+
res = false if not ret[:stdout].match(/\(#{version}\)/)
|
54
|
+
end
|
55
|
+
res
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_link(link, target)
|
59
|
+
check_zero(:check_link, link, target)
|
60
|
+
end
|
61
|
+
|
62
|
+
def check_listening(port)
|
63
|
+
check_zero(:check_listening, port)
|
64
|
+
end
|
65
|
+
|
66
|
+
def check_mode(file, mode)
|
67
|
+
check_zero(:check_mode, file, mode)
|
68
|
+
end
|
69
|
+
|
70
|
+
def check_owner(file, owner)
|
71
|
+
check_zero(:check_owner, file, owner)
|
72
|
+
end
|
73
|
+
|
74
|
+
def check_running(process)
|
75
|
+
ret = do_check(commands.check_running(process))
|
76
|
+
if ret[:exit_code] == 1 || ret[:stdout] =~ /stopped/
|
77
|
+
ret = do_check(commands.check_process(process))
|
78
|
+
end
|
79
|
+
ret[:exit_code] == 0
|
80
|
+
end
|
81
|
+
|
82
|
+
def check_user(user)
|
83
|
+
check_zero(:check_user, user)
|
84
|
+
end
|
85
|
+
|
86
|
+
def check_belonging_group(user, group)
|
87
|
+
check_zero(:check_belonging_group, user, group)
|
88
|
+
end
|
89
|
+
|
90
|
+
def check_cron_entry(user, entry)
|
91
|
+
check_zero(:check_cron_entry, user, entry)
|
92
|
+
end
|
93
|
+
|
94
|
+
def check_iptables_rule(rule, table, chain)
|
95
|
+
check_zero(:check_iptables_rule, rule, table, chain)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'puppet'
|
2
|
+
require 'puppet/type/file'
|
3
|
+
require 'puppet/type/group'
|
4
|
+
require 'puppet/type/user'
|
5
|
+
require 'puppet/type/package'
|
6
|
+
require 'puppet/type/service'
|
7
|
+
|
8
|
+
module Serverspec
|
9
|
+
module Backend
|
10
|
+
class Puppet < Exec # Use Exec methods as fallbacks
|
11
|
+
|
12
|
+
def check_directory(directory)
|
13
|
+
d = ::Puppet::Type::File.new(:name => directory, :ensure => 'directory')
|
14
|
+
d.insync?(d.retrieve)
|
15
|
+
end
|
16
|
+
|
17
|
+
def check_enabled(service)
|
18
|
+
s = ::Puppet::Type::Service.new(:name => service, :enable => 'true')
|
19
|
+
s.insync?(s.retrieve)
|
20
|
+
end
|
21
|
+
|
22
|
+
def check_file(file)
|
23
|
+
f = ::Puppet::Type::File.new(:name => file, :ensure => 'file')
|
24
|
+
f.insync?(f.retrieve)
|
25
|
+
end
|
26
|
+
|
27
|
+
def check_group(group)
|
28
|
+
g = ::Puppet::Type::Group.new(:name => group)
|
29
|
+
g_real = g.retrieve
|
30
|
+
if g.provider.exists?
|
31
|
+
g.insync?(g_real)
|
32
|
+
else
|
33
|
+
false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def check_grouped(file, group)
|
38
|
+
f = ::Puppet::Type::File.new(:name => file, :group => group)
|
39
|
+
f.insync?(f.retrieve)
|
40
|
+
end
|
41
|
+
|
42
|
+
def check_installed(package)
|
43
|
+
p = ::Puppet::Type::Package.new(:name => package)
|
44
|
+
p_real = p.retrieve
|
45
|
+
if p.exists?
|
46
|
+
p.insync?(p_real)
|
47
|
+
else
|
48
|
+
false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def check_installed_by_gem(package, version)
|
53
|
+
p = ::Puppet::Type::Package.new(:name => package, :provider => 'gem',
|
54
|
+
:ensure => version || 'present')
|
55
|
+
p_real = p.retrieve
|
56
|
+
if p.exists?
|
57
|
+
p.insync?(p_real)
|
58
|
+
else
|
59
|
+
false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def check_link(link, target)
|
64
|
+
f = ::Puppet::Type::File.new(:name => link, :ensure => 'link', :target => target)
|
65
|
+
f.insync?(f.retrieve)
|
66
|
+
end
|
67
|
+
|
68
|
+
# check_listening: inherited
|
69
|
+
|
70
|
+
def check_mode(file, mode)
|
71
|
+
f = ::Puppet::Type::File.new(:name => file, :mode => mode)
|
72
|
+
f.insync?(f.retrieve)
|
73
|
+
end
|
74
|
+
|
75
|
+
def check_owner(file, owner)
|
76
|
+
f = ::Puppet::Type::File.new(:name => file, :owner => owner)
|
77
|
+
f.insync?(f.retrieve)
|
78
|
+
end
|
79
|
+
|
80
|
+
def check_running(process)
|
81
|
+
s = ::Puppet::Type::Service.new(:name => process, :ensure => 'running')
|
82
|
+
s.insync?(s.retrieve)
|
83
|
+
end
|
84
|
+
|
85
|
+
def check_user(user)
|
86
|
+
u = ::Puppet::Type::User.new(:name => user)
|
87
|
+
u_real = u.retrieve
|
88
|
+
if u.provider.exists?
|
89
|
+
u.insync?(u_real)
|
90
|
+
else
|
91
|
+
false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# check_belonging_group: inherited, TODO
|
96
|
+
#def check_belonging_group(user, group)
|
97
|
+
# return false unless check_user(user)
|
98
|
+
# u = ::Puppet::Type::User.new(:name => user)
|
99
|
+
# u_real = u.retrieve
|
100
|
+
# # Get groups and compare
|
101
|
+
#end
|
102
|
+
|
103
|
+
# check_cron_entry: inherited
|
104
|
+
|
105
|
+
# check_iptables_rule: inherited
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'serverspec/backend/exec'
|
2
|
+
|
3
|
+
module Serverspec
|
4
|
+
module Backend
|
5
|
+
class Ssh < Exec
|
6
|
+
def do_check(cmd, opt={})
|
7
|
+
cmd = "sudo #{cmd}" if not RSpec.configuration.ssh.options[:user] == 'root'
|
8
|
+
ssh_exec!(cmd)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def ssh_exec!(command)
|
13
|
+
stdout_data = ''
|
14
|
+
stderr_data = ''
|
15
|
+
exit_code = nil
|
16
|
+
exit_signal = nil
|
17
|
+
|
18
|
+
ssh = RSpec.configuration.ssh
|
19
|
+
ssh.open_channel do |channel|
|
20
|
+
channel.request_pty do |ch, success|
|
21
|
+
abort "Could not obtain pty " if !success
|
22
|
+
end
|
23
|
+
channel.exec("#{command}") do |ch, success|
|
24
|
+
abort "FAILED: couldn't execute command (ssh.channel.exec)" if !success
|
25
|
+
channel.on_data do |ch,data|
|
26
|
+
stdout_data += data
|
27
|
+
end
|
28
|
+
|
29
|
+
channel.on_extended_data do |ch,type,data|
|
30
|
+
stderr_data += data
|
31
|
+
end
|
32
|
+
|
33
|
+
channel.on_request("exit-status") do |ch,data|
|
34
|
+
exit_code = data.read_long
|
35
|
+
end
|
36
|
+
|
37
|
+
channel.on_request("exit-signal") do |ch, data|
|
38
|
+
exit_signal = data.read_long
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
ssh.loop
|
43
|
+
{ :stdout => stdout_data, :stderr => stderr_data, :exit_code => exit_code, :exit_signal => exit_signal }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Serverspec
|
2
|
+
module SshHelper
|
3
|
+
def self.included(mod)
|
4
|
+
puts
|
5
|
+
puts "***********************************************************"
|
6
|
+
puts "Serverspec::SshHelper in spec/spec_helper.rb is deprecated."
|
7
|
+
puts "Use Serverspec::Helper::Ssh instead."
|
8
|
+
puts "Or remove spec/spec_helper.rb and run severspec-init again."
|
9
|
+
puts "***********************************************************"
|
10
|
+
puts
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
module DebianHelper
|
15
|
+
def self.included(mod)
|
16
|
+
puts
|
17
|
+
puts "**************************************************************"
|
18
|
+
puts "Serverspec::DebianHelper in spec/spec_helper.rb is deprecated."
|
19
|
+
puts "Use Serverspec::Helper::Debian instead."
|
20
|
+
puts "Or remove spec/spec_helper.rb and run severspec-init again."
|
21
|
+
puts "**************************************************************"
|
22
|
+
puts
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
module GentooHelper
|
27
|
+
def self.included(mod)
|
28
|
+
puts
|
29
|
+
puts "**************************************************************"
|
30
|
+
puts "Serverspec::GentooHelper in spec/spec_helper.rb is deprecated."
|
31
|
+
puts "Use Serverspec::Helper::Gentoo instead."
|
32
|
+
puts "Or remove spec/spec_helper.rb and run severspec-init again."
|
33
|
+
puts "**************************************************************"
|
34
|
+
puts
|
35
|
+
exit 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
module RedHatHelper
|
39
|
+
def self.included(mod)
|
40
|
+
puts
|
41
|
+
puts "**************************************************************"
|
42
|
+
puts "Serverspec::RedHatHelper in spec/spec_helper.rb is deprecated."
|
43
|
+
puts "Use Serverspec::Helper::RedHat instead."
|
44
|
+
puts "Or remove spec/spec_helper.rb and run severspec-init again."
|
45
|
+
puts "**************************************************************"
|
46
|
+
puts
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
module SolarisHelper
|
51
|
+
def self.included(mod)
|
52
|
+
puts
|
53
|
+
puts "***************************************************************"
|
54
|
+
puts "Serverspec::SolarisHelper in spec/spec_helper.rb is deprecated."
|
55
|
+
puts "Use Serverspec::Helper::Solaris instead."
|
56
|
+
puts "Or remove spec/spec_helper.rb and run severspec-init again."
|
57
|
+
puts "***************************************************************"
|
58
|
+
puts
|
59
|
+
exit 1
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/serverspec/helper.rb
CHANGED
@@ -1,79 +1,15 @@
|
|
1
1
|
require 'etc'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
ssh = RSpec.configuration.ssh
|
18
|
-
ssh.open_channel do |channel|
|
19
|
-
channel.request_pty do |ch, success|
|
20
|
-
abort "Could not obtain pty " if !success
|
21
|
-
end
|
22
|
-
channel.exec("#{command}") do |ch, success|
|
23
|
-
abort "FAILED: couldn't execute command (ssh.channel.exec)" if !success
|
24
|
-
channel.on_data do |ch,data|
|
25
|
-
stdout_data += data
|
26
|
-
end
|
27
|
-
|
28
|
-
channel.on_extended_data do |ch,type,data|
|
29
|
-
stderr_data += data
|
30
|
-
end
|
31
|
-
|
32
|
-
channel.on_request("exit-status") do |ch,data|
|
33
|
-
exit_code = data.read_long
|
34
|
-
end
|
35
|
-
|
36
|
-
channel.on_request("exit-signal") do |ch, data|
|
37
|
-
exit_signal = data.read_long
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
ssh.loop
|
42
|
-
{ :stdout => stdout_data, :stderr => stderr_data, :exit_code => exit_code, :exit_signal => exit_signal }
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
module ExecHelper
|
47
|
-
def do_check(cmd, opts={})
|
48
|
-
stdout = `#{cmd} 2>&1`
|
49
|
-
# In ruby 1.9, it is possible to use Open3.capture3, but not in 1.8
|
50
|
-
#stdout, stderr, status = Open3.capture3(cmd)
|
51
|
-
{ :stdout => stdout, :stderr => nil,
|
52
|
-
:exit_code => $?, :exit_signal => nil }
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
module RedHatHelper
|
57
|
-
def commands
|
58
|
-
Serverspec::Commands::RedHat.new
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
module DebianHelper
|
63
|
-
def commands
|
64
|
-
Serverspec::Commands::Debian.new
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
module GentooHelper
|
69
|
-
def commands
|
70
|
-
Serverspec::Commands::Gentoo.new
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
module SolarisHelper
|
75
|
-
def commands
|
76
|
-
Serverspec::Commands::Solaris.new
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
3
|
+
# Backend helpers
|
4
|
+
require 'serverspec/helper/ssh'
|
5
|
+
require 'serverspec/helper/exec'
|
6
|
+
require 'serverspec/helper/puppet'
|
7
|
+
|
8
|
+
# Command helpers
|
9
|
+
require 'serverspec/helper/redhat'
|
10
|
+
require 'serverspec/helper/debian'
|
11
|
+
require 'serverspec/helper/gentoo'
|
12
|
+
require 'serverspec/helper/solaris'
|
13
|
+
|
14
|
+
# Obsoleted helpers
|
15
|
+
require 'serverspec/helper/obsoleted'
|
@@ -1,11 +1,6 @@
|
|
1
1
|
RSpec::Matchers.define :be_installed_by_gem do
|
2
2
|
match do |name|
|
3
|
-
|
4
|
-
res = ret[:exit_code] == 0
|
5
|
-
if res && @version
|
6
|
-
res = false if not ret[:stdout].match(/\(#{@version}\)/)
|
7
|
-
end
|
8
|
-
res
|
3
|
+
backend.check_installed_by_gem(name, @version)
|
9
4
|
end
|
10
5
|
chain :with_version do |version|
|
11
6
|
@version = version
|
@@ -1,9 +1,5 @@
|
|
1
1
|
RSpec::Matchers.define :be_running do
|
2
2
|
match do |process|
|
3
|
-
|
4
|
-
if ret[:exit_code] == 1 || ret[:stdout] =~ /stopped/
|
5
|
-
ret = do_check(commands.check_process(process))
|
6
|
-
end
|
7
|
-
ret[:exit_code] == 0
|
3
|
+
backend.check_running(process)
|
8
4
|
end
|
9
5
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
RSpec::Matchers.define :contain do |pattern|
|
2
2
|
match do |file|
|
3
3
|
if (@from || @to).nil?
|
4
|
-
cmd = commands.check_file_contain(file, pattern)
|
4
|
+
cmd = backend.commands.check_file_contain(file, pattern)
|
5
5
|
else
|
6
|
-
cmd = commands.check_file_contain_within(file, pattern, @from, @to)
|
6
|
+
cmd = backend.commands.check_file_contain_within(file, pattern, @from, @to)
|
7
7
|
end
|
8
|
-
ret = do_check(cmd)
|
8
|
+
ret = backend.do_check(cmd)
|
9
9
|
ret[:exit_code] == 0
|
10
10
|
end
|
11
11
|
# for contain(pattern).from(/A/).to(/B/)
|
@@ -1,7 +1,6 @@
|
|
1
1
|
RSpec::Matchers.define :have_iptables_rule do |rule|
|
2
2
|
match do |iptables|
|
3
|
-
|
4
|
-
ret[:exit_code] == 0
|
3
|
+
backend.check_iptables_rule(rule, @table, @chain)
|
5
4
|
end
|
6
5
|
chain :with_table do |table|
|
7
6
|
@table = table
|
data/lib/serverspec/setup.rb
CHANGED
@@ -8,6 +8,7 @@ Select a backend type:
|
|
8
8
|
|
9
9
|
1) SSH
|
10
10
|
2) Exec (local)
|
11
|
+
3) Puppet providers (local)
|
11
12
|
|
12
13
|
Select number:
|
13
14
|
EOF
|
@@ -15,7 +16,7 @@ EOF
|
|
15
16
|
num = gets.to_i - 1
|
16
17
|
puts
|
17
18
|
|
18
|
-
@backend_type = [ 'Ssh', 'Exec' ][num]
|
19
|
+
@backend_type = [ 'Ssh', 'Exec', 'Puppet' ][num]
|
19
20
|
if @backend_type == 'Ssh'
|
20
21
|
print "Input target host name: "
|
21
22
|
@hostname = gets.chomp
|
@@ -41,6 +42,7 @@ EOF
|
|
41
42
|
puts
|
42
43
|
|
43
44
|
@os_type = [ 'RedHat', 'Debian', 'Gentoo', 'Solaris', nil ][num]
|
45
|
+
|
44
46
|
[ 'spec', "spec/#{@hostname}" ].each { |dir| safe_mkdir(dir) }
|
45
47
|
safe_create_spec
|
46
48
|
safe_create_spec_helper
|
@@ -96,7 +98,7 @@ EOF
|
|
96
98
|
content = <<-EOF
|
97
99
|
require 'serverspec'
|
98
100
|
require 'pathname'
|
99
|
-
|
101
|
+
### include requirements ###
|
100
102
|
|
101
103
|
RSpec.configure do |c|
|
102
104
|
### include backend helper ###
|
@@ -106,9 +108,11 @@ end
|
|
106
108
|
EOF
|
107
109
|
|
108
110
|
if not @backend_type.nil?
|
109
|
-
content.gsub!(/### include backend helper ###/, "c.include(Serverspec::#{@backend_type}
|
110
|
-
|
111
|
-
|
111
|
+
content.gsub!(/### include backend helper ###/, "c.include(Serverspec::Helper::#{@backend_type})")
|
112
|
+
case @backend_type
|
113
|
+
when 'Ssh'
|
114
|
+
content.gsub!(/### include requirements ###/, "require 'net/ssh'")
|
115
|
+
content.gsub!(/### include backend conf ###/, "c.before do
|
112
116
|
host = File.basename(Pathname.new(example.metadata[:location]).dirname)
|
113
117
|
if c.host != host
|
114
118
|
c.ssh.close if c.ssh
|
@@ -118,11 +122,14 @@ EOF
|
|
118
122
|
c.ssh = Net::SSH.start(c.host, user, options)
|
119
123
|
end
|
120
124
|
end
|
125
|
+
")
|
126
|
+
when 'Puppet'
|
127
|
+
content.gsub!(/### include requirements ###/, "require 'puppet'\nrequire 'serverspec/backend/puppet'
|
121
128
|
")
|
122
129
|
end
|
123
130
|
end
|
124
131
|
if not @os_type.nil?
|
125
|
-
content.gsub!(/### include os helper ###/, "c.include(Serverspec::#{@os_type}
|
132
|
+
content.gsub!(/### include os helper ###/, "c.include(Serverspec::Helper::#{@os_type})")
|
126
133
|
end
|
127
134
|
|
128
135
|
if File.exists? 'spec/spec_helper.rb'
|
data/lib/serverspec/version.rb
CHANGED
data/lib/serverspec.rb
CHANGED
@@ -2,6 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rspec'
|
3
3
|
require 'serverspec/version'
|
4
4
|
require 'serverspec/matchers'
|
5
|
+
require 'serverspec/backend'
|
5
6
|
require 'serverspec/helper'
|
6
7
|
require 'serverspec/setup'
|
7
8
|
require 'serverspec/commands/base'
|
@@ -11,11 +12,11 @@ require 'serverspec/commands/gentoo'
|
|
11
12
|
require 'serverspec/commands/solaris'
|
12
13
|
|
13
14
|
RSpec.configure do |c|
|
14
|
-
c.include(Serverspec::
|
15
|
-
c.include(Serverspec::
|
16
|
-
c.include(Serverspec::
|
17
|
-
c.include(Serverspec::
|
18
|
-
c.include(Serverspec::
|
15
|
+
c.include(Serverspec::Helper::Ssh)
|
16
|
+
c.include(Serverspec::Helper::RedHat, :os => :redhat)
|
17
|
+
c.include(Serverspec::Helper::Debian, :os => :debian)
|
18
|
+
c.include(Serverspec::Helper::Gentoo, :os => :gentoo)
|
19
|
+
c.include(Serverspec::Helper::Solaris, :os => :solaris)
|
19
20
|
c.add_setting :host, :default => nil
|
20
21
|
c.add_setting :ssh, :default => nil
|
21
22
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
include Serverspec::
|
3
|
+
include Serverspec::Helper::Debian
|
4
4
|
|
5
5
|
describe commands.check_enabled('httpd') do
|
6
6
|
it { should eq 'ls /etc/rc3.d/ | grep httpd' }
|
@@ -79,7 +79,7 @@ describe commands.check_link('/etc/system-release', '/etc/redhat-release') do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
describe commands.check_installed_by_gem('jekyll') do
|
82
|
-
it { should eq 'gem list --local | grep jekyll' }
|
82
|
+
it { should eq 'gem list --local | grep \'^jekyll \'' }
|
83
83
|
end
|
84
84
|
|
85
85
|
describe commands.check_belonging_group('root', 'wheel') do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
include Serverspec::
|
3
|
+
include Serverspec::Helper::Gentoo
|
4
4
|
|
5
5
|
describe commands.check_enabled('httpd') do
|
6
6
|
it { should eq "/sbin/rc-update show | grep '^\\s*httpd\\s*|\\s*\\(boot\\|default\\)'" }
|
@@ -79,7 +79,7 @@ describe commands.check_link('/etc/system-release', '/etc/redhat-release') do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
describe commands.check_installed_by_gem('jekyll') do
|
82
|
-
it { should eq 'gem list --local | grep jekyll' }
|
82
|
+
it { should eq 'gem list --local | grep \'^jekyll \'' }
|
83
83
|
end
|
84
84
|
|
85
85
|
describe commands.check_belonging_group('root', 'wheel') do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
include Serverspec::
|
3
|
+
include Serverspec::Helper::RedHat
|
4
4
|
|
5
5
|
describe commands.check_enabled('httpd') do
|
6
6
|
it { should eq 'chkconfig --list httpd | grep 3:on' }
|
@@ -79,7 +79,7 @@ describe commands.check_link('/etc/system-release', '/etc/redhat-release') do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
describe commands.check_installed_by_gem('jekyll') do
|
82
|
-
it { should eq 'gem list --local | grep jekyll' }
|
82
|
+
it { should eq 'gem list --local | grep \'^jekyll \'' }
|
83
83
|
end
|
84
84
|
|
85
85
|
describe commands.check_belonging_group('root', 'wheel') do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
include Serverspec::
|
3
|
+
include Serverspec::Helper::Solaris
|
4
4
|
|
5
5
|
describe commands.check_enabled('httpd') do
|
6
6
|
it { should eq "svcs -l httpd 2> /dev/null | grep 'enabled true'" }
|
@@ -79,7 +79,7 @@ describe commands.check_link('/etc/system-release', '/etc/redhat-release') do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
describe commands.check_installed_by_gem('jekyll') do
|
82
|
-
it { should eq 'gem list --local | grep jekyll' }
|
82
|
+
it { should eq 'gem list --local | grep \'^jekyll \'' }
|
83
83
|
end
|
84
84
|
|
85
85
|
describe commands.check_belonging_group('root', 'wheel') do
|
data/spec/spec_helper.rb
CHANGED
@@ -6,12 +6,14 @@ PROJECT_ROOT = (Pathname.new(File.dirname(__FILE__)) + '..').expand_path
|
|
6
6
|
Dir[PROJECT_ROOT.join("spec/support/**/*.rb")].each { |file| require(file) }
|
7
7
|
|
8
8
|
module Serverspec
|
9
|
-
module
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
module Backend
|
10
|
+
class Ssh
|
11
|
+
def do_check(cmd)
|
12
|
+
if cmd =~ /invalid/
|
13
|
+
{ :stdout => '', :stderr => '', :exit_code => 1, :exit_signal => nil }
|
14
|
+
else
|
15
|
+
{ :stdout => ::RSpec.configuration.stdout, :stderr => '', :exit_code => 0, :exit_signal => nil }
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
metadata
CHANGED
@@ -1,89 +1,90 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: serverspec
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Gosuke Miyashita
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2013-04-08 00:00:00 +09:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
15
22
|
name: net-ssh
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
31
36
|
name: bundler
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '1.3'
|
38
|
-
type: :development
|
39
37
|
prerelease: false
|
40
|
-
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
|
-
requirements:
|
40
|
+
requirements:
|
43
41
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 9
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 3
|
47
|
+
version: "1.3"
|
54
48
|
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rspec
|
55
52
|
prerelease: false
|
56
|
-
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
54
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
70
62
|
type: :development
|
63
|
+
version_requirements: *id003
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: rake
|
71
66
|
prerelease: false
|
72
|
-
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
68
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
type: :development
|
77
|
+
version_requirements: *id004
|
78
|
+
description: RSpec tests for your servers provisioned by Puppet, Chef or anything else
|
79
|
+
email:
|
81
80
|
- gosukenator@gmail.com
|
82
|
-
executables:
|
81
|
+
executables:
|
83
82
|
- serverspec-init
|
84
83
|
extensions: []
|
84
|
+
|
85
85
|
extra_rdoc_files: []
|
86
|
-
|
86
|
+
|
87
|
+
files:
|
87
88
|
- .gitignore
|
88
89
|
- .travis.yml
|
89
90
|
- Gemfile
|
@@ -92,12 +93,24 @@ files:
|
|
92
93
|
- Rakefile
|
93
94
|
- bin/serverspec-init
|
94
95
|
- lib/serverspec.rb
|
96
|
+
- lib/serverspec/backend.rb
|
97
|
+
- lib/serverspec/backend/exec.rb
|
98
|
+
- lib/serverspec/backend/puppet.rb
|
99
|
+
- lib/serverspec/backend/ssh.rb
|
95
100
|
- lib/serverspec/commands/base.rb
|
96
101
|
- lib/serverspec/commands/debian.rb
|
97
102
|
- lib/serverspec/commands/gentoo.rb
|
98
103
|
- lib/serverspec/commands/redhat.rb
|
99
104
|
- lib/serverspec/commands/solaris.rb
|
100
105
|
- lib/serverspec/helper.rb
|
106
|
+
- lib/serverspec/helper/debian.rb
|
107
|
+
- lib/serverspec/helper/exec.rb
|
108
|
+
- lib/serverspec/helper/gentoo.rb
|
109
|
+
- lib/serverspec/helper/obsoleted.rb
|
110
|
+
- lib/serverspec/helper/puppet.rb
|
111
|
+
- lib/serverspec/helper/redhat.rb
|
112
|
+
- lib/serverspec/helper/solaris.rb
|
113
|
+
- lib/serverspec/helper/ssh.rb
|
101
114
|
- lib/serverspec/matchers.rb
|
102
115
|
- lib/serverspec/matchers/be_directory.rb
|
103
116
|
- lib/serverspec/matchers/be_enabled.rb
|
@@ -130,32 +143,41 @@ files:
|
|
130
143
|
- spec/solaris/matchers_spec.rb
|
131
144
|
- spec/spec_helper.rb
|
132
145
|
- spec/support/shared_matcher_examples.rb
|
146
|
+
has_rdoc: true
|
133
147
|
homepage: http://serverspec.org/
|
134
|
-
licenses:
|
148
|
+
licenses:
|
135
149
|
- MIT
|
136
150
|
post_install_message:
|
137
151
|
rdoc_options: []
|
138
|
-
|
152
|
+
|
153
|
+
require_paths:
|
139
154
|
- lib
|
140
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
156
|
none: false
|
142
|
-
requirements:
|
143
|
-
- -
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
|
146
|
-
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
hash: 3
|
161
|
+
segments:
|
162
|
+
- 0
|
163
|
+
version: "0"
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
165
|
none: false
|
148
|
-
requirements:
|
149
|
-
- -
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
hash: 3
|
170
|
+
segments:
|
171
|
+
- 0
|
172
|
+
version: "0"
|
152
173
|
requirements: []
|
174
|
+
|
153
175
|
rubyforge_project:
|
154
|
-
rubygems_version: 1.
|
176
|
+
rubygems_version: 1.3.7
|
155
177
|
signing_key:
|
156
178
|
specification_version: 3
|
157
179
|
summary: RSpec tests for your servers provisioned by Puppet, Chef or anything else
|
158
|
-
test_files:
|
180
|
+
test_files:
|
159
181
|
- spec/debian/commands_spec.rb
|
160
182
|
- spec/debian/matchers_spec.rb
|
161
183
|
- spec/gentoo/commands_spec.rb
|