serverspec 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,25 +1,19 @@
1
- require 'net/ssh'
2
1
  require 'etc'
3
2
 
4
3
  module Serverspec
5
4
  module Helper
6
- def ssh_exec(host, cmd, opt={})
7
- options = Net::SSH::Config.for(host)
8
- user = options[:user] || Etc.getlogin
9
-
10
- ret = nil
11
- Net::SSH.start(host, user, options) do |ssh|
12
- ret = ssh_exec!(ssh, "sudo #{cmd}")
13
- end
14
- ret
5
+ def ssh_exec(cmd, opt={})
6
+ ssh_exec!("sudo #{cmd}")
15
7
  end
16
8
 
17
9
  private
18
- def ssh_exec!(ssh, command)
10
+ def ssh_exec!(command)
19
11
  stdout_data = ''
20
12
  stderr_data = ''
21
13
  exit_code = nil
22
14
  exit_signal = nil
15
+
16
+ ssh = RSpec.configuration.ssh
23
17
  ssh.open_channel do |channel|
24
18
  channel.request_pty do |ch, success|
25
19
  abort "Could not obtain pty " if !success
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :be_directory do
2
2
  match do |actual|
3
- ret = ssh_exec(RSpec.configuration.host, commands.check_directory(actual))
3
+ ret = ssh_exec(commands.check_directory(actual))
4
4
  ret[:exit_code] == 0
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :be_enabled do
2
2
  match do |actual|
3
- ret = ssh_exec(RSpec.configuration.host, commands.check_enabled(actual))
3
+ ret = ssh_exec(commands.check_enabled(actual))
4
4
  ret[:exit_code] == 0
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :be_file do
2
2
  match do |actual|
3
- ret = ssh_exec(RSpec.configuration.host, commands.check_file(actual))
3
+ ret = ssh_exec(commands.check_file(actual))
4
4
  ret[:exit_code] == 0
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :be_group do
2
2
  match do |actual|
3
- ret = ssh_exec(RSpec.configuration.host, commands.check_group(actual))
3
+ ret = ssh_exec(commands.check_group(actual))
4
4
  ret[:exit_code] == 0
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :be_grouped_into do |group|
2
2
  match do |file|
3
- ret = ssh_exec(RSpec.configuration.host, commands.check_grouped(file, group))
3
+ ret = ssh_exec(commands.check_grouped(file, group))
4
4
  ret[:exit_code] == 0
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :be_installed do
2
2
  match do |actual|
3
- ret = ssh_exec(RSpec.configuration.host, commands.check_installed(actual))
3
+ ret = ssh_exec(commands.check_installed(actual))
4
4
  ret[:exit_code] == 0
5
5
  end
6
6
  end
@@ -1,7 +1,7 @@
1
1
  RSpec::Matchers.define :be_listening do
2
2
  match do |actual|
3
3
  port = actual.gsub(/port\s+/, '')
4
- ret = ssh_exec(RSpec.configuration.host, commands.check_listening(port))
4
+ ret = ssh_exec(commands.check_listening(port))
5
5
  ret[:exit_code] == 0
6
6
  end
7
7
  end
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :be_mode do |mode|
2
2
  match do |file|
3
- ret = ssh_exec(RSpec.configuration.host, commands.check_mode(file, mode))
3
+ ret = ssh_exec(commands.check_mode(file, mode))
4
4
  ret[:exit_code] == 0
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :be_owned_by do |owner|
2
2
  match do |file|
3
- ret = ssh_exec(RSpec.configuration.host, commands.check_owner(file, owner))
3
+ ret = ssh_exec(commands.check_owner(file, owner))
4
4
  ret[:exit_code] == 0
5
5
  end
6
6
  end
@@ -1,8 +1,8 @@
1
1
  RSpec::Matchers.define :be_running do
2
2
  match do |actual|
3
- ret = ssh_exec(RSpec.configuration.host, commands.check_running(actual))
3
+ ret = ssh_exec(commands.check_running(actual))
4
4
  if ret[:exit_code] == 1
5
- ret = ssh_exec(RSpec.configuration.host, commands.check_process(actual))
5
+ ret = ssh_exec(commands.check_process(actual))
6
6
  end
7
7
  ret[:exit_code] == 0
8
8
  end
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :be_user do
2
2
  match do |actual|
3
- ret = ssh_exec(RSpec.configuration.host, commands.check_user(actual))
3
+ ret = ssh_exec(commands.check_user(actual))
4
4
  ret[:exit_code] == 0
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :contain do |expected|
2
2
  match do |actual|
3
- ret = ssh_exec(RSpec.configuration.host, commands.check_file_contain(actual, expected))
3
+ ret = ssh_exec(commands.check_file_contain(actual, expected))
4
4
  ret[:exit_code] == 0
5
5
  end
6
6
  end
@@ -57,10 +57,18 @@ EOF
57
57
  content = <<-EOF
58
58
  require 'serverspec'
59
59
  require 'pathname'
60
+ require 'net/ssh'
60
61
 
61
62
  RSpec.configure do |c|
62
63
  c.before do
63
- c.host = File.basename(Pathname.new(example.metadata[:location]).dirname)
64
+ host = File.basename(Pathname.new(example.metadata[:location]).dirname)
65
+ if c.host != host
66
+ c.ssh.close if c.ssh
67
+ c.host = host
68
+ options = Net::SSH::Config.for(c.host)
69
+ user = options[:user] || Etc.getlogin
70
+ c.ssh = Net::SSH.start(c.host, user, options)
71
+ end
64
72
  end
65
73
  end
66
74
  EOF
@@ -1,3 +1,3 @@
1
1
  module Serverspec
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
data/lib/serverspec.rb CHANGED
@@ -17,4 +17,5 @@ RSpec.configure do |c|
17
17
  c.include(Serverspec::GentooHelper, :os => :gentoo)
18
18
  c.include(Serverspec::SolarisHelper, :os => :solaris)
19
19
  c.add_setting :host, :default => nil
20
+ c.add_setting :ssh, :default => nil
20
21
  end
metadata CHANGED
@@ -1,90 +1,88 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: serverspec
3
- version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 12
10
- version: 0.0.12
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.13
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Gosuke Miyashita
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-03-28 00:00:00 +09:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2013-03-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: net-ssh
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: bundler
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
39
25
  none: false
40
- requirements:
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
41
35
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 9
44
- segments:
45
- - 1
46
- - 3
47
- version: "1.3"
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
48
38
  type: :development
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: rspec
52
39
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
54
49
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
62
54
  type: :development
63
- version_requirements: *id003
64
- - !ruby/object:Gem::Dependency
65
- name: rake
66
55
  prerelease: false
67
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
68
57
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
76
70
  type: :development
77
- version_requirements: *id004
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
78
  description: RSpec tests for your provisioned servers
79
- email:
79
+ email:
80
80
  - gosukenator@gmail.com
81
- executables:
81
+ executables:
82
82
  - serverspec-init
83
83
  extensions: []
84
-
85
84
  extra_rdoc_files: []
86
-
87
- files:
85
+ files:
88
86
  - .gitignore
89
87
  - Gemfile
90
88
  - LICENSE.txt
@@ -122,41 +120,32 @@ files:
122
120
  - spec/solaris/matchers_spec.rb
123
121
  - spec/spec_helper.rb
124
122
  - spec/support/shared_matcher_examples.rb
125
- has_rdoc: true
126
123
  homepage: https://github.com/mizzy/serverspec
127
- licenses:
124
+ licenses:
128
125
  - MIT
129
126
  post_install_message:
130
127
  rdoc_options: []
131
-
132
- require_paths:
128
+ require_paths:
133
129
  - lib
134
- required_ruby_version: !ruby/object:Gem::Requirement
130
+ required_ruby_version: !ruby/object:Gem::Requirement
135
131
  none: false
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- hash: 3
140
- segments:
141
- - 0
142
- version: "0"
143
- required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
137
  none: false
145
- requirements:
146
- - - ">="
147
- - !ruby/object:Gem::Version
148
- hash: 3
149
- segments:
150
- - 0
151
- version: "0"
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
152
142
  requirements: []
153
-
154
143
  rubyforge_project:
155
- rubygems_version: 1.3.7
144
+ rubygems_version: 1.8.25
156
145
  signing_key:
157
146
  specification_version: 3
158
147
  summary: RSpec tests for your provisioned servers
159
- test_files:
148
+ test_files:
160
149
  - spec/debian/matchers_spec.rb
161
150
  - spec/gentoo/matchers_spec.rb
162
151
  - spec/redhat/matchers_spec.rb