windows_chef_zero 1.0.0 → 2.0.0

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: 4666dd1d2ea774b19ba452bed9f93a19fa80179a
4
- data.tar.gz: f0296afe4f2dbfa51b53c574cd5f2841ace837fe
3
+ metadata.gz: 8852b072697c45ec2929629cb4a7f3adc124f08b
4
+ data.tar.gz: e567b02c0754c5cba762946252f9099f7e973946
5
5
  SHA512:
6
- metadata.gz: 4477b598fcd9b7348f7f100bdafe1a5a2197d39d2cd22bbf876abe04a77449108b99f45bc14e254b29fdf3fa60059b650de236c845c392511d5d65889c5322c8
7
- data.tar.gz: 9eb12329f03af3ea4c488af4c615249e830dbe7e0c260f13a70f4903770e2e46c4e43e3f8bee6474f01d48860842fbf47b15d29a6687c7cabd90f0960897fee3
6
+ metadata.gz: adbd7e1609fe6dc6a673d19062bf3c665a5ba8c5d93b77c0969be0e3f48cc532786539ee4e89cd5f1807a81191e3702905a4e93918a683c63000d3fee0713eac
7
+ data.tar.gz: 65280e4fd8619bdc914b47763390ad21614e11276b3f21d4b697da868ce59b030187eb6a5e20dcc542d2ecc52b7ab02afa4bed4d9386427d4fa1413058077e41
@@ -10,7 +10,7 @@ module Kitchen
10
10
  class WindowsChefZero < ChefZero
11
11
 
12
12
  default_config :sudo, false
13
- default_config :require_chef_omnibus, false
13
+ default_config :chef_omnibus_url, "http://www.getchef.com/chef/install.msi"
14
14
  default_config :windows_root_path, 'C:\Windows\Temp\kitchen'
15
15
  default_config :windows_chef_bindir, 'C:\opscode\chef\bin'
16
16
  default_config :disabled_ohai_plugins, %w[
@@ -20,16 +20,30 @@ module Kitchen
20
20
  windows::virtualization windows::kernel_devices
21
21
  ]
22
22
 
23
+ # It would be difficult to make the existing
24
+ # `Kitchen::Provisioner::ChefBase#install_command`
25
+ # Windows-friendly so we'll just make it no-op.
26
+ def install_command; end
27
+
23
28
  def create_sandbox
24
29
  super
30
+ prepare_install_ps1 if config[:require_chef_omnibus]
25
31
  prepare_chef_client_zero_rb
26
32
  prepare_validation_pem
27
33
  prepare_client_rb
28
34
  prepare_run_script
29
35
  end
30
36
 
37
+ # We're hacking Test Kitchen's life-cycle a little here, but YOLO.
31
38
  def run_command
32
- File.join(config[:root_path], "run_client.bat")
39
+ cmds = []
40
+ cmds << install_chef_command if config[:require_chef_omnibus]
41
+ cmds << File.join(config[:windows_root_path], "run_client.bat")
42
+ # Since these commands most likely run under cygwin's `/bin/sh`
43
+ # let's make sure all paths have forward slashes.
44
+ cmds.map { |cmd|
45
+ cmd.gsub("\\", "/")
46
+ }.join("; ")
33
47
  end
34
48
 
35
49
  private
@@ -83,6 +97,44 @@ module Kitchen
83
97
  file.write(windows_run_command)
84
98
  end
85
99
  end
100
+
101
+ def prepare_install_ps1
102
+ url = config[:chef_omnibus_url]
103
+ flag = config[:require_chef_omnibus]
104
+ version = if flag.is_a?(String) && flag != "latest"
105
+ "v=#{flag.downcase}"
106
+ else
107
+ ""
108
+ end
109
+
110
+ File.open(File.join(sandbox_path, "install.ps1"), "wb") do |file|
111
+ file.write <<-INSTALL.gsub(/^ {12}/, "")
112
+ $env:Path = "C:\\opscode\\chef\\bin"
113
+
114
+ # Retrieve current Chef version
115
+ try {
116
+ $installed_chef_version = [string](chef-solo -v)
117
+ } catch [Exception] {
118
+ $installed_chef_version = ''
119
+ }
120
+
121
+ # If the current and desired versions don't match
122
+ # install Chef.
123
+ if (-Not ($installed_chef_version -match '#{flag}')) {
124
+ Write-Host "-----> Installing Chef Omnibus (#{flag})"
125
+ $downloader = New-Object System.Net.WebClient
126
+ $download_path = Join-Path '#{config[:windows_root_path]}' 'chef-client-#{flag}.windows.msi'
127
+ $downloader.DownloadFile('#{url}?#{version}', $download_path)
128
+ $install_process = Start-Process -FilePath 'msiexec.exe' -ArgumentList "/q /i $download_path" -Wait -Passthru
129
+ }
130
+ INSTALL
131
+ end
132
+ end
133
+
134
+ def install_chef_command
135
+ install_script_path = File.join(config[:windows_root_path], "install.ps1")
136
+ "powershell.exe -InputFormat None -ExecutionPolicy bypass -File #{install_script_path}"
137
+ end
86
138
  end
87
139
  end
88
140
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "windows_chef_zero"
5
- spec.version = "1.0.0"
5
+ spec.version = "2.0.0"
6
6
  spec.authors = ["Sean Porter"]
7
7
  spec.email = ["portertech@gmail.com"]
8
8
  spec.summary = "A Test-Kitchen Chef Zero provisioner for Windows"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: windows_chef_zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Porter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-09 00:00:00.000000000 Z
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen