serverspec 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/serverspec/helper.rb +10 -1
- data/lib/serverspec/matchers/be_directory.rb +1 -1
- data/lib/serverspec/matchers/be_enabled.rb +1 -1
- data/lib/serverspec/matchers/be_file.rb +1 -1
- data/lib/serverspec/matchers/be_group.rb +1 -1
- data/lib/serverspec/matchers/be_grouped_into.rb +1 -1
- data/lib/serverspec/matchers/be_installed.rb +1 -1
- data/lib/serverspec/matchers/be_installed_by_gem.rb +1 -1
- data/lib/serverspec/matchers/be_linked_to.rb +1 -1
- data/lib/serverspec/matchers/be_listening.rb +1 -1
- data/lib/serverspec/matchers/be_mode.rb +1 -1
- data/lib/serverspec/matchers/be_owned_by.rb +1 -1
- data/lib/serverspec/matchers/be_running.rb +2 -2
- data/lib/serverspec/matchers/be_user.rb +1 -1
- data/lib/serverspec/matchers/belong_to_group.rb +1 -1
- data/lib/serverspec/matchers/contain.rb +1 -1
- data/lib/serverspec/matchers/get_stdout.rb +1 -1
- data/lib/serverspec/matchers/have_cron_entry.rb +1 -1
- data/lib/serverspec/matchers/have_iptables_rule.rb +1 -1
- data/lib/serverspec/setup.rb +31 -6
- data/lib/serverspec/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
data/lib/serverspec/helper.rb
CHANGED
@@ -2,7 +2,7 @@ require 'etc'
|
|
2
2
|
|
3
3
|
module Serverspec
|
4
4
|
module SshHelper
|
5
|
-
def
|
5
|
+
def do_check(cmd, opt={})
|
6
6
|
cmd = "sudo #{cmd}" if not RSpec.configuration.ssh.options[:user] == 'root'
|
7
7
|
ssh_exec!(cmd)
|
8
8
|
end
|
@@ -41,7 +41,16 @@ module Serverspec
|
|
41
41
|
ssh.loop
|
42
42
|
{ :stdout => stdout_data, :stderr => stderr_data, :exit_code => exit_code, :exit_signal => exit_signal }
|
43
43
|
end
|
44
|
+
end
|
44
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
|
45
54
|
end
|
46
55
|
|
47
56
|
module RedHatHelper
|
@@ -1,6 +1,6 @@
|
|
1
1
|
RSpec::Matchers.define :be_installed_by_gem do
|
2
2
|
match do |name|
|
3
|
-
ret =
|
3
|
+
ret = do_check(commands.check_installed_by_gem(name))
|
4
4
|
res = ret[:exit_code] == 0
|
5
5
|
if res && @version
|
6
6
|
res = false if not ret[:stdout].match(/\(#{@version}\)/)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
RSpec::Matchers.define :be_running do
|
2
2
|
match do |process|
|
3
|
-
ret =
|
3
|
+
ret = do_check(commands.check_running(process))
|
4
4
|
if ret[:exit_code] == 1 || ret[:stdout] =~ /stopped/
|
5
|
-
ret =
|
5
|
+
ret = do_check(commands.check_process(process))
|
6
6
|
end
|
7
7
|
ret[:exit_code] == 0
|
8
8
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
RSpec::Matchers.define :have_iptables_rule do |rule|
|
2
2
|
match do |iptables|
|
3
|
-
ret =
|
3
|
+
ret = do_check(commands.check_iptables_rule(rule, @table, @chain))
|
4
4
|
ret[:exit_code] == 0
|
5
5
|
end
|
6
6
|
chain :with_table do |table|
|
data/lib/serverspec/setup.rb
CHANGED
@@ -3,8 +3,25 @@ require 'fileutils'
|
|
3
3
|
module Serverspec
|
4
4
|
class Setup
|
5
5
|
def self.run
|
6
|
-
|
7
|
-
|
6
|
+
prompt = <<-EOF
|
7
|
+
Select a backend type:
|
8
|
+
|
9
|
+
1) SSH
|
10
|
+
2) Exec (local)
|
11
|
+
|
12
|
+
Select number:
|
13
|
+
EOF
|
14
|
+
print prompt.chop
|
15
|
+
num = gets.to_i - 1
|
16
|
+
puts
|
17
|
+
|
18
|
+
@backend_type = [ 'Ssh', 'Exec' ][num]
|
19
|
+
if @backend_type == 'Ssh'
|
20
|
+
print "Input target host name: "
|
21
|
+
@hostname = gets.chomp
|
22
|
+
else
|
23
|
+
@hostname = 'localhost'
|
24
|
+
end
|
8
25
|
|
9
26
|
prompt = <<-EOF
|
10
27
|
|
@@ -82,8 +99,16 @@ require 'pathname'
|
|
82
99
|
require 'net/ssh'
|
83
100
|
|
84
101
|
RSpec.configure do |c|
|
102
|
+
### include backend helper ###
|
85
103
|
### include os helper ###
|
86
|
-
|
104
|
+
### include backend conf ###
|
105
|
+
end
|
106
|
+
EOF
|
107
|
+
|
108
|
+
if not @backend_type.nil?
|
109
|
+
content.gsub!(/### include backend helper ###/, "c.include(Serverspec::#{@backend_type}Helper)")
|
110
|
+
if @backend_type == 'Ssh'
|
111
|
+
content.gsub!(/### include backend conf ###/, "c.before do
|
87
112
|
host = File.basename(Pathname.new(example.metadata[:location]).dirname)
|
88
113
|
if c.host != host
|
89
114
|
c.ssh.close if c.ssh
|
@@ -93,9 +118,9 @@ RSpec.configure do |c|
|
|
93
118
|
c.ssh = Net::SSH.start(c.host, user, options)
|
94
119
|
end
|
95
120
|
end
|
96
|
-
|
97
|
-
|
98
|
-
|
121
|
+
")
|
122
|
+
end
|
123
|
+
end
|
99
124
|
if not @os_type.nil?
|
100
125
|
content.gsub!(/### include os helper ###/, "c.include(Serverspec::#{@os_type}Helper)")
|
101
126
|
end
|
data/lib/serverspec/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.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-04-
|
12
|
+
date: 2013-04-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-ssh
|