vagrant-dsc 1.0.10 → 1.1.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: f7a7b684574c26b5bcf147def321de8149691c22
4
- data.tar.gz: 74830fc81b58b8b334a6023d6354580f29b995eb
3
+ metadata.gz: bb46c21c9dad5ddf2db40a8a841534d6f05a11e1
4
+ data.tar.gz: cc3926215945aa34552386b308336b6a59e664bb
5
5
  SHA512:
6
- metadata.gz: b13745414a9573bcb4d18f2175a17fecd952d4e8359d0b370d2b1e0c6af580a6697cb3c5a54692d109123954e8f1119b2aa46f7ea7ff5a3dcd258df4edc73172
7
- data.tar.gz: 7eb8afd365a96f8932ef9d00979a264972eeb22124a60cf01a98da23cab8725d6848cf9b4077f63e8ead2706abc4e5e6e97de4f1475e48b83fe86537b16b16a8
6
+ metadata.gz: 8405032a7b4fd7aa23daed69c33e378e0523cb855145dd2468bd0e8ec49eabba932ad1823ac6996927be042091a7e2083664c94d6c5e02d6f2202ae2f3867576
7
+ data.tar.gz: 80a245e2d999405d4f6843eb65c39727dc627929f1c905ccf5785eca6fb23f0f82b19370d0b397e998014ad3a2872762ebfe37e331bde0b83a74c8fe36245155
data/.gitignore CHANGED
@@ -21,4 +21,5 @@ tmp
21
21
  *.a
22
22
  mkmf.log
23
23
  .vagrant
24
- .idea
24
+ .idea
25
+ bin/
@@ -0,0 +1,15 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "name": "Launch Tests",
6
+ "type": "Ruby",
7
+ "request": "launch",
8
+ "cwd": "${workspaceRoot}",
9
+ "program": "${workspaceRoot}/bin/rake",
10
+ "args": [
11
+ "spec"
12
+ ]
13
+ }
14
+ ]
15
+ }
data/README.md CHANGED
@@ -64,6 +64,14 @@ In your Vagrantfile, add the following plugin and configure to your needs:
64
64
  # @return [Array] Set of relative module paths.
65
65
  dsc.module_path = ["manifests", "modules"]
66
66
 
67
+ # Set of modules that should installed from the [PowerShell Gallery](https://www.powershellgallery.com/)
68
+ #
69
+ # Requires Powershell 5 or PowerShellGet on box installed
70
+ #
71
+ # These modules are downloaded and installed when provisong.
72
+ # If module is allready installed no update is done.
73
+ dsc.module_install = ["xNetworking", "xComputerManagement"]
74
+
67
75
  # The type of synced folders to use when sharing the data
68
76
  # required for the provisioner to work properly.
69
77
  #
@@ -144,6 +152,16 @@ bundle exec vagrant up
144
152
 
145
153
  There is a test Vagrant DSC setup in `./development` that is a good example of a simple acceptance test.
146
154
 
155
+ ### Visual Studio Code
156
+
157
+ You can run the test from Visual Studio Code. This needs the binstubs from bundler. Run
158
+ ```
159
+ bundler install --binstubs
160
+ ```
161
+ to get them.
162
+
163
+ After this you can run the tests with F5.
164
+
147
165
  ## Contributing
148
166
 
149
167
  1. Fork it ( https://github.com/[my-github-username]/vagrant-dsc/fork )
data/appveyor.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  install:
2
2
  - set PATH=C:\Ruby22\bin;%PATH%
3
- - bundle install
3
+ - gem install bundler -v 1.12.5
4
+ - bundle _1.12.5_ install
4
5
 
5
6
  build: off
6
7
 
@@ -10,4 +11,4 @@ before_test:
10
11
  - bundle -v
11
12
 
12
13
  test_script:
13
- - bundle exec rake spec
14
+ - bundle _1.12.5_ exec rake spec
@@ -17,7 +17,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
17
17
 
18
18
  # Every Vagrant virtual environment requires a box to build off of.
19
19
  config.vm.box = "mfellows/windows2012r2"
20
- config.vm.box_version = "1.0.0"
20
+ config.vm.box_version = "1.0.1"
21
21
 
22
22
 
23
23
  hostname = "vagrantdsc.local"
@@ -61,6 +61,9 @@ module VagrantPlugins
61
61
  # Temporary working directory on the guest machine.
62
62
  attr_accessor :temp_dir
63
63
 
64
+ # Modules to install
65
+ attr_accessor :module_install
66
+
64
67
  # Fully qualified path to the configuration file.
65
68
  #
66
69
  # Do not override this.
@@ -83,6 +86,7 @@ module VagrantPlugins
83
86
  @configuration_params = {}
84
87
  @synced_folder_type = UNSET_VALUE
85
88
  @temp_dir = UNSET_VALUE
89
+ @module_install = UNSET_VALUE
86
90
  @logger = Log4r::Logger.new("vagrant::vagrant_dsc")
87
91
  end
88
92
 
@@ -99,6 +103,7 @@ module VagrantPlugins
99
103
  @module_path = nil if @module_path == UNSET_VALUE
100
104
  @synced_folder_type = nil if @synced_folder_type == UNSET_VALUE
101
105
  @temp_dir = nil if @temp_dir == UNSET_VALUE
106
+ @module_install = nil if @module_install == UNSET_VALUE
102
107
  @mof_path = nil if @mof_path == UNSET_VALUE
103
108
  @configuration_name = File.basename(@configuration_file, File.extname(@configuration_file)) if @configuration_name == UNSET_VALUE
104
109
  @manifests_path = File.dirname(@configuration_file) if @manifests_path == UNSET_VALUE
@@ -40,3 +40,6 @@ en:
40
40
  "Absolute 'module_path' not allowed. Please provide a path relative to your Vagrantfile."
41
41
  failure_status: |-
42
42
  "DSC Status is \"Failure\"."
43
+
44
+ winRMAuthorizationError_recover: |-
45
+ The Host disconnect the active connection. Try to wait for the completion of DSC.
@@ -1,6 +1,5 @@
1
1
  require "log4r"
2
2
  require 'erb'
3
- require "vagrant/util/powershell"
4
3
 
5
4
  module VagrantPlugins
6
5
  module DSC
@@ -99,15 +98,21 @@ module VagrantPlugins
99
98
 
100
99
  write_dsc_runner_script(generate_dsc_runner_script)
101
100
 
102
- run_dsc_apply
103
-
101
+ begin
102
+ run_dsc_apply
103
+ rescue VagrantPlugins::CommunicatorWinRM::Errors::AuthenticationFailed
104
+ # when install set a domain controller windows kills the active connection with a AuthenticationFailed.
105
+ # The DSC job is still running and new connections are possible, so try to wait
106
+ @machine.ui.info(I18n.t("vagrant_dsc.winRMAuthorizationError_recover"))
107
+ end
108
+
104
109
  wait_for_dsc_completion
105
110
  end
106
111
 
107
112
  # Waits for the completion of the dsc configuration if dsc needs reboots. This currntly only works for WMF5 and needs wait_for_reboot
108
113
  def wait_for_dsc_completion
109
- return if Vagrant::Util::PowerShell.version.to_i < 5 || !@machine.guest.capability?(:wait_for_reboot)
110
-
114
+ powershell_version = get_guest_powershell_version
115
+ return if powershell_version.to_i < 5 || !@machine.guest.capability?(:wait_for_reboot)
111
116
  dsc_running = true
112
117
 
113
118
  while dsc_running
@@ -130,6 +135,11 @@ module VagrantPlugins
130
135
  end
131
136
  end
132
137
 
138
+ def get_guest_powershell_version
139
+ version = @machine.communicate.shell.powershell("$PSVersionTable.PSVersion.Major")
140
+ return version[:data][0][:stdout]
141
+ end
142
+
133
143
  def get_lcm_state
134
144
  state = @machine.communicate.shell.powershell("(Get-DscLocalConfigurationManager).LCMState")
135
145
  return state[:data][0][:stdout]
@@ -211,6 +221,7 @@ module VagrantPlugins
211
221
  configuration_name: @config.configuration_name,
212
222
  manifests_path: @config.manifests_path,
213
223
  temp_path: @config.temp_dir,
224
+ module_install: @config.module_install.nil? ? "" : @config.module_install.join(";"),
214
225
  parameters: @config.configuration_params.map { |k,v| "#{k}" + (!v.nil? ? " \"#{v}\"": '') }.join(" ")
215
226
  })
216
227
  end
@@ -15,6 +15,15 @@ $env:PSModulePath="$absoluteModulePaths;${env:PSModulePath}"
15
15
  ("<%= options[:module_paths] %>".Split(";") | ForEach-Object { gci -Recurse $_ | ForEach-Object { Unblock-File $_.FullName} })
16
16
  <% end %>
17
17
 
18
+ <% if !options[:module_install].empty? %>
19
+ Write-Host "Ensure Modules"
20
+ if ((Get-PSRepository -Name PSGallery).InstallationPolicy -ne "Trusted") {
21
+ Set-PSRepository -Name PSGallery -InstallationPolicy "Trusted"
22
+ }
23
+ # Install-Modules only installs if the module is not installed
24
+ "<%= options[:module_install] %>".Split(";") | foreach { Install-Module $_ }
25
+ <% end %>
26
+
18
27
  $script = $(Join-Path "<%= options[:temp_path] %>" "<%= options[:configuration_file_path] %>" -Resolve)
19
28
  echo "PSModulePath Configured: ${env:PSModulePath}"
20
29
  echo ""
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module Dsc
3
- VERSION = "1.0.10"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -219,13 +219,40 @@ describe VagrantPlugins::DSC::Provisioner do
219
219
  subject.provision
220
220
  end
221
221
 
222
+ it "should try to recover if AuthenticationFailed" do
223
+ allow(communicator).to receive(:sudo)
224
+ allow(communicator).to receive(:test)
225
+ allow(communicator).to receive(:upload)
226
+ allow(subject).to receive(:verify_shared_folders).and_return(true)
227
+ allow(subject).to receive(:verify_dsc).and_return(true)
228
+ allow(subject).to receive(:run_dsc_apply).and_raise(VagrantPlugins::CommunicatorWinRM::Errors::AuthenticationFailed)
229
+ allow(guest).to receive(:capability?).with(:wait_for_reboot).and_return(true)
230
+ allow(guest).to receive(:capability).with(:wait_for_reboot)
231
+ expect(subject).to receive(:wait_for_dsc_completion)
232
+
233
+ subject.provision
234
+ end
235
+
236
+ it "should not try to recover from other exceptions" do
237
+ allow(communicator).to receive(:sudo)
238
+ allow(communicator).to receive(:test)
239
+ allow(communicator).to receive(:upload)
240
+ allow(subject).to receive(:verify_shared_folders).and_return(true)
241
+ allow(subject).to receive(:verify_dsc).and_return(true)
242
+ allow(guest).to receive(:capability?).with(:wait_for_reboot).and_return(true)
243
+ allow(guest).to receive(:capability).with(:wait_for_reboot)
244
+ allow(subject).to receive(:run_dsc_apply).and_raise()
245
+
246
+ expect{ subject.provision }.to raise_error(RuntimeError)
247
+ end
248
+
222
249
  it "should wait for pending reboot" do
223
250
  allow_any_instance_of(Object).to receive(:sleep)
224
251
  allow(guest).to receive(:capability?).with(:wait_for_reboot).and_return(true)
225
252
  allow(communicator).to receive(:shell).and_return(shell)
226
253
  allow(subject).to receive(:get_lcm_state).and_return("PendingReboot", "Busy", "Sucess")
227
254
  allow(subject).to receive(:get_configuration_status).and_return("Sucess")
228
- allow(Vagrant::Util::PowerShell).to receive(:version).and_return("5")
255
+ allow(subject).to receive(:get_guest_powershell_version).and_return("5")
229
256
  expect(guest).to receive(:capability).with(:wait_for_reboot)
230
257
 
231
258
  subject.wait_for_dsc_completion
@@ -237,7 +264,7 @@ describe VagrantPlugins::DSC::Provisioner do
237
264
  allow(communicator).to receive(:shell).and_return(shell)
238
265
  allow(subject).to receive(:get_lcm_state).and_return("PendingReboot", "Busy", "PendingReboot", "Busy", "Idle")
239
266
  allow(subject).to receive(:get_configuration_status).and_return("Success")
240
- allow(Vagrant::Util::PowerShell).to receive(:version).and_return("5")
267
+ allow(subject).to receive(:get_guest_powershell_version).and_return("5")
241
268
  expect(guest).to receive(:capability).twice.with(:wait_for_reboot)
242
269
 
243
270
  subject.wait_for_dsc_completion
@@ -250,12 +277,28 @@ describe VagrantPlugins::DSC::Provisioner do
250
277
  allow(guest).to receive(:capability).with(:wait_for_reboot)
251
278
  allow(subject).to receive(:get_lcm_state).and_return("PendingReboot", "Busy", "PendingConfiguration")
252
279
  allow(subject).to receive(:get_configuration_status).and_return("Failure")
253
- allow(Vagrant::Util::PowerShell).to receive(:version).and_return("5")
280
+ allow(subject).to receive(:get_guest_powershell_version).and_return("5")
254
281
  expect(subject).to receive(:show_dsc_failure_message)
255
282
 
256
283
  subject.wait_for_dsc_completion
257
284
  end
258
285
 
286
+ it "should not get the lcm state if powershell version is 4" do
287
+ allow(guest).to receive(:capability?).with(:wait_for_reboot).and_return(true)
288
+ allow(communicator).to receive(:shell).and_return(shell)
289
+ allow(subject).to receive(:get_guest_powershell_version).and_return("4")
290
+ expect(subject).to_not receive(:get_lcm_state)
291
+
292
+ subject.wait_for_dsc_completion
293
+ end
294
+
295
+ it "should get the guest powershell version" do
296
+ allow(communicator).to receive(:shell).and_return(shell)
297
+ expect(shell).to receive(:powershell).with("$PSVersionTable.PSVersion.Major").and_return({:data => [{:stdout => "4"}]})
298
+
299
+ expect(subject.get_guest_powershell_version).to eq("4")
300
+ end
301
+
259
302
  it "should get the lcm state" do
260
303
  allow(communicator).to receive(:shell).and_return(shell)
261
304
  expect(shell).to receive(:powershell).with("(Get-DscLocalConfigurationManager).LCMState").and_return({:data => [{:stdout => "LCMState"}]})
@@ -347,6 +390,7 @@ echo \"Adding to path: $absoluteModulePaths\"
347
390
  $env:PSModulePath=\"$absoluteModulePaths;${env:PSModulePath}\"
348
391
  (\"/tmp/vagrant-dsc-1/modules-0;/tmp/vagrant-dsc-1/modules-1\".Split(\";\") | ForEach-Object { gci -Recurse $_ | ForEach-Object { Unblock-File $_.FullName} })
349
392
 
393
+
350
394
  $script = $(Join-Path \"/tmp/vagrant-dsc-1\" \"manifests/MyWebsite.ps1\" -Resolve)
351
395
  echo \"PSModulePath Configured: ${env:PSModulePath}\"
352
396
  echo \"\"
@@ -390,6 +434,7 @@ echo \"Adding to path: $absoluteModulePaths\"
390
434
  $env:PSModulePath=\"$absoluteModulePaths;${env:PSModulePath}\"
391
435
  (\"/tmp/vagrant-dsc-1/modules-0;/tmp/vagrant-dsc-1/modules-1\".Split(\";\") | ForEach-Object { gci -Recurse $_ | ForEach-Object { Unblock-File $_.FullName} })
392
436
 
437
+
393
438
  $script = $(Join-Path \"/tmp/vagrant-dsc-1\" \"../manifests/MyWebsite.ps1\" -Resolve)
394
439
  echo \"PSModulePath Configured: ${env:PSModulePath}\"
395
440
  echo \"\"
@@ -432,6 +477,7 @@ echo \"Adding to path: $absoluteModulePaths\"
432
477
  $env:PSModulePath=\"$absoluteModulePaths;${env:PSModulePath}\"
433
478
  (\"/tmp/vagrant-dsc-1/modules-0;/tmp/vagrant-dsc-1/modules-1\".Split(\";\") | ForEach-Object { gci -Recurse $_ | ForEach-Object { Unblock-File $_.FullName} })
434
479
 
480
+
435
481
  $script = $(Join-Path \"/tmp/vagrant-dsc-1\" \"manifests/MyWebsite.ps1\" -Resolve)
436
482
  echo \"PSModulePath Configured: ${env:PSModulePath}\"
437
483
  echo \"\"
@@ -472,6 +518,7 @@ echo \"Adding to path: $absoluteModulePaths\"
472
518
  $env:PSModulePath=\"$absoluteModulePaths;${env:PSModulePath}\"
473
519
  (\"/tmp/vagrant-dsc-1/modules-0;/tmp/vagrant-dsc-1/modules-1\".Split(\";\") | ForEach-Object { gci -Recurse $_ | ForEach-Object { Unblock-File $_.FullName} })
474
520
 
521
+
475
522
  $script = $(Join-Path \"/tmp/vagrant-dsc-1\" \"manifests/MyWebsite.ps1\" -Resolve)
476
523
  echo \"PSModulePath Configured: ${env:PSModulePath}\"
477
524
  echo \"\"
@@ -515,6 +562,7 @@ echo \"Adding to path: $absoluteModulePaths\"
515
562
  $env:PSModulePath=\"$absoluteModulePaths;${env:PSModulePath}\"
516
563
  (\"/tmp/vagrant-dsc-1/modules-0;/tmp/vagrant-dsc-1/modules-1\".Split(\";\") | ForEach-Object { gci -Recurse $_ | ForEach-Object { Unblock-File $_.FullName} })
517
564
 
565
+
518
566
  $script = $(Join-Path \"/tmp/vagrant-dsc-1\" \"manifests/MyWebsite.ps1\" -Resolve)
519
567
  echo \"PSModulePath Configured: ${env:PSModulePath}\"
520
568
  echo \"\"
@@ -568,6 +616,7 @@ echo \"Adding to path: $absoluteModulePaths\"
568
616
  $env:PSModulePath=\"$absoluteModulePaths;${env:PSModulePath}\"
569
617
  (\"/tmp/vagrant-dsc-1/modules-0;/tmp/vagrant-dsc-1/modules-1\".Split(\";\") | ForEach-Object { gci -Recurse $_ | ForEach-Object { Unblock-File $_.FullName} })
570
618
 
619
+
571
620
  $script = $(Join-Path \"/tmp/vagrant-dsc-1\" \"manifests/MyWebsite.ps1\" -Resolve)
572
621
  echo \"PSModulePath Configured: ${env:PSModulePath}\"
573
622
  echo \"\"
@@ -582,6 +631,55 @@ $StagingPath = $(Join-Path \"/tmp/vagrant-dsc-1\" \"staging\")
582
631
  $Config = $(iex (Get-Content (Join-Path \"/tmp/vagrant-dsc-1\" \"manifests/MyConfig.psd1\" -Resolve) | Out-String))
583
632
  MyWebsite -OutputPath $StagingPath -ConfigurationData $Config
584
633
 
634
+ # Start a DSC Configuration run
635
+ Start-DscConfiguration -Force -Wait -Verbose -Path $StagingPath
636
+ del $StagingPath\\*.mof
637
+ "
638
+
639
+ expect(script).to eq(expect_script)
640
+ end
641
+ end
642
+
643
+ context "with module_install" do
644
+ it "should generate a valid powershell command" do
645
+ root_config.module_install = ["xNetworking", "xSQLServer"]
646
+
647
+ script = subject.generate_dsc_runner_script
648
+ expect_script = "#
649
+ # DSC Runner.
650
+ #
651
+ # Bootstraps the DSC environment, sets up configuration data
652
+ # and runs the DSC Configuration.
653
+ #
654
+ #
655
+
656
+ # Set the local PowerShell Module environment path
657
+ $absoluteModulePaths = [string]::Join(\";\", (\"/tmp/vagrant-dsc-1/modules-0;/tmp/vagrant-dsc-1/modules-1\".Split(\";\") | ForEach-Object { $_ | Resolve-Path }))
658
+
659
+ echo \"Adding to path: $absoluteModulePaths\"
660
+ $env:PSModulePath=\"$absoluteModulePaths;${env:PSModulePath}\"
661
+ (\"/tmp/vagrant-dsc-1/modules-0;/tmp/vagrant-dsc-1/modules-1\".Split(\";\") | ForEach-Object { gci -Recurse $_ | ForEach-Object { Unblock-File $_.FullName} })
662
+
663
+ Write-Host \"Ensure Modules\"
664
+ if ((Get-PSRepository -Name PSGallery).InstallationPolicy -ne \"Trusted\") {
665
+ Set-PSRepository -Name PSGallery -InstallationPolicy \"Trusted\"
666
+ }
667
+ # Install-Modules only installs if the module is not installed
668
+ \"xNetworking;xSQLServer\".Split(\";\") | foreach { Install-Module $_ }
669
+
670
+ $script = $(Join-Path \"/tmp/vagrant-dsc-1\" \"manifests/MyWebsite.ps1\" -Resolve)
671
+ echo \"PSModulePath Configured: ${env:PSModulePath}\"
672
+ echo \"\"
673
+ echo \"Running Configuration file: ${script}\"
674
+
675
+ # Generate the MOF file, only if a MOF path not already provided.
676
+ # Import the Manifest
677
+ . $script
678
+
679
+ cd \"/tmp/vagrant-dsc-1\"
680
+ $StagingPath = $(Join-Path \"/tmp/vagrant-dsc-1\" \"staging\")
681
+ MyWebsite -OutputPath $StagingPath
682
+
585
683
  # Start a DSC Configuration run
586
684
  Start-DscConfiguration -Force -Wait -Verbose -Path $StagingPath
587
685
  del $StagingPath\\*.mof
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-dsc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Fellows
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2016-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -104,6 +104,7 @@ extra_rdoc_files: []
104
104
  files:
105
105
  - ".gitignore"
106
106
  - ".travis.yml"
107
+ - ".vscode/launch.json"
107
108
  - Gemfile
108
109
  - LICENSE.txt
109
110
  - README.md
@@ -152,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
153
  version: '0'
153
154
  requirements: []
154
155
  rubyforge_project:
155
- rubygems_version: 2.4.6
156
+ rubygems_version: 2.5.1
156
157
  signing_key:
157
158
  specification_version: 4
158
159
  summary: DSC Provisioner for Vagrant