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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4cd4a2f0043137e883ac5bc8d1c39bb16e3befab
4
- data.tar.gz: fb184638708430d79e6d315b3ba26cdfbbc7f76c
3
+ metadata.gz: 24ce450626fa848a1956f904c62f132ef4c72a48
4
+ data.tar.gz: e3d006fd2e4b9e275b2df7e971be7664bf027949
5
5
  SHA512:
6
- metadata.gz: 8570cdc9ab705ebebc81fbd38993cbbe02a9ab4be8cb111e1543deccc8e882b11bf2301352d482a15233a7c074d5bf74f7a76ebe3437eb94af3aaeecff44fd8f
7
- data.tar.gz: 45b0adc803fa83452708cb024720adbf58e8f38b350f5caaa1b4d2c3a9b0906ce3fe39ed5a0105ca81c06421b73ebbc298142db9511c397b7defdf838982c94e
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
- @@backend = nil
13
- def self.configuration
14
- Specinfra::Configuration
15
- end
12
+ class << self
13
+ def configuration
14
+ Specinfra::Configuration
15
+ end
16
16
 
17
- def self.command
18
- Specinfra::Command::Base
19
- end
17
+ def command
18
+ Specinfra::Command::Base
19
+ end
20
20
 
21
- def self.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
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
 
@@ -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
-
@@ -3,11 +3,9 @@ require 'specinfra/command_result'
3
3
  require 'specinfra/command/processor'
4
4
 
5
5
  module Specinfra
6
- class Backend
6
+ module Backend
7
7
  class Base
8
- def initialize(config)
9
- @config = config
10
- end
8
+ include Singleton
11
9
 
12
10
  def set_example(e)
13
11
  @example = e
@@ -1,7 +1,7 @@
1
1
  require 'open3'
2
2
 
3
3
  module Specinfra
4
- class Backend
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] || @config[: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
- class Backend
2
+ module Backend
3
3
  class Docker < Exec
4
4
  def initialize
5
5
  @images = []
6
- ::Docker.url = @config[: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(@config[:docker_image])
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 = @config[:path]
43
+ if path = Specinfra::configuration::path
44
44
  (opts['Env'] ||= {})['PATH'] = path
45
45
  end
46
46
 
@@ -1,5 +1,5 @@
1
1
  module Specinfra
2
- class Backend
2
+ module Backend
3
3
  class Dockerfile < Specinfra::Backend::Base
4
4
  def initialize
5
5
  @lines = []
@@ -3,7 +3,7 @@ require 'fileutils'
3
3
  require 'shellwords'
4
4
 
5
5
  module Specinfra
6
- class Backend
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 = @config[: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 = @config[:shell] || '/bin/sh'
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 = @config[: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 @config[:pre_command]
65
- pre_cmd = build_command(@config[:pre_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
- class Backend
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(@config[:lxc])
31
+ @ct ||= ::LXC::Container.new(RSpec.configuration.lxc)
31
32
  end
32
33
  end
33
34
  end
@@ -1,5 +1,5 @@
1
1
  module Specinfra
2
- class Backend
2
+ module Backend
3
3
  module PowerShell
4
4
  class Command
5
5
  attr_reader :import_functions, :script
@@ -1,11 +1,11 @@
1
1
  require 'base64'
2
2
 
3
3
  module Specinfra
4
- class Backend
4
+ module Backend
5
5
  module PowerShell
6
6
  module ScriptHelper
7
7
  def build_command(cmd)
8
- path = @config[: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 = @config[:path]
22
- if @config[:pre_command]
21
+ path = Specinfra.configuration.path
22
+ if Specinfra.configuration.pre_command
23
23
  cmd.strip!
24
24
  cmd =
25
25
  <<-EOF
26
- if (#{@config[:pre_command]})
26
+ if (#{Specinfra.configuration.pre_command})
27
27
  {
28
28
  #{cmd}
29
29
  }
@@ -1,7 +1,7 @@
1
1
  require 'singleton'
2
2
 
3
3
  module Specinfra
4
- class Backend
4
+ module Backend
5
5
  class ShellScript < Base
6
6
  def initialize
7
7
  @lines = [ "#!/bin/sh", "" ]
@@ -2,7 +2,7 @@ require 'specinfra/backend/exec'
2
2
  require 'net/ssh'
3
3
  require 'net/scp'
4
4
  module Specinfra
5
- class Backend
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 = @config[:env] || {}
29
+ env = Specinfra.configuration.env || {}
30
30
  env[:LANG] ||= 'C'
31
31
 
32
- ssh_options = @config[: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 = @config[:ssh_options][:user]
53
- disable_sudo = @config[: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 @config[:scp].nil?
62
- @config[:scp] = create_scp
61
+ if Specinfra.configuration.scp.nil?
62
+ Specinfra.configuration.scp = create_scp
63
63
  end
64
64
 
65
- scp = @config[: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
- @config[:host],
73
- @config[:ssh_options][:user],
74
- @config[:ssh_options]
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 = @config[: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 @config[:ssh].nil?
93
- @config[:ssh] = create_ssh
92
+ if Specinfra.configuration.ssh.nil?
93
+ Specinfra.configuration.ssh = create_ssh
94
94
  end
95
95
 
96
- ssh = @config[:ssh]
96
+ ssh = Specinfra.configuration.ssh
97
97
  ssh.open_channel do |channel|
98
- if @config[:sudo_password] or @config[:request_pty]
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 "#{@config[:sudo_password]}\n"
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 write "set :request_pty, true" in your spec_helper.rb or other appropriate file.'
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 = @config[: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 = @config[: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
- class Backend
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 = @config[:winrm]
8
+ winrm = Specinfra.configuration.winrm
9
9
 
10
10
  result = winrm.powershell(script)
11
11
  stdout, stderr = [:stdout, :stderr].map do |s|
@@ -33,14 +33,6 @@ module Specinfra
33
33
  @os
34
34
  end
35
35
 
36
- def [](key)
37
- self.send(key)
38
- end
39
-
40
- def []=(key, val)
41
- self.send(key, val)
42
- end
43
-
44
36
  def method_missing(meth, val=nil)
45
37
  key = meth.to_s
46
38
  key.gsub!(/=$/, '')
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "2.0.0.beta24"
2
+ VERSION = "2.0.0.beta25"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,7 @@ require 'rspec/its'
5
5
  set :backend, :exec
6
6
 
7
7
  module Specinfra
8
- class Backend
8
+ module Backend
9
9
  class Ssh
10
10
  def run_command(cmd, opts={})
11
11
  CommandResult.new :stdout => nil, :exit_status => 0
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.beta24
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-08 00:00:00.000000000 Z
11
+ date: 2014-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh