specinfra 2.0.0.beta23 → 2.0.0.beta24

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: 30e5563459eccf2fd3b164a49140aa965dc5eaa4
4
- data.tar.gz: 5701805fa1e3c448ba4c00c656fefd8deb60d658
3
+ metadata.gz: 4cd4a2f0043137e883ac5bc8d1c39bb16e3befab
4
+ data.tar.gz: fb184638708430d79e6d315b3ba26cdfbbc7f76c
5
5
  SHA512:
6
- metadata.gz: 6970820c76d47fb28c76ba7a543f02b08fff1a6df365d6c0f5055273f2f209f3ad7e40ec99ff6fa715bc951e499438314f7b85199f8d12286688f3c43f70e6f4
7
- data.tar.gz: de50164311e3649be7f2adf55ab4513aeb199fd1fcee18e59c1ead1785f0b5747a813c409cae64ef4cdf21b718bcd7a23ce46e091d70f730d6a4e9dad10d463f
6
+ metadata.gz: 8570cdc9ab705ebebc81fbd38993cbbe02a9ab4be8cb111e1543deccc8e882b11bf2301352d482a15233a7c074d5bf74f7a76ebe3437eb94af3aaeecff44fd8f
7
+ data.tar.gz: 45b0adc803fa83452708cb024720adbf58e8f38b350f5caaa1b4d2c3a9b0906ce3fe39ed5a0105ca81c06421b73ebbc298142db9511c397b7defdf838982c94e
@@ -3,9 +3,11 @@ require 'specinfra/command_result'
3
3
  require 'specinfra/command/processor'
4
4
 
5
5
  module Specinfra
6
- module Backend
6
+ class Backend
7
7
  class Base
8
- include Singleton
8
+ def initialize(config)
9
+ @config = config
10
+ end
9
11
 
10
12
  def set_example(e)
11
13
  @example = e
@@ -1,7 +1,7 @@
1
1
  require 'open3'
2
2
 
3
3
  module Specinfra
4
- module Backend
4
+ class 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] || Specinfra.configuration.architecture
41
+ architecture = @example.metadata[:architecture] || @config[:architecture]
42
42
 
43
43
  case architecture
44
44
  when :i386 then x86_powershell
@@ -1,9 +1,9 @@
1
1
  module Specinfra
2
- module Backend
2
+ class Backend
3
3
  class Docker < Exec
4
4
  def initialize
5
5
  @images = []
6
- ::Docker.url = Specinfra.configuration.docker_url
6
+ ::Docker.url = @config[: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(Specinfra.configuration.docker_image)
30
+ @base_image ||= ::Docker::Image.get(@config[: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 = Specinfra::configuration::path
43
+ if path = @config[:path]
44
44
  (opts['Env'] ||= {})['PATH'] = path
45
45
  end
46
46
 
@@ -1,5 +1,5 @@
1
1
  module Specinfra
2
- module Backend
2
+ class 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
- module Backend
6
+ class 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 = Specinfra.configuration.env || {}
32
+ env = @config[: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 = Specinfra.configuration.shell || '/bin/sh'
51
+ shell = @config[: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 = Specinfra.configuration.path
55
+ path = @config[: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 Specinfra.configuration.pre_command
65
- pre_cmd = build_command(Specinfra.configuration.pre_command)
64
+ if @config[:pre_command]
65
+ pre_cmd = build_command(@config[:pre_command])
66
66
  "#{pre_cmd} && #{cmd}"
67
67
  else
68
68
  cmd
@@ -1,6 +1,5 @@
1
-
2
1
  module Specinfra
3
- module Backend
2
+ class Backend
4
3
  class Lxc < Exec
5
4
  def run_command(cmd, opts={})
6
5
  cmd = build_command(cmd)
@@ -28,7 +27,7 @@ module Specinfra
28
27
  end
29
28
 
30
29
  def ct
31
- @ct ||= ::LXC::Container.new(RSpec.configuration.lxc)
30
+ @ct ||= ::LXC::Container.new(@config[:lxc])
32
31
  end
33
32
  end
34
33
  end
@@ -1,5 +1,5 @@
1
1
  module Specinfra
2
- module Backend
2
+ class 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
- module Backend
4
+ class Backend
5
5
  module PowerShell
6
6
  module ScriptHelper
7
7
  def build_command(cmd)
8
- path = Specinfra.configuration.path
8
+ path = @config[: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 = Specinfra.configuration.path
22
- if Specinfra.configuration.pre_command
21
+ path = @config[:path]
22
+ if @config[:pre_command]
23
23
  cmd.strip!
24
24
  cmd =
25
25
  <<-EOF
26
- if (#{Specinfra.configuration.pre_command})
26
+ if (#{@config[:pre_command]})
27
27
  {
28
28
  #{cmd}
29
29
  }
@@ -1,19 +1,80 @@
1
1
  function FindIISWebsite
2
2
  {
3
3
  param($name)
4
+
4
5
  Import-Module WebAdministration
5
6
 
6
- Try {
7
- Get-Item "IIS:\Sites\$name" -Erroraction silentlycontinue
8
- }
9
- Catch [System.IO.FileNotFoundException] {
10
- Get-Item "IIS:\Sites\$name" -Erroraction silentlycontinue
11
- }
7
+ Try {
8
+ Get-Item "IIS:\Sites\$name" -Erroraction silentlycontinue
9
+ }
10
+ Catch [System.IO.FileNotFoundException] {
11
+ Get-Item "IIS:\Sites\$name" -Erroraction silentlycontinue
12
+ }
12
13
  }
13
14
 
14
15
  function FindIISAppPool
15
16
  {
16
17
  param($name)
17
- import-module WebAdministration
18
+
19
+ Import-Module WebAdministration
20
+
18
21
  Get-Item "IIS:\AppPools\$name" -Erroraction silentlycontinue
19
- }
22
+ }
23
+
24
+ function FindSiteBindings
25
+ {
26
+ param($name, $protocol, $hostHeader, $port, $ipAddress)
27
+
28
+ Import-Module WebAdministration
29
+
30
+ Get-WebBinding -Name $name -Protocol $protocol -HostHeader $hostHeader -Port $port -IPAddress $ipAddress
31
+ }
32
+
33
+ function FindSiteVirtualDir
34
+ {
35
+ param($name, $vdir, $path)
36
+
37
+ Import-Module WebAdministration
38
+
39
+ $webVirtDirPath = [string]::Format('IIS:\Sites\{0}\{1}',$name, $vdir);
40
+ if (Test-Path $webVirtDirPath)
41
+ {
42
+ if ([string]::IsNullOrEmpty($path))
43
+ {
44
+ $true
45
+ }
46
+ else
47
+ {
48
+ (Get-Item $webVirtDirPath).physicalPath -eq $path
49
+ }
50
+ }
51
+ else
52
+ {
53
+ $false
54
+ }
55
+ }
56
+
57
+ function FindSiteApplication
58
+ {
59
+ param($name, $app, $pool, $physicalPath)
60
+
61
+ Import-Module WebAdministration
62
+
63
+ $path = "IIS:\Sites\${name}\${app}"
64
+ $result = $false
65
+ if (Test-Path $path)
66
+ {
67
+ $result = $true
68
+ if ([string]::IsNullOrEmpty($pool) -eq $false)
69
+ {
70
+ $result = $result -and (Get-Item $path).applicationPool -eq $pool
71
+ }
72
+
73
+ if ([string]::IsNullOrEmpty($physicalPath) -eq $false)
74
+ {
75
+ $result = $result -and (Get-Item $path).physicalPath -eq $physicalPath
76
+ }
77
+ }
78
+
79
+ $result
80
+ }
@@ -1,7 +1,7 @@
1
1
  require 'singleton'
2
2
 
3
3
  module Specinfra
4
- module Backend
4
+ class 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
- module Backend
5
+ class 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 = Specinfra.configuration.env || {}
29
+ env = @config[:env] || {}
30
30
  env[:LANG] ||= 'C'
31
31
 
32
- ssh_options = Specinfra.configuration.ssh_options || {}
32
+ ssh_options = @config[: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 = Specinfra.configuration.ssh_options[:user]
53
- disable_sudo = Specinfra.configuration.disable_sudo
52
+ user = @config[:ssh_options][:user]
53
+ disable_sudo = @config[: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 Specinfra.configuration.scp.nil?
62
- Specinfra.configuration.scp = create_scp
61
+ if @config[:scp].nil?
62
+ @config[:scp] = create_scp
63
63
  end
64
64
 
65
- scp = Specinfra.configuration.scp
65
+ scp = @config[: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
- Specinfra.configuration.host,
73
- Specinfra.configuration.ssh_options[:user],
74
- Specinfra.configuration.ssh_options
72
+ @config[:host],
73
+ @config[:ssh_options][:user],
74
+ @config[:ssh_options]
75
75
  )
76
76
  end
77
77
 
78
78
  def create_scp
79
- ssh = Specinfra.configuration.ssh
79
+ ssh = @config[: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 Specinfra.configuration.ssh.nil?
93
- Specinfra.configuration.ssh = create_ssh
92
+ if @config[:ssh].nil?
93
+ @config[:ssh] = create_ssh
94
94
  end
95
95
 
96
- ssh = Specinfra.configuration.ssh
96
+ ssh = @config[:ssh]
97
97
  ssh.open_channel do |channel|
98
- if Specinfra.configuration.sudo_password or Specinfra.configuration.request_pty
98
+ if @config[:sudo_password] or @config[: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 "#{Specinfra.configuration.sudo_password}\n"
107
+ channel.send_data "#{@config[: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 set "Specinfra.configuration.request_pty = true" or "c.request_pty = true" in your spec_helper.rb or other appropriate file.'
115
+ abort 'Please write "set :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 = Specinfra.configuration.sudo_path
139
+ if sudo_path = @config[:sudo_path]
140
140
  sudo_path += '/sudo'
141
141
  else
142
142
  sudo_path = 'sudo'
143
143
  end
144
144
 
145
- sudo_options = Specinfra.configuration.sudo_options
145
+ sudo_options = @config[: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
- module Backend
2
+ class 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 = Specinfra.configuration.winrm
8
+ winrm = @config[:winrm]
9
9
 
10
10
  result = winrm.powershell(script)
11
11
  stdout, stderr = [:stdout, :stderr].map do |s|
@@ -9,3 +9,12 @@ 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
+
@@ -55,5 +55,15 @@ class Specinfra::Command::Windows::Base::IisAppPool < Specinfra::Command::Window
55
55
  exec "(FindIISAppPool -name '#{name}').recycling.periodicRestart.time.TotalMinutes -eq #{minutes}"
56
56
  end
57
57
  end
58
+
59
+ def check_has_managed_pipeline_mode(name, mode)
60
+ Backend::PowerShell::Command.new do
61
+ using 'find_iis_component.ps1'
62
+ exec "(FindIISAppPool -name '#{name}').managedPipelineMode -eq '#{mode}'"
63
+ end
64
+ end
58
65
  end
59
66
  end
67
+
68
+
69
+
@@ -34,5 +34,26 @@ class Specinfra::Command::Windows::Base::IisWebsite < Specinfra::Command::Window
34
34
  exec "[System.Environment]::ExpandEnvironmentVariables( ( FindIISWebsite -name '#{name}' ).physicalPath ).replace('\\', '/' ) -eq ('#{path}'.trimEnd('/').replace('\\', '/'))"
35
35
  end
36
36
  end
37
+
38
+ def check_has_site_bindings(name, port, protocol, ipaddress, host_header)
39
+ Backend::PowerShell::Command.new do
40
+ using 'find_iis_component.ps1'
41
+ exec "(FindSiteBindings -name '#{name}' -protocol '#{protocol}' -hostHeader '#{host_header}' -port #{port} -ipAddress '#{ipaddress}').count -gt 0"
42
+ end
43
+ end
44
+
45
+ def check_has_virtual_dir(name, vdir, path)
46
+ Backend::PowerShell::Command.new do
47
+ using 'find_iis_component.ps1'
48
+ exec "(FindSiteVirtualDir -name '#{name}' -vdir '#{vdir}' -path '#{path}') -eq $true"
49
+ end
50
+ end
51
+
52
+ def check_has_site_application(name, app, pool, physical_path)
53
+ Backend::PowerShell::Command.new do
54
+ using 'find_iis_component.ps1'
55
+ exec "(FindSiteApplication -name '#{name}' -app '#{app}' -pool '#{pool}' -physicalPath '#{physical_path}') -eq $true"
56
+ end
57
+ end
37
58
  end
38
59
  end
@@ -33,6 +33,14 @@ 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
+
36
44
  def method_missing(meth, val=nil)
37
45
  key = meth.to_s
38
46
  key.gsub!(/=$/, '')
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "2.0.0.beta23"
2
+ VERSION = "2.0.0.beta24"
3
3
  end
data/lib/specinfra.rb CHANGED
@@ -9,23 +9,22 @@ require 'specinfra/runner'
9
9
  include Specinfra
10
10
 
11
11
  module Specinfra
12
- class << self
13
- def configuration
14
- Specinfra::Configuration
15
- end
12
+ @@backend = nil
13
+ def self.configuration
14
+ Specinfra::Configuration
15
+ end
16
16
 
17
- def command
18
- Specinfra::Command::Base
19
- end
17
+ def self.command
18
+ Specinfra::Command::Base
19
+ end
20
20
 
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"
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
28
26
  end
27
+ @@backend ||= Specinfra::Backend.new(type, Specinfra.configuration)
29
28
  end
30
29
  end
31
30
 
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
- module Backend
8
+ class 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.beta23
4
+ version: 2.0.0.beta24
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-06 00:00:00.000000000 Z
11
+ date: 2014-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh