serverspec 0.9.0 → 0.9.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.
- checksums.yaml +4 -4
- data/bin/serverspec-init +0 -75
- data/lib/serverspec/setup.rb +80 -1
- data/lib/serverspec/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db9382459ee16f535fa09efbe1227d821f06156a
|
4
|
+
data.tar.gz: 586c2b1e2d923d3279b28e32bb587e2ef43b58a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8844aeac98285e412ae03cca2bfc86846104e31c72827042676e23ed65c7de47f892f5c019b12d329a5bf48513aac77893fd5df1b638f9ddeb251e533f5f71d5
|
7
|
+
data.tar.gz: 143c9e0d6b86f4796559b916cb54f7a80035764d7f93ab404850e6e5daca7d9020e5f35077304e912c47068bc1ec215928f9bdad394b0fb8bb509f51a519169d
|
data/bin/serverspec-init
CHANGED
@@ -5,78 +5,3 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
|
5
5
|
require 'serverspec'
|
6
6
|
|
7
7
|
Serverspec::Setup.run
|
8
|
-
|
9
|
-
__END__
|
10
|
-
require 'serverspec'
|
11
|
-
<% if @os_type == 'UN*X' -%>
|
12
|
-
require 'pathname'
|
13
|
-
<% end -%>
|
14
|
-
<% if @backend_type == 'Ssh' -%>
|
15
|
-
require 'net/ssh'
|
16
|
-
<% end -%>
|
17
|
-
<% if @backend_type == 'WinRM' -%>
|
18
|
-
require 'winrm'
|
19
|
-
<% end -%>
|
20
|
-
|
21
|
-
include Serverspec::Helper::<%= @backend_type %>
|
22
|
-
<% if @os_type == 'UN*X' -%>
|
23
|
-
include Serverspec::Helper::DetectOS
|
24
|
-
<% else -%>
|
25
|
-
include Serverspec::Helper::Windows
|
26
|
-
<% end -%>
|
27
|
-
|
28
|
-
<% if @os_type == 'UN*X' -%>
|
29
|
-
RSpec.configure do |c|
|
30
|
-
if ENV['ASK_SUDO_PASSWORD']
|
31
|
-
require 'highline/import'
|
32
|
-
c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
|
33
|
-
else
|
34
|
-
c.sudo_password = ENV['SUDO_PASSWORD']
|
35
|
-
end
|
36
|
-
<%- if @backend_type == 'Ssh' -%>
|
37
|
-
c.before :all do
|
38
|
-
block = self.class.metadata[:example_group_block]
|
39
|
-
if RUBY_VERSION.start_with?('1.8')
|
40
|
-
file = block.to_s.match(/.*@(.*):[0-9]+>/)[1]
|
41
|
-
else
|
42
|
-
file = block.source_location.first
|
43
|
-
end
|
44
|
-
host = File.basename(Pathname.new(file).dirname)
|
45
|
-
if c.host != host
|
46
|
-
c.ssh.close if c.ssh
|
47
|
-
c.host = host
|
48
|
-
options = Net::SSH::Config.for(c.host)
|
49
|
-
user = options[:user] || Etc.getlogin
|
50
|
-
<%- if @vagrant -%>
|
51
|
-
vagrant_up = `vagrant up #{@hostname}`
|
52
|
-
config = `vagrant ssh-config #{@hostname}`
|
53
|
-
if config != ''
|
54
|
-
config.each_line do |line|
|
55
|
-
if match = /HostName (.*)/.match(line)
|
56
|
-
c.host = match[1]
|
57
|
-
elsif match = /User (.*)/.match(line)
|
58
|
-
user = match[1]
|
59
|
-
elsif match = /IdentityFile (.*)/.match(line)
|
60
|
-
options[:keys] = [match[1].gsub(/\"/,'')]
|
61
|
-
elsif match = /Port (.*)/.match(line)
|
62
|
-
options[:port] = match[1]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
<%- end -%>
|
67
|
-
c.ssh = Net::SSH.start(c.host, user, options)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
<%- end -%>
|
71
|
-
end
|
72
|
-
<% end -%>
|
73
|
-
<% if @backend_type == 'WinRM'-%>
|
74
|
-
RSpec.configure do |c|
|
75
|
-
user = <username>
|
76
|
-
pass = <password>
|
77
|
-
endpoint = "http://<hostname>:5985/wsman"
|
78
|
-
|
79
|
-
c.winrm = ::WinRM::WinRMWebService.new(endpoint, :ssl, :user => user, :pass => pass, :basic_auth_only => true)
|
80
|
-
c.winrm.set_timeout 300 # 5 minutes max timeout for any operation
|
81
|
-
end
|
82
|
-
<% end -%>
|
data/lib/serverspec/setup.rb
CHANGED
@@ -139,7 +139,7 @@ EOF
|
|
139
139
|
|
140
140
|
def self.safe_create_spec_helper
|
141
141
|
requirements = []
|
142
|
-
content = ERB.new(
|
142
|
+
content = ERB.new(spec_helper_template, nil, '-').result(binding)
|
143
143
|
if File.exists? 'spec/spec_helper.rb'
|
144
144
|
old_content = File.read('spec/spec_helper.rb')
|
145
145
|
if old_content != content
|
@@ -210,5 +210,84 @@ EOF
|
|
210
210
|
exit 1
|
211
211
|
end
|
212
212
|
end
|
213
|
+
|
214
|
+
def self.spec_helper_template
|
215
|
+
template = <<-EOF
|
216
|
+
require 'serverspec'
|
217
|
+
<% if @os_type == 'UN*X' -%>
|
218
|
+
require 'pathname'
|
219
|
+
<% end -%>
|
220
|
+
<% if @backend_type == 'Ssh' -%>
|
221
|
+
require 'net/ssh'
|
222
|
+
<% end -%>
|
223
|
+
<% if @backend_type == 'WinRM' -%>
|
224
|
+
require 'winrm'
|
225
|
+
<% end -%>
|
226
|
+
|
227
|
+
include Serverspec::Helper::<%= @backend_type %>
|
228
|
+
<% if @os_type == 'UN*X' -%>
|
229
|
+
include Serverspec::Helper::DetectOS
|
230
|
+
<% else -%>
|
231
|
+
include Serverspec::Helper::Windows
|
232
|
+
<% end -%>
|
233
|
+
|
234
|
+
<% if @os_type == 'UN*X' -%>
|
235
|
+
RSpec.configure do |c|
|
236
|
+
if ENV['ASK_SUDO_PASSWORD']
|
237
|
+
require 'highline/import'
|
238
|
+
c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
|
239
|
+
else
|
240
|
+
c.sudo_password = ENV['SUDO_PASSWORD']
|
241
|
+
end
|
242
|
+
<%- if @backend_type == 'Ssh' -%>
|
243
|
+
c.before :all do
|
244
|
+
block = self.class.metadata[:example_group_block]
|
245
|
+
if RUBY_VERSION.start_with?('1.8')
|
246
|
+
file = block.to_s.match(/.*@(.*):[0-9]+>/)[1]
|
247
|
+
else
|
248
|
+
file = block.source_location.first
|
249
|
+
end
|
250
|
+
host = File.basename(Pathname.new(file).dirname)
|
251
|
+
if c.host != host
|
252
|
+
c.ssh.close if c.ssh
|
253
|
+
c.host = host
|
254
|
+
options = Net::SSH::Config.for(c.host)
|
255
|
+
user = options[:user] || Etc.getlogin
|
256
|
+
<%- if @vagrant -%>
|
257
|
+
vagrant_up = `vagrant up #{@hostname}`
|
258
|
+
config = `vagrant ssh-config #{@hostname}`
|
259
|
+
if config != ''
|
260
|
+
config.each_line do |line|
|
261
|
+
if match = /HostName (.*)/.match(line)
|
262
|
+
c.host = match[1]
|
263
|
+
elsif match = /User (.*)/.match(line)
|
264
|
+
user = match[1]
|
265
|
+
elsif match = /IdentityFile (.*)/.match(line)
|
266
|
+
options[:keys] = [match[1].gsub(/\"/,'')]
|
267
|
+
elsif match = /Port (.*)/.match(line)
|
268
|
+
options[:port] = match[1]
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
<%- end -%>
|
273
|
+
c.ssh = Net::SSH.start(c.host, user, options)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
<%- end -%>
|
277
|
+
end
|
278
|
+
<% end -%>
|
279
|
+
<% if @backend_type == 'WinRM'-%>
|
280
|
+
RSpec.configure do |c|
|
281
|
+
user = <username>
|
282
|
+
pass = <password>
|
283
|
+
endpoint = "http://<hostname>:5985/wsman"
|
284
|
+
|
285
|
+
c.winrm = ::WinRM::WinRMWebService.new(endpoint, :ssl, :user => user, :pass => pass, :basic_auth_only => true)
|
286
|
+
c.winrm.set_timeout 300 # 5 minutes max timeout for any operation
|
287
|
+
end
|
288
|
+
<% end -%>
|
289
|
+
EOF
|
290
|
+
template
|
291
|
+
end
|
213
292
|
end
|
214
293
|
end
|
data/lib/serverspec/version.rb
CHANGED