kitchen-dsc 0.1.2 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f56f2af0cfeec590f12172b55f424593b2eeefa9
4
- data.tar.gz: 4ce34552f09fc64a8f27a61f341f6be7e3ac0360
3
+ metadata.gz: 3d4befbf6fdfec388662bfbc319ffac10e2dae3b
4
+ data.tar.gz: 088d558c6f4f46b0352906dbae8681da726794ed
5
5
  SHA512:
6
- metadata.gz: c3aaf48b5c09b0d0801e5ef5fcee9c3962fa4600ea08b2d4de164eb8abaa5691ec4c5dc2be7c233c9310604ab8289e24bc292d2f81f8185765069bc5de33f56d
7
- data.tar.gz: fc2de1fe451d96aa6d6680f957be61eb77dcc3527c40e77ee9d08e25f24868d3e1bb0ed37df228b7022820ede299decc9ea31826e4e792eac4bc9b6dd58e3372
6
+ metadata.gz: e9e84ab1f3b2738eaefd28e4d1c0328d09f25b5e48df8d7bf0c2f8aba86a91e1fd4d8ede3af46e2067e7234b1656e61895f1eb7b3593a34c20f34fc334b21573
7
+ data.tar.gz: b7e5d9f1c0934af9c9f8a7856a85efb0ea0593245b1fa1c4e94d8a650e80e1beebbb39ae2b075efa6f363d2c180017bbcd1e23cfe447e2ffc9efa9e4b333d4dc
data/README.md CHANGED
@@ -8,4 +8,38 @@ You'll need a driver box with WMF4 or greater (ONLY WINDOWS SYSTEMS)
8
8
  ## Installation & Setup
9
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
10
 
11
- ## Example Configuration
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).
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kitchen
4
4
  module Dsc
5
- VERSION = '0.1.2'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -16,46 +16,92 @@ module Kitchen
16
16
 
17
17
  module Provisioner
18
18
  class Dsc < Base
19
-
20
19
  kitchen_provisioner_api_version 2
21
20
 
22
21
  attr_accessor :tmp_dir
23
22
 
24
23
  default_config :modules_path, 'modules'
24
+ default_config :configuration_script_folder, 'examples'
25
25
  default_config :configuration_script, 'dsc_configuration.ps1'
26
26
 
27
-
27
+ default_config :dsc_local_configuration_manager_version, 'wmf4'
28
28
  default_config :dsc_local_configuration_manager, {
29
- :wmf4 => {
30
- :reboot_if_needed => false
31
- },
32
- :wmf5 => {
33
- :reboot_if_needed => false,
34
- :debug_mode => false
35
- }
29
+ action_after_reboot: 'StopConfiguration',
30
+ allow_module_overwrite: false,
31
+ certificate_id: nil,
32
+ configuration_mode: 'ApplyAndAutoCorrect',
33
+ configuration_mode_frequency_mins: 30,
34
+ debug_mode: 'All',
35
+ reboot_if_needed: false,
36
+ refresh_frequency_mins: 15,
37
+ refresh_mode: 'PUSH'
36
38
  }
37
39
 
40
+ # Disable line length check, it is all embedded script.
41
+ # rubocop:disable Metrics/LineLength
38
42
  def install_command
43
+ lcm_config = config[:dsc_local_configuration_manager]
44
+ case config[:dsc_local_configuration_manager_version]
45
+ when 'wmf4_legacy'
46
+ lcm_configuration_script = <<-LCMSETUP
47
+ configuration SetupLCM
48
+ {
49
+ LocalConfigurationManager
50
+ {
51
+ AllowModuleOverwrite = [bool]::Parse('#{lcm_config[:allow_module_overwrite]}')
52
+ CertificateID = '#{lcm_config[:certificate_id].nil? ? '$null' : lcm_config[:certificate_id]}'
53
+ ConfigurationMode = '#{lcm_config[:configuration_mode]}'
54
+ ConfigurationModeFrequencyMins = #{lcm_config[:configuration_mode_frequency_mins]}
55
+ RebootNodeIfNeeded = [bool]::Parse('#{lcm_config[:reboot_if_needed]}')
56
+ RefreshFrequencyMins = #{lcm_config[:refresh_frequency_mins]}
57
+ RefreshMode = '#{lcm_config[:refresh_mode]}'
58
+ }
59
+ }
60
+ SetupLCM
61
+ Set-DscLocalConfigurationManager -Path ./SetupLCM
62
+ LCMSETUP
63
+ when 'wmf4_with_update', 'wmf5'
64
+ lcm_configuration_script = <<-LCMSETUP
65
+ configuration SetupLCM
66
+ {
67
+ LocalConfigurationManager
68
+ {
69
+ ActionAfterReboot = '#{lcm_config[:action_after_reboot]}'
70
+ AllowModuleOverwrite = [bool]::Parse('#{lcm_config[:allow_module_overwrite]}')
71
+ CertificateID = '#{lcm_config[:certificate_id].nil? ? '$null' : lcm_config[:certificate_id]}'
72
+ ConfigurationMode = '#{lcm_config[:configuration_mode]}'
73
+ ConfigurationModeFrequencyMins = #{lcm_config[:configuration_mode_frequency_mins]}
74
+ DebugMode = '#{lcm_config[:debug_mode]}'
75
+ RebootNodeIfNeeded = [bool]::Parse('#{lcm_config[:reboot_if_needed]}')
76
+ RefreshFrequencyMins = #{lcm_config[:refresh_frequency_mins]}
77
+ RefreshMode = '#{lcm_config[:refresh_mode]}'
78
+ }
79
+ }
80
+ SetupLCM
81
+ Set-DscLocalConfigurationManager -Path ./SetupLCM
82
+ LCMSETUP
83
+ end
84
+ wrap_shell_code(lcm_configuration_script)
39
85
  end
86
+ # rubocop:enable Metrics/LineLength
40
87
 
41
88
  def init_command
42
89
  end
43
90
 
44
91
  def create_sandbox
45
92
  super
46
- module_path = File.join(config[:kitchen_root], config[:modules_path])
47
- sandbox_module_path = File.join(sandbox_path, 'modules')
48
- configuration_script_path = File.join(config[:kitchen_root], config[:configuration_script])
49
- sandbox_configuration_script_path = File.join(sandbox_path, config[:configuration_script])
50
-
51
93
  info('Staging DSC Resource Modules for copy to the SUT')
52
- debug("Moving #{module_path} to #{sandbox_module_path}")
53
- FileUtils.cp_r(module_path, sandbox_module_path)
54
-
55
- debug("Moving #{configuration_script_path} to #{sandbox_configuration_script_path}")
56
- FileUtils.cp(configuration_script_path, sandbox_configuration_script_path)
94
+ if resource_module?
95
+ prepare_resource_style_directory
96
+ else
97
+ prepare_repo_style_directory
98
+ end
99
+ info('Staging DSC configuration script for copy to the SUT')
100
+ prepare_configuration_script
57
101
  end
58
102
 
103
+ # Disable line length check, it is all logging and embedded script.
104
+ # rubocop:disable Metrics/LineLength
59
105
  def prepare_command
60
106
  info('Moving DSC Resources onto PSModulePath')
61
107
  info("Generating the MOF script for the configuration #{current_configuration}")
@@ -63,7 +109,10 @@ module Kitchen
63
109
  dir ( join-path #{config[:root_path]} 'modules/*') -directory |
64
110
  copy-item -destination $env:programfiles/windowspowershell/modules/ -recurse -force
65
111
 
66
- mkdir 'c:/configurations' | out-null
112
+ if (-not (test-path 'c:/configurations'))
113
+ {
114
+ mkdir 'c:/configurations' | out-null
115
+ }
67
116
  $ConfigurationScriptPath = Join-path #{config[:root_path]} #{config[:configuration_script]}
68
117
  if (-not (test-path $ConfigurationScriptPath))
69
118
  {
@@ -75,11 +124,12 @@ module Kitchen
75
124
  debug("Shelling out: #{stage_resources_and_generate_mof_script}")
76
125
  wrap_shell_code(stage_resources_and_generate_mof_script)
77
126
  end
127
+ # rubocop:enable Metrics/LineLength
78
128
 
79
129
  def run_command
80
130
  info("Running the configuration #{current_configuration}")
81
131
  run_configuration_script = <<-EOH
82
- $job = start-dscconfiguration -Path c:/configurations/
132
+ $job = start-dscconfiguration -Path c:/configurations/ -force
83
133
  $job | wait-job
84
134
  $job.childjobs[0].verbose
85
135
  EOH
@@ -94,10 +144,58 @@ module Kitchen
94
144
  config.keys.include?(:run_list) ? config[:run_list][0] : @instance.suite.name
95
145
  end
96
146
 
97
- def is_resource_module?
98
- #TODO
147
+ def resource_module?
148
+ module_metadata_file = File.join(config[:kitchen_root], "#{module_name}.psd1")
149
+ module_dsc_resource_folder = File.join(config[:kitchen_root], 'DSCResources')
150
+ File.exist?(module_metadata_file) &&
151
+ File.exist?(module_dsc_resource_folder)
152
+ end
153
+
154
+ def list_files(path)
155
+ base_directory_content = Dir.glob(File.join(path, '*'))
156
+ nested_directory_content = Dir.glob(File.join(path, '*/**/*'))
157
+ all_directory_content =([base_directory_content, nested_directory_content]).flatten
158
+
159
+ ignore_files = ['Gemfile', 'Gemfile.lock', 'README.md', 'LICENSE.txt']
160
+ all_directory_content.reject do |f|
161
+ debug("Enumerating #{f}")
162
+ ignore_files.include?(File.basename(f)) || File.directory?(f)
163
+ end
164
+ end
165
+
166
+ def module_name
167
+ File.basename(config[:kitchen_root])
168
+ end
169
+
170
+ def prepare_resource_style_directory
171
+ sandbox_base_module_path = File.join(sandbox_path, "modules/#{module_name}")
172
+
173
+ base = config[:kitchen_root]
174
+ list_files(base).each do |src|
175
+ dest = File.join(sandbox_base_module_path, src.sub("#{base}/", ''))
176
+ FileUtils.mkdir_p(File.dirname(dest))
177
+ debug("Staging #{src} ")
178
+ debug(" at #{dest}")
179
+ FileUtils.cp(src, dest, preserve: true)
180
+ end
181
+ end
182
+
183
+ def prepare_repo_style_directory
184
+ module_path = File.join(config[:kitchen_root], config[:modules_path])
185
+ sandbox_module_path = File.join(sandbox_path, 'modules')
186
+
187
+ debug("Moving #{module_path} to #{sandbox_module_path}")
188
+ FileUtils.cp_r(module_path, sandbox_module_path)
99
189
  end
100
190
 
191
+ def prepare_configuration_script
192
+ configuration_script_file = File.join(config[:configuration_script_folder], config[:configuration_script])
193
+ configuration_script_path = File.join(config[:kitchen_root], configuration_script_file)
194
+ sandbox_configuration_script_path = File.join(sandbox_path, config[:configuration_script])
195
+
196
+ debug("Moving #{configuration_script_path} to #{sandbox_configuration_script_path}")
197
+ FileUtils.cp(configuration_script_path, sandbox_configuration_script_path)
198
+ end
101
199
  end
102
200
  end
103
201
  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.1.2
4
+ version: 0.2.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-08 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |+
14
14
  == DESCRIPTION: