kitchen-dsc 0.10.1 → 0.11.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: 15912b49fe3ff3144d49f605434b15e05fb155bf
4
- data.tar.gz: 7cc40f3a658927a59ca6d6f1241392943244677e
3
+ metadata.gz: e624fe030f3b2b0b22bc97d9225668a67c55045e
4
+ data.tar.gz: f9c7ce4985d3115dc6ee61f10dd57d76f96b17b4
5
5
  SHA512:
6
- metadata.gz: e26cd1fccd5af9d09ffef4dc1a0ca1075d3f25d48155525a5f2fbaeef5fa978818f818377b42e86679acb8bc3d91e210521a5f7903e0de5931a644195714611b
7
- data.tar.gz: 14e5db6f434eb11ef8dcadf47ee70fbcdbc06c30e54fc7636036c5cefe48d04b49003dc86e4279a65f7d6372c4f6433d87b0a93ea122a2756f9b8f9ea7d84fde
6
+ metadata.gz: 6c6bdec9163a77a027f07101c4806305528b8b3aa6b7d2694c7ea000d56ba3b25d62a8c922f3f410adc3c81383056ceafccf14d0b8683c7cceb14709b0e7823e
7
+ data.tar.gz: '0686ca5ffd4a6b58115220aab4d157ef11a34a588e2b76d50326d880012a2d5f073a6a7d3db7e6ccec16aa7f49a356d1d37567ae159f648b43847b614cd3058f'
@@ -1,7 +1,7 @@
1
- # encoding: utf-8
2
-
3
- module Kitchen
4
- module Dsc
5
- VERSION = '0.10.1'.freeze
6
- end
7
- end
1
+ # encoding: utf-8
2
+
3
+ module Kitchen
4
+ module Dsc
5
+ VERSION = '0.11.0'.freeze
6
+ end
7
+ end
@@ -1,311 +1,328 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Author:: Steven Murawski (<steven.murawski@gmail.com>)
4
- #
5
- # Copyright (C) 2014 Steven Murawski
6
- #
7
- # Licensed under the Apache 2 License.
8
- # See LICENSE for more details
9
-
10
- require "fileutils"
11
- require "pathname"
12
- require "kitchen/provisioner/base"
13
- require "kitchen/util"
14
- require "dsc_lcm_configuration"
15
-
16
- module Kitchen
17
- module Provisioner
18
- class Dsc < Base
19
- kitchen_provisioner_api_version 2
20
-
21
- attr_accessor :tmp_dir
22
-
23
- default_config :modules_path, "modules"
24
-
25
- default_config :configuration_script_folder, "examples"
26
- default_config :configuration_script, "dsc_configuration.ps1"
27
- default_config :configuration_name do |provisioner|
28
- provisioner.instance.suite.name
29
- end
30
-
31
- default_config :configuration_data_variable, "ConfigurationData"
32
- default_config :configuration_data
33
-
34
- default_config :nuget_force_bootstrap, true
35
- default_config :gallery_uri
36
- default_config :gallery_name
37
- default_config :modules_from_gallery
38
-
39
- default_config :dsc_local_configuration_manager_version, "wmf4"
40
- default_config :dsc_local_configuration_manager, {}
41
-
42
- def finalize_config!(instance)
43
- config[:dsc_local_configuration_manager] = lcm.lcm_config
44
- super(instance)
45
- end
46
-
47
- def install_command
48
- full_lcm_configuration_script = <<-EOH
49
- #{lcm.lcm_configuration_script}
50
-
51
- $null = SetupLCM
52
- Set-DscLocalConfigurationManager -Path ./SetupLCM | out-null
53
- EOH
54
-
55
- wrap_powershell_code(full_lcm_configuration_script)
56
- end
57
-
58
- def init_command
59
- script = <<-EOH
60
- #{setup_config_directory_script}
61
- #{install_module_script if install_modules?}
62
- EOH
63
- wrap_powershell_code(script)
64
- end
65
-
66
- def create_sandbox
67
- super
68
- info("Staging DSC Resource Modules for copy to the SUT")
69
- if powershell_module?
70
- prepare_resource_style_directory
71
- else
72
- prepare_repo_style_directory
73
- end
74
- info("Staging DSC configuration script for copy to the SUT")
75
- prepare_configuration_script
76
- end
77
-
78
- def prepare_command
79
- info("Moving DSC Resources onto PSModulePath")
80
- info("Generating the MOF script for the configuration #{config[:configuration_name]}")
81
- stage_resources_and_generate_mof_script = <<-EOH
82
-
83
- if(Test-Path c:/configurations)
84
- {
85
- Remove-Item -Recurse -Force c:/configurations
86
- }
87
-
88
- $Error.clear()
89
-
90
- if (Test-Path (join-path #{config[:root_path]} 'modules'))
91
- {
92
- dir ( join-path #{config[:root_path]} 'modules/*') -directory |
93
- copy-item -destination $env:programfiles/windowspowershell/modules/ -recurse -force
94
- }
95
- if (-not (test-path 'c:/configurations'))
96
- {
97
- mkdir 'c:/configurations' | out-null
98
- }
99
- $ConfigurationScriptPath = Join-path #{config[:root_path]} #{sandboxed_configuration_script}
100
- if (-not (test-path $ConfigurationScriptPath))
101
- {
102
- throw "Failed to find $ConfigurationScriptPath"
103
- }
104
- invoke-expression (get-content $ConfigurationScriptPath -raw)
105
-
106
- if (-not (get-command #{config[:configuration_name]}))
107
- {
108
- throw "Failed to create a configuration command #{config[:configuration_name]}"
109
- }
110
-
111
- #{configuration_data_assignment unless config[:configuration_data].nil?}
112
-
113
- try{
114
- $null = #{config[:configuration_name]} -outputpath c:/configurations #{"-configurationdata $" + configuration_data_variable}
115
- }
116
- catch{
117
- }
118
-
119
- if($Error -ne $null)
120
- {
121
- $Error[-1]
122
- exit 1
123
- }
124
-
125
- EOH
126
- debug("Shelling out: #{stage_resources_and_generate_mof_script}")
127
- wrap_powershell_code(stage_resources_and_generate_mof_script)
128
- end
129
-
130
- def run_command
131
- config[:retry_on_exit_code] = [35] if config[:retry_on_exit_code].empty?
132
- config[:max_retries] = 3 if config[:max_retries] == 1
133
-
134
- info("Running the configuration #{config[:configuration_name]}")
135
- run_configuration_script = <<-EOH
136
- $job = start-dscconfiguration -Path c:/configurations/ -force
137
- $job | wait-job
138
- $verbose_output = $job.childjobs[0].verbose
139
- $verbose_output
140
- if ($verbose_output -match 'A reboot is required to progress further. Please reboot the system.') {
141
- "A reboot is required to continue."
142
- shutdown /r /t 15
143
- exit 35
144
- }
145
- $dsc_errors = $job.childjobs[0].Error
146
- if ($dsc_errors -ne $null) {
147
- $dsc_errors
148
- exit 1
149
- }
150
- EOH
151
-
152
- debug("Shelling out: #{run_configuration_script}")
153
- wrap_powershell_code(run_configuration_script)
154
- end
155
-
156
- private
157
-
158
- def lcm
159
- @lcm ||= begin
160
- lcm_version = config[:dsc_local_configuration_manager_version]
161
- lcm_config = config[:dsc_local_configuration_manager]
162
- DscLcmConfiguration::Factory.create(lcm_version, lcm_config)
163
- end
164
- end
165
-
166
- def setup_config_directory_script
167
- "mkdir (split-path (join-path #{config[:root_path]} #{sandboxed_configuration_script})) -force | out-null"
168
- end
169
-
170
- def powershell_module_params(module_specification_hash)
171
- keys = module_specification_hash.keys.reject { |k| k.to_s.casecmp('force') == 0 }
172
- unless keys.any? { |k| k.to_s.downcase == 'repository' }
173
- keys.push(:repository)
174
- module_specification_hash[:repository] = psmodule_repository_name
175
- end
176
- keys.map { |key| "-#{key} #{module_specification_hash[key]}" }.join(' ')
177
- end
178
-
179
- def powershell_modules
180
- Array(config[:modules_from_gallery]).map do |powershell_module|
181
- params = if powershell_module.is_a? Hash
182
- powershell_module_params(powershell_module)
183
- else
184
- "-name '#{powershell_module}' -Repository #{psmodule_repository_name}"
185
- end
186
- "install-module #{params} -force | out-null"
187
- end
188
- end
189
-
190
- def nuget_force_bootstrap
191
- return unless config[:nuget_force_bootstrap]
192
- info("Bootstrapping the nuget package provider for PowerShell PackageManagement.")
193
- "install-packageprovider nuget -force -forcebootstrap | out-null"
194
- end
195
-
196
- def psmodule_repository_name
197
- return "PSGallery" if config[:gallery_name].nil? && config[:gallery_uri].nil?
198
- return "testing" if config[:gallery_name].nil?
199
- config[:gallery_name]
200
- end
201
-
202
- def register_psmodule_repository
203
- return if config[:gallery_uri].nil?
204
- info("Registering a new PowerShellGet Repository - #{psmodule_repository_name}")
205
- "register-packagesource -providername PowerShellGet -name '#{psmodule_repository_name}' -location '#{config[:gallery_uri]}' -force -trusted"
206
- end
207
-
208
- def install_module_script
209
- return if config[:modules_from_gallery].nil?
210
- <<-EOH
211
- #{nuget_force_bootstrap}
212
- #{register_psmodule_repository}
213
- #{powershell_modules.join("\n")}
214
- EOH
215
- end
216
-
217
- def install_modules?
218
- config[:dsc_local_configuration_manager_version] == "wmf5" &&
219
- !config[:modules_from_gallery].nil?
220
- end
221
-
222
- def configuration_data_variable
223
- config[:configuration_data_variable].nil? ? "ConfigurationData" : config[:configuration_data_variable]
224
- end
225
-
226
- def configuration_data_assignment
227
- "$" + configuration_data_variable + " = " + ps_hash(config[:configuration_data])
228
- end
229
-
230
- def wrap_powershell_code(code)
231
- wrap_shell_code(["$ProgressPreference = 'SilentlyContinue';", code].join("\n"))
232
- end
233
-
234
- def powershell_module?
235
- module_metadata_file = File.join(config[:kitchen_root], "#{module_name}.psd1")
236
- File.exist?(module_metadata_file)
237
- end
238
-
239
- def list_files(path)
240
- base_directory_content = Dir.glob(File.join(path, "*"))
241
- nested_directory_content = Dir.glob(File.join(path, "*/**/*"))
242
- all_directory_content = [base_directory_content, nested_directory_content].flatten
243
-
244
- ignore_files = ["Gemfile", "Gemfile.lock", "README.md", "LICENSE.txt"]
245
- all_directory_content.reject do |f|
246
- debug("Enumerating #{f}")
247
- ignore_files.include?(File.basename(f)) || File.directory?(f)
248
- end
249
- end
250
-
251
- def module_name
252
- File.basename(config[:kitchen_root])
253
- end
254
-
255
- def prepare_resource_style_directory
256
- sandbox_base_module_path = File.join(sandbox_path, "modules/#{module_name}")
257
-
258
- base = config[:kitchen_root]
259
- list_files(base).each do |src|
260
- dest = File.join(sandbox_base_module_path, src.sub("#{base}/", ""))
261
- FileUtils.mkdir_p(File.dirname(dest))
262
- debug("Staging #{src} ")
263
- debug(" at #{dest}")
264
- FileUtils.cp(src, dest, :preserve => true)
265
- end
266
- end
267
-
268
- def prepare_repo_style_directory
269
- module_path = File.join(config[:kitchen_root], config[:modules_path])
270
- sandbox_module_path = File.join(sandbox_path, "modules")
271
-
272
- if Dir.exist?(module_path)
273
- debug("Moving #{module_path} to #{sandbox_module_path}")
274
- FileUtils.cp_r(module_path, sandbox_module_path)
275
- else
276
- debug("The modules path #{module_path} was not found. Not moving to #{sandbox_module_path}.")
277
- end
278
- end
279
-
280
- def sandboxed_configuration_script
281
- File.join("configuration", config[:configuration_script])
282
- end
283
-
284
- def pad(depth = 0)
285
- " " * depth
286
- end
287
-
288
- def ps_hash(obj, depth = 0)
289
- if obj.is_a?(Hash)
290
- obj.map do |k, v|
291
- %{#{pad(depth + 2)}#{ps_hash(k)} = #{ps_hash(v, depth + 2)}}
292
- end.join(";\n").insert(0, "@{\n").insert(-1, "\n#{pad(depth)}}")
293
- elsif obj.is_a?(Array)
294
- array_string = obj.map { |v| ps_hash(v, depth + 4) }.join(",")
295
- "#{pad(depth)}@(\n#{array_string}\n)"
296
- else
297
- %{"#{obj}"}
298
- end
299
- end
300
-
301
- def prepare_configuration_script
302
- configuration_script_file = File.join(config[:configuration_script_folder], config[:configuration_script])
303
- configuration_script_path = File.join(config[:kitchen_root], configuration_script_file)
304
- sandbox_configuration_script_path = File.join(sandbox_path, sandboxed_configuration_script)
305
- FileUtils.mkdir_p(File.dirname(sandbox_configuration_script_path))
306
- debug("Moving #{configuration_script_path} to #{sandbox_configuration_script_path}")
307
- FileUtils.cp(configuration_script_path, sandbox_configuration_script_path)
308
- end
309
- end
310
- end
311
- end
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Steven Murawski (<steven.murawski@gmail.com>)
4
+ #
5
+ # Copyright (C) 2014 Steven Murawski
6
+ #
7
+ # Licensed under the Apache 2 License.
8
+ # See LICENSE for more details
9
+
10
+ require "fileutils"
11
+ require "pathname"
12
+ require "kitchen/provisioner/base"
13
+ require "kitchen/util"
14
+ require "dsc_lcm_configuration"
15
+
16
+ module Kitchen
17
+ module Provisioner
18
+ class Dsc < Base
19
+ kitchen_provisioner_api_version 2
20
+
21
+ attr_accessor :tmp_dir
22
+
23
+ default_config :modules_path, "modules"
24
+
25
+ default_config :configuration_script_folder, "examples"
26
+ default_config :configuration_script, "dsc_configuration.ps1"
27
+ default_config :configuration_name do |provisioner|
28
+ [provisioner.instance.suite.name]
29
+ end
30
+
31
+ default_config :configuration_data_variable, "ConfigurationData"
32
+
33
+ default_config :nuget_force_bootstrap, true
34
+ default_config :gallery_uri
35
+ default_config :gallery_name
36
+ default_config :modules_from_gallery
37
+
38
+ default_config :dsc_local_configuration_manager_version, "wmf4"
39
+ default_config :dsc_local_configuration_manager, {}
40
+
41
+ def finalize_config!(instance)
42
+ config[:dsc_local_configuration_manager] = lcm.lcm_config
43
+ super(instance)
44
+ end
45
+
46
+ def install_command
47
+ full_lcm_configuration_script = <<-EOH
48
+ #{lcm.lcm_configuration_script}
49
+
50
+ $null = SetupLCM
51
+ Set-DscLocalConfigurationManager -Path ./SetupLCM | out-null
52
+ EOH
53
+
54
+ wrap_powershell_code(full_lcm_configuration_script)
55
+ end
56
+
57
+ def init_command
58
+ script = <<-EOH
59
+ #{setup_config_directory_script}
60
+ #{install_module_script if install_modules?}
61
+ EOH
62
+ wrap_powershell_code(script)
63
+ end
64
+
65
+ def create_sandbox
66
+ super
67
+ info("Staging DSC Resource Modules for copy to the SUT")
68
+ if powershell_module?
69
+ prepare_resource_style_directory
70
+ else
71
+ prepare_repo_style_directory
72
+ end
73
+ info("Staging DSC configuration script for copy to the SUT")
74
+ prepare_configuration_script
75
+ end
76
+
77
+ def prepare_command
78
+ info("Moving DSC Resources onto PSModulePath")
79
+ scripts = <<-EOH
80
+
81
+ if (Test-Path (join-path #{config[:root_path]} 'modules'))
82
+ {
83
+ dir ( join-path #{config[:root_path]} 'modules/*') -directory |
84
+ copy-item -destination $env:programfiles/windowspowershell/modules/ -recurse -force
85
+ }
86
+
87
+ $ConfigurationScriptPath = Join-path #{config[:root_path]} #{sandboxed_configuration_script}
88
+ if (-not (test-path $ConfigurationScriptPath))
89
+ {
90
+ throw "Failed to find $ConfigurationScriptPath"
91
+ }
92
+ invoke-expression (get-content $ConfigurationScriptPath -raw)
93
+
94
+ EOH
95
+ ensure_array(config[:configuration_name]).each do |configuration|
96
+ info("Generating the MOF script for the configuration #{configuration}")
97
+ stage_resources_and_generate_mof_script = <<-EOH
98
+
99
+ if(Test-Path c:/configurations/#{configuration})
100
+ {
101
+ Remove-Item -Recurse -Force c:/configurations/#{configuration}
102
+ }
103
+
104
+ $Error.clear()
105
+
106
+ if (-not (test-path 'c:/configurations'))
107
+ {
108
+ mkdir 'c:/configurations' | out-null
109
+ }
110
+
111
+ if (-not (get-command #{configuration}))
112
+ {
113
+ throw "Failed to create a configuration command #{configuration}"
114
+ }
115
+
116
+ #{configuration_data_assignment unless config[:configuration_data].nil?}
117
+
118
+ try{
119
+ $null = #{configuration} -outputpath c:/configurations/#{configuration} #{"-configurationdata $" + configuration_data_variable}
120
+ }
121
+ catch{
122
+ }
123
+
124
+ if($Error -ne $null)
125
+ {
126
+ $Error[-1]
127
+ exit 1
128
+ }
129
+
130
+ EOH
131
+ scripts << stage_resources_and_generate_mof_script
132
+ end
133
+ debug("Shelling out: #{scripts}")
134
+ wrap_powershell_code(scripts)
135
+ end
136
+
137
+ def run_command
138
+ config[:retry_on_exit_code] = [35] if config[:retry_on_exit_code].empty?
139
+ config[:max_retries] = 3 if config[:max_retries] == 1
140
+ scripts = ''
141
+ ensure_array(config[:configuration_name]).each do |configuration|
142
+ info("Running the configuration #{configuration}")
143
+ run_configuration_script = <<-EOH
144
+ $job = start-dscconfiguration -Path c:/configurations/#{configuration} -force
145
+ $job | wait-job
146
+ $verbose_output = $job.childjobs[0].verbose
147
+ $verbose_output
148
+ if ($verbose_output -match 'A reboot is required to progress further. Please reboot the system.') {
149
+ "A reboot is required to continue."
150
+ shutdown /r /t 15
151
+ exit 35
152
+ }
153
+ $dsc_errors = $job.childjobs[0].Error
154
+ if ($dsc_errors -ne $null) {
155
+ $dsc_errors
156
+ exit 1
157
+ }
158
+ EOH
159
+ scripts << run_configuration_script
160
+ end
161
+ debug("Shelling out: #{scripts}")
162
+ wrap_powershell_code(scripts)
163
+ end
164
+
165
+ private
166
+
167
+ def lcm
168
+ @lcm ||= begin
169
+ lcm_version = config[:dsc_local_configuration_manager_version]
170
+ lcm_config = config[:dsc_local_configuration_manager]
171
+ DscLcmConfiguration::Factory.create(lcm_version, lcm_config)
172
+ end
173
+ end
174
+
175
+ def setup_config_directory_script
176
+ "mkdir (split-path (join-path #{config[:root_path]} #{sandboxed_configuration_script})) -force | out-null"
177
+ end
178
+
179
+ def powershell_module_params(module_specification_hash)
180
+ keys = module_specification_hash.keys.reject { |k| k.to_s.casecmp('force') == 0 }
181
+ unless keys.any? { |k| k.to_s.downcase == 'repository' }
182
+ keys.push(:repository)
183
+ module_specification_hash[:repository] = psmodule_repository_name
184
+ end
185
+ keys.map { |key| "-#{key} #{module_specification_hash[key]}" }.join(' ')
186
+ end
187
+
188
+ def powershell_modules
189
+ Array(config[:modules_from_gallery]).map do |powershell_module|
190
+ params = if powershell_module.is_a? Hash
191
+ powershell_module_params(powershell_module)
192
+ else
193
+ "-name '#{powershell_module}' -Repository #{psmodule_repository_name}"
194
+ end
195
+ "install-module #{params} -force | out-null"
196
+ end
197
+ end
198
+
199
+ def nuget_force_bootstrap
200
+ return unless config[:nuget_force_bootstrap]
201
+ info("Bootstrapping the nuget package provider for PowerShell PackageManagement.")
202
+ "install-packageprovider nuget -force -forcebootstrap | out-null"
203
+ end
204
+
205
+ def psmodule_repository_name
206
+ return "PSGallery" if config[:gallery_name].nil? && config[:gallery_uri].nil?
207
+ return "testing" if config[:gallery_name].nil?
208
+ config[:gallery_name]
209
+ end
210
+
211
+ def register_psmodule_repository
212
+ return if config[:gallery_uri].nil?
213
+ info("Registering a new PowerShellGet Repository - #{psmodule_repository_name}")
214
+ "register-packagesource -providername PowerShellGet -name '#{psmodule_repository_name}' -location '#{config[:gallery_uri]}' -force -trusted"
215
+ end
216
+
217
+ def install_module_script
218
+ return if config[:modules_from_gallery].nil?
219
+ <<-EOH
220
+ #{nuget_force_bootstrap}
221
+ #{register_psmodule_repository}
222
+ #{powershell_modules.join("\n")}
223
+ EOH
224
+ end
225
+
226
+ def install_modules?
227
+ config[:dsc_local_configuration_manager_version] == "wmf5" &&
228
+ !config[:modules_from_gallery].nil?
229
+ end
230
+
231
+ def configuration_data_variable
232
+ config[:configuration_data_variable].nil? ? "ConfigurationData" : config[:configuration_data_variable]
233
+ end
234
+
235
+ def configuration_data_assignment
236
+ "$" + configuration_data_variable + " = " + ps_hash(config[:configuration_data])
237
+ end
238
+
239
+ def wrap_powershell_code(code)
240
+ wrap_shell_code(["$ProgressPreference = 'SilentlyContinue';", code].join("\n"))
241
+ end
242
+
243
+ def powershell_module?
244
+ module_metadata_file = File.join(config[:kitchen_root], "#{module_name}.psd1")
245
+ File.exist?(module_metadata_file)
246
+ end
247
+
248
+ def list_files(path)
249
+ base_directory_content = Dir.glob(File.join(path, "*"))
250
+ nested_directory_content = Dir.glob(File.join(path, "*/**/*"))
251
+ all_directory_content = [base_directory_content, nested_directory_content].flatten
252
+
253
+ ignore_files = ["Gemfile", "Gemfile.lock", "README.md", "LICENSE.txt"]
254
+ all_directory_content.reject do |f|
255
+ debug("Enumerating #{f}")
256
+ ignore_files.include?(File.basename(f)) || File.directory?(f)
257
+ end
258
+ end
259
+
260
+ def module_name
261
+ File.basename(config[:kitchen_root])
262
+ end
263
+
264
+ def prepare_resource_style_directory
265
+ sandbox_base_module_path = File.join(sandbox_path, "modules/#{module_name}")
266
+
267
+ base = config[:kitchen_root]
268
+ list_files(base).each do |src|
269
+ dest = File.join(sandbox_base_module_path, src.sub("#{base}/", ""))
270
+ FileUtils.mkdir_p(File.dirname(dest))
271
+ debug("Staging #{src} ")
272
+ debug(" at #{dest}")
273
+ FileUtils.cp(src, dest, :preserve => true)
274
+ end
275
+ end
276
+
277
+ def prepare_repo_style_directory
278
+ module_path = File.join(config[:kitchen_root], config[:modules_path])
279
+ sandbox_module_path = File.join(sandbox_path, "modules")
280
+
281
+ if Dir.exist?(module_path)
282
+ debug("Moving #{module_path} to #{sandbox_module_path}")
283
+ FileUtils.cp_r(module_path, sandbox_module_path)
284
+ else
285
+ debug("The modules path #{module_path} was not found. Not moving to #{sandbox_module_path}.")
286
+ end
287
+ end
288
+
289
+ def sandboxed_configuration_script
290
+ File.join("configuration", config[:configuration_script])
291
+ end
292
+
293
+ def pad(depth = 0)
294
+ " " * depth
295
+ end
296
+
297
+ def ps_hash(obj, depth = 0)
298
+ if obj.is_a?(Hash)
299
+ obj.map do |k, v|
300
+ %{#{pad(depth + 2)}#{ps_hash(k)} = #{ps_hash(v, depth + 2)}}
301
+ end.join(";\n").insert(0, "@{\n").insert(-1, "\n#{pad(depth)}}")
302
+ elsif obj.is_a?(Array)
303
+ array_string = obj.map { |v| ps_hash(v, depth + 4) }.join(",")
304
+ "#{pad(depth)}@(\n#{array_string}\n)"
305
+ else
306
+ %{"#{obj}"}
307
+ end
308
+ end
309
+
310
+ def prepare_configuration_script
311
+ configuration_script_file = File.join(config[:configuration_script_folder], config[:configuration_script])
312
+ configuration_script_path = File.join(config[:kitchen_root], configuration_script_file)
313
+ sandbox_configuration_script_path = File.join(sandbox_path, sandboxed_configuration_script)
314
+ FileUtils.mkdir_p(File.dirname(sandbox_configuration_script_path))
315
+ debug("Moving #{configuration_script_path} to #{sandbox_configuration_script_path}")
316
+ FileUtils.cp(configuration_script_path, sandbox_configuration_script_path)
317
+ end
318
+
319
+ def ensure_array(thing)
320
+ if thing.is_a?(Array)
321
+ return thing
322
+ else
323
+ return [thing]
324
+ end
325
+ end
326
+ end
327
+ end
328
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-dsc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Murawski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-05 00:00:00.000000000 Z
11
+ date: 2017-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen