serverspec 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/serverspec.rb CHANGED
@@ -17,6 +17,7 @@ RSpec.configure do |c|
17
17
  c.include(Serverspec::Helper::Debian, :os => :debian)
18
18
  c.include(Serverspec::Helper::Gentoo, :os => :gentoo)
19
19
  c.include(Serverspec::Helper::Solaris, :os => :solaris)
20
- c.add_setting :host, :default => nil
21
- c.add_setting :ssh, :default => nil
20
+ c.add_setting :host, :default => nil
21
+ c.add_setting :ssh, :default => nil
22
+ c.add_setting :sudo_password, :default => nil
22
23
  end
@@ -22,31 +22,14 @@ module Serverspec
22
22
  ret[:exit_code] == 0
23
23
  end
24
24
 
25
- def check_directory(directory)
26
- check_zero(:check_directory, directory)
25
+ # Default action is to call check_zero with args
26
+ def method_missing(meth, *args, &block)
27
+ # Remove example object from *args
28
+ args.shift
29
+ check_zero(meth, *args)
27
30
  end
28
31
 
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)
32
+ def check_installed_by_gem(example, package, version)
50
33
  ret = do_check(commands.check_installed_by_gem(package))
51
34
  res = ret[:exit_code] == 0
52
35
  if res && version
@@ -55,23 +38,7 @@ module Serverspec
55
38
  res
56
39
  end
57
40
 
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)
41
+ def check_running(example, process)
75
42
  ret = do_check(commands.check_running(process))
76
43
  if ret[:exit_code] == 1 || ret[:stdout] =~ /stopped/
77
44
  ret = do_check(commands.check_process(process))
@@ -79,32 +46,12 @@ module Serverspec
79
46
  ret[:exit_code] == 0
80
47
  end
81
48
 
82
- def check_running_under_supervisor(process)
49
+ def check_running_under_supervisor(example, process)
83
50
  ret = do_check(commands.check_running_under_supervisor(process))
84
51
  ret[:exit_code] == 0 && ret[:stdout] =~ /RUNNING/
85
52
  end
86
53
 
87
- def check_user(user)
88
- check_zero(:check_user, user)
89
- end
90
-
91
- def check_belonging_group(user, group)
92
- check_zero(:check_belonging_group, user, group)
93
- end
94
-
95
- def check_cron_entry(user, entry)
96
- check_zero(:check_cron_entry, user, entry)
97
- end
98
-
99
- def check_iptables_rule(rule, table, chain)
100
- check_zero(:check_iptables_rule, rule, table, chain)
101
- end
102
-
103
- def check_zfs(zfs, property)
104
- check_zero(:check_zfs, zfs, property)
105
- end
106
-
107
- def check_readable(file, by_whom)
54
+ def check_readable(example, file, by_whom)
108
55
  mode = sprintf('%04s',do_check(commands.get_mode(file))[:stdout].strip)
109
56
  mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
110
57
  if by_whom.nil?
@@ -118,7 +65,7 @@ module Serverspec
118
65
  end
119
66
  end
120
67
 
121
- def check_writable(file, by_whom)
68
+ def check_writable(example, file, by_whom)
122
69
  mode = sprintf('%04s',do_check(commands.get_mode(file))[:stdout].strip)
123
70
  mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
124
71
  if by_whom.nil?
@@ -132,7 +79,7 @@ module Serverspec
132
79
  end
133
80
  end
134
81
 
135
- def check_executable(file, by_whom)
82
+ def check_executable(example, file, by_whom)
136
83
  mode = sprintf('%04s',do_check(commands.get_mode(file))[:stdout].strip)
137
84
  mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
138
85
  if by_whom.nil?
@@ -9,22 +9,22 @@ module Serverspec
9
9
  module Backend
10
10
  class Puppet < Exec # Use Exec methods as fallbacks
11
11
 
12
- def check_directory(directory)
12
+ def check_directory(example, directory)
13
13
  d = ::Puppet::Type::File.new(:name => directory, :ensure => 'directory')
14
14
  d.insync?(d.retrieve)
15
15
  end
16
16
 
17
- def check_enabled(service)
17
+ def check_enabled(example, service)
18
18
  s = ::Puppet::Type::Service.new(:name => service, :enable => 'true')
19
19
  s.insync?(s.retrieve)
20
20
  end
21
21
 
22
- def check_file(file)
22
+ def check_file(example, file)
23
23
  f = ::Puppet::Type::File.new(:name => file, :ensure => 'file')
24
24
  f.insync?(f.retrieve)
25
25
  end
26
26
 
27
- def check_group(group)
27
+ def check_group(example, group)
28
28
  g = ::Puppet::Type::Group.new(:name => group)
29
29
  g_real = g.retrieve
30
30
  if g.provider.exists?
@@ -34,12 +34,12 @@ module Serverspec
34
34
  end
35
35
  end
36
36
 
37
- def check_grouped(file, group)
37
+ def check_grouped(example, file, group)
38
38
  f = ::Puppet::Type::File.new(:name => file, :group => group)
39
39
  f.insync?(f.retrieve)
40
40
  end
41
41
 
42
- def check_installed(package)
42
+ def check_installed(example, package)
43
43
  p = ::Puppet::Type::Package.new(:name => package)
44
44
  p_real = p.retrieve
45
45
  if p.exists?
@@ -49,7 +49,7 @@ module Serverspec
49
49
  end
50
50
  end
51
51
 
52
- def check_installed_by_gem(package, version)
52
+ def check_installed_by_gem(example, package, version)
53
53
  p = ::Puppet::Type::Package.new(:name => package, :provider => 'gem',
54
54
  :ensure => version || 'present')
55
55
  p_real = p.retrieve
@@ -60,29 +60,29 @@ module Serverspec
60
60
  end
61
61
  end
62
62
 
63
- def check_link(link, target)
63
+ def check_link(example, link, target)
64
64
  f = ::Puppet::Type::File.new(:name => link, :ensure => 'link', :target => target)
65
65
  f.insync?(f.retrieve)
66
66
  end
67
67
 
68
68
  # check_listening: inherited
69
69
 
70
- def check_mode(file, mode)
70
+ def check_mode(example, file, mode)
71
71
  f = ::Puppet::Type::File.new(:name => file, :mode => mode)
72
72
  f.insync?(f.retrieve)
73
73
  end
74
74
 
75
- def check_owner(file, owner)
75
+ def check_owner(example, file, owner)
76
76
  f = ::Puppet::Type::File.new(:name => file, :owner => owner)
77
77
  f.insync?(f.retrieve)
78
78
  end
79
79
 
80
- def check_running(process)
80
+ def check_running(example, process)
81
81
  s = ::Puppet::Type::Service.new(:name => process, :ensure => 'running')
82
82
  s.insync?(s.retrieve)
83
83
  end
84
84
 
85
- def check_user(user)
85
+ def check_user(example, user)
86
86
  u = ::Puppet::Type::User.new(:name => user)
87
87
  u_real = u.retrieve
88
88
  if u.provider.exists?
@@ -22,15 +22,19 @@ module Serverspec
22
22
  end
23
23
  channel.exec("#{command}") do |ch, success|
24
24
  abort "FAILED: couldn't execute command (ssh.channel.exec)" if !success
25
- channel.on_data do |ch,data|
26
- stdout_data += data
25
+ channel.on_data do |ch, data|
26
+ if data =~ /^\[sudo\] password for/
27
+ channel.send_data "#{RSpec.configuration.sudo_password}\n"
28
+ else
29
+ stdout_data += data
30
+ end
27
31
  end
28
32
 
29
- channel.on_extended_data do |ch,type,data|
33
+ channel.on_extended_data do |ch, type, data|
30
34
  stderr_data += data
31
35
  end
32
36
 
33
- channel.on_request("exit-status") do |ch,data|
37
+ channel.on_request("exit-status") do |ch, data|
34
38
  exit_code = data.read_long
35
39
  end
36
40
 
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define :be_directory do
2
2
  match do |actual|
3
- backend.check_directory(actual)
3
+ backend.check_directory(example, actual)
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define :be_enabled do
2
2
  match do |actual|
3
- backend.check_enabled(actual)
3
+ backend.check_enabled(example, actual)
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :be_executable do
2
2
  match do |file|
3
- backend.check_executable(file, @by_whom)
3
+ backend.check_executable(example, file, @by_whom)
4
4
  end
5
5
  chain :by do |by_whom|
6
6
  @by_whom = by_whom
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define :be_file do
2
2
  match do |actual|
3
- backend.check_file(actual)
3
+ backend.check_file(example, actual)
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define :be_group do
2
2
  match do |actual|
3
- backend.check_group(actual)
3
+ backend.check_group(example, actual)
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define :be_grouped_into do |group|
2
2
  match do |file|
3
- backend.check_grouped(file, group)
3
+ backend.check_grouped(example, file, group)
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  RSpec::Matchers.define :be_installed do
2
2
  match do |name|
3
3
  if @provider.nil?
4
- backend.check_installed(name)
4
+ backend.check_installed(example, name)
5
5
  else
6
6
  check_method = "check_installed_by_#{@provider}".to_sym
7
7
 
@@ -9,7 +9,7 @@ RSpec::Matchers.define :be_installed do
9
9
  raise ArgumentError.new("`be_installed` matcher doesn't support #{@under}")
10
10
  end
11
11
 
12
- backend.send(check_method, name, @version)
12
+ backend.send(check_method, example, name, @version)
13
13
  end
14
14
  end
15
15
 
@@ -8,7 +8,7 @@ Please use be_installed.by('gem') instead.
8
8
  ***************************************************
9
9
 
10
10
  EOF
11
- backend.check_installed_by_gem(name, @version)
11
+ backend.check_installed_by_gem(example, name, @version)
12
12
  end
13
13
  chain :with_version do |version|
14
14
  @version = version
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define :be_linked_to do |target|
2
2
  match do |link|
3
- backend.check_link(link, target)
3
+ backend.check_link(example, link, target)
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :be_listening do
2
2
  match do |actual|
3
3
  port = actual.gsub(/port\s+/, '')
4
- backend.check_listening(port)
4
+ backend.check_listening(example, port)
5
5
  end
6
6
  end
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define :be_mode do |mode|
2
2
  match do |file|
3
- backend.check_mode(file, mode)
3
+ backend.check_mode(example, file, mode)
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define :be_owned_by do |owner|
2
2
  match do |file|
3
- backend.check_owner(file, owner)
3
+ backend.check_owner(example, file, owner)
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :be_readable do
2
2
  match do |file|
3
- backend.check_readable(file, @by_whom)
3
+ backend.check_readable(example, file, @by_whom)
4
4
  end
5
5
  chain :by do |by_whom|
6
6
  @by_whom = by_whom
@@ -7,9 +7,9 @@ RSpec::Matchers.define :be_running do
7
7
  raise ArgumentError.new("`be_running` matcher doesn't support #{@under}")
8
8
  end
9
9
 
10
- backend.send(check_method, process)
10
+ backend.send(check_method, example, process)
11
11
  else
12
- backend.check_running(process)
12
+ backend.check_running(example, process)
13
13
  end
14
14
 
15
15
  end
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define :be_user do
2
2
  match do |actual|
3
- backend.check_user(actual)
3
+ backend.check_user(example, actual)
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :be_writable do
2
2
  match do |file|
3
- backend.check_writable(file, @by_whom)
3
+ backend.check_writable(example, file, @by_whom)
4
4
  end
5
5
  chain :by do |by_whom|
6
6
  @by_whom = by_whom
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :be_zfs do
2
2
  match do |zfs|
3
- backend.check_zfs(zfs, @property)
3
+ backend.check_zfs(example, zfs, @property)
4
4
  end
5
5
 
6
6
  chain :with do |property|
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define :belong_to_group do |group|
2
2
  match do |user|
3
- backend.check_belonging_group(user, group)
3
+ backend.check_belonging_group(example, user, group)
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  RSpec::Matchers.define :have_cron_entry do |entry|
2
2
  match do |actual|
3
3
  @user ||= 'root'
4
- backend.check_cron_entry(@user, entry)
4
+ backend.check_cron_entry(example, @user, entry)
5
5
  end
6
6
  chain :with_user do |user|
7
7
  @user = user
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :have_iptables_rule do |rule|
2
2
  match do |iptables|
3
- backend.check_iptables_rule(rule, @table, @chain)
3
+ backend.check_iptables_rule(example, rule, @table, @chain)
4
4
  end
5
5
  chain :with_table do |table|
6
6
  @table = table
@@ -101,6 +101,7 @@ require 'pathname'
101
101
  ### include requirements ###
102
102
 
103
103
  RSpec.configure do |c|
104
+ c.sudo_password = ENV['SUDO_PASSWORD']
104
105
  ### include backend helper ###
105
106
  ### include os helper ###
106
107
  ### include backend conf ###
@@ -1,3 +1,3 @@
1
1
  module Serverspec
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
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-09 00:00:00.000000000 Z
12
+ date: 2013-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ssh