knife-cloud 1.0.0.rc.0

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.
Files changed (68) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +33 -0
  3. data/.travis.yml +7 -0
  4. data/CHANGELOG.md +11 -0
  5. data/CONTRIBUTING.md +5 -0
  6. data/Gemfile +9 -0
  7. data/LICENSE +201 -0
  8. data/README.md +420 -0
  9. data/Rakefile +35 -0
  10. data/knife-cloud.gemspec +27 -0
  11. data/lib/chef/knife/cloud/chefbootstrap/bootstrap_distribution.rb +31 -0
  12. data/lib/chef/knife/cloud/chefbootstrap/bootstrap_options.rb +191 -0
  13. data/lib/chef/knife/cloud/chefbootstrap/bootstrap_protocol.rb +69 -0
  14. data/lib/chef/knife/cloud/chefbootstrap/bootstrapper.rb +78 -0
  15. data/lib/chef/knife/cloud/chefbootstrap/ssh_bootstrap_protocol.rb +179 -0
  16. data/lib/chef/knife/cloud/chefbootstrap/unix_distribution.rb +31 -0
  17. data/lib/chef/knife/cloud/chefbootstrap/windows_distribution.rb +32 -0
  18. data/lib/chef/knife/cloud/chefbootstrap/winrm_bootstrap_protocol.rb +85 -0
  19. data/lib/chef/knife/cloud/command.rb +101 -0
  20. data/lib/chef/knife/cloud/exceptions.rb +38 -0
  21. data/lib/chef/knife/cloud/fog/options.rb +29 -0
  22. data/lib/chef/knife/cloud/fog/service.rb +200 -0
  23. data/lib/chef/knife/cloud/helpers.rb +39 -0
  24. data/lib/chef/knife/cloud/list_resource_command.rb +97 -0
  25. data/lib/chef/knife/cloud/list_resource_options.rb +21 -0
  26. data/lib/chef/knife/cloud/server/create_command.rb +165 -0
  27. data/lib/chef/knife/cloud/server/create_options.rb +80 -0
  28. data/lib/chef/knife/cloud/server/delete_command.rb +68 -0
  29. data/lib/chef/knife/cloud/server/delete_options.rb +42 -0
  30. data/lib/chef/knife/cloud/server/list_command.rb +84 -0
  31. data/lib/chef/knife/cloud/server/list_options.rb +43 -0
  32. data/lib/chef/knife/cloud/server/options.rb +39 -0
  33. data/lib/chef/knife/cloud/server/show_command.rb +55 -0
  34. data/lib/chef/knife/cloud/server/show_options.rb +36 -0
  35. data/lib/chef/knife/cloud/service.rb +91 -0
  36. data/lib/knife-cloud/version.rb +6 -0
  37. data/lib/test/fixtures/knife.rb +9 -0
  38. data/lib/test/fixtures/validation.pem +27 -0
  39. data/lib/test/knife-utils/helper.rb +39 -0
  40. data/lib/test/knife-utils/knife_test_utils.rb +40 -0
  41. data/lib/test/knife-utils/matchers.rb +29 -0
  42. data/lib/test/knife-utils/test_bed.rb +56 -0
  43. data/lib/test/templates/chef-full-chef-zero.erb +67 -0
  44. data/lib/test/templates/windows-chef-client-msi.erb +231 -0
  45. data/lib/test/templates/windows-shell.erb +77 -0
  46. data/spec/resource_spec_helper.rb +49 -0
  47. data/spec/server_command_common_spec_helper.rb +48 -0
  48. data/spec/spec_helper.rb +25 -0
  49. data/spec/support/shared_examples_for_command.rb +35 -0
  50. data/spec/support/shared_examples_for_servercreatecommand.rb +144 -0
  51. data/spec/support/shared_examples_for_serverdeletecommand.rb +77 -0
  52. data/spec/support/shared_examples_for_service.rb +85 -0
  53. data/spec/unit/bootstrap_protocol_spec.rb +70 -0
  54. data/spec/unit/bootstrapper_spec.rb +171 -0
  55. data/spec/unit/cloud_command_spec.rb +35 -0
  56. data/spec/unit/command_spec.rb +49 -0
  57. data/spec/unit/fog_service_spec.rb +138 -0
  58. data/spec/unit/list_resource_command_spec.rb +136 -0
  59. data/spec/unit/server_create_command_spec.rb +198 -0
  60. data/spec/unit/server_delete_command_spec.rb +25 -0
  61. data/spec/unit/server_list_command_spec.rb +119 -0
  62. data/spec/unit/server_show_command_spec.rb +64 -0
  63. data/spec/unit/service_spec.rb +46 -0
  64. data/spec/unit/ssh_bootstrap_protocol_spec.rb +116 -0
  65. data/spec/unit/unix_distribution_spec.rb +37 -0
  66. data/spec/unit/windows_distribution_spec.rb +37 -0
  67. data/spec/unit/winrm_bootstrap_protocol_spec.rb +106 -0
  68. metadata +248 -0
@@ -0,0 +1,29 @@
1
+ require 'rspec'
2
+ require File.expand_path(File.dirname(__FILE__) +'/knife_test_utils')
3
+
4
+ RSpec::Matchers.define :have_outcome do |outcome_spec|
5
+ match do |executed_shellout_command|
6
+ valid_keys = [:status, :stdout, :stderr]
7
+ if outcome_spec.keys & valid_keys == []
8
+ throw "You did not specify values for any of #{valid_keys}!"
9
+ end
10
+ print
11
+ @status = outcome_spec[:status] ? (executed_shellout_command.exitstatus == outcome_spec[:status]) : true
12
+ @stdout = outcome_spec[:stdout] ? (executed_shellout_command.stdout =~ outcome_spec[:stdout]) : true
13
+ @stderr = outcome_spec[:stderr] ? (executed_shellout_command.stderr =~ outcome_spec[:stderr]) : true
14
+ @status && @stdout && @stderr
15
+ end
16
+ # Could just spit out `executed_shellout_command.inspect`, but I
17
+ # find the formatting suboptimal for testing error messages.
18
+ failure_message do |executed_shellout_command|
19
+ "Executed command should have matched the outcome spec #{outcome_spec.inspect}, but it didn't!\n
20
+ \tFailed Command: #{executed_shellout_command.command}\n
21
+ \tCommand Setting: #{RSpec::KnifeTestUtils.command_setting(executed_shellout_command).inspect}\n
22
+ \tExit Status: #{executed_shellout_command.exitstatus}\n
23
+ \tStandard Output:\n
24
+ #{executed_shellout_command.stdout}\n
25
+ \tStandard Error:\n
26
+ #{executed_shellout_command.stderr}"
27
+ end
28
+
29
+ end
@@ -0,0 +1,56 @@
1
+ # Copyright: Copyright (c) 2012 Opscode, Inc.
2
+ # License: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Author:: Ameya Varade (<ameya.varade@clogeny.com>)
17
+
18
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
19
+
20
+ module KnifeTestBed
21
+ include KnifeTestHelper
22
+ def init_test
23
+ puts "\nCreating Test Data\n"
24
+ create_file("#{temp_dir}", "validation.pem", "../../fixtures/validation.pem" )
25
+ create_file("#{temp_dir}", "knife.rb", "../../fixtures/knife.rb")
26
+ create_file("#{temp_dir}", "chef-full-chef-zero.erb", "../../templates/chef-full-chef-zero.erb")
27
+ create_file("#{temp_dir}", "windows-chef-client-msi.erb", "../../templates/windows-chef-client-msi.erb")
28
+ create_file("#{temp_dir}", "windows-shell.erb", "../../templates/windows-shell.erb")
29
+ end
30
+
31
+ def cleanup_test_data
32
+ puts "\nCleaning Test Data\n"
33
+ FileUtils.rm_rf("#{temp_dir}")
34
+ puts "\nDone\n"
35
+ end
36
+
37
+ def get_knife_rb_path
38
+ "#{temp_dir}/" + "knife.rb"
39
+ end
40
+
41
+ def get_validation_pem_path
42
+ "#{temp_dir}/" + "validation.pem"
43
+ end
44
+
45
+ def get_linux_template_file_path
46
+ "#{temp_dir}/" + "chef-full-chef-zero.erb"
47
+ end
48
+
49
+ def get_windows_msi_template_file_path
50
+ "#{temp_dir}/" + "windows-chef-client-msi.erb"
51
+ end
52
+
53
+ def get_windows_shell_template_file_path
54
+ "#{temp_dir}/" + "windows-shell.erb"
55
+ end
56
+ end
@@ -0,0 +1,67 @@
1
+ bash -c '
2
+ <%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
3
+
4
+ exists() {
5
+ if command -v $1 &>/dev/null
6
+ then
7
+ return 0
8
+ else
9
+ return 1
10
+ fi
11
+ }
12
+
13
+ install_sh="http://opscode.com/chef/install.sh"
14
+ version_string="-v <%= chef_version %>"
15
+
16
+ if ! exists /usr/bin/chef-client; then
17
+ if exists wget; then
18
+ bash <(wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %> ${install_sh} -O -) ${version_string}
19
+ elif exists curl; then
20
+ bash <(curl -L <%= "--proxy \"#{knife_config[:bootstrap_proxy]}\" " if knife_config[:bootstrap_proxy] %> ${install_sh}) ${version_string}
21
+ else
22
+ echo "Neither wget nor curl found. Please install one and try again." >&2
23
+ exit 1
24
+ fi
25
+ fi
26
+
27
+ mkdir -p /etc/chef
28
+
29
+ awk NF > /etc/chef/validation.pem <<'EOP'
30
+ <%= validation_key %>
31
+ EOP
32
+ chmod 0600 /etc/chef/validation.pem
33
+
34
+ <% if @chef_config[:encrypted_data_bag_secret] -%>
35
+ awk NF > /etc/chef/encrypted_data_bag_secret <<'EOP'
36
+ <%= encrypted_data_bag_secret %>
37
+ EOP
38
+ chmod 0600 /etc/chef/encrypted_data_bag_secret
39
+ <% end -%>
40
+
41
+ <%# Generate Ohai Hints -%>
42
+ <% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
43
+ mkdir -p /etc/chef/ohai/hints
44
+
45
+ <% @chef_config[:knife][:hints].each do |name, hash| -%>
46
+ cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
47
+ <%= hash.to_json %>
48
+ EOP
49
+ <% end -%>
50
+ <% end -%>
51
+
52
+ cat > /etc/chef/client.rb <<'EOP'
53
+ <%= config_content %>
54
+ EOP
55
+
56
+ cat > /etc/chef/first-boot.json <<'EOP'
57
+ <%= first_boot.to_json %>
58
+ EOP
59
+
60
+ <%# Use the embedded ruby/gems and install chef-zero -%>
61
+ apt-get update
62
+ apt-get install libssl-dev make g++ -y
63
+ /opt/chef/embedded/bin/gem install chef-zero --no-ri --no-rdoc
64
+ echo -e "require \"chef_zero/server\"\nserver = ChefZero::Server.new(:port => 8889)\nserver.start" > /tmp/chef_zero_startup.rb
65
+ /opt/chef/embedded/bin/ruby /tmp/chef_zero_startup.rb &
66
+
67
+ <%= start_chef %>'
@@ -0,0 +1,231 @@
1
+ @rem
2
+ @rem Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ @rem Copyright:: Copyright (c) 2011 Opscode, Inc.
4
+ @rem License:: Apache License, Version 2.0
5
+ @rem
6
+ @rem Licensed under the Apache License, Version 2.0 (the "License");
7
+ @rem you may not use this file except in compliance with the License.
8
+ @rem You may obtain a copy of the License at
9
+ @rem
10
+ @rem http://www.apache.org/licenses/LICENSE-2.0
11
+ @rem
12
+ @rem Unless required by applicable law or agreed to in writing, software
13
+ @rem distributed under the License is distributed on an "AS IS" BASIS,
14
+ @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ @rem See the License for the specific language governing permissions and
16
+ @rem limitations under the License.
17
+ @rem
18
+
19
+ @rem Use delayed environment expansion so that ERRORLEVEL can be evaluated with the
20
+ @rem !ERRORLEVEL! syntax which evaluates at execution of the line of script, not when
21
+ @rem the line is read. See help for the /E switch from cmd.exe /? .
22
+ @setlocal ENABLEDELAYEDEXPANSION
23
+
24
+ <%= "SETX HTTP_PROXY \"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] %>
25
+
26
+ @set BOOTSTRAP_DIRECTORY=<%= bootstrap_directory %>
27
+ @echo Checking for existing directory "%BOOTSTRAP_DIRECTORY%"...
28
+ @if NOT EXIST %BOOTSTRAP_DIRECTORY% (
29
+ @echo Existing directory not found, creating.
30
+ @mkdir %BOOTSTRAP_DIRECTORY%
31
+ ) else (
32
+ @echo Existing directory found, skipping creation.
33
+ )
34
+
35
+ > <%= bootstrap_directory %>\wget.vbs (
36
+ <%= win_wget %>
37
+ )
38
+
39
+ > <%= bootstrap_directory %>\wget.ps1 (
40
+ <%= win_wget_ps %>
41
+ )
42
+
43
+ @rem Determine the version and the architecture
44
+
45
+ @FOR /F "usebackq tokens=1-8 delims=.[] " %%A IN (`ver`) DO (
46
+ @set WinMajor=%%D
47
+ @set WinMinor=%%E
48
+ @set WinBuild=%%F
49
+ )
50
+
51
+ @echo Detected Windows Version %WinMajor%.%WinMinor% Build %WinBuild%
52
+
53
+ @set LATEST_OS_VERSION_MAJOR=6
54
+ @set LATEST_OS_VERSION_MINOR=3
55
+
56
+ @if /i %WinMajor% GTR %LATEST_OS_VERSION_MAJOR% goto VersionUnknown
57
+ @if /i %WinMajor% EQU %LATEST_OS_VERSION_MAJOR% (
58
+ @if /i %WinMinor% GTR %LATEST_OS_VERSION_MINOR% goto VersionUnknown
59
+ )
60
+
61
+ goto Version%WinMajor%.%WinMinor%
62
+
63
+ :VersionUnknown
64
+ @rem If this is an unknown version of windows set the default
65
+ @set MACHINE_OS=2008r2
66
+ @echo Warning: Unknown version of Windows, assuming default of Windows %MACHINE_OS%
67
+ goto architecture_select
68
+
69
+ :Version6.0
70
+ @set MACHINE_OS=2008
71
+ goto architecture_select
72
+
73
+ :Version5.2
74
+ @set MACHINE_OS=2003r2
75
+ goto architecture_select
76
+
77
+ :Version6.1
78
+ @set MACHINE_OS=2008r2
79
+ goto architecture_select
80
+
81
+ :Version6.2
82
+ @set MACHINE_OS=2012
83
+ goto architecture_select
84
+
85
+ @rem Currently Windows Server 2012 R2 is treated as equivalent to Windows Server 2012
86
+ :Version6.3
87
+ goto Version6.2
88
+
89
+ :architecture_select
90
+ goto Architecture%PROCESSOR_ARCHITEW6432%
91
+
92
+ :Architecture
93
+ goto Architecture%PROCESSOR_ARCHITECTURE%
94
+
95
+ @rem If this is an unknown architecture set the default
96
+ @set MACHINE_ARCH=i686
97
+ goto install
98
+
99
+ :Architecturex86
100
+ @set MACHINE_ARCH=i686
101
+ goto install
102
+
103
+ :Architectureamd64
104
+ @set MACHINE_ARCH=x86_64
105
+ goto install
106
+
107
+ :install
108
+ @rem Install Chef using chef-client MSI installer
109
+
110
+ <% url="https://www.opscode.com/chef/download?p=windows&pv=%MACHINE_OS%&m=%MACHINE_ARCH%" -%>
111
+ <% url += "&v=#{@config[:bootstrap_version]}" if @config.key? :bootstrap_version -%>
112
+ @set "REMOTE_SOURCE_MSI_URL=<%= url %>"
113
+ @set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>"
114
+ @set "CHEF_CLIENT_MSI_LOG_PATH=%TEMP%\chef-client-msi%RANDOM%.log"
115
+ @set "FALLBACK_QUERY_STRING=&DownloadContext=PowerShell"
116
+
117
+ @rem Clear any pre-existing downloads
118
+ @echo Checking for existing downloaded package at "%LOCAL_DESTINATION_MSI_PATH%"
119
+ @if EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
120
+ @echo Found existing downloaded package, deleting.
121
+ @del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
122
+ @if ERRORLEVEL 1 (
123
+ echo Warning: Failed to delete pre-existing package with status code !ERRORLEVEL! > "&2"
124
+ )
125
+ ) else (
126
+ echo No existing downloaded packages to delete.
127
+ )
128
+
129
+ @rem If there is somehow a name collision, remove pre-existing log
130
+ @if EXIST "%CHEF_CLIENT_MSI_LOG_PATH%" del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
131
+
132
+ @echo Attempting to download client package using cscript...
133
+ cscript /nologo <%= bootstrap_directory %>\wget.vbs /url:"%REMOTE_SOURCE_MSI_URL%" /path:"%LOCAL_DESTINATION_MSI_PATH%"
134
+
135
+ @rem Work around issues found in Windows Server 2012 around job objects not respecting WSMAN memory quotas
136
+ @rem that cause the MSI download process to exceed the quota even when it is increased by administrators.
137
+ @rem Retry the download using a more memory-efficient mechanism that only works if PowerShell is available.
138
+ @set DOWNLOAD_ERROR_STATUS=!ERRORLEVEL!
139
+ @if ERRORLEVEL 1 (
140
+ @echo Failed cscript download with status code !DOWNLOAD_ERROR_STATUS! > "&2"
141
+ @if !DOWNLOAD_ERROR_STATUS!==0 set DOWNLOAD_ERROR_STATUS=2
142
+ ) else (
143
+ @rem Sometimes the error level is not set even when the download failed,
144
+ @rem so check for the file to be sure it is there -- if it is not, we will retry
145
+ @if NOT EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
146
+ echo Failed download: download completed, but downloaded file not found > "&2"
147
+ set DOWNLOAD_ERROR_STATUS=2
148
+ ) else (
149
+ echo Download via cscript succeeded.
150
+ )
151
+ )
152
+
153
+ @if NOT %DOWNLOAD_ERROR_STATUS%==0 (
154
+ @echo Warning: Failed to download "%REMOTE_SOURCE_MSI_URL%" to "%LOCAL_DESTINATION_MSI_PATH%"
155
+ @echo Warning: Retrying download with PowerShell if available...
156
+
157
+ @if EXIST "%LOCAL_DESTINATION_MSI_PATH%" del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
158
+
159
+ @set powershell_download=powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File <%= bootstrap_directory %>\wget.ps1 "%REMOTE_SOURCE_MSI_URL%%FALLBACK_QUERY_STRING%" "%LOCAL_DESTINATION_MSI_PATH%"
160
+ @echo !powershell_download!
161
+ @call !powershell_download!
162
+ @if NOT ERRORLEVEL 1 (
163
+ echo Download via PowerShell succeeded.
164
+ ) else (
165
+ echo Failed to download "%REMOTE_SOURCE_MSI_URL%" with status code !ERRORLEVEL!. > "&2"
166
+ echo Exiting without bootstrapping due to download failure. > "&2"
167
+ exit /b 1
168
+ )
169
+ )
170
+
171
+ @echo Installing downloaded client package...
172
+
173
+ <%= install_chef %>
174
+
175
+ @if ERRORLEVEL 1 (
176
+ echo Chef-client package failed to install with status code !ERRORLEVEL!. > "&2"
177
+ echo See installation log for additional detail: %CHEF_CLIENT_MSI_LOG_PATH%. > "&2"
178
+ ) else (
179
+ @echo Installation completed successfully
180
+ del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
181
+ )
182
+
183
+ @endlocal
184
+
185
+ @echo off
186
+ echo Writing validation key...
187
+
188
+ > <%= bootstrap_directory %>\validation.pem (
189
+ <%= validation_key %>
190
+ )
191
+
192
+ echo Validation key written.
193
+ @echo on
194
+
195
+ <% if @config[:encrypted_data_bag_secret] -%>
196
+ > <%= bootstrap_directory %>\encrypted_data_bag_secret (
197
+ <%= encrypted_data_bag_secret %>
198
+ )
199
+ <% end -%>
200
+
201
+ <%# Generate Ohai Hints -%>
202
+ <% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
203
+ mkdir <%= bootstrap_directory %>\ohai\hints
204
+
205
+ <% @chef_config[:knife][:hints].each do |name, hash| -%>
206
+ > <%= bootstrap_directory %>\ohai\hints\<%= name %>.json (
207
+ <%= escape_and_echo(hash.to_json) %>
208
+ )
209
+ <% end -%>
210
+ <% end -%>
211
+
212
+ > <%= bootstrap_directory %>\client.rb (
213
+ <%= config_content %>
214
+ )
215
+
216
+ > <%= bootstrap_directory %>\first-boot.json (
217
+ <%= first_boot %>
218
+ )
219
+
220
+ <%# Use the embedded ruby/gems and install chef-zero -%>
221
+ del C:\chef_zero_startup.rb
222
+ cd "C:\opscode\chef\embedded\bin\"
223
+ gem install chef-zero --no-ri --no-rdoc
224
+ echo require "chef_zero/server" >C:\chef_zero_startup.rb
225
+ echo server=ChefZero::Server.new(:port =^> 8889) >>C:\chef_zero_startup.rb
226
+ echo server.start >>C:\chef_zero_startup.rb
227
+ C:\opscode\chef\embedded\bin\ruby C:\chef_zero_startup.rb
228
+
229
+ @echo Starting chef to bootstrap the node...
230
+ <%= start_chef %>
231
+
@@ -0,0 +1,77 @@
1
+ @rem
2
+ @rem Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ @rem Copyright:: Copyright (c) 2011 Opscode, Inc.
4
+ @rem License:: Apache License, Version 2.0
5
+ @rem
6
+ @rem Licensed under the Apache License, Version 2.0 (the "License");
7
+ @rem you may not use this file except in compliance with the License.
8
+ @rem You may obtain a copy of the License at
9
+ @rem
10
+ @rem http://www.apache.org/licenses/LICENSE-2.0
11
+ @rem
12
+ @rem Unless required by applicable law or agreed to in writing, software
13
+ @rem distributed under the License is distributed on an "AS IS" BASIS,
14
+ @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ @rem See the License for the specific language governing permissions and
16
+ @rem limitations under the License.
17
+ @rem
18
+
19
+ <%= "SETX HTTP_PROXY \"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] %>
20
+ mkdir C:\chef
21
+
22
+ > C:\chef\wget.vbs (
23
+ <%= win_wget %>
24
+ )
25
+
26
+ cscript /nologo C:\chef\wget.vbs /url:http://files.rubyforge.vm.bytemark.co.uk/rubyinstaller/rubyinstaller-1.8.7-p334.exe /path:%TEMP%\rubyinstaller.exe
27
+ %TEMP%\rubyinstaller.exe /verysilent /dir="C:\ruby" /tasks="assocfiles,modpath"
28
+
29
+ @rem Install the Ruby Dev Kit so we compile us some native gems
30
+ cscript /nologo C:\chef\wget.vbs /url:http://cloud.github.com/downloads/oneclick/rubyinstaller/DevKit-tdm-32-4.5.1-20101214-1400-sfx.exe /path:%TEMP%\rubydevkit.exe
31
+ mkdir C:\DevKit
32
+ copy %TEMP%\rubydevkit.exe C:\DevKit
33
+ cmd.exe /C C:\DevKit\rubydevkit.exe -y
34
+
35
+ @rem update path during bootstrap session
36
+ SET PATH=%PATH%;C:\ruby\bin
37
+
38
+ cmd.exe /C ruby c:/DevKit/dk.rb init
39
+ cmd.exe /C ruby c:/DevKit/dk.rb install
40
+
41
+ cmd.exe /C gem install win32-api win32-service --platform=mswin32
42
+ cmd.exe /C gem install win32-open3 rdp-ruby-wmi windows-api windows-pr --no-rdoc --no-ri --verbose
43
+
44
+ @rem Install Chef gems separately to prevent 'failed to allocate memory' errors
45
+ cmd.exe /C gem install ohai --no-rdoc --no-ri --verbose
46
+ cmd.exe /C gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %>
47
+
48
+ > C:\chef\validation.pem (
49
+ <%= validation_key %>
50
+ )
51
+
52
+ <% if @config[:encrypted_data_bag_secret] -%>
53
+ > C:\chef\encrypted_data_bag_secret (
54
+ <%= encrypted_data_bag_secret %>
55
+ )
56
+ <% end -%>
57
+
58
+ > C:\chef\client.rb (
59
+ echo.require 'win32ole'
60
+ echo.WIN32OLE.codepage = WIN32OLE::CP_UTF8
61
+ <%= config_content %>
62
+ )
63
+
64
+ > C:\chef\first-boot.json (
65
+ <%= run_list %>
66
+ )
67
+
68
+ <%# Use the embedded ruby/gems and install chef-zero -%>
69
+ del C:\chef_zero_startup.rb
70
+ cd "C:\opscode\chef\embedded\bin\"
71
+ gem install chef-zero --no-ri --no-rdoc
72
+ echo require 'chef_zero/server' >C:\chef_zero_startup.rb
73
+ echo server=ChefZero::Server.new(:port =^> 8889) >>C:\chef_zero_startup.rb
74
+ echo server.start >>C:\chef_zero_startup.rb
75
+ C:\opscode\chef\embedded\bin\ruby C:\chef_zero_startup.rb
76
+
77
+ <%= start_chef %>
@@ -0,0 +1,49 @@
1
+ #
2
+ # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
3
+ # Copyright:: Copyright (c) 2014 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ $:.unshift File.expand_path('../../lib', __FILE__)
19
+ require 'json'
20
+
21
+ # Creates a resource class that can dynamically add attributes to
22
+ # instances and set the values
23
+ module JSONModule
24
+ def to_json
25
+ hash = {}
26
+ self.instance_variables.each do |var|
27
+ hash[var] = self.instance_variable_get var
28
+ end
29
+ hash.to_json
30
+ end
31
+ def from_json! string
32
+ JSON.load(string).each do |var, val|
33
+ self.instance_variable_set var, val
34
+ end
35
+ end
36
+ end
37
+
38
+ class TestResource
39
+ include JSONModule
40
+ def initialize(*args)
41
+ args.each do |arg|
42
+ arg.each do |key, value|
43
+ add_attribute = "class << self; attr_accessor :#{key}; end"
44
+ eval(add_attribute)
45
+ eval("@#{key} = value")
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,48 @@
1
+ #
2
+ # Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
3
+ # Copyright:: Copyright (c) 2014 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ $:.unshift File.expand_path('../../lib', __FILE__)
19
+
20
+ # Common helper methods used accrossed knife plugin during Integration testing.
21
+ #
22
+ # run_cmd_check_status_and_output: It checks knife plugin command exitstatus(i.e '0' = succeed and '1' = fails)
23
+ # and also checks command output(i.e stdout or stderr)
24
+ #
25
+ # run_cmd_check_stdout: It checks commands stdout.
26
+ #
27
+ # server_create_common_bfr_aftr: Its contains common before and after blocks used for server create
28
+
29
+ def run_cmd_check_status_and_output(expected_status = "succeed", expected_result = nil)
30
+ it do
31
+ match_status("should #{expected_status}")
32
+ expect(cmd_output).to include(expected_result) if expected_result
33
+ end
34
+ end
35
+
36
+ def run_cmd_check_stdout(expected_result)
37
+ it { match_stdout(/#{expected_result}/) }
38
+ end
39
+
40
+ def server_create_common_bfr_aftr(platform = "linux")
41
+ before { create_node_name(platform) }
42
+ after { run(delete_instance_cmd("#{cmd_output}")) }
43
+ end
44
+
45
+ def rm_known_host
46
+ known_hosts = File.expand_path("~") + "/.ssh/known_hosts"
47
+ FileUtils.rm_rf(known_hosts)
48
+ end
@@ -0,0 +1,25 @@
1
+ #
2
+ # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
3
+ # Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
4
+ # Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ $:.unshift File.expand_path('../../lib', __FILE__)
20
+ require 'json'
21
+ require 'chef/knife/cloud/exceptions'
22
+ require 'chef/exceptions'
23
+ require 'chef/config'
24
+ require 'resource_spec_helper'
25
+ require 'server_command_common_spec_helper'
@@ -0,0 +1,35 @@
1
+ #
2
+ # Author:: Mukta Aphale (<mukta.aphale@clogeny.com>)
3
+ # Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
4
+ # Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require 'chef/knife/cloud/command'
20
+ require 'chef/knife/cloud/service'
21
+
22
+ shared_examples_for Chef::Knife::Cloud::Command do |instance|
23
+ it "runs with correct method calls" do
24
+ allow(instance).to receive(:execute_command)
25
+ allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
26
+ expect(instance).to receive(:set_default_config).ordered
27
+ expect(instance).to receive(:validate!).ordered
28
+ expect(instance).to receive(:validate_params!).ordered
29
+ expect(instance).to receive(:create_service_instance).ordered
30
+ expect(instance).to receive(:before_exec_command).ordered
31
+ expect(instance).to receive(:execute_command).ordered
32
+ expect(instance).to receive(:after_exec_command).ordered
33
+ instance.run
34
+ end
35
+ end