specinfra 2.0.0.beta24 → 2.0.0.beta25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/specinfra.rb +14 -13
- data/lib/specinfra/backend.rb +0 -9
- data/lib/specinfra/backend/base.rb +2 -4
- data/lib/specinfra/backend/cmd.rb +2 -2
- data/lib/specinfra/backend/docker.rb +4 -4
- data/lib/specinfra/backend/dockerfile.rb +1 -1
- data/lib/specinfra/backend/exec.rb +6 -6
- data/lib/specinfra/backend/lxc.rb +3 -2
- data/lib/specinfra/backend/powershell/command.rb +1 -1
- data/lib/specinfra/backend/powershell/script_helper.rb +5 -5
- data/lib/specinfra/backend/shellscript.rb +1 -1
- data/lib/specinfra/backend/ssh.rb +20 -20
- data/lib/specinfra/backend/winrm.rb +2 -2
- data/lib/specinfra/configuration.rb +0 -8
- data/lib/specinfra/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24ce450626fa848a1956f904c62f132ef4c72a48
|
4
|
+
data.tar.gz: e3d006fd2e4b9e275b2df7e971be7664bf027949
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecd328a61efbd1eebc319b4c071ec7669f99642c0c54ea1e867c350918e4878b8cc3c74cc3418b4c660a382952879efe62616282909be301ddbdc13d0225929f
|
7
|
+
data.tar.gz: bf8524a84cb798e02d8fe2dd9c05a66f5d8ecd08f200518c5128f2ace79186f9e75451ff6b9bf64c0160d421c0747811d821c58fd556901820d12222a1cc33a7
|
data/lib/specinfra.rb
CHANGED
@@ -9,22 +9,23 @@ require 'specinfra/runner'
|
|
9
9
|
include Specinfra
|
10
10
|
|
11
11
|
module Specinfra
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
class << self
|
13
|
+
def configuration
|
14
|
+
Specinfra::Configuration
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def command
|
18
|
+
Specinfra::Command::Base
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
def backend
|
22
|
+
type = Specinfra.configuration.backend
|
23
|
+
if type.nil?
|
24
|
+
warn "No backend type is specified. Fall back to :exec type."
|
25
|
+
type = :exec
|
26
|
+
end
|
27
|
+
eval "Specinfra::Backend::#{type.to_s.to_camel_case}.instance"
|
26
28
|
end
|
27
|
-
@@backend ||= Specinfra::Backend.new(type, Specinfra.configuration)
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
data/lib/specinfra/backend.rb
CHANGED
@@ -9,12 +9,3 @@ require 'specinfra/backend/lxc'
|
|
9
9
|
require 'specinfra/backend/winrm'
|
10
10
|
require 'specinfra/backend/shellscript'
|
11
11
|
require 'specinfra/backend/dockerfile'
|
12
|
-
|
13
|
-
module Specinfra
|
14
|
-
class Backend
|
15
|
-
def Backend.new(type, config)
|
16
|
-
eval "Specinfra::Backend::#{type.to_s.to_camel_case}.new(config)"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'open3'
|
2
2
|
|
3
3
|
module Specinfra
|
4
|
-
|
4
|
+
module Backend
|
5
5
|
class Cmd < Base
|
6
6
|
include PowerShell::ScriptHelper
|
7
7
|
|
@@ -38,7 +38,7 @@ module Specinfra
|
|
38
38
|
private
|
39
39
|
|
40
40
|
def powershell
|
41
|
-
architecture = @example.metadata[:architecture] ||
|
41
|
+
architecture = @example.metadata[:architecture] || Specinfra.configuration.architecture
|
42
42
|
|
43
43
|
case architecture
|
44
44
|
when :i386 then x86_powershell
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Specinfra
|
2
|
-
|
2
|
+
module Backend
|
3
3
|
class Docker < Exec
|
4
4
|
def initialize
|
5
5
|
@images = []
|
6
|
-
::Docker.url =
|
6
|
+
::Docker.url = Specinfra.configuration.docker_url
|
7
7
|
end
|
8
8
|
|
9
9
|
def run_command(cmd, opts={})
|
@@ -27,7 +27,7 @@ module Specinfra
|
|
27
27
|
private
|
28
28
|
|
29
29
|
def base_image
|
30
|
-
@base_image ||= ::Docker::Image.get(
|
30
|
+
@base_image ||= ::Docker::Image.get(Specinfra.configuration.docker_image)
|
31
31
|
end
|
32
32
|
|
33
33
|
def current_image
|
@@ -40,7 +40,7 @@ module Specinfra
|
|
40
40
|
'Cmd' => %W{/bin/sh -c #{cmd}},
|
41
41
|
}.merge(opts)
|
42
42
|
|
43
|
-
if path =
|
43
|
+
if path = Specinfra::configuration::path
|
44
44
|
(opts['Env'] ||= {})['PATH'] = path
|
45
45
|
end
|
46
46
|
|
@@ -3,7 +3,7 @@ require 'fileutils'
|
|
3
3
|
require 'shellwords'
|
4
4
|
|
5
5
|
module Specinfra
|
6
|
-
|
6
|
+
module Backend
|
7
7
|
class Exec < Base
|
8
8
|
|
9
9
|
def run_command(cmd, opts={})
|
@@ -29,7 +29,7 @@ module Specinfra
|
|
29
29
|
|
30
30
|
keys.each { |key| ENV["_SPECINFRA_#{key}"] = ENV[key] ; ENV.delete(key) }
|
31
31
|
|
32
|
-
env =
|
32
|
+
env = Specinfra.configuration.env || {}
|
33
33
|
env[:LANG] ||= 'C'
|
34
34
|
|
35
35
|
env.each do |key, value|
|
@@ -48,11 +48,11 @@ module Specinfra
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def build_command(cmd)
|
51
|
-
shell =
|
51
|
+
shell = Specinfra.configuration.shell || '/bin/sh'
|
52
52
|
cmd = cmd.shelljoin if cmd.is_a?(Array)
|
53
53
|
cmd = "#{shell.shellescape} -c #{cmd.shellescape}"
|
54
54
|
|
55
|
-
path =
|
55
|
+
path = Specinfra.configuration.path
|
56
56
|
if path
|
57
57
|
cmd = %Q{env PATH="#{path}" #{cmd}}
|
58
58
|
end
|
@@ -61,8 +61,8 @@ module Specinfra
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def add_pre_command(cmd)
|
64
|
-
if
|
65
|
-
pre_cmd = build_command(
|
64
|
+
if Specinfra.configuration.pre_command
|
65
|
+
pre_cmd = build_command(Specinfra.configuration.pre_command)
|
66
66
|
"#{pre_cmd} && #{cmd}"
|
67
67
|
else
|
68
68
|
cmd
|
@@ -1,5 +1,6 @@
|
|
1
|
+
|
1
2
|
module Specinfra
|
2
|
-
|
3
|
+
module Backend
|
3
4
|
class Lxc < Exec
|
4
5
|
def run_command(cmd, opts={})
|
5
6
|
cmd = build_command(cmd)
|
@@ -27,7 +28,7 @@ module Specinfra
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def ct
|
30
|
-
@ct ||= ::LXC::Container.new(
|
31
|
+
@ct ||= ::LXC::Container.new(RSpec.configuration.lxc)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'base64'
|
2
2
|
|
3
3
|
module Specinfra
|
4
|
-
|
4
|
+
module Backend
|
5
5
|
module PowerShell
|
6
6
|
module ScriptHelper
|
7
7
|
def build_command(cmd)
|
8
|
-
path =
|
8
|
+
path = Specinfra.configuration.path
|
9
9
|
if path
|
10
10
|
cmd.strip!
|
11
11
|
cmd =
|
@@ -18,12 +18,12 @@ EOF
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def add_pre_command(cmd)
|
21
|
-
path =
|
22
|
-
if
|
21
|
+
path = Specinfra.configuration.path
|
22
|
+
if Specinfra.configuration.pre_command
|
23
23
|
cmd.strip!
|
24
24
|
cmd =
|
25
25
|
<<-EOF
|
26
|
-
if (#{
|
26
|
+
if (#{Specinfra.configuration.pre_command})
|
27
27
|
{
|
28
28
|
#{cmd}
|
29
29
|
}
|
@@ -2,7 +2,7 @@ require 'specinfra/backend/exec'
|
|
2
2
|
require 'net/ssh'
|
3
3
|
require 'net/scp'
|
4
4
|
module Specinfra
|
5
|
-
|
5
|
+
module Backend
|
6
6
|
class Ssh < Exec
|
7
7
|
def prompt
|
8
8
|
'Password: '
|
@@ -26,10 +26,10 @@ module Specinfra
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def with_env
|
29
|
-
env =
|
29
|
+
env = Specinfra.configuration.env || {}
|
30
30
|
env[:LANG] ||= 'C'
|
31
31
|
|
32
|
-
ssh_options =
|
32
|
+
ssh_options = Specinfra.configuration.ssh_options || {}
|
33
33
|
ssh_options[:send_env] ||= []
|
34
34
|
|
35
35
|
env.each do |key, value|
|
@@ -49,8 +49,8 @@ module Specinfra
|
|
49
49
|
|
50
50
|
def build_command(cmd)
|
51
51
|
cmd = super(cmd)
|
52
|
-
user =
|
53
|
-
disable_sudo =
|
52
|
+
user = Specinfra.configuration.ssh_options[:user]
|
53
|
+
disable_sudo = Specinfra.configuration.disable_sudo
|
54
54
|
if user != 'root' && !disable_sudo
|
55
55
|
cmd = "#{sudo} -p '#{prompt}' #{cmd}"
|
56
56
|
end
|
@@ -58,25 +58,25 @@ module Specinfra
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def copy_file(from, to)
|
61
|
-
if
|
62
|
-
|
61
|
+
if Specinfra.configuration.scp.nil?
|
62
|
+
Specinfra.configuration.scp = create_scp
|
63
63
|
end
|
64
64
|
|
65
|
-
scp =
|
65
|
+
scp = Specinfra.configuration.scp
|
66
66
|
scp.upload!(from, to)
|
67
67
|
end
|
68
68
|
|
69
69
|
private
|
70
70
|
def create_ssh
|
71
71
|
Net::SSH.start(
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
Specinfra.configuration.host,
|
73
|
+
Specinfra.configuration.ssh_options[:user],
|
74
|
+
Specinfra.configuration.ssh_options
|
75
75
|
)
|
76
76
|
end
|
77
77
|
|
78
78
|
def create_scp
|
79
|
-
ssh =
|
79
|
+
ssh = Specinfra.configuration.ssh
|
80
80
|
if ssh.nil?
|
81
81
|
ssh = create_ssh
|
82
82
|
end
|
@@ -89,13 +89,13 @@ module Specinfra
|
|
89
89
|
exit_status = nil
|
90
90
|
exit_signal = nil
|
91
91
|
|
92
|
-
if
|
93
|
-
|
92
|
+
if Specinfra.configuration.ssh.nil?
|
93
|
+
Specinfra.configuration.ssh = create_ssh
|
94
94
|
end
|
95
95
|
|
96
|
-
ssh =
|
96
|
+
ssh = Specinfra.configuration.ssh
|
97
97
|
ssh.open_channel do |channel|
|
98
|
-
if
|
98
|
+
if Specinfra.configuration.sudo_password or Specinfra.configuration.request_pty
|
99
99
|
channel.request_pty do |ch, success|
|
100
100
|
abort "Could not obtain pty " if !success
|
101
101
|
end
|
@@ -104,7 +104,7 @@ module Specinfra
|
|
104
104
|
abort "FAILED: couldn't execute command (ssh.channel.exec)" if !success
|
105
105
|
channel.on_data do |ch, data|
|
106
106
|
if data.match /^#{prompt}/
|
107
|
-
channel.send_data "#{
|
107
|
+
channel.send_data "#{Specinfra.configuration.sudo_password}\n"
|
108
108
|
else
|
109
109
|
stdout_data += data
|
110
110
|
end
|
@@ -112,7 +112,7 @@ module Specinfra
|
|
112
112
|
|
113
113
|
channel.on_extended_data do |ch, type, data|
|
114
114
|
if data.match /you must have a tty to run sudo/
|
115
|
-
abort 'Please
|
115
|
+
abort 'Please set "Specinfra.configuration.request_pty = true" or "c.request_pty = true" in your spec_helper.rb or other appropriate file.'
|
116
116
|
end
|
117
117
|
|
118
118
|
if data.match /^sudo: no tty present and no askpass program specified/
|
@@ -136,13 +136,13 @@ module Specinfra
|
|
136
136
|
end
|
137
137
|
|
138
138
|
def sudo
|
139
|
-
if sudo_path =
|
139
|
+
if sudo_path = Specinfra.configuration.sudo_path
|
140
140
|
sudo_path += '/sudo'
|
141
141
|
else
|
142
142
|
sudo_path = 'sudo'
|
143
143
|
end
|
144
144
|
|
145
|
-
sudo_options =
|
145
|
+
sudo_options = Specinfra.configuration.sudo_options
|
146
146
|
if sudo_options
|
147
147
|
sudo_options = sudo_options.shelljoin if sudo_options.is_a?(Array)
|
148
148
|
sudo_options = ' ' + sudo_options
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Specinfra
|
2
|
-
|
2
|
+
module Backend
|
3
3
|
class WinRM < Base
|
4
4
|
include PowerShell::ScriptHelper
|
5
5
|
|
6
6
|
def run_command(cmd, opts={})
|
7
7
|
script = create_script(cmd)
|
8
|
-
winrm =
|
8
|
+
winrm = Specinfra.configuration.winrm
|
9
9
|
|
10
10
|
result = winrm.powershell(script)
|
11
11
|
stdout, stderr = [:stdout, :stderr].map do |s|
|
data/lib/specinfra/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: specinfra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.beta25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gosuke Miyashita
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|