kitchen-dsc 0.9.2 → 0.11.1

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
- SHA1:
3
- metadata.gz: 0043ea70755d3de429c6744f3103a484c9841cec
4
- data.tar.gz: 005604228f4f2424e72fb41dc9e5a09c1ca9d42e
2
+ SHA256:
3
+ metadata.gz: 4ade7390054a821859906f83d82fa6aa9db0870107d9cc57a089fb21af5daf53
4
+ data.tar.gz: 229a88ab64db1172e971767a680b5c06b495f7bb91b9f2e9c4caaa7e360ea4e0
5
5
  SHA512:
6
- metadata.gz: 65587a52d7f8d0a40d014cc5f28b8c18a32a69512bd22cf1776a545878c638526559f4ccdabe07db6b95ffc33c92e0a90d75b1d3fa376cf29f5dc19a1e49f1e0
7
- data.tar.gz: 8fb1f84cb6d84cfa0b949e45e2b4bf0aba3dcfd653dcf4ce688f685e1ab501f7e8c1f20d35dda377017199b5417cc947deb70f537e61e0931dfe81727c7aa5d2
6
+ metadata.gz: 3cfbe09cfe4174b14d57db58236e8f172366d74c693866c1df6e55bd89c15a5c3869a025c300fe7651d9d2fdca00deb8ff99c3dfba9cff6d9dc17a5c2d95d0af
7
+ data.tar.gz: 2b51a1fdefd9b1bc951d95949ac37110b0a4f953209f83522f323527e982fc789797f0be1459dfd2f1b3d8dab933bafafb4c30e97be2240acf0c3b9bbbce802c
data/README.md CHANGED
@@ -3,6 +3,9 @@
3
3
  # kitchen-dsc
4
4
  A Test Kitchen Provisioner for PowerShell DSC
5
5
 
6
+ ## Status
7
+
8
+ This software project is no longer under active development as it has no active maintainers. The software may continue to work for some or all use cases, but issues filed in GitHub will most likely not be triaged. If a new maintainer is interested in working on this project please come chat with us in #test-kitchen on Chef Community Slack.
6
9
 
7
10
  ## Requirements
8
11
  You'll need a driver box with WMF4 or greater (ONLY WINDOWS SYSTEMS)
@@ -105,4 +108,4 @@ suite:
105
108
  AllNodes:
106
109
  - nodename: localhost
107
110
  role: webserver
108
- ```
111
+ ```
@@ -1,41 +1,46 @@
1
- # encoding: utf-8
2
-
3
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
4
- require 'kitchen-dsc/version'
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require "kitchen-dsc/version"
5
3
 
6
4
  Gem::Specification.new do |s|
7
- s.name = 'kitchen-dsc'
5
+ s.name = "kitchen-dsc"
8
6
  s.version = Kitchen::Dsc::VERSION
9
- s.authors = ['Steven Murawski']
10
- s.email = ['smurawski@chef.io']
11
- s.homepage = 'https://github.com/test-kitchen/kitchen-dsc'
12
- s.summary = 'PowerShell DSC provisioner for test-kitchen'
13
- candidates = Dir.glob('lib/**/*') + ['README.md', 'kitchen-dsc.gemspec']
7
+ s.authors = ["Steven Murawski"]
8
+ s.email = ["smurawski@chef.io"]
9
+ s.homepage = "https://github.com/test-kitchen/kitchen-dsc"
10
+ s.summary = "PowerShell DSC provisioner for test-kitchen"
11
+ candidates = Dir.glob("lib/**/*") + ["README.md", "kitchen-dsc.gemspec"]
14
12
  s.files = candidates.sort
15
13
  s.platform = Gem::Platform::RUBY
16
- s.require_paths = ['lib']
17
- s.rubyforge_project = '[none]'
18
- s.license = 'Apache 2'
19
- s.description = <<-EOF
20
- == DESCRIPTION:
14
+ s.require_paths = ["lib"]
15
+ s.rubyforge_project = "[none]"
16
+ s.license = "Apache-2.0"
17
+ s.description = <<~EOF
18
+ == DESCRIPTION:
21
19
 
22
- DSC Provisioner for Test Kitchen
20
+ DSC Provisioner for Test Kitchen
23
21
 
24
- == FEATURES:
22
+ == FEATURES:
25
23
 
26
- TBD
24
+ TBD
27
25
 
28
- EOF
29
- s.add_dependency 'test-kitchen', '~> 1.10'
26
+ EOF
27
+ s.add_dependency "test-kitchen", ">= 1.9"
28
+ s.add_dependency "dsc_lcm_configuration"
30
29
 
31
- s.add_development_dependency 'countloc', '~> 0.4'
32
- s.add_development_dependency 'rake'
33
- s.add_development_dependency 'rspec', '~> 3.2'
34
- s.add_development_dependency 'simplecov', '~> 0.9'
30
+ s.add_development_dependency "countloc", "~> 0.4"
31
+ s.add_development_dependency "rake"
32
+ s.add_development_dependency "rspec", "~> 3.2"
33
+ s.add_development_dependency "simplecov", "~> 0.9"
34
+ s.add_development_dependency "minitest", "~> 5.3"
35
+ s.add_development_dependency "yard", "~> 0.8"
36
+ s.add_development_dependency "pry"
37
+ s.add_development_dependency "pry-stack_explorer"
38
+ s.add_development_dependency "pry-byebug"
39
+ s.add_development_dependency "rb-readline"
35
40
 
36
41
  # style and complexity libraries are tightly version pinned as newer releases
37
42
  # may introduce new and undesireable style choices which would be immediately
38
43
  # enforced in CI
39
- s.add_development_dependency 'finstyle', '1.4.0'
40
- s.add_development_dependency 'cane', '2.6.2'
44
+ s.add_development_dependency "chefstyle", "1.2.1"
45
+ s.add_development_dependency "cane", "3.0.0"
41
46
  end
@@ -1,7 +1,5 @@
1
- # encoding: utf-8
2
-
3
1
  module Kitchen
4
2
  module Dsc
5
- VERSION = '0.9.2'.freeze
3
+ VERSION = "0.11.1".freeze
6
4
  end
7
5
  end
@@ -1,16 +1,16 @@
1
- # -*- encoding: utf-8 -*-
2
1
  #
3
2
  # Author:: Steven Murawski (<steven.murawski@gmail.com>)
4
3
  #
5
4
  # Copyright (C) 2014 Steven Murawski
6
5
  #
7
- # Licensed under the MIT License.
6
+ # Licensed under the Apache 2 License.
8
7
  # See LICENSE for more details
9
8
 
10
- require 'fileutils'
11
- require 'pathname'
12
- require 'kitchen/provisioner/base'
13
- require 'kitchen/util'
9
+ require "fileutils" unless defined?(FileUtils)
10
+ require "pathname" unless defined?(Pathname)
11
+ require "kitchen/provisioner/base"
12
+ require "kitchen/util"
13
+ require "dsc_lcm_configuration"
14
14
 
15
15
  module Kitchen
16
16
  module Provisioner
@@ -19,137 +19,175 @@ module Kitchen
19
19
 
20
20
  attr_accessor :tmp_dir
21
21
 
22
- default_config :modules_path, 'modules'
22
+ default_config :modules_path, "modules"
23
23
 
24
- default_config :configuration_script_folder, 'examples'
25
- default_config :configuration_script, 'dsc_configuration.ps1'
24
+ default_config :configuration_script_folder, "examples"
25
+ default_config :configuration_script, "dsc_configuration.ps1"
26
26
  default_config :configuration_name do |provisioner|
27
- provisioner.instance.suite.name
27
+ [provisioner.instance.suite.name]
28
28
  end
29
29
 
30
- default_config :configuration_data_variable, 'ConfigurationData'
31
- default_config :configuration_data
30
+ default_config :configuration_data_variable, "ConfigurationData"
32
31
 
33
32
  default_config :nuget_force_bootstrap, true
34
33
  default_config :gallery_uri
35
34
  default_config :gallery_name
36
35
  default_config :modules_from_gallery
37
36
 
38
- default_config :dsc_local_configuration_manager_version, 'wmf4'
39
- default_config :dsc_local_configuration_manager
37
+ default_config :dsc_local_configuration_manager_version, "wmf4"
38
+ default_config :dsc_local_configuration_manager, {}
40
39
 
41
- def override_lcm_setting?(name)
42
- if config[:dsc_local_configuration_manager].nil? ||
43
- config[:dsc_local_configuration_manager][name.to_sym].nil?
44
- false
45
- else
46
- true
47
- end
40
+ def finalize_config!(instance)
41
+ config[:dsc_local_configuration_manager] = lcm.lcm_config
42
+ super(instance)
48
43
  end
49
44
 
50
- def resolve_lcm_setting(name, default_value)
51
- if override_lcm_setting? name
52
- config[:dsc_local_configuration_manager][name.to_sym]
45
+ def install_command
46
+ full_lcm_configuration_script = <<-EOH
47
+ #{lcm.lcm_configuration_script}
48
+
49
+ $null = SetupLCM
50
+ Set-DscLocalConfigurationManager -Path ./SetupLCM | out-null
51
+ EOH
52
+
53
+ wrap_powershell_code(full_lcm_configuration_script)
54
+ end
55
+
56
+ def init_command
57
+ script = <<~EOH
58
+ #{setup_config_directory_script}
59
+ #{install_module_script if install_modules?}
60
+ EOH
61
+ wrap_powershell_code(script)
62
+ end
63
+
64
+ def create_sandbox
65
+ super
66
+ info("Staging DSC Resource Modules for copy to the SUT")
67
+ if powershell_module?
68
+ prepare_resource_style_directory
53
69
  else
54
- default_value
70
+ prepare_repo_style_directory
55
71
  end
72
+ info("Staging DSC configuration script for copy to the SUT")
73
+ prepare_configuration_script
56
74
  end
57
75
 
58
- def lcm_settings
76
+ def prepare_command
77
+ info("Moving DSC Resources onto PSModulePath")
78
+ scripts = <<-EOH
79
+
80
+ if (Test-Path (join-path #{config[:root_path]} 'modules'))
59
81
  {
60
- action_after_reboot: (resolve_lcm_setting 'action_after_reboot', 'StopConfiguration'),
61
- allow_module_overwrite: (resolve_lcm_setting 'allow_module_overwrite', false),
62
- certificate_id: (resolve_lcm_setting 'certificate_id', nil),
63
- configuration_mode: (resolve_lcm_setting 'configuration_mode', 'ApplyAndAutoCorrect'),
64
- debug_mode: (resolve_lcm_setting 'debug_mode', 'All'),
65
- reboot_if_needed: (resolve_lcm_setting 'reboot_if_needed', false),
66
- refresh_mode: (resolve_lcm_setting 'refresh_mode', 'PUSH')
82
+ dir ( join-path #{config[:root_path]} 'modules/*') -directory |
83
+ copy-item -destination $env:programfiles/windowspowershell/modules/ -recurse -force
67
84
  }
68
- end
69
85
 
70
- def install_command
71
- lcm_config = lcm_settings
72
- case config[:dsc_local_configuration_manager_version]
73
- when 'wmf4_legacy', 'wmf4'
74
- lcm_configuration_script = <<-LCMSETUP
75
- configuration SetupLCM
86
+ $ConfigurationScriptPath = Join-path #{config[:root_path]} #{sandboxed_configuration_script}
87
+ if (-not (test-path $ConfigurationScriptPath))
88
+ {
89
+ throw "Failed to find $ConfigurationScriptPath"
90
+ }
91
+ invoke-expression (get-content $ConfigurationScriptPath -raw)
92
+
93
+ EOH
94
+ ensure_array(config[:configuration_name]).each do |configuration|
95
+ info("Generating the MOF script for the configuration #{configuration}")
96
+ stage_resources_and_generate_mof_script = <<-EOH
97
+
98
+ if(Test-Path c:/configurations/#{configuration})
76
99
  {
77
- LocalConfigurationManager
78
- {
79
- AllowModuleOverwrite = [bool]::Parse('#{lcm_config[:allow_module_overwrite]}')
80
- CertificateID = '#{lcm_config[:certificate_id].nil? ? '$null' : lcm_config[:certificate_id]}'
81
- ConfigurationMode = '#{lcm_config[:configuration_mode]}'
82
- ConfigurationModeFrequencyMins = #{lcm_config[:configuration_mode_frequency_mins].nil? ? '30' : lcm_config[:configuration_mode_frequency_mins]}
83
- RebootNodeIfNeeded = [bool]::Parse('#{lcm_config[:reboot_if_needed]}')
84
- RefreshFrequencyMins = #{lcm_config[:refresh_frequency_mins].nil? ? '15' : lcm_config[:refresh_frequency_mins]}
85
- RefreshMode = '#{lcm_config[:refresh_mode]}'
86
- }
100
+ Remove-Item -Recurse -Force c:/configurations/#{configuration}
87
101
  }
88
- LCMSETUP
89
- when 'wmf4_with_update'
90
- lcm_configuration_script = <<-LCMSETUP
91
- configuration SetupLCM
102
+
103
+ $Error.clear()
104
+
105
+ if (-not (test-path 'c:/configurations'))
92
106
  {
93
- LocalConfigurationManager
94
- {
95
- ActionAfterReboot = '#{lcm_config[:action_after_reboot]}'
96
- AllowModuleOverwrite = [bool]::Parse('#{lcm_config[:allow_module_overwrite]}')
97
- CertificateID = '#{lcm_config[:certificate_id].nil? ? '$null' : lcm_config[:certificate_id]}'
98
- ConfigurationMode = '#{lcm_config[:configuration_mode]}'
99
- ConfigurationModeFrequencyMins = #{lcm_config[:configuration_mode_frequency_mins].nil? ? '30' : lcm_config[:configuration_mode_frequency_mins]}
100
- DebugMode = '#{lcm_config[:debug_mode]}'
101
- RebootNodeIfNeeded = [bool]::Parse('#{lcm_config[:reboot_if_needed]}')
102
- RefreshFrequencyMins = #{lcm_config[:refresh_frequency_mins].nil? ? '15' : lcm_config[:refresh_frequency_mins]}
103
- RefreshMode = '#{lcm_config[:refresh_mode]}'
104
- }
107
+ mkdir 'c:/configurations' | out-null
105
108
  }
106
- LCMSETUP
107
- when 'wmf5'
108
- lcm_configuration_script = <<-LCMSETUP
109
- [DSCLocalConfigurationManager()]
110
- configuration SetupLCM
109
+
110
+ if (-not (get-command #{configuration}))
111
111
  {
112
- Settings
113
- {
114
- ActionAfterReboot = '#{lcm_config[:action_after_reboot]}'
115
- AllowModuleOverwrite = [bool]::Parse('#{lcm_config[:allow_module_overwrite]}')
116
- CertificateID = '#{lcm_config[:certificate_id].nil? ? '$null' : lcm_config[:certificate_id]}'
117
- ConfigurationMode = '#{lcm_config[:configuration_mode]}'
118
- ConfigurationModeFrequencyMins = #{lcm_config[:configuration_mode_frequency_mins].nil? ? '15' : lcm_config[:configuration_mode_frequency_mins]}
119
- DebugMode = '#{lcm_config[:debug_mode]}'
120
- RebootNodeIfNeeded = [bool]::Parse('#{lcm_config[:reboot_if_needed]}')
121
- RefreshFrequencyMins = #{lcm_config[:refresh_frequency_mins].nil? ? '30' : lcm_config[:refresh_frequency_mins]}
122
- RefreshMode = '#{lcm_config[:refresh_mode]}'
123
- }
112
+ throw "Failed to create a configuration command #{configuration}"
113
+ }
114
+
115
+ #{configuration_data_assignment unless config[:configuration_data].nil?}
116
+
117
+ try{
118
+ $null = #{configuration} -outputpath c:/configurations/#{configuration} #{"-configurationdata $" + configuration_data_variable}
124
119
  }
125
- LCMSETUP
120
+ catch{
121
+ }
122
+
123
+ if($Error -ne $null)
124
+ {
125
+ $Error[-1]
126
+ exit 1
127
+ }
128
+
129
+ EOH
130
+ scripts << stage_resources_and_generate_mof_script
126
131
  end
127
- full_lcm_configuration_script = <<-EOH
128
- #{lcm_configuration_script}
132
+ debug("Shelling out: #{scripts}")
133
+ wrap_powershell_code(scripts)
134
+ end
129
135
 
130
- $null = SetupLCM
131
- Set-DscLocalConfigurationManager -Path ./SetupLCM | out-null
132
- EOH
136
+ def run_command
137
+ config[:retry_on_exit_code] = [35] if config[:retry_on_exit_code].empty?
138
+ config[:max_retries] = 3 if config[:max_retries] == 1
139
+ scripts = ""
140
+ ensure_array(config[:configuration_name]).each do |configuration|
141
+ info("Running the configuration #{configuration}")
142
+ run_configuration_script = <<-EOH
143
+ $job = start-dscconfiguration -Path c:/configurations/#{configuration} -force
144
+ $job | wait-job
145
+ $verbose_output = $job.childjobs[0].verbose
146
+ $verbose_output
147
+ if ($verbose_output -match 'A reboot is required to progress further. Please reboot the system.') {
148
+ "A reboot is required to continue."
149
+ shutdown /r /t 15
150
+ exit 35
151
+ }
152
+ $dsc_errors = $job.childjobs[0].Error
153
+ if ($dsc_errors -ne $null) {
154
+ $dsc_errors
155
+ exit 1
156
+ }
157
+ EOH
158
+ scripts << run_configuration_script
159
+ end
160
+ debug("Shelling out: #{scripts}")
161
+ wrap_powershell_code(scripts)
162
+ end
133
163
 
134
- wrap_powershell_code(full_lcm_configuration_script)
164
+ private
165
+
166
+ def lcm
167
+ @lcm ||= begin
168
+ lcm_version = config[:dsc_local_configuration_manager_version]
169
+ lcm_config = config[:dsc_local_configuration_manager]
170
+ DscLcmConfiguration::Factory.create(lcm_version, lcm_config)
171
+ end
135
172
  end
136
- # rubocop:enable Metrics/LineLength
137
173
 
138
174
  def setup_config_directory_script
139
175
  "mkdir (split-path (join-path #{config[:root_path]} #{sandboxed_configuration_script})) -force | out-null"
140
176
  end
141
177
 
178
+ def powershell_module_params(module_specification_hash)
179
+ keys = module_specification_hash.keys.reject { |k| k.to_s.casecmp("force") == 0 }
180
+ unless keys.any? { |k| k.to_s.downcase == "repository" }
181
+ keys.push(:repository)
182
+ module_specification_hash[:repository] = psmodule_repository_name
183
+ end
184
+ keys.map { |key| "-#{key} #{module_specification_hash[key]}" }.join(" ")
185
+ end
186
+
142
187
  def powershell_modules
143
188
  Array(config[:modules_from_gallery]).map do |powershell_module|
144
189
  params = if powershell_module.is_a? Hash
145
- keys = powershell_module.keys.reject { |k| k.to_s.downcase! == 'force' }
146
- unless keys.any? { |k| k.to_s.downcase! == 'repository' }
147
- keys.push(:repository)
148
- powershell_module[:repository] = psmodule_repository_name
149
- end
150
- keys.map do |key|
151
- "-#{key} #{powershell_module[key]}"
152
- end.join(' ')
190
+ powershell_module_params(powershell_module)
153
191
  else
154
192
  "-name '#{powershell_module}' -Repository #{psmodule_repository_name}"
155
193
  end
@@ -159,24 +197,28 @@ module Kitchen
159
197
 
160
198
  def nuget_force_bootstrap
161
199
  return unless config[:nuget_force_bootstrap]
162
- info('Bootstrapping the nuget package provider for PowerShell PackageManagement.')
163
- 'install-packageprovider nuget -force -forcebootstrap | out-null'
200
+
201
+ info("Bootstrapping the nuget package provider for PowerShell PackageManagement.")
202
+ "install-packageprovider nuget -force -forcebootstrap | out-null"
164
203
  end
165
204
 
166
205
  def psmodule_repository_name
167
- return 'PSGallery' if config[:gallery_name].nil? && config[:gallery_uri].nil?
168
- return 'testing' if config[:gallery_name].nil?
206
+ return "PSGallery" if config[:gallery_name].nil? && config[:gallery_uri].nil?
207
+ return "testing" if config[:gallery_name].nil?
208
+
169
209
  config[:gallery_name]
170
210
  end
171
211
 
172
212
  def register_psmodule_repository
173
213
  return if config[:gallery_uri].nil?
214
+
174
215
  info("Registering a new PowerShellGet Repository - #{psmodule_repository_name}")
175
216
  "register-packagesource -providername PowerShellGet -name '#{psmodule_repository_name}' -location '#{config[:gallery_uri]}' -force -trusted"
176
217
  end
177
218
 
178
219
  def install_module_script
179
220
  return if config[:modules_from_gallery].nil?
221
+
180
222
  <<-EOH
181
223
  #{nuget_force_bootstrap}
182
224
  #{register_psmodule_repository}
@@ -185,101 +227,20 @@ module Kitchen
185
227
  end
186
228
 
187
229
  def install_modules?
188
- config[:dsc_local_configuration_manager_version] == 'wmf5' &&
230
+ config[:dsc_local_configuration_manager_version] == "wmf5" &&
189
231
  !config[:modules_from_gallery].nil?
190
232
  end
191
233
 
192
- def init_command
193
- script = <<-EOH
194
- #{setup_config_directory_script}
195
- #{install_module_script if install_modules?}
196
- EOH
197
- wrap_powershell_code(script)
198
- end
199
-
200
- def create_sandbox
201
- super
202
- info('Staging DSC Resource Modules for copy to the SUT')
203
- if powershell_module?
204
- prepare_resource_style_directory
205
- else
206
- prepare_repo_style_directory
207
- end
208
- info('Staging DSC configuration script for copy to the SUT')
209
- prepare_configuration_script
210
- end
211
-
212
- def prepare_command
213
- info('Moving DSC Resources onto PSModulePath')
214
- info("Generating the MOF script for the configuration #{config[:configuration_name]}")
215
- stage_resources_and_generate_mof_script = <<-EOH
216
- if (Test-Path (join-path #{config[:root_path]} 'modules'))
217
- {
218
- dir ( join-path #{config[:root_path]} 'modules/*') -directory |
219
- copy-item -destination $env:programfiles/windowspowershell/modules/ -recurse -force
220
- }
221
- if (-not (test-path 'c:/configurations'))
222
- {
223
- mkdir 'c:/configurations' | out-null
224
- }
225
- $ConfigurationScriptPath = Join-path #{config[:root_path]} #{sandboxed_configuration_script}
226
- if (-not (test-path $ConfigurationScriptPath))
227
- {
228
- throw "Failed to find $ConfigurationScriptPath"
229
- }
230
- invoke-expression (get-content $ConfigurationScriptPath -raw)
231
- if (-not (get-command #{config[:configuration_name]}))
232
- {
233
- throw "Failed to create a configuration command #{config[:configuration_name]}"
234
- }
235
-
236
- #{configuration_data_assignment unless config[:configuration_data].nil?}
237
-
238
- $null = #{config[:configuration_name]} -outputpath c:/configurations #{'-configurationdata $' + configuration_data_variable}
239
- EOH
240
- debug("Shelling out: #{stage_resources_and_generate_mof_script}")
241
- wrap_powershell_code(stage_resources_and_generate_mof_script)
242
- end
243
- # rubocop:enable Metrics/LineLength
244
-
245
234
  def configuration_data_variable
246
- config[:configuration_data_variable].nil? ? 'ConfigurationData' : config[:configuration_data_variable]
235
+ config[:configuration_data_variable].nil? ? "ConfigurationData" : config[:configuration_data_variable]
247
236
  end
248
237
 
249
238
  def configuration_data_assignment
250
- '$' + configuration_data_variable + ' = ' + ps_hash(config[:configuration_data])
251
- end
252
-
253
- def run_command
254
- config[:retry_on_exit_code] = [35] if config[:retry_on_exit_code].empty?
255
- config[:max_retries] = 3 if config[:max_retries] == 1
256
-
257
- info("Running the configuration #{config[:configuration_name]}")
258
- run_configuration_script = <<-EOH
259
- $job = start-dscconfiguration -Path c:/configurations/ -force
260
- $job | wait-job
261
- $verbose_output = $job.childjobs[0].verbose
262
- $verbose_output
263
- if ($verbose_output -match 'A reboot is required to progress further. Please reboot the system.') {
264
- "A reboot is required to continue."
265
- shutdown /r /t 15
266
- exit 35
267
- }
268
- $dsc_errors = $job.childjobs[0].Error
269
- if ($dsc_errors -ne $null) {
270
- $dsc_errors
271
- exit 1
272
- }
273
- EOH
274
-
275
- debug("Shelling out: #{run_configuration_script}")
276
- wrap_powershell_code(run_configuration_script)
239
+ "$" + configuration_data_variable + " = " + ps_hash(config[:configuration_data])
277
240
  end
278
241
 
279
- private
280
-
281
242
  def wrap_powershell_code(code)
282
- wrap_shell_code( [ "$ProgressPreference = 'SilentlyContinue';", code ].join("\n") )
243
+ wrap_shell_code(["$ProgressPreference = 'SilentlyContinue';", code].join("\n"))
283
244
  end
284
245
 
285
246
  def powershell_module?
@@ -288,11 +249,11 @@ module Kitchen
288
249
  end
289
250
 
290
251
  def list_files(path)
291
- base_directory_content = Dir.glob(File.join(path, '*'))
292
- nested_directory_content = Dir.glob(File.join(path, '*/**/*'))
252
+ base_directory_content = Dir.glob(File.join(path, "*"))
253
+ nested_directory_content = Dir.glob(File.join(path, "*/**/*"))
293
254
  all_directory_content = [base_directory_content, nested_directory_content].flatten
294
255
 
295
- ignore_files = ['Gemfile', 'Gemfile.lock', 'README.md', 'LICENSE.txt']
256
+ ignore_files = ["Gemfile", "Gemfile.lock", "README.md", "LICENSE.txt"]
296
257
  all_directory_content.reject do |f|
297
258
  debug("Enumerating #{f}")
298
259
  ignore_files.include?(File.basename(f)) || File.directory?(f)
@@ -308,7 +269,7 @@ module Kitchen
308
269
 
309
270
  base = config[:kitchen_root]
310
271
  list_files(base).each do |src|
311
- dest = File.join(sandbox_base_module_path, src.sub("#{base}/", ''))
272
+ dest = File.join(sandbox_base_module_path, src.sub("#{base}/", ""))
312
273
  FileUtils.mkdir_p(File.dirname(dest))
313
274
  debug("Staging #{src} ")
314
275
  debug(" at #{dest}")
@@ -318,7 +279,7 @@ module Kitchen
318
279
 
319
280
  def prepare_repo_style_directory
320
281
  module_path = File.join(config[:kitchen_root], config[:modules_path])
321
- sandbox_module_path = File.join(sandbox_path, 'modules')
282
+ sandbox_module_path = File.join(sandbox_path, "modules")
322
283
 
323
284
  if Dir.exist?(module_path)
324
285
  debug("Moving #{module_path} to #{sandbox_module_path}")
@@ -329,23 +290,23 @@ module Kitchen
329
290
  end
330
291
 
331
292
  def sandboxed_configuration_script
332
- File.join('configuration', config[:configuration_script])
293
+ File.join("configuration", config[:configuration_script])
333
294
  end
334
295
 
335
296
  def pad(depth = 0)
336
- ' ' * depth
297
+ " " * depth
337
298
  end
338
299
 
339
300
  def ps_hash(obj, depth = 0)
340
301
  if obj.is_a?(Hash)
341
302
  obj.map do |k, v|
342
- %(#{pad(depth + 2)}#{ps_hash(k)} = #{ps_hash(v, depth + 2)})
303
+ %{#{pad(depth + 2)}#{ps_hash(k)} = #{ps_hash(v, depth + 2)}}
343
304
  end.join(";\n").insert(0, "@{\n").insert(-1, "\n#{pad(depth)}}")
344
305
  elsif obj.is_a?(Array)
345
- array_string = obj.map { |v| ps_hash(v, depth + 4) }.join(',')
306
+ array_string = obj.map { |v| ps_hash(v, depth + 4) }.join(",")
346
307
  "#{pad(depth)}@(\n#{array_string}\n)"
347
308
  else
348
- %("#{obj}")
309
+ %{"#{obj}"}
349
310
  end
350
311
  end
351
312
 
@@ -357,6 +318,14 @@ module Kitchen
357
318
  debug("Moving #{configuration_script_path} to #{sandbox_configuration_script_path}")
358
319
  FileUtils.cp(configuration_script_path, sandbox_configuration_script_path)
359
320
  end
321
+
322
+ def ensure_array(thing)
323
+ if thing.is_a?(Array)
324
+ thing
325
+ else
326
+ [thing]
327
+ end
328
+ end
360
329
  end
361
330
  end
362
331
  end
@@ -0,0 +1,86 @@
1
+ #
2
+ # Author:: Steven Murawski (<steven.murawski@gmail.com>)
3
+ #
4
+ # Copyright (C) 2014 Steven Murawski
5
+ #
6
+ # Licensed under the Apache 2 License.
7
+ # See LICENSE for more details
8
+
9
+ require_relative "lcm_v4"
10
+ require_relative "lcm_v5"
11
+
12
+ module Kitchen
13
+ module Provisioner
14
+ module DscLcm
15
+ class LcmBase
16
+
17
+ def lcm_properties
18
+ {
19
+ allow_module_overwrite: false,
20
+ certificate_id: nil,
21
+ configuration_mode: "ApplyAndAutoCorrect",
22
+ configuration_mode_frequency_mins: 30,
23
+ reboot_if_needed: false,
24
+ refresh_mode: "PUSH",
25
+ refresh_frequency_mins: 15,
26
+ }
27
+ end
28
+
29
+ def initialize(config = {})
30
+ @certificate_id = nil
31
+ lcm_properties.each do |setting, value|
32
+ send(setting, value)
33
+ end
34
+
35
+ config.each do |setting, value|
36
+ send(setting, value)
37
+ end
38
+ end
39
+
40
+ def method_missing(name, *args)
41
+ return super unless lcm_properties.keys.include?(name)
42
+
43
+ if args.length == 1
44
+ instance_variable_set("@#{name}", args.first)
45
+ else
46
+ instance_variable_get("@#{name}")
47
+ end
48
+ end
49
+
50
+ def certificate_id(value = nil)
51
+ if value.nil?
52
+ @certificate_id.nil? ? "$null" : "'#{@certificate_id}'"
53
+ else
54
+ @certificate_id = value
55
+ end
56
+ end
57
+
58
+ def lcm_config
59
+ hash = {}
60
+ lcm_properties.keys.each do |key|
61
+ hash[key] = send(key)
62
+ end
63
+ hash
64
+ end
65
+
66
+ def lcm_configuration_script
67
+ <<-LCMSETUP
68
+ configuration SetupLCM
69
+ {
70
+ LocalConfigurationManager
71
+ {
72
+ AllowModuleOverwrite = [bool]::Parse('#{allow_module_overwrite}')
73
+ CertificateID = #{certificate_id}
74
+ ConfigurationMode = '#{configuration_mode}'
75
+ ConfigurationModeFrequencyMins = #{configuration_mode_frequency_mins}
76
+ RebootNodeIfNeeded = [bool]::Parse('#{reboot_if_needed}')
77
+ RefreshFrequencyMins = #{refresh_frequency_mins}
78
+ RefreshMode = '#{refresh_mode}'
79
+ }
80
+ }
81
+ LCMSETUP
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,52 @@
1
+ #
2
+ # Author:: Steven Murawski (<steven.murawski@gmail.com>)
3
+ #
4
+ # Copyright (C) 2014 Steven Murawski
5
+ #
6
+ # Licensed under the Apache 2 License.
7
+ # See LICENSE for more details
8
+
9
+ require_relative "lcm_base"
10
+
11
+ module Kitchen
12
+ module Provisioner
13
+ module DscLcm
14
+ class LcmV4 < LcmBase
15
+
16
+ def lcm_properties
17
+ {
18
+ action_after_reboot: "StopConfiguration",
19
+ allow_module_overwrite: false,
20
+ certificate_id: nil,
21
+ configuration_mode: "ApplyAndAutoCorrect",
22
+ configuration_mode_frequency_mins: 30,
23
+ debug_mode: "All",
24
+ reboot_if_needed: false,
25
+ refresh_mode: "PUSH",
26
+ refresh_frequency_mins: 15,
27
+ }
28
+ end
29
+
30
+ def lcm_configuration_script
31
+ <<-LCMSETUP
32
+ configuration SetupLCM
33
+ {
34
+ LocalConfigurationManager
35
+ {
36
+ ActionAfterReboot = '#{action_after_reboot}'
37
+ AllowModuleOverwrite = [bool]::Parse('#{allow_module_overwrite}')
38
+ CertificateID = #{certificate_id}
39
+ ConfigurationMode = '#{configuration_mode}'
40
+ ConfigurationModeFrequencyMins = #{configuration_mode_frequency_mins}
41
+ DebugMode = '#{debug_mode}'
42
+ RebootNodeIfNeeded = [bool]::Parse('#{reboot_if_needed}')
43
+ RefreshFrequencyMins = #{refresh_frequency_mins}
44
+ RefreshMode = '#{refresh_mode}'
45
+ }
46
+ }
47
+ LCMSETUP
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,53 @@
1
+ #
2
+ # Author:: Steven Murawski (<steven.murawski@gmail.com>)
3
+ #
4
+ # Copyright (C) 2014 Steven Murawski
5
+ #
6
+ # Licensed under the Apache 2 License.
7
+ # See LICENSE for more details
8
+
9
+ require_relative "lcm_base"
10
+
11
+ module Kitchen
12
+ module Provisioner
13
+ module DscLcm
14
+ class LcmV5 < LcmBase
15
+
16
+ def lcm_properties
17
+ {
18
+ action_after_reboot: "StopConfiguration",
19
+ allow_module_overwrite: false,
20
+ certificate_id: nil,
21
+ configuration_mode: "ApplyAndAutoCorrect",
22
+ configuration_mode_frequency_mins: 15,
23
+ debug_mode: "All",
24
+ reboot_if_needed: false,
25
+ refresh_mode: "PUSH",
26
+ refresh_frequency_mins: 30,
27
+ }
28
+ end
29
+
30
+ def lcm_configuration_script
31
+ <<-LCMSETUP
32
+ [DSCLocalConfigurationManager()]
33
+ configuration SetupLCM
34
+ {
35
+ Settings
36
+ {
37
+ ActionAfterReboot = '#{action_after_reboot}'
38
+ AllowModuleOverwrite = [bool]::Parse('#{allow_module_overwrite}')
39
+ CertificateID = #{certificate_id}
40
+ ConfigurationMode = '#{configuration_mode}'
41
+ ConfigurationModeFrequencyMins = #{configuration_mode_frequency_mins}
42
+ DebugMode = '#{debug_mode}'
43
+ RebootNodeIfNeeded = [bool]::Parse('#{reboot_if_needed}')
44
+ RefreshFrequencyMins = #{refresh_frequency_mins}
45
+ RefreshMode = '#{refresh_mode}'
46
+ }
47
+ }
48
+ LCMSETUP
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-dsc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Murawski
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-20 00:00:00.000000000 Z
11
+ date: 2020-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: '1.9'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dsc_lcm_configuration
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: countloc
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -81,33 +95,117 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0.9'
83
97
  - !ruby/object:Gem::Dependency
84
- name: finstyle
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry-stack_explorer
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry-byebug
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rb-readline
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: chefstyle
85
183
  requirement: !ruby/object:Gem::Requirement
86
184
  requirements:
87
185
  - - '='
88
186
  - !ruby/object:Gem::Version
89
- version: 1.4.0
187
+ version: 1.2.1
90
188
  type: :development
91
189
  prerelease: false
92
190
  version_requirements: !ruby/object:Gem::Requirement
93
191
  requirements:
94
192
  - - '='
95
193
  - !ruby/object:Gem::Version
96
- version: 1.4.0
194
+ version: 1.2.1
97
195
  - !ruby/object:Gem::Dependency
98
196
  name: cane
99
197
  requirement: !ruby/object:Gem::Requirement
100
198
  requirements:
101
199
  - - '='
102
200
  - !ruby/object:Gem::Version
103
- version: 2.6.2
201
+ version: 3.0.0
104
202
  type: :development
105
203
  prerelease: false
106
204
  version_requirements: !ruby/object:Gem::Requirement
107
205
  requirements:
108
206
  - - '='
109
207
  - !ruby/object:Gem::Version
110
- version: 2.6.2
208
+ version: 3.0.0
111
209
  description: |+
112
210
  == DESCRIPTION:
113
211
 
@@ -127,11 +225,14 @@ files:
127
225
  - kitchen-dsc.gemspec
128
226
  - lib/kitchen-dsc/version.rb
129
227
  - lib/kitchen/provisioner/dsc.rb
228
+ - lib/kitchen/provisioner/dsc_lcm/lcm_base.rb
229
+ - lib/kitchen/provisioner/dsc_lcm/lcm_v4.rb
230
+ - lib/kitchen/provisioner/dsc_lcm/lcm_v5.rb
130
231
  homepage: https://github.com/test-kitchen/kitchen-dsc
131
232
  licenses:
132
- - Apache 2
233
+ - Apache-2.0
133
234
  metadata: {}
134
- post_install_message:
235
+ post_install_message:
135
236
  rdoc_options: []
136
237
  require_paths:
137
238
  - lib
@@ -146,10 +247,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
247
  - !ruby/object:Gem::Version
147
248
  version: '0'
148
249
  requirements: []
149
- rubyforge_project: "[none]"
150
- rubygems_version: 2.6.4
151
- signing_key:
250
+ rubygems_version: 3.1.2
251
+ signing_key:
152
252
  specification_version: 4
153
253
  summary: PowerShell DSC provisioner for test-kitchen
154
254
  test_files: []
155
- has_rdoc:
255
+ ...