vagrant-windows-domain 1.1.12 → 1.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: 6935c271e7991ba222a5b9cc75bc7b48bf380551
4
- data.tar.gz: 1683dd749c1aa220908d942dba0dce3d6934fc41
3
+ metadata.gz: 37f4d0b98f1c8ef3ed13f7df4c7873d80f989e7a
4
+ data.tar.gz: 11ff28a22ab25368c455195e971167447617b439
5
5
  SHA512:
6
- metadata.gz: 3f115da7c99ff86bc26c401b3c7608d5625b315a8db76eef951569fae6733452764b58a3920974f0d6337707e2c308025043a91e6bc1e559912863155b573400
7
- data.tar.gz: 86dae6af5c39d9ad77c2092ea8b1995483fe73ffe33510643aed14d75c7ec4e19b46c490cab00cc553d9529e993509b93b518881a25b217217cfaa6f43fe6ca9
6
+ metadata.gz: 92a8e46f287fad2cc852bd0b444dd75ee68c671000f12bec1c0aad6de904cac1b81f53840e012abc1f0ea46f06543ee935f7efef0a54cfd0487775cbb24fa43e
7
+ data.tar.gz: ed683d8d59acd3ceafa4bee83ef04390136764efe2f9762eff960fde970f48370d8a81ae1be73e5c9875d6af785b1c345ecee4ee5ec15012328f169941107b53
data/.travis.yml CHANGED
@@ -2,10 +2,11 @@ language: ruby
2
2
  before_install:
3
3
  - rvm @global do gem uninstall bundler --all --executables
4
4
  - gem uninstall bundler --all --executables
5
- - gem install bundler --version '< 1.7.0'
5
+ - gem install bundler --version 1.12.5
6
+ - gem install bundler --version 1.12.5
6
7
  rvm:
7
- - 2.0.0
8
- - 2.1.0
8
+ - 2.2.3
9
+ - 2.3.0
9
10
  - ruby-head
10
11
  matrix:
11
12
  allow_failures:
@@ -13,7 +14,7 @@ matrix:
13
14
  fast_finish: true
14
15
  env:
15
16
  matrix:
16
- - VAGRANT_VERSION=v1.6.5
17
+ - VAGRANT_VERSION=v1.8.0
17
18
  global:
18
19
  secure: bs4ezY+1Wksy8hH3nymPJ3AL99mpXULVc/AIh16JetEYw1850QkX7r4gQukMlcyByKUhxucjDLid0Y+KDH5kGMM16QjrVQGhAnUQzMoLD2qPbAaxDCUqpCJtFEEQKYxJvFvEK8a5SQzAsTVG4sgABQ/MllsIIH0FjkWgFtH6050=
19
- script: bundle exec rake test:unit
20
+ script: bundle _1.12.5_ exec rake test:unit
data/README.md CHANGED
@@ -28,7 +28,7 @@ config.vm.provision :windows_domain do |domain|
28
28
 
29
29
  # The new Computer Name to use when joining the domain.
30
30
  #
31
- # Uses the Rename-Computer PowerShell command. ORRRR -NewName flag??
31
+ # Uses the Rename-Computer PowerShell command.
32
32
  # Specifies a new name for the computer in the new domain.
33
33
  domain.computer_name = "myfandangledname"
34
34
 
@@ -74,7 +74,44 @@ This is a great real-life example to get you on your way.
74
74
 
75
75
  Currently the plugin supports any Windows environment with Powershell 3+ installed (2008r2, 2012r2 should work nicely).
76
76
 
77
- ## Uninistallation
77
+ ## Development
78
+
79
+ Before getting started, read the Vagrant plugin [development basics](https://docs.vagrantup.com/v2/plugins/development-basics.html) and [packaging](https://docs.vagrantup.com/v2/plugins/packaging.html) documentation.
80
+
81
+ You will need Ruby 2.1.5 and Bundler v1.12.5 installed before proceeding.
82
+
83
+ _NOTE_: it _must_ be bundler v1.12.5 due to a hard dependency in Vagrant at this time.
84
+
85
+ ```
86
+ git clone git@github.com:mefellows/vagrant-dsc.git
87
+ cd vagrant-dsc
88
+ bundle install
89
+ ```
90
+
91
+ Run tests:
92
+ ```
93
+ bundle exec rake spec
94
+ ```
95
+
96
+ Run Vagrant in context of current vagrant-dsc plugin:
97
+ ```
98
+ cd <directory>
99
+ bundle exec vagrant up
100
+ ```
101
+
102
+ There is a test Vagrant DSC setup in `./development` that is a good example of a simple acceptance test.
103
+
104
+ ### Multiple Bundlers?
105
+
106
+ If you have multiple Bundler versions, you can still use 1.12.5 with the following:
107
+
108
+ ```
109
+ bundle _1.12.5_ <command>
110
+ ```
111
+
112
+ e.g. `bundle _1.12.5_ exec rake spec`
113
+
114
+ ## Uninstallation
78
115
 
79
116
  ```vagrant plugin uninstall vagrant-windows-domain```
80
117
 
@@ -45,16 +45,20 @@ module VagrantPlugins
45
45
  if [:not_created].include? @machine.state.id
46
46
  @logger.debug("Machine not created, nothing to do")
47
47
  elsif [:running].include? @machine.state.id
48
- answer = @machine.env.ui.ask("Are you sure you want to destroy this machine and disconnect from #{@config.domain}? (y/n)")
49
- return unless answer.downcase == 'y' # Bail out of destroy and prevent middleware from continuing on
48
+ if !(env[:force_confirm_box_remove] || env[:force_confirm_destroy])
49
+ answer = @machine.env.ui.ask("Are you sure you want to destroy this machine and disconnect from #{@config.domain}? (y/n)")
50
+ return unless answer.downcase == 'y' # Bail out of destroy and prevent middleware from continuing on
51
+ end
50
52
 
51
- env[:force_confirm_destroy] = true # Prevent the popup dialog again
52
- @logger.debug("Valid configuration detected, triggering leave domain action")
53
- @provisioner.destroy
53
+ env[:force_confirm_destroy] = true # Prevent the popup dialog again
54
+ @logger.debug("Valid configuration detected, triggering leave domain action")
55
+ @provisioner.destroy
54
56
  else
55
57
  @machine.env.ui.say(:warn, "Machine is currently not running. To properly leave the #{@config.domain} network the machine needs to be running and connected to the network in which it was provisioned. Please run `vagrant up` and then `vagrant destroy`.\n")
56
- answer = @machine.env.ui.ask("Would you like to continue destroying this machine, leaving this machine orphaned in the '#{@config.domain}' network? If so, type 'destroy'")
57
- return unless answer.downcase == 'destroy' # Bail out of destroy and prevent middleware from continuing on
58
+ if !(env[:force_confirm_box_remove] || env[:force_confirm_destroy])
59
+ answer = @machine.env.ui.ask("Would you like to continue destroying this machine, leaving this machine orphaned in the '#{@config.domain}' network? If so, type 'destroy'")
60
+ return unless answer.downcase == 'destroy' # Bail out of destroy and prevent middleware from continuing on
61
+ end
58
62
 
59
63
  # OK, we're being naughty and letting the rest of the middleware do their things (i.e. destroy the machine, and such)
60
64
 
@@ -45,6 +45,9 @@ module VagrantPlugins
45
45
  # When this option is used username/password are not required
46
46
  attr_accessor :unsecure
47
47
 
48
+ # The trigger whether plugin should rename the computer or omit the renaming
49
+ attr_accessor :rename
50
+
48
51
  def initialize
49
52
  super
50
53
  @domain = UNSET_VALUE
@@ -54,6 +57,7 @@ module VagrantPlugins
54
57
  @join_options = {}
55
58
  @ou_path = UNSET_VALUE
56
59
  @unsecure = UNSET_VALUE
60
+ @rename = UNSET_VALUE
57
61
  @logger = Log4r::Logger.new("vagrant::vagrant_windows_domain")
58
62
  end
59
63
 
@@ -72,6 +76,7 @@ module VagrantPlugins
72
76
  @join_options = [] if @join_options == UNSET_VALUE
73
77
  @ou_path = nil if @ou_path == UNSET_VALUE
74
78
  @unsecure = false if @unsecure == UNSET_VALUE
79
+ @rename = true if @rename == UNSET_VALUE
75
80
  end
76
81
 
77
82
  # Validate configuration and return a hash of errors.
@@ -47,22 +47,68 @@ module VagrantPlugins
47
47
  raise WindowsDomainError, :unsupported_platform if !windows?
48
48
  end
49
49
 
50
+
51
+ def is_part_of_domain(computer_name, domain)
52
+ command = <<-EOH
53
+ function Test-PartOfDomain($computerName, $domain){
54
+ $computerSystem = gwmi win32_computersystem
55
+ $partofDomain = ($computerSystem.Name -eq $computerName) -and ($computerSystem.PartOfDomain) -and ($computerSystem.Domain -eq $domain)
56
+
57
+ if ($partofDomain) {
58
+ exit 0
59
+ } else {
60
+ exit 1
61
+ }
62
+ }
63
+ Test-PartOfDomain -computerName '#{computer_name}' -domain '#{domain}'
64
+ EOH
65
+ @machine.communicate.test(command, sudo: true)
66
+ end
67
+
68
+ def is_joined_to_domain()
69
+ command = <<-EOH
70
+ function Test-JoinedToADomain(){
71
+ $computerSystem = gwmi win32_computersystem
72
+ $partOfDomain = $computerSystem.PartOfDomain
73
+ if ($partofDomain) {
74
+ exit 0
75
+ } else {
76
+ exit 1
77
+ }
78
+ }
79
+ Test-JoinedToADomain
80
+ EOH
81
+ @machine.communicate.test(command, sudo: true)
82
+ end
83
+
84
+
50
85
  # Run the Provisioner!
51
86
  def provision
52
87
  verify_guest_capability
53
88
 
54
89
  @old_computer_name = get_guest_computer_name(machine)
55
-
56
- @machine.env.ui.say(:info, "Connecting guest machine to domain '#{config.domain}' with computer name '#{config.computer_name}'")
57
90
 
58
- set_credentials
91
+ result = is_part_of_domain(config.computer_name, config.domain)
92
+
93
+ if result
94
+ @machine.env.ui.say(:info, "Guest machine with computer name '#{config.computer_name}' is already a member of domain '#{config.domain}'")
95
+ else
96
+ @machine.env.ui.say(:info, "Connecting guest machine to domain '#{config.domain}' with computer name '#{config.computer_name}'")
97
+
98
+ set_credentials
59
99
 
60
- result = join_domain
100
+ result = join_domain
61
101
 
62
- remove_command_runner_script
102
+ remove_command_runner_script
63
103
 
64
- if result
65
- restart_guest
104
+ if result
105
+ #Often requires 2 reboots to ensure that all AD stuff has been applied
106
+ @logger.debug("Need to reboot to join the domain correctly - 1st reboot")
107
+ restart_guest
108
+
109
+ @logger.debug("Need to reboot to join the domain correctly - 2nd reboot")
110
+ restart_guest
111
+ end
66
112
  end
67
113
  end
68
114
 
@@ -89,6 +135,8 @@ module VagrantPlugins
89
135
  if (config.username == nil)
90
136
  @logger.info("==> Requesting username as none provided")
91
137
  config.username = @machine.env.ui.ask("Please enter your domain username: ")
138
+ else
139
+ @logger.info("==> Using domain username: #{config.username}")
92
140
  end
93
141
 
94
142
  if (config.password == nil)
@@ -104,9 +152,13 @@ module VagrantPlugins
104
152
  # to be cleaned up.
105
153
  def destroy
106
154
  if @config && @config.domain != nil
107
- set_credentials
108
- if leave_domain
109
- restart_guest
155
+ if is_joined_to_domain()
156
+ set_credentials
157
+ result = leave_domain
158
+ if result
159
+ @logger.debug("Need to reboot to leave the domain correctly")
160
+ restart_guest
161
+ end
110
162
  end
111
163
  else
112
164
  @logger.debug("Not leaving domain on `destroy` action - no valid configuration detected")
@@ -119,10 +171,13 @@ module VagrantPlugins
119
171
  @machine.env.ui.say(:info, "Restarting computer for updates to take effect.")
120
172
  options = {}
121
173
  options[:provision_ignore_sentinel] = false
174
+ options[:lock] = false
122
175
  @machine.action(:reload, options)
123
- begin
124
- sleep @restart_sleep_duration
125
- end until @machine.communicate.ready?
176
+ Timeout.timeout(@machine.config.vm.boot_timeout) do
177
+ begin
178
+ sleep @restart_sleep_duration
179
+ end until @machine.communicate.ready?
180
+ end
126
181
  end
127
182
 
128
183
  # Verify that we can call the remote operations.
@@ -149,17 +204,36 @@ module VagrantPlugins
149
204
  def generate_command_runner_script(add_to_domain=true)
150
205
  path = File.expand_path("../templates/runner.ps1", __FILE__)
151
206
 
207
+ if @config.computer_name != nil && @old_computer_name != nil && @config.computer_name.casecmp(@old_computer_name) != 0
208
+ @config.rename = true
209
+ end
210
+
152
211
  Vagrant::Util::TemplateRenderer.render(path, options: {
153
212
  config: @config,
154
213
  username: @config.username,
155
214
  password: @config.password,
156
215
  domain: @config.domain,
216
+ computer_name: @config.computer_name,
217
+ ou_path: @config.ou_path,
157
218
  add_to_domain: add_to_domain,
158
219
  unsecure: @config.unsecure,
220
+ rename: @config.rename,
159
221
  parameters: generate_command_arguments(add_to_domain)
222
+ }, options_rename: {
223
+ parameters: generate_command_arguments_rename
160
224
  })
161
225
  end
162
226
 
227
+ # Generates the argument list for rename
228
+ def generate_command_arguments_rename
229
+
230
+ params = {"-NewName" => @config.computer_name}
231
+ params["-DomainCredential $credentials"] = nil
232
+ join_params = @config.join_options.map { |a| "#{a}" }.join(',')
233
+ params.map { |k,v| "#{k}" + (!v.nil? ? " #{v}": '') }.join(' ') + join_params
234
+
235
+ end
236
+
163
237
  # Generates the argument list
164
238
  def generate_command_arguments(add_to_domain=true)
165
239
 
@@ -179,6 +253,12 @@ module VagrantPlugins
179
253
  if @config.ou_path
180
254
  params["-OUPath"] = "'#{@config.ou_path}'"
181
255
  end
256
+
257
+ # Remove with unsecure
258
+ join_params = @config.join_options.map { |a| "#{a}" }.join(',')
259
+ if join_params.to_s != ''
260
+ params["-Options"] = join_params
261
+ end
182
262
  else
183
263
  params = {}
184
264
  if !@config.unsecure
@@ -186,10 +266,7 @@ module VagrantPlugins
186
266
  end
187
267
  end
188
268
 
189
- # Remove with unsecure
190
- join_params = @config.join_options.map { |a| "#{a}" }.join(',')
191
- params.map { |k,v| "#{k}" + (!v.nil? ? " #{v}": '') }.join(' ') + join_params
192
-
269
+ params.map { |k,v| "#{k}" + (!v.nil? ? " #{v}": '') }.join(' ')
193
270
  end
194
271
 
195
272
  # Writes the PowerShell runner script to a location on the guest.
@@ -1,9 +1,78 @@
1
+ function Test-PartOfDomain($computerName, $domain){
2
+ $computerSystem = gwmi win32_computersystem
3
+ return ($computerSystem.Name -eq $computerName) -and ($computerSystem.PartOfDomain) -and ($computerSystem.Domain -eq $domain)
4
+ }
5
+
6
+ function Test-JoinedToADomain(){
7
+ $computerSystem = gwmi win32_computersystem
8
+ return $computerSystem.PartOfDomain
9
+ }
10
+
11
+ function Repair-OpenSSHPasswd(){
12
+ $passwdPath = 'C:\Program Files\OpenSSH\etc\passwd'
13
+ $mkpasswdPath = 'C:\Program Files\OpenSSH\bin\mkpasswd.exe'
14
+ if ((Test-Path $passwdPath) -and (Test-Path $mkpasswdPath)){
15
+ $passwd = &$mkpasswdPath
16
+ $passwd = $passwd -replace '^([^+]*\+)', ''
17
+ $passwd | Set-Content $passwdPath -Encoding Ascii
18
+ }
19
+ }
20
+
21
+ $computerName='<%= options[:computer_name] %>'
1
22
  <% if options[:username] != nil && options[:unsecure] != true %>
2
- $secpasswd = ConvertTo-SecureString "<%= options[:password] %>" -AsPlainText -Force
3
- $credentials = New-Object System.Management.Automation.PSCredential ("<%= options[:username] %>", $secpasswd)
23
+ $domain='<%= options[:domain] %>'
24
+ $username='<%= options[:username] %>'
25
+ $password='<%= options[:password] %>'
26
+ $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
27
+ $credentials = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
4
28
  <% end %>
5
29
  <% if options[:add_to_domain] === true %>
6
- Add-Computer <%= options[:parameters] %> -Verbose -Force
30
+ if (Test-PartOfDomain -computerName $computerName -domain $domain){
31
+ throw "$computerName already part of domain $domain"
32
+ } else {
33
+ Add-Computer <%= options[:parameters] %> -Verbose -Force -PassThru
34
+
35
+ # Rename computer separately: Fixes GH issue #11
36
+ <% if options[:rename] === true %>
37
+ $completed = $false
38
+ while ( -not $completed) {
39
+ try {
40
+ Rename-Computer <%= options_rename[:parameters] %> -Verbose -Force -ErrorAction Stop
41
+ $completed = $true
42
+ } catch {
43
+ if ($retrycount -ge 5) {
44
+ Write-Host ("Rename failed the maximum number of $retrycount times.")
45
+ throw
46
+ } else {
47
+ Write-Host ("Rename failed, Retrying in 5 seconds...")
48
+ Start-sleep -s 5
49
+ $retrycount++
50
+ }
51
+ }
52
+ }
53
+ <% end %>
54
+
55
+ Repair-OpenSSHPasswd
56
+
57
+ # Fix vagrant-windows GH-129, if there's an existing scheduled
58
+ # reboot cancel it so shutdown succeeds
59
+ &shutdown /a
60
+
61
+ # Force shutdown the machine now
62
+ &shutdown /s /t 15 /c "Vagrant Halt" /f /d p:4:1
63
+ }
7
64
  <% else %>
8
- Remove-Computer <%= options[:parameters] %> -Workgroup "WORKGROUP" -Verbose -Force
9
- <% end %>
65
+ if (!(Test-JoinedToADomain)) {
66
+ Throw "$computerName not part of any domain"
67
+ } else {
68
+ Remove-Computer <%= options[:parameters] %> -Workgroup 'WORKGROUP' -Verbose -Force -PassThru
69
+ Repair-OpenSSHPasswd
70
+
71
+ # Fix vagrant-windows GH-129, if there's an existing scheduled
72
+ # reboot cancel it so shutdown succeeds
73
+ &shutdown /a
74
+
75
+ # Force shutdown the machine now
76
+ &shutdown /s /t 15 /c "Vagrant Halt" /f /d p:4:1
77
+ }
78
+ <% end %>
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module WindowsDomain
3
- VERSION = "1.1.12"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -21,7 +21,7 @@ describe VagrantPlugins::WindowsDomain::LeaveDomain do
21
21
  let(:module_path) { ["foo/modules", "foo/modules2"] }
22
22
  let(:config) { VagrantPlugins::WindowsDomain::Config.new }
23
23
  let(:vm) { double("vm", provisioners: [double("prov", config: config)]) }
24
- let(:root_config) { double("root_config", vm: vm) }
24
+ let(:root_config) { double("root_config", vm: vm) }
25
25
  let(:env) { {:ui => ui, :machine => machine} }
26
26
  let(:machine) { double("machine", ui: ui, id: "1234", config: root_config) }
27
27
  let(:provisioner) { double("provisioner") }
@@ -73,10 +73,12 @@ describe VagrantPlugins::WindowsDomain::Provisioner do
73
73
  it "should join the domain" do
74
74
  allow(communicator).to receive(:upload)
75
75
  allow(ui).to receive(:info)
76
+ expect(communicator).to receive(:test)
77
+ expect(vm).to receive(:boot_timeout).twice
76
78
  expect(communicator).to receive(:sudo).with("powershell -ExecutionPolicy Bypass -OutputFormat Text -file c:/tmp/vagrant-windows-domain-runner.ps1", {:elevated=>true, :error_check=>true, :error_key=>nil, :good_exit=>0, :shell=>:powershell})
77
79
  expect(communicator).to receive(:sudo).with("del c:/tmp/vagrant-windows-domain-runner.ps1")
78
- expect(machine).to receive(:action). with(:reload, {:provision_ignore_sentinel=>false})
79
- expect(communicator).to receive(:ready?).and_return(true)
80
+ expect(machine).to receive(:action).with(:reload, {:provision_ignore_sentinel=>false, :lock=>false}).twice
81
+ expect(communicator).to receive(:ready?).and_return(true).twice
80
82
  subject.restart_sleep_duration = 0
81
83
  subject.provision
82
84
  expect(subject.old_computer_name).to eq("myoldcomputername")
@@ -85,21 +87,25 @@ describe VagrantPlugins::WindowsDomain::Provisioner do
85
87
  it "should restart the machine on a successful domain join" do
86
88
  allow(communicator).to receive(:upload)
87
89
  allow(ui).to receive(:info)
90
+ expect(communicator).to receive(:test)
91
+ expect(vm).to receive(:boot_timeout).twice
88
92
  expect(communicator).to receive(:sudo).with("powershell -ExecutionPolicy Bypass -OutputFormat Text -file c:/tmp/vagrant-windows-domain-runner.ps1", {:elevated=>true, :error_check=>true, :error_key=>nil, :good_exit=>0, :shell=>:powershell})
89
93
  expect(communicator).to receive(:sudo).with("del c:/tmp/vagrant-windows-domain-runner.ps1")
90
- expect(machine).to receive(:action). with(:reload, {:provision_ignore_sentinel=>false})
91
- expect(communicator).to receive(:ready?).and_return(true)
94
+ expect(machine).to receive(:action). with(:reload, {:provision_ignore_sentinel=>false, :lock=>false}).twice
95
+ expect(communicator).to receive(:ready?).and_return(true).twice
92
96
  subject.restart_sleep_duration = 0
93
97
  subject.provision
94
98
  end
95
99
 
96
100
  it "should not restart the machine on a failed domain join attempt" do
97
101
  allow(communicator).to receive(:upload)
102
+ expect(communicator).to receive(:test)
103
+ expect(vm).to_not receive(:boot_timeout)
98
104
  allow(ui).to receive(:info).with("some exception thrown!", {:color=>:red, :new_line=>false, :prefix=>false}) # Red output on error please!
99
105
  allow(ui).to receive(:info).with("\"Running Windows Domain Provisioner\"")
100
106
  expect(communicator).to receive(:sudo).with("powershell -ExecutionPolicy Bypass -OutputFormat Text -file c:/tmp/vagrant-windows-domain-runner.ps1", {:elevated=>true, :error_check=>true, :error_key=>nil, :good_exit=>0, :shell=>:powershell}).and_yield(:stderr, "some exception thrown!")
101
107
  expect(communicator).to receive(:sudo).with("del c:/tmp/vagrant-windows-domain-runner.ps1")
102
- expect(machine).to_not receive(:action). with(:reload, {:provision_ignore_sentinel=>false})
108
+ expect(machine).to_not receive(:action). with(:reload, {:provision_ignore_sentinel=>false, :lock=>false})
103
109
  subject.restart_sleep_duration = 0
104
110
  subject.provision
105
111
  end
@@ -150,18 +156,24 @@ describe VagrantPlugins::WindowsDomain::Provisioner do
150
156
 
151
157
  describe "cleanup" do
152
158
  before do
159
+ allow(machine).to receive(:root_config).and_return(root_config)
160
+ machine.stub(config: root_config, env: env, id: "1234")
161
+ allow(ui).to receive(:say).with(any_args)
162
+ allow(machine).to receive(:communicate).and_return(communicator)
153
163
  allow(communicator).to receive(:shell).and_return(shell)
154
- allow(shell).to receive(:powershell).and_yield(:stdout, "myoldcomputername")
155
- config = double(config)
156
- allow(machine).to receive(:config).and_return(config)
157
- allow(config).to receive(:windows_domain).and_return(root_config)
158
- allow(machine).to receive(:env).and_return(env)
164
+ allow(shell).to receive(:powershell).with("$env:COMPUTERNAME").and_yield(:stdout, "myoldcomputername")
165
+ allow(root_config).to receive(:vm).and_return(vm)
166
+ allow(vm).to receive(:communicator).and_return(:winrm)
167
+ allow(communicator).to receive(:sudo).with("which Add-Computer", {:error_class=>VagrantPlugins::WindowsDomain::WindowsDomainError, :error_key=>:binary_not_detected, :domain=>"foo.com", :binary=>"Add-Computer"})
168
+ allow(communicator).to receive(:sudo).with("which Remove-Computer", {:error_class=>VagrantPlugins::WindowsDomain::WindowsDomainError, :error_key=>:binary_not_detected, :domain=>"foo.com", :binary=>"Remove-Computer"})
159
169
 
160
170
  root_config.domain = "foo.com"
161
171
  root_config.username = "username"
162
172
  root_config.password = "password"
173
+
163
174
  root_config.finalize!
164
175
  root_config.validate(machine)
176
+ subject.configure(root_config)
165
177
  end
166
178
 
167
179
  it "should leave domain" do
@@ -177,13 +189,14 @@ describe VagrantPlugins::WindowsDomain::Provisioner do
177
189
 
178
190
  it "should leave domain when a `vagrant destroy` is issued" do
179
191
  allow(machine).to receive(:communicate).and_return(communicator)
180
-
192
+ expect(communicator).to receive(:test).and_return(true)
193
+ expect(vm).to receive(:boot_timeout)
181
194
  expect(communicator).to receive(:upload)
182
195
  expect(communicator).to receive(:sudo).with("powershell -ExecutionPolicy Bypass -OutputFormat Text -file c:/tmp/vagrant-windows-domain-runner.ps1", {:elevated=>true, :error_check=>true, :error_key=>nil, :good_exit=>0, :shell=>:powershell}).and_yield(:stdout, "deleted")
183
196
  expect(ui).to receive(:info).with("\"Running Windows Domain Provisioner\"")
184
197
  expect(ui).to receive(:info).with("deleted", {:color=>:green, :new_line=>false, :prefix=>false})
185
198
  expect(ui).to receive(:say).with(:info, "Restarting computer for updates to take effect.")
186
- expect(machine).to receive(:action). with(:reload, {:provision_ignore_sentinel=>false})
199
+ expect(machine).to receive(:action). with(:reload, {:provision_ignore_sentinel=>false, :lock=>false})
187
200
  expect(ui).to_not receive(:say)
188
201
  expect(ui).to_not receive(:ask)
189
202
  expect(communicator).to receive(:ready?).and_return(true)
@@ -207,13 +220,15 @@ describe VagrantPlugins::WindowsDomain::Provisioner do
207
220
  allow(machine).to receive(:communicate).and_return(communicator)
208
221
  allow(machine).to receive(:env).and_return(env)
209
222
 
223
+ expect(vm).to receive(:boot_timeout)
224
+ expect(communicator).to receive(:test).and_return(true)
210
225
  expect(communicator).to receive(:upload)
211
226
  expect(communicator).to receive(:sudo).with("powershell -ExecutionPolicy Bypass -OutputFormat Text -file c:/tmp/vagrant-windows-domain-runner.ps1", {:elevated=>true, :error_check=>true, :error_key=>nil, :good_exit=>0, :shell=>:powershell}).and_yield(:stdout, "deleted")
212
227
  expect(ui).to receive(:info).with(any_args).twice
213
228
  expect(ui).to receive(:ask).with("Please enter your domain password (output will be hidden): ", {:echo=>false}).and_return("myusername")
214
229
  expect(ui).to receive(:ask).with("Please enter your domain username: ")
215
230
  expect(ui).to receive(:say).with(:info, "Restarting computer for updates to take effect.")
216
- expect(machine).to receive(:action). with(:reload, {:provision_ignore_sentinel=>false})
231
+ expect(machine).to receive(:action). with(:reload, {:provision_ignore_sentinel=>false, :lock=>false})
217
232
  expect(communicator).to receive(:ready?).and_return(true)
218
233
  subject.restart_sleep_duration = 0
219
234
 
@@ -221,82 +236,4 @@ describe VagrantPlugins::WindowsDomain::Provisioner do
221
236
  end
222
237
 
223
238
  end
224
-
225
- describe "Powershell runner script" do
226
- before do
227
- allow(machine).to receive(:root_config).and_return(root_config)
228
- machine.stub(config: root_config, env: env, id: "1234")
229
- allow(ui).to receive(:say).with(any_args)
230
- allow(machine).to receive(:communicate).and_return(communicator)
231
- allow(communicator).to receive(:shell).and_return(shell)
232
- allow(shell).to receive(:powershell).with("$env:COMPUTERNAME").and_yield(:stdout, "myoldcomputername")
233
- allow(root_config).to receive(:vm).and_return(vm)
234
- allow(vm).to receive(:communicator).and_return(:winrm)
235
- root_config.domain = "foo.com"
236
- root_config.username = "username"
237
- root_config.password = "password"
238
- root_config.finalize!
239
- root_config.validate(machine)
240
- end
241
-
242
- context "with credentials provided" do
243
-
244
- it "should generate a valid powershell command to add the computer to a domain" do
245
- script = subject.generate_command_runner_script
246
- expect_script =
247
- %Q{$secpasswd = ConvertTo-SecureString "password" -AsPlainText -Force
248
- $credentials = New-Object System.Management.Automation.PSCredential ("username", $secpasswd)
249
- Add-Computer -DomainName foo.com -Credential $credentials -Verbose -Force
250
- }
251
- expect(script).to eq(expect_script)
252
- end
253
-
254
- it "should generate a valid powershell command to remove the computer from a domain" do
255
- script = subject.generate_command_runner_script(false)
256
- expect_script =
257
- %Q{$secpasswd = ConvertTo-SecureString "password" -AsPlainText -Force
258
- $credentials = New-Object System.Management.Automation.PSCredential ("username", $secpasswd)
259
- Remove-Computer -UnjoinDomainCredential $credentials -Workgroup "WORKGROUP" -Verbose -Force
260
- }
261
- expect(script).to eq(expect_script)
262
- end
263
-
264
- context "with join options" do
265
- it "should rename the computer on join" do
266
-
267
- root_config.computer_name = "mynewcomputername"
268
- root_config.ou_path = "OU=testOU,DC=domain,DC=Domain,DC=com"
269
- root_config.finalize!
270
- root_config.validate(machine)
271
-
272
- script = subject.generate_command_runner_script
273
- expect_script =
274
- %Q{$secpasswd = ConvertTo-SecureString "password" -AsPlainText -Force
275
- $credentials = New-Object System.Management.Automation.PSCredential ("username", $secpasswd)
276
- Add-Computer -DomainName foo.com -Credential $credentials -NewName 'mynewcomputername' -OUPath 'OU=testOU,DC=domain,DC=Domain,DC=com' -Verbose -Force
277
- }
278
- expect(script).to eq(expect_script)
279
- end
280
- end
281
- end
282
-
283
- context "with 'unsecure' parameter provided" do
284
- before do
285
- root_config.unsecure = true
286
- end
287
-
288
- it "should generate a valid powershell command to add the computer to a domain" do
289
- script = subject.generate_command_runner_script.strip
290
- expect_script = "Add-Computer -DomainName foo.com -Unsecure -Verbose -Force"
291
- expect(script).to eq(expect_script)
292
- end
293
-
294
- it "should generate a valid powershell command to remove the computer from a domain" do
295
- script = subject.generate_command_runner_script(false).strip
296
- expect_script = "Remove-Computer -Workgroup \"WORKGROUP\" -Verbose -Force"
297
- expect(script).to eq(expect_script)
298
- end
299
- end
300
-
301
- end
302
239
  end
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,7 @@ require 'vagrant-windows-domain/plugin'
6
6
  require 'rspec/its'
7
7
  require 'base'
8
8
 
9
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
9
+ SimpleCov.formatters = [
10
10
  SimpleCov::Formatter::HTMLFormatter,
11
11
  Coveralls::SimpleCov::Formatter
12
12
  ]
@@ -18,7 +18,7 @@ end
18
18
 
19
19
  RSpec.configure do |config|
20
20
  config.expect_with :rspec do |c|
21
- c.syntax = :expect
21
+ c.syntax = [:should, :expect]
22
22
  end
23
23
  config.color = true
24
24
  config.tty = true
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "rake", '~> 10.3', '>= 10.3.0'
22
- spec.add_development_dependency "bundler", "~> 1.6", '>= 1.6.0'
23
- spec.add_development_dependency "coveralls", "~> 0.7.1", '>= 0.7.1'
24
- spec.add_development_dependency "rspec-core", '~> 3.1', '>= 3.1.0'
25
- spec.add_development_dependency "rspec-expectations", '~> 3.1', '>= 3.1.0'
26
- spec.add_development_dependency "rspec-mocks", '~> 3.1', '>= 3.1.0'
27
- spec.add_development_dependency "rspec-its", "~> 1.0.1", '>= 1.0.0'
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "bundler", ">= 1.5.2", "<= 1.12.5"
23
+ spec.add_development_dependency "coveralls", "~> 0.8.10", '>= 0.8.10'
24
+ spec.add_development_dependency "rspec-core", '~> 3.4.2', '>= 3.4.2'
25
+ spec.add_development_dependency "rspec-expectations", '~> 3.4.0', '>= 3.4.0'
26
+ spec.add_development_dependency "rspec-mocks", '~> 3.4.1', '>= 3.4.1'
27
+ spec.add_development_dependency "rspec-its", "~> 1.2.0", '>= 1.2.0'
28
28
  end
metadata CHANGED
@@ -1,155 +1,149 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-windows-domain
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.12
4
+ version: 1.2.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: 2015-02-23 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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '10.3'
20
- - - '>='
21
- - !ruby/object:Gem::Version
22
- version: 10.3.0
19
+ version: '0'
23
20
  type: :development
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '10.3'
30
- - - '>='
24
+ - - ">="
31
25
  - !ruby/object:Gem::Version
32
- version: 10.3.0
26
+ version: '0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: bundler
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - ~>
31
+ - - ">="
38
32
  - !ruby/object:Gem::Version
39
- version: '1.6'
40
- - - '>='
33
+ version: 1.5.2
34
+ - - "<="
41
35
  - !ruby/object:Gem::Version
42
- version: 1.6.0
36
+ version: 1.12.5
43
37
  type: :development
44
38
  prerelease: false
45
39
  version_requirements: !ruby/object:Gem::Requirement
46
40
  requirements:
47
- - - ~>
41
+ - - ">="
48
42
  - !ruby/object:Gem::Version
49
- version: '1.6'
50
- - - '>='
43
+ version: 1.5.2
44
+ - - "<="
51
45
  - !ruby/object:Gem::Version
52
- version: 1.6.0
46
+ version: 1.12.5
53
47
  - !ruby/object:Gem::Dependency
54
48
  name: coveralls
55
49
  requirement: !ruby/object:Gem::Requirement
56
50
  requirements:
57
- - - ~>
51
+ - - "~>"
58
52
  - !ruby/object:Gem::Version
59
- version: 0.7.1
60
- - - '>='
53
+ version: 0.8.10
54
+ - - ">="
61
55
  - !ruby/object:Gem::Version
62
- version: 0.7.1
56
+ version: 0.8.10
63
57
  type: :development
64
58
  prerelease: false
65
59
  version_requirements: !ruby/object:Gem::Requirement
66
60
  requirements:
67
- - - ~>
61
+ - - "~>"
68
62
  - !ruby/object:Gem::Version
69
- version: 0.7.1
70
- - - '>='
63
+ version: 0.8.10
64
+ - - ">="
71
65
  - !ruby/object:Gem::Version
72
- version: 0.7.1
66
+ version: 0.8.10
73
67
  - !ruby/object:Gem::Dependency
74
68
  name: rspec-core
75
69
  requirement: !ruby/object:Gem::Requirement
76
70
  requirements:
77
- - - ~>
71
+ - - "~>"
78
72
  - !ruby/object:Gem::Version
79
- version: '3.1'
80
- - - '>='
73
+ version: 3.4.2
74
+ - - ">="
81
75
  - !ruby/object:Gem::Version
82
- version: 3.1.0
76
+ version: 3.4.2
83
77
  type: :development
84
78
  prerelease: false
85
79
  version_requirements: !ruby/object:Gem::Requirement
86
80
  requirements:
87
- - - ~>
81
+ - - "~>"
88
82
  - !ruby/object:Gem::Version
89
- version: '3.1'
90
- - - '>='
83
+ version: 3.4.2
84
+ - - ">="
91
85
  - !ruby/object:Gem::Version
92
- version: 3.1.0
86
+ version: 3.4.2
93
87
  - !ruby/object:Gem::Dependency
94
88
  name: rspec-expectations
95
89
  requirement: !ruby/object:Gem::Requirement
96
90
  requirements:
97
- - - ~>
91
+ - - "~>"
98
92
  - !ruby/object:Gem::Version
99
- version: '3.1'
100
- - - '>='
93
+ version: 3.4.0
94
+ - - ">="
101
95
  - !ruby/object:Gem::Version
102
- version: 3.1.0
96
+ version: 3.4.0
103
97
  type: :development
104
98
  prerelease: false
105
99
  version_requirements: !ruby/object:Gem::Requirement
106
100
  requirements:
107
- - - ~>
101
+ - - "~>"
108
102
  - !ruby/object:Gem::Version
109
- version: '3.1'
110
- - - '>='
103
+ version: 3.4.0
104
+ - - ">="
111
105
  - !ruby/object:Gem::Version
112
- version: 3.1.0
106
+ version: 3.4.0
113
107
  - !ruby/object:Gem::Dependency
114
108
  name: rspec-mocks
115
109
  requirement: !ruby/object:Gem::Requirement
116
110
  requirements:
117
- - - ~>
111
+ - - "~>"
118
112
  - !ruby/object:Gem::Version
119
- version: '3.1'
120
- - - '>='
113
+ version: 3.4.1
114
+ - - ">="
121
115
  - !ruby/object:Gem::Version
122
- version: 3.1.0
116
+ version: 3.4.1
123
117
  type: :development
124
118
  prerelease: false
125
119
  version_requirements: !ruby/object:Gem::Requirement
126
120
  requirements:
127
- - - ~>
121
+ - - "~>"
128
122
  - !ruby/object:Gem::Version
129
- version: '3.1'
130
- - - '>='
123
+ version: 3.4.1
124
+ - - ">="
131
125
  - !ruby/object:Gem::Version
132
- version: 3.1.0
126
+ version: 3.4.1
133
127
  - !ruby/object:Gem::Dependency
134
128
  name: rspec-its
135
129
  requirement: !ruby/object:Gem::Requirement
136
130
  requirements:
137
- - - ~>
131
+ - - "~>"
138
132
  - !ruby/object:Gem::Version
139
- version: 1.0.1
140
- - - '>='
133
+ version: 1.2.0
134
+ - - ">="
141
135
  - !ruby/object:Gem::Version
142
- version: 1.0.0
136
+ version: 1.2.0
143
137
  type: :development
144
138
  prerelease: false
145
139
  version_requirements: !ruby/object:Gem::Requirement
146
140
  requirements:
147
- - - ~>
141
+ - - "~>"
148
142
  - !ruby/object:Gem::Version
149
- version: 1.0.1
150
- - - '>='
143
+ version: 1.2.0
144
+ - - ">="
151
145
  - !ruby/object:Gem::Version
152
- version: 1.0.0
146
+ version: 1.2.0
153
147
  description: Adds and Removes Windows Guests from a Windows Domain, as part of the
154
148
  standard machine lifecycle.
155
149
  email:
@@ -158,8 +152,8 @@ executables: []
158
152
  extensions: []
159
153
  extra_rdoc_files: []
160
154
  files:
161
- - .gitignore
162
- - .travis.yml
155
+ - ".gitignore"
156
+ - ".travis.yml"
163
157
  - Gemfile
164
158
  - LICENSE.txt
165
159
  - README.md
@@ -189,17 +183,17 @@ require_paths:
189
183
  - lib
190
184
  required_ruby_version: !ruby/object:Gem::Requirement
191
185
  requirements:
192
- - - '>='
186
+ - - ">="
193
187
  - !ruby/object:Gem::Version
194
188
  version: '0'
195
189
  required_rubygems_version: !ruby/object:Gem::Requirement
196
190
  requirements:
197
- - - '>='
191
+ - - ">="
198
192
  - !ruby/object:Gem::Version
199
193
  version: '0'
200
194
  requirements: []
201
195
  rubyforge_project:
202
- rubygems_version: 2.4.1
196
+ rubygems_version: 2.5.1
203
197
  signing_key:
204
198
  specification_version: 4
205
199
  summary: Windows Domain Provisioner for Vagrant