specinfra 2.0.0.beta1 → 2.0.0.beta2
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/lib/specinfra.rb +5 -5
- data/lib/specinfra/backend/base.rb +1 -1
- data/lib/specinfra/backend/cmd.rb +2 -2
- data/lib/specinfra/backend/docker.rb +3 -3
- data/lib/specinfra/backend/dockerfile.rb +2 -2
- data/lib/specinfra/backend/exec.rb +6 -6
- data/lib/specinfra/backend/lxc.rb +1 -1
- 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 +11 -11
- data/lib/specinfra/backend/winrm.rb +2 -2
- data/lib/specinfra/command/aix.rb +1 -1
- data/lib/specinfra/command/arch.rb +1 -1
- data/lib/specinfra/command/base.rb +1 -1
- data/lib/specinfra/command/darwin.rb +1 -1
- data/lib/specinfra/command/debian.rb +1 -1
- data/lib/specinfra/command/freebsd.rb +1 -1
- data/lib/specinfra/command/freebsd10.rb +1 -1
- data/lib/specinfra/command/gentoo.rb +1 -1
- data/lib/specinfra/command/linux.rb +1 -1
- data/lib/specinfra/command/openbsd.rb +1 -1
- data/lib/specinfra/command/plamo.rb +1 -1
- data/lib/specinfra/command/redhat.rb +1 -1
- data/lib/specinfra/command/smartos.rb +1 -1
- data/lib/specinfra/command/solaris.rb +1 -1
- data/lib/specinfra/command/solaris10.rb +1 -1
- data/lib/specinfra/command/solaris11.rb +1 -1
- data/lib/specinfra/command/suse.rb +1 -1
- data/lib/specinfra/command/ubuntu.rb +1 -1
- data/lib/specinfra/command/windows.rb +1 -1
- data/lib/specinfra/command_result.rb +1 -1
- data/lib/specinfra/configuration.rb +1 -1
- data/lib/specinfra/helper.rb +2 -2
- data/lib/specinfra/helper/backend.rb +5 -5
- data/lib/specinfra/helper/configuration.rb +3 -3
- data/lib/specinfra/helper/detect_os.rb +4 -4
- data/lib/specinfra/helper/docker.rb +1 -1
- data/lib/specinfra/helper/lxc.rb +1 -1
- data/lib/specinfra/helper/os.rb +2 -2
- data/lib/specinfra/helper/properties.rb +3 -3
- data/lib/specinfra/properties.rb +1 -1
- data/lib/specinfra/version.rb +2 -2
- data/spec/backend/exec/build_command_spec.rb +2 -2
- data/spec/backend/ssh/build_command_spec.rb +2 -2
- data/spec/configuration_spec.rb +1 -1
- data/spec/helper/backend_spec.rb +4 -4
- data/spec/helper/properties_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -2
- data/specinfra.gemspec +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: affb586181cbed5a5df08b7051e34fe1b825862b
|
4
|
+
data.tar.gz: 38a773ddead03328e9f581ff9ba2bae517f7968d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76f82c0a871297f8b98ee2bad8fa982bdae82d06515200fe9ac5ccc8ea896d1194f6354dddeb49d896ebb5da10df1e906a6f8e5a398cbda9f6ccb624e06a80e0
|
7
|
+
data.tar.gz: d5f364ea6e222a2d8ac6d82e7a4b4759ae6f126b5a0f14cb1d1dbe2ff3af8778b78e3792ee6212948e38a6cfbc24cb5cc03ce436c951557be3e1f37ba54669c8
|
data/lib/specinfra.rb
CHANGED
@@ -5,19 +5,19 @@ require "specinfra/command"
|
|
5
5
|
require "specinfra/command_result"
|
6
6
|
require "specinfra/configuration"
|
7
7
|
|
8
|
-
include
|
8
|
+
include Specinfra
|
9
9
|
|
10
|
-
module
|
10
|
+
module Specinfra
|
11
11
|
class << self
|
12
12
|
def configuration
|
13
|
-
|
13
|
+
Specinfra::Configuration
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
if defined?(RSpec)
|
19
19
|
RSpec.configure do |c|
|
20
|
-
c.include(
|
20
|
+
c.include(Specinfra::Helper::Configuration)
|
21
21
|
c.add_setting :os, :default => nil
|
22
22
|
c.add_setting :host, :default => nil
|
23
23
|
c.add_setting :ssh, :default => nil
|
@@ -25,7 +25,7 @@ if defined?(RSpec)
|
|
25
25
|
c.add_setting :sudo_password, :default => nil
|
26
26
|
c.add_setting :winrm, :default => nil
|
27
27
|
c.add_setting :architecture, :default => :x86_64
|
28
|
-
|
28
|
+
Specinfra.configuration.defaults.each { |k, v| c.add_setting k, :default => v }
|
29
29
|
c.before :each do
|
30
30
|
if respond_to?(:backend) && backend.respond_to?(:set_example)
|
31
31
|
example = RSpec.respond_to?(:current_example) ? RSpec.current_example : self.example
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'open3'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Specinfra
|
4
4
|
module Backend
|
5
5
|
class Cmd < Base
|
6
6
|
include PowerShell::ScriptHelper
|
@@ -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,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Specinfra
|
2
2
|
module Backend
|
3
3
|
class Docker < Exec
|
4
4
|
def initialize
|
@@ -31,7 +31,7 @@ module SpecInfra
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def base_image
|
34
|
-
@base_image ||= ::Docker::Image.get(
|
34
|
+
@base_image ||= ::Docker::Image.get(Specinfra.configuration.docker_image)
|
35
35
|
end
|
36
36
|
|
37
37
|
def current_image
|
@@ -44,7 +44,7 @@ module SpecInfra
|
|
44
44
|
'Cmd' => %W{/bin/sh -c #{cmd}},
|
45
45
|
}.merge(opts)
|
46
46
|
|
47
|
-
if path =
|
47
|
+
if path = Specinfra::configuration::path
|
48
48
|
(opts['Env'] ||= {})['PATH'] = path
|
49
49
|
end
|
50
50
|
|
@@ -2,7 +2,7 @@ require 'singleton'
|
|
2
2
|
require 'fileutils'
|
3
3
|
require 'shellwords'
|
4
4
|
|
5
|
-
module
|
5
|
+
module Specinfra
|
6
6
|
module Backend
|
7
7
|
class Exec < Base
|
8
8
|
|
@@ -34,11 +34,11 @@ module SpecInfra
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def build_command(cmd)
|
37
|
-
shell =
|
37
|
+
shell = Specinfra.configuration.shell || '/bin/sh'
|
38
38
|
cmd = cmd.shelljoin if cmd.is_a?(Array)
|
39
39
|
cmd = "#{shell.shellescape} -c #{cmd.shellescape}"
|
40
40
|
|
41
|
-
path =
|
41
|
+
path = Specinfra.configuration.path
|
42
42
|
if path
|
43
43
|
cmd = "env PATH=#{path.shellescape}:\"$PATH\" #{cmd}"
|
44
44
|
end
|
@@ -47,8 +47,8 @@ module SpecInfra
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def add_pre_command(cmd)
|
50
|
-
if
|
51
|
-
pre_cmd = build_command(
|
50
|
+
if Specinfra.configuration.pre_command
|
51
|
+
pre_cmd = build_command(Specinfra.configuration.pre_command)
|
52
52
|
"#{pre_cmd} && #{cmd}"
|
53
53
|
else
|
54
54
|
cmd
|
@@ -184,7 +184,7 @@ module SpecInfra
|
|
184
184
|
end
|
185
185
|
|
186
186
|
def check_os
|
187
|
-
return
|
187
|
+
return Specinfra.configuration.os if Specinfra.configuration.os
|
188
188
|
if run_command('ls /etc/redhat-release').success?
|
189
189
|
line = run_command('cat /etc/redhat-release').stdout
|
190
190
|
if line =~ /release (\d[\d.]*)/
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'base64'
|
2
2
|
|
3
|
-
module
|
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
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'specinfra/backend/exec'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Specinfra
|
4
4
|
module Backend
|
5
5
|
class Ssh < Exec
|
6
6
|
def run_command(cmd, opt={})
|
@@ -20,8 +20,8 @@ module SpecInfra
|
|
20
20
|
|
21
21
|
def build_command(cmd)
|
22
22
|
cmd = super(cmd)
|
23
|
-
user =
|
24
|
-
disable_sudo =
|
23
|
+
user = Specinfra.configuration.ssh.options[:user]
|
24
|
+
disable_sudo = Specinfra.configuration.disable_sudo
|
25
25
|
if user != 'root' && !disable_sudo
|
26
26
|
cmd = "#{sudo} #{cmd}"
|
27
27
|
end
|
@@ -29,7 +29,7 @@ module SpecInfra
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def copy_file(from, to)
|
32
|
-
scp =
|
32
|
+
scp = Specinfra.configuration.scp
|
33
33
|
begin
|
34
34
|
scp.upload!(from, to)
|
35
35
|
rescue => e
|
@@ -44,11 +44,11 @@ module SpecInfra
|
|
44
44
|
stderr_data = ''
|
45
45
|
exit_status = nil
|
46
46
|
exit_signal = nil
|
47
|
-
pass_prompt =
|
47
|
+
pass_prompt = Specinfra.configuration.pass_prompt || /^\[sudo\] password for/
|
48
48
|
|
49
|
-
ssh =
|
49
|
+
ssh = Specinfra.configuration.ssh
|
50
50
|
ssh.open_channel do |channel|
|
51
|
-
if
|
51
|
+
if Specinfra.configuration.sudo_password or Specinfra.configuration.request_pty
|
52
52
|
channel.request_pty do |ch, success|
|
53
53
|
abort "Could not obtain pty " if !success
|
54
54
|
end
|
@@ -57,7 +57,7 @@ module SpecInfra
|
|
57
57
|
abort "FAILED: couldn't execute command (ssh.channel.exec)" if !success
|
58
58
|
channel.on_data do |ch, data|
|
59
59
|
if data.match pass_prompt
|
60
|
-
channel.send_data "#{
|
60
|
+
channel.send_data "#{Specinfra.configuration.sudo_password}\n"
|
61
61
|
else
|
62
62
|
stdout_data += data
|
63
63
|
end
|
@@ -65,7 +65,7 @@ module SpecInfra
|
|
65
65
|
|
66
66
|
channel.on_extended_data do |ch, type, data|
|
67
67
|
if data.match /you must have a tty to run sudo/
|
68
|
-
abort 'Please set "
|
68
|
+
abort 'Please set "Specinfra.configuration.request_pty = true" or "c.request_pty = true" in your spec_helper.rb or other appropreate file.'
|
69
69
|
end
|
70
70
|
|
71
71
|
if data.match /^sudo: no tty present and no askpass program specified/
|
@@ -89,13 +89,13 @@ module SpecInfra
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def sudo
|
92
|
-
if sudo_path =
|
92
|
+
if sudo_path = Specinfra.configuration.sudo_path
|
93
93
|
sudo_path += '/sudo'
|
94
94
|
else
|
95
95
|
sudo_path = 'sudo'
|
96
96
|
end
|
97
97
|
|
98
|
-
sudo_options =
|
98
|
+
sudo_options = Specinfra.configuration.sudo_options
|
99
99
|
if sudo_options
|
100
100
|
sudo_options = sudo_options.shelljoin if sudo_options.is_a?(Array)
|
101
101
|
sudo_options = ' ' + sudo_options
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module
|
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/helper.rb
CHANGED
@@ -2,7 +2,7 @@ require 'specinfra/helper/os'
|
|
2
2
|
require 'specinfra/helper/detect_os'
|
3
3
|
|
4
4
|
require 'specinfra/helper/backend'
|
5
|
-
include
|
5
|
+
include Specinfra::Helper::Backend
|
6
6
|
|
7
7
|
require 'specinfra/helper/docker'
|
8
8
|
require 'specinfra/helper/lxc'
|
@@ -10,4 +10,4 @@ require 'specinfra/helper/lxc'
|
|
10
10
|
require 'specinfra/helper/configuration'
|
11
11
|
|
12
12
|
require 'specinfra/helper/properties'
|
13
|
-
include
|
13
|
+
include Specinfra::Helper::Properties
|
@@ -1,13 +1,13 @@
|
|
1
|
-
module
|
1
|
+
module Specinfra
|
2
2
|
module Helper
|
3
3
|
['Exec', 'Ssh', 'Cmd', 'Docker', 'WinRM', 'ShellScript', 'Dockerfile', 'Lxc'].each do |type|
|
4
4
|
eval <<-EOF
|
5
5
|
module #{type}
|
6
6
|
def backend(commands_object=nil)
|
7
7
|
if ! respond_to?(:commands)
|
8
|
-
commands_object =
|
8
|
+
commands_object = Specinfra::Command::Base.new
|
9
9
|
end
|
10
|
-
instance =
|
10
|
+
instance = Specinfra::Backend::#{type}.instance
|
11
11
|
instance.set_commands(commands_object || commands)
|
12
12
|
instance
|
13
13
|
end
|
@@ -17,8 +17,8 @@ module SpecInfra
|
|
17
17
|
|
18
18
|
module Backend
|
19
19
|
def backend_for(type)
|
20
|
-
instance = self.class.const_get('
|
21
|
-
commands = self.class.const_get('
|
20
|
+
instance = self.class.const_get('Specinfra').const_get('Backend').const_get(type.to_s.capitalize).instance
|
21
|
+
commands = self.class.const_get('Specinfra').const_get('Command').const_get(instance.check_os[:family]).new
|
22
22
|
instance.set_commands(commands)
|
23
23
|
instance
|
24
24
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Specinfra
|
2
2
|
module Helper
|
3
3
|
module Configuration
|
4
4
|
def subject
|
@@ -27,13 +27,13 @@ module SpecInfra
|
|
27
27
|
# end
|
28
28
|
# end
|
29
29
|
def build_configurations
|
30
|
-
|
30
|
+
Specinfra::Configuration.defaults.keys.each do |c|
|
31
31
|
if self.respond_to?(c.to_sym)
|
32
32
|
value = self.send(c)
|
33
33
|
else
|
34
34
|
value = RSpec.configuration.send(c) if defined?(RSpec)
|
35
35
|
end
|
36
|
-
|
36
|
+
Specinfra::Configuration.instance_variable_set("@#{c}", value)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
module
|
1
|
+
module Specinfra
|
2
2
|
module Helper
|
3
3
|
module DetectOS
|
4
4
|
def commands
|
5
5
|
property[:os_by_host] = {} if ! property[:os_by_host]
|
6
|
-
host =
|
6
|
+
host = Specinfra.configuration.ssh ? Specinfra.configuration.ssh.host : 'localhost'
|
7
7
|
|
8
8
|
if property[:os_by_host][host]
|
9
9
|
os = property[:os_by_host][host]
|
10
10
|
else
|
11
11
|
# Set command object explicitly to avoid `stack too deep`
|
12
|
-
os = backend(
|
12
|
+
os = backend(Specinfra::Command::Base.new).check_os
|
13
13
|
property[:os_by_host][host] = os
|
14
14
|
end
|
15
|
-
self.class.const_get('
|
15
|
+
self.class.const_get('Specinfra').const_get('Command').const_get(os[:family]).new
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/lib/specinfra/helper/lxc.rb
CHANGED
data/lib/specinfra/helper/os.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'specinfra/properties'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Specinfra
|
4
4
|
module Helper
|
5
5
|
module Properties
|
6
6
|
def property
|
7
|
-
|
7
|
+
Specinfra::Properties.instance.properties
|
8
8
|
end
|
9
9
|
def set_property(prop)
|
10
|
-
|
10
|
+
Specinfra::Properties.instance.properties(prop)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
data/lib/specinfra/properties.rb
CHANGED
data/lib/specinfra/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "2.0.0.
|
1
|
+
module Specinfra
|
2
|
+
VERSION = "2.0.0.beta2"
|
3
3
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
include
|
3
|
+
include Specinfra::Helper::Exec
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe Specinfra::Backend::Exec do
|
6
6
|
describe '#build_command' do
|
7
7
|
context 'with simple command' do
|
8
8
|
it 'should escape spaces' do
|
data/spec/configuration_spec.rb
CHANGED
data/spec/helper/backend_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'backend_for(:type) returns correct backend object' do
|
4
|
-
it 'backend_for(:exec) returns
|
5
|
-
expect(backend_for(:exec)).to be_an_instance_of
|
4
|
+
it 'backend_for(:exec) returns Specinfra::Backend::Exec' do
|
5
|
+
expect(backend_for(:exec)).to be_an_instance_of Specinfra::Backend::Exec
|
6
6
|
end
|
7
7
|
|
8
|
-
it 'backend_for(:ssh) returns
|
9
|
-
expect(backend_for(:ssh)).to be_an_instance_of
|
8
|
+
it 'backend_for(:ssh) returns Specinfra::Backend::Ssh' do
|
9
|
+
expect(backend_for(:ssh)).to be_an_instance_of Specinfra::Backend::Ssh
|
10
10
|
end
|
11
11
|
end
|
data/spec/spec_helper.rb
CHANGED
data/specinfra.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'specinfra/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "specinfra"
|
8
|
-
spec.version =
|
8
|
+
spec.version = Specinfra::VERSION
|
9
9
|
spec.authors = ["Gosuke Miyashita"]
|
10
10
|
spec.email = ["gosukenator@gmail.com"]
|
11
11
|
spec.description = %q{Common layer for serverspec and configspec}
|