kitchen-dsc 0.3.0 → 0.4.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: 42a5ff439d0535a553f3adb5a8c514e8f1bf7b91
4
- data.tar.gz: 00d6cedc27bce66bb5e9e2533b5e6ccc08949516
3
+ metadata.gz: 2427c0b295f805d273274902356713f2b43f7830
4
+ data.tar.gz: 71aa87ccaa88df2c2d8421d634553494afde038e
5
5
  SHA512:
6
- metadata.gz: 84b3e6a84d2c80ce8755115f3c3a5c31a941660f4273145bbbc3f29546110fe7fb769c02f7985756d1d359cbc1fa67c1e1faacad6601955d9fb30f5e8be575c4
7
- data.tar.gz: 0b71ff875f127f6734ad85137a02f91072708b084ca6b145c4d544090105b7b3be085ee32389217bd6088dc6a7706a2043760d260019ac4c7d3871ce122b5850
6
+ metadata.gz: c3e29b049b24fc18d267ef0e90f3eb3e2ff6c8de25b9dc1a793bbec011373df3ca872ade1734a320b1550c20954ea9acb2a9c3d3bb550b12c5b42d153a91114b
7
+ data.tar.gz: a272c13d4c2b14b07123f1ddc0e4e8350593cdab32169dfb4ebdd0539b35808729bbfd1c933c6cbc871ef74a8f35d992bcd015e89219ce0b76dc07859ffb9353
data/README.md CHANGED
@@ -1,45 +1,50 @@
1
- # kitchen-dsc
2
- A Test Kitchen Provisioner for PowerShell DSC
3
-
4
-
5
- ## Requirements
6
- You'll need a driver box with WMF4 or greater (ONLY WINDOWS SYSTEMS)
7
-
8
- ## Installation & Setup
9
- You'll need the test-kitchen & kitchen-dsc gems installed in your system, along with kitchen-vagrant or some ther suitable driver for test-kitchen.
10
-
11
- ## Example Configurations
12
- [Repository Style Testing](https://github.com/smurawski/dsc-kitchen-project)
13
- [Module Style Testing](https://github.com/powershellorg/cwebadministration/tree/smurawski/adding_tests)
14
-
15
- ## Configuration Settings
16
- * configuration_script_folder
17
- * Defaults to 'examples'.
18
- * The location of a PowerShell script(s) containing the DSC configuration command(s).
19
- * configuration_script
20
- * Defaults to 'dsc_configuration.ps1'
21
- * The name of the PowerShell script containing the DSC configuration command(s).
22
- * The configuration command name used defaults to the suite name (and can be overridden by the run_list parameter in the suite).
23
- * dsc_local_configuration_manager_version
24
- * Defaults to 'wmf4' ()
25
- * Identifies what version of the LCM is in place
26
- * Other valid values are 'wmf4_with_update' and 'wmf5'
27
- * Currently the only difference between wmf4 and wmf4_with_update/wmf5 is the action_after_reboot and the debug_mode settings. Eventually, I'd like to add support for partial configurations, pull servers, etc..
28
- * In this context, wmf4_with_update refers to wmf4 with KB3000850 applied (to add support for WMF 5 generated configurations, plus some fixes).
29
- * dsc_local_configuration_manager
30
- * Settings for the LCM
31
- * Defaults are:
32
- * action_after_reboot = 'StopConfiguration' # wmf4_with_update or wmf5
33
- * allow_module_overwrite = false
34
- * certificate_id = nil
35
- * configuration_mode = 'ApplyAndAutoCorrect'
36
- * configuration_mode_frequency_mins = 30
37
- * debug_mode = 'All' # wmf4_with_update or wmf5
38
- * refresh_frequency_mins = 15
39
- * refresh_mode = 'PUSH'
40
-
41
- ### Specific to repository style testing
42
- * modules_path
43
- * Defaults to 'modules'.
44
- * Points to the location of modules containing DSC resources to upload
45
- * This path is relative to the root of the repository (the location of the .kitchen.yml).
1
+ [![Gem Version](https://badge.fury.io/rb/kitchen-dsc.svg)](http://badge.fury.io/rb/kitchen-dsc)
2
+
3
+ # kitchen-dsc
4
+ A Test Kitchen Provisioner for PowerShell DSC
5
+
6
+
7
+ ## Requirements
8
+ You'll need a driver box with WMF4 or greater (ONLY WINDOWS SYSTEMS)
9
+
10
+ ## Installation & Setup
11
+ You'll need the test-kitchen & kitchen-dsc gems installed in your system, along with kitchen-vagrant or some ther suitable driver for test-kitchen.
12
+
13
+ ## Example Configurations
14
+ * [Repository Style Testing](https://github.com/smurawski/dsc-kitchen-project)
15
+ * [Module Style Testing](https://github.com/powershellorg/cwebadministration/tree/smurawski/adding_tests)
16
+
17
+ ## Configuration Settings
18
+ * configuration_script_folder
19
+ * Defaults to 'examples'.
20
+ * The location of a PowerShell script(s) containing the DSC configuration command(s).
21
+ * configuration_script
22
+ * Defaults to 'dsc_configuration.ps1'
23
+ * The name of the PowerShell script containing the DSC configuration command(s) (and possibly configuration data)
24
+ * configuration_name
25
+ * Name of the configuration to run, defaults to the suite name.
26
+ * configuration_data_variable
27
+ * Name of the variable in the configuration_script that contains the ConfigurationData hashtable
28
+ * dsc_local_configuration_manager_version
29
+ * Defaults to 'wmf4' ()
30
+ * Identifies what version of the LCM is in place
31
+ * Other valid values are 'wmf4_with_update' and 'wmf5'
32
+ * Currently the only difference between wmf4 and wmf4_with_update/wmf5 is the action_after_reboot and the debug_mode settings. Eventually, I'd like to add support for partial configurations, pull servers, etc..
33
+ * In this context, wmf4_with_update refers to wmf4 with KB3000850 applied (to add support for WMF 5 generated configurations, plus some fixes).
34
+ * dsc_local_configuration_manager
35
+ * Settings for the LCM
36
+ * Defaults are:
37
+ * action_after_reboot = 'StopConfiguration' # wmf4_with_update or wmf5
38
+ * allow_module_overwrite = false
39
+ * certificate_id = nil
40
+ * configuration_mode = 'ApplyAndAutoCorrect'
41
+ * configuration_mode_frequency_mins = 30 # 15 on wmf5
42
+ * debug_mode = 'All' # wmf4_with_update
43
+ * refresh_frequency_mins = 15 # 30 on wmf5
44
+ * refresh_mode = 'PUSH'
45
+
46
+ ### Specific to repository style testing
47
+ * modules_path
48
+ * Defaults to 'modules'.
49
+ * Points to the location of modules containing DSC resources to upload
50
+ * This path is relative to the root of the repository (the location of the .kitchen.yml).
data/kitchen-dsc.gemspec CHANGED
@@ -1,30 +1,41 @@
1
- # encoding: utf-8
2
-
3
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
4
- require 'kitchen-dsc/version'
5
-
6
- Gem::Specification.new do |s|
7
- s.name = 'kitchen-dsc'
8
- s.version = Kitchen::Dsc::VERSION
9
- s.authors = ['Steven Murawski']
10
- s.email = ['steven.murawski@gmail.com']
11
- s.homepage = 'https://github.com/smurawski/kitchen-dsc'
12
- s.summary = 'PowerShell DSC provisioner for test-kitchen'
13
- candidates = Dir.glob('lib/**/*') + ['README.md', 'kitchen-dsc.gemspec']
14
- s.files = candidates.sort
15
- s.platform = Gem::Platform::RUBY
16
- s.require_paths = ['lib']
17
- s.rubyforge_project = '[none]'
18
- s.license = 'MIT'
19
- s.description = <<-EOF
20
- == DESCRIPTION:
21
-
22
- DSC Provisioner for Test Kitchen
23
-
24
- == FEATURES:
25
-
26
- TBD
27
-
28
- EOF
29
-
30
- end
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
4
+ require 'kitchen-dsc/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'kitchen-dsc'
8
+ s.version = Kitchen::Dsc::VERSION
9
+ s.authors = ['Steven Murawski']
10
+ s.email = ['steven.murawski@gmail.com']
11
+ s.homepage = 'https://github.com/smurawski/kitchen-dsc'
12
+ s.summary = 'PowerShell DSC provisioner for test-kitchen'
13
+ candidates = Dir.glob('lib/**/*') + ['README.md', 'kitchen-dsc.gemspec']
14
+ s.files = candidates.sort
15
+ 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:
21
+
22
+ DSC Provisioner for Test Kitchen
23
+
24
+ == FEATURES:
25
+
26
+ TBD
27
+
28
+ EOF
29
+ s.add_dependency "test-kitchen", "~> 1.4"
30
+
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"
35
+
36
+ # style and complexity libraries are tightly version pinned as newer releases
37
+ # may introduce new and undesireable style choices which would be immediately
38
+ # enforced in CI
39
+ s.add_development_dependency "finstyle", "1.4.0"
40
+ s.add_development_dependency "cane", "2.6.2"
41
+ end
@@ -1,209 +1,241 @@
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 MIT License.
8
- # See LICENSE for more details
9
-
10
- require 'fileutils'
11
- require 'pathname'
12
- require 'kitchen/provisioner/base'
13
- require 'kitchen/util'
14
-
15
- module Kitchen
16
-
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
- default_config :configuration_script_folder, 'examples'
25
- default_config :configuration_script, 'dsc_configuration.ps1'
26
- default_config :configuration_name do |provisioner|
27
- provisioner.instance.suite.name
28
- end
29
- default_config :configuration_data_variable
30
-
31
- default_config :dsc_local_configuration_manager_version, 'wmf4'
32
- default_config :dsc_local_configuration_manager, {
33
- action_after_reboot: 'StopConfiguration',
34
- allow_module_overwrite: false,
35
- certificate_id: nil,
36
- configuration_mode: 'ApplyAndAutoCorrect',
37
- configuration_mode_frequency_mins: 30,
38
- debug_mode: 'All',
39
- reboot_if_needed: false,
40
- refresh_frequency_mins: 15,
41
- refresh_mode: 'PUSH'
42
- }
43
-
44
- # Disable line length check, it is all embedded script.
45
- # rubocop:disable Metrics/LineLength
46
- def install_command
47
- lcm_config = config[:dsc_local_configuration_manager]
48
- case config[:dsc_local_configuration_manager_version]
49
- when 'wmf4_legacy', 'wmf4'
50
- lcm_configuration_script = <<-LCMSETUP
51
- configuration SetupLCM
52
- {
53
- LocalConfigurationManager
54
- {
55
- AllowModuleOverwrite = [bool]::Parse('#{lcm_config[:allow_module_overwrite]}')
56
- CertificateID = '#{lcm_config[:certificate_id].nil? ? '$null' : lcm_config[:certificate_id]}'
57
- ConfigurationMode = '#{lcm_config[:configuration_mode]}'
58
- ConfigurationModeFrequencyMins = #{lcm_config[:configuration_mode_frequency_mins]}
59
- RebootNodeIfNeeded = [bool]::Parse('#{lcm_config[:reboot_if_needed]}')
60
- RefreshFrequencyMins = #{lcm_config[:refresh_frequency_mins]}
61
- RefreshMode = '#{lcm_config[:refresh_mode]}'
62
- }
63
- }
64
- SetupLCM
65
- Set-DscLocalConfigurationManager -Path ./SetupLCM
66
- LCMSETUP
67
- when 'wmf4_with_update', 'wmf5'
68
- lcm_configuration_script = <<-LCMSETUP
69
- configuration SetupLCM
70
- {
71
- LocalConfigurationManager
72
- {
73
- ActionAfterReboot = '#{lcm_config[:action_after_reboot]}'
74
- AllowModuleOverwrite = [bool]::Parse('#{lcm_config[:allow_module_overwrite]}')
75
- CertificateID = '#{lcm_config[:certificate_id].nil? ? '$null' : lcm_config[:certificate_id]}'
76
- ConfigurationMode = '#{lcm_config[:configuration_mode]}'
77
- ConfigurationModeFrequencyMins = #{lcm_config[:configuration_mode_frequency_mins]}
78
- DebugMode = '#{lcm_config[:debug_mode]}'
79
- RebootNodeIfNeeded = [bool]::Parse('#{lcm_config[:reboot_if_needed]}')
80
- RefreshFrequencyMins = #{lcm_config[:refresh_frequency_mins]}
81
- RefreshMode = '#{lcm_config[:refresh_mode]}'
82
- }
83
- }
84
- $null = SetupLCM
85
- Set-DscLocalConfigurationManager -Path ./SetupLCM
86
- LCMSETUP
87
- end
88
- wrap_shell_code(lcm_configuration_script)
89
- end
90
- # rubocop:enable Metrics/LineLength
91
-
92
- def init_command
93
- end
94
-
95
- def create_sandbox
96
- super
97
- info('Staging DSC Resource Modules for copy to the SUT')
98
- if resource_module?
99
- prepare_resource_style_directory
100
- else
101
- prepare_repo_style_directory
102
- end
103
- info('Staging DSC configuration script for copy to the SUT')
104
- prepare_configuration_script
105
- end
106
-
107
- # Disable line length check, it is all logging and embedded script.
108
- # rubocop:disable Metrics/LineLength
109
- def prepare_command
110
- info('Moving DSC Resources onto PSModulePath')
111
- info("Generating the MOF script for the configuration #{config[:configuration_name]}")
112
- stage_resources_and_generate_mof_script = <<-EOH
113
- dir ( join-path #{config[:root_path]} 'modules/*') -directory |
114
- copy-item -destination $env:programfiles/windowspowershell/modules/ -recurse -force
115
-
116
- if (-not (test-path 'c:/configurations'))
117
- {
118
- mkdir 'c:/configurations' | out-null
119
- }
120
- $ConfigurationScriptPath = Join-path #{config[:root_path]} #{sandboxed_configuration_script}
121
- if (-not (test-path $ConfigurationScriptPath))
122
- {
123
- throw "Failed to find $ConfigurationScriptPath"
124
- }
125
- invoke-expression (get-content $ConfigurationScriptPath -raw)
126
- if (-not (get-command #{config[:configuration_name]}))
127
- {
128
- throw "Failed to create a configuration command #{config[:configuration_name]}"
129
- }
130
- $null = #{config[:configuration_name]} -outputpath c:/configurations #{'-configurationdata $' + config[:configuration_data_variable] if config[:configuration_data_variable]}
131
- EOH
132
- debug("Shelling out: #{stage_resources_and_generate_mof_script}")
133
- wrap_shell_code(stage_resources_and_generate_mof_script)
134
- end
135
- # rubocop:enable Metrics/LineLength
136
-
137
- def run_command
138
- info("Running the configuration #{config[:configuration_name]}")
139
- run_configuration_script = <<-EOH
140
- $job = start-dscconfiguration -Path c:/configurations/ -force
141
- $job | wait-job
142
- $job.childjobs[0].verbose
143
- EOH
144
-
145
- debug("Shelling out: #{run_configuration_script}")
146
- wrap_shell_code(run_configuration_script)
147
- end
148
-
149
- private
150
-
151
- def resource_module?
152
- module_metadata_file = File.join(config[:kitchen_root], "#{module_name}.psd1")
153
- module_dsc_resource_folder = File.join(config[:kitchen_root], 'DSCResources')
154
- File.exist?(module_metadata_file) &&
155
- File.exist?(module_dsc_resource_folder)
156
- end
157
-
158
- def list_files(path)
159
- base_directory_content = Dir.glob(File.join(path, '*'))
160
- nested_directory_content = Dir.glob(File.join(path, '*/**/*'))
161
- all_directory_content =([base_directory_content, nested_directory_content]).flatten
162
-
163
- ignore_files = ['Gemfile', 'Gemfile.lock', 'README.md', 'LICENSE.txt']
164
- all_directory_content.reject do |f|
165
- debug("Enumerating #{f}")
166
- ignore_files.include?(File.basename(f)) || File.directory?(f)
167
- end
168
- end
169
-
170
- def module_name
171
- File.basename(config[:kitchen_root])
172
- end
173
-
174
- def prepare_resource_style_directory
175
- sandbox_base_module_path = File.join(sandbox_path, "modules/#{module_name}")
176
-
177
- base = config[:kitchen_root]
178
- list_files(base).each do |src|
179
- dest = File.join(sandbox_base_module_path, src.sub("#{base}/", ''))
180
- FileUtils.mkdir_p(File.dirname(dest))
181
- debug("Staging #{src} ")
182
- debug(" at #{dest}")
183
- FileUtils.cp(src, dest, preserve: true)
184
- end
185
- end
186
-
187
- def prepare_repo_style_directory
188
- module_path = File.join(config[:kitchen_root], config[:modules_path])
189
- sandbox_module_path = File.join(sandbox_path, 'modules')
190
-
191
- debug("Moving #{module_path} to #{sandbox_module_path}")
192
- FileUtils.cp_r(module_path, sandbox_module_path)
193
- end
194
-
195
- def sandboxed_configuration_script
196
- File.join('configuration', config[:configuration_script])
197
- end
198
-
199
- def prepare_configuration_script
200
- configuration_script_file = File.join(config[:configuration_script_folder], config[:configuration_script])
201
- configuration_script_path = File.join(config[:kitchen_root], configuration_script_file)
202
- sandbox_configuration_script_path = File.join(sandbox_path, sandboxed_configuration_script)
203
- FileUtils.mkdir_p(File.dirname(sandbox_configuration_script_path))
204
- debug("Moving #{configuration_script_path} to #{sandbox_configuration_script_path}")
205
- FileUtils.cp(configuration_script_path, sandbox_configuration_script_path)
206
- end
207
- end
208
- end
209
- 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 MIT License.
8
+ # See LICENSE for more details
9
+
10
+ require 'fileutils'
11
+ require 'pathname'
12
+ require 'kitchen/provisioner/base'
13
+ require 'kitchen/util'
14
+
15
+ module Kitchen
16
+
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
+ default_config :configuration_data_variable
31
+
32
+ default_config :dsc_local_configuration_manager_version, 'wmf4'
33
+ default_config :dsc_local_configuration_manager, {
34
+ action_after_reboot: 'StopConfiguration',
35
+ allow_module_overwrite: false,
36
+ certificate_id: nil,
37
+ configuration_mode: 'ApplyAndAutoCorrect',
38
+ debug_mode: 'All',
39
+ reboot_if_needed: false,
40
+ refresh_mode: 'PUSH'
41
+ }
42
+
43
+ # Disable line length check, it is all embedded script.
44
+ # rubocop:disable Metrics/LineLength
45
+ def install_command
46
+ lcm_config = config[:dsc_local_configuration_manager]
47
+ case config[:dsc_local_configuration_manager_version]
48
+ when 'wmf4_legacy', 'wmf4'
49
+ lcm_configuration_script = <<-LCMSETUP
50
+ configuration SetupLCM
51
+ {
52
+ LocalConfigurationManager
53
+ {
54
+ AllowModuleOverwrite = [bool]::Parse('#{lcm_config[:allow_module_overwrite]}')
55
+ CertificateID = '#{lcm_config[:certificate_id].nil? ? '$null' : lcm_config[:certificate_id]}'
56
+ ConfigurationMode = '#{lcm_config[:configuration_mode]}'
57
+ ConfigurationModeFrequencyMins = #{lcm_config[:configuration_mode_frequency_mins].nil? ? '30' : lcm_config[:configuration_mode_frequency_mins]}
58
+ RebootNodeIfNeeded = [bool]::Parse('#{lcm_config[:reboot_if_needed]}')
59
+ RefreshFrequencyMins = #{lcm_config[:refresh_frequency_mins].nil? ? '15' : lcm[:refresh_frequency_mins]}
60
+ RefreshMode = '#{lcm_config[:refresh_mode]}'
61
+ }
62
+ }
63
+ LCMSETUP
64
+ when 'wmf4_with_update'
65
+ lcm_configuration_script = <<-LCMSETUP
66
+ configuration SetupLCM
67
+ {
68
+ LocalConfigurationManager
69
+ {
70
+ ActionAfterReboot = '#{lcm_config[:action_after_reboot]}'
71
+ AllowModuleOverwrite = [bool]::Parse('#{lcm_config[:allow_module_overwrite]}')
72
+ CertificateID = '#{lcm_config[:certificate_id].nil? ? '$null' : lcm_config[:certificate_id]}'
73
+ ConfigurationMode = '#{lcm_config[:configuration_mode]}'
74
+ ConfigurationModeFrequencyMins = #{lcm_config[:configuration_mode_frequency_mins].nil? ? '30' : lcm_config[:configuration_mode_frequency_mins]}
75
+ DebugMode = '#{lcm_config[:debug_mode]}'
76
+ RebootNodeIfNeeded = [bool]::Parse('#{lcm_config[:reboot_if_needed]}')
77
+ RefreshFrequencyMins = #{lcm_config[:refresh_frequency_mins].nil? ? '15' : lcm[:refresh_frequency_mins]}
78
+ RefreshMode = '#{lcm_config[:refresh_mode]}'
79
+ }
80
+ }
81
+ LCMSETUP
82
+ when 'wmf5'
83
+ lcm_configuration_script = <<-LCMSETUP
84
+ configuration SetupLCM
85
+ {
86
+ LocalConfigurationManager
87
+ {
88
+ ActionAfterReboot = '#{lcm_config[:action_after_reboot]}'
89
+ AllowModuleOverwrite = [bool]::Parse('#{lcm_config[:allow_module_overwrite]}')
90
+ CertificateID = '#{lcm_config[:certificate_id].nil? ? '$null' : lcm_config[:certificate_id]}'
91
+ ConfigurationMode = '#{lcm_config[:configuration_mode]}'
92
+ ConfigurationModeFrequencyMins = #{lcm_config[:configuration_mode_frequency_mins].nil? ? '15' : lcm_config[:configuration_mode_frequency_mins]}
93
+ RebootNodeIfNeeded = [bool]::Parse('#{lcm_config[:reboot_if_needed]}')
94
+ RefreshFrequencyMins = #{lcm_config[:refresh_frequency_mins].nil? ? '30' : lcm[:refresh_frequency_mins]}
95
+ RefreshMode = '#{lcm_config[:refresh_mode]}'
96
+ }
97
+ }
98
+ LCMSETUP
99
+ end
100
+ full_lcm_configuration_script = <<-EOH
101
+ #{lcm_configuration_script}
102
+
103
+ $null = SetupLCM
104
+ Set-DscLocalConfigurationManager -Path ./SetupLCM
105
+ EOH
106
+
107
+ wrap_shell_code(full_lcm_configuration_script)
108
+ end
109
+ # rubocop:enable Metrics/LineLength
110
+
111
+ def init_command
112
+ end
113
+
114
+ def create_sandbox
115
+ super
116
+ info('Staging DSC Resource Modules for copy to the SUT')
117
+ if resource_module? || class_resource_module?
118
+ prepare_resource_style_directory
119
+ else
120
+ prepare_repo_style_directory
121
+ end
122
+ info('Staging DSC configuration script for copy to the SUT')
123
+ prepare_configuration_script
124
+ end
125
+
126
+ # Disable line length check, it is all logging and embedded script.
127
+ # rubocop:disable Metrics/LineLength
128
+ def prepare_command
129
+ info('Moving DSC Resources onto PSModulePath')
130
+ info("Generating the MOF script for the configuration #{config[:configuration_name]}")
131
+ stage_resources_and_generate_mof_script = <<-EOH
132
+ if (Test-Path (join-path #{config[:root_path]} 'modules'))
133
+ {
134
+ dir ( join-path #{config[:root_path]} 'modules/*') -directory |
135
+ copy-item -destination $env:programfiles/windowspowershell/modules/ -recurse -force
136
+ }
137
+ if (-not (test-path 'c:/configurations'))
138
+ {
139
+ mkdir 'c:/configurations' | out-null
140
+ }
141
+ $ConfigurationScriptPath = Join-path #{config[:root_path]} #{sandboxed_configuration_script}
142
+ if (-not (test-path $ConfigurationScriptPath))
143
+ {
144
+ throw "Failed to find $ConfigurationScriptPath"
145
+ }
146
+ invoke-expression (get-content $ConfigurationScriptPath -raw)
147
+ if (-not (get-command #{config[:configuration_name]}))
148
+ {
149
+ throw "Failed to create a configuration command #{config[:configuration_name]}"
150
+ }
151
+ $null = #{config[:configuration_name]} -outputpath c:/configurations #{'-configurationdata $' + config[:configuration_data_variable] if config[:configuration_data_variable]}
152
+ EOH
153
+ debug("Shelling out: #{stage_resources_and_generate_mof_script}")
154
+ wrap_shell_code(stage_resources_and_generate_mof_script)
155
+ end
156
+ # rubocop:enable Metrics/LineLength
157
+
158
+ def run_command
159
+ info("Running the configuration #{config[:configuration_name]}")
160
+ run_configuration_script = <<-EOH
161
+ $job = start-dscconfiguration -Path c:/configurations/ -force
162
+ $job | wait-job
163
+ $job.childjobs[0].verbose
164
+ EOH
165
+
166
+ debug("Shelling out: #{run_configuration_script}")
167
+ wrap_shell_code(run_configuration_script)
168
+ end
169
+
170
+ private
171
+
172
+ def resource_module?
173
+ module_metadata_file = File.join(config[:kitchen_root], "#{module_name}.psd1")
174
+ module_dsc_resource_folder = File.join(config[:kitchen_root], 'DSCResources')
175
+ File.exist?(module_metadata_file) &&
176
+ File.exist?(module_dsc_resource_folder)
177
+ end
178
+
179
+ def class_resource_module?
180
+ module_metadata_file = File.join(config[:kitchen_root], "#{module_name}.psd1")
181
+ module_dsc_resource_folder = File.join(config[:kitchen_root], 'DSCResources')
182
+ File.exist?(module_metadata_file) &&
183
+ !File.exist?(module_dsc_resource_folder)
184
+ end
185
+
186
+ def list_files(path)
187
+ base_directory_content = Dir.glob(File.join(path, '*'))
188
+ nested_directory_content = Dir.glob(File.join(path, '*/**/*'))
189
+ all_directory_content =([base_directory_content, nested_directory_content]).flatten
190
+
191
+ ignore_files = ['Gemfile', 'Gemfile.lock', 'README.md', 'LICENSE.txt']
192
+ all_directory_content.reject do |f|
193
+ debug("Enumerating #{f}")
194
+ ignore_files.include?(File.basename(f)) || File.directory?(f)
195
+ end
196
+ end
197
+
198
+ def module_name
199
+ File.basename(config[:kitchen_root])
200
+ end
201
+
202
+ def prepare_resource_style_directory
203
+ sandbox_base_module_path = File.join(sandbox_path, "modules/#{module_name}")
204
+
205
+ base = config[:kitchen_root]
206
+ list_files(base).each do |src|
207
+ dest = File.join(sandbox_base_module_path, src.sub("#{base}/", ''))
208
+ FileUtils.mkdir_p(File.dirname(dest))
209
+ debug("Staging #{src} ")
210
+ debug(" at #{dest}")
211
+ FileUtils.cp(src, dest, preserve: true)
212
+ end
213
+ end
214
+
215
+ def prepare_repo_style_directory
216
+ module_path = File.join(config[:kitchen_root], config[:modules_path])
217
+ sandbox_module_path = File.join(sandbox_path, 'modules')
218
+
219
+ if Dir.exist?(module_path)
220
+ debug("Moving #{module_path} to #{sandbox_module_path}")
221
+ FileUtils.cp_r(module_path, sandbox_module_path)
222
+ else
223
+ debug("The modules path #{module_path} was not found. Not moving to #{sandbox_module_path}.")
224
+ end
225
+ end
226
+
227
+ def sandboxed_configuration_script
228
+ File.join('configuration', config[:configuration_script])
229
+ end
230
+
231
+ def prepare_configuration_script
232
+ configuration_script_file = File.join(config[:configuration_script_folder], config[:configuration_script])
233
+ configuration_script_path = File.join(config[:kitchen_root], configuration_script_file)
234
+ sandbox_configuration_script_path = File.join(sandbox_path, sandboxed_configuration_script)
235
+ FileUtils.mkdir_p(File.dirname(sandbox_configuration_script_path))
236
+ debug("Moving #{configuration_script_path} to #{sandbox_configuration_script_path}")
237
+ FileUtils.cp(configuration_script_path, sandbox_configuration_script_path)
238
+ end
239
+ end
240
+ end
241
+ end
@@ -1,7 +1,7 @@
1
- # encoding: utf-8
2
-
3
- module Kitchen
4
- module Dsc
5
- VERSION = '0.3.0'
6
- end
7
- end
1
+ # encoding: utf-8
2
+
3
+ module Kitchen
4
+ module Dsc
5
+ VERSION = '0.4.0'
6
+ end
7
+ end
metadata CHANGED
@@ -1,15 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-dsc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.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: 2015-04-21 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test-kitchen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: countloc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: finstyle
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.4.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.4.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: cane
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 2.6.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 2.6.2
13
111
  description: |+
14
112
  == DESCRIPTION:
15
113
 
@@ -31,7 +129,7 @@ files:
31
129
  - lib/kitchen/provisioner/dsc.rb
32
130
  homepage: https://github.com/smurawski/kitchen-dsc
33
131
  licenses:
34
- - MIT
132
+ - Apache 2
35
133
  metadata: {}
36
134
  post_install_message:
37
135
  rdoc_options: []
@@ -49,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
147
  version: '0'
50
148
  requirements: []
51
149
  rubyforge_project: "[none]"
52
- rubygems_version: 2.4.4
150
+ rubygems_version: 2.4.8
53
151
  signing_key:
54
152
  specification_version: 4
55
153
  summary: PowerShell DSC provisioner for test-kitchen