vagrant-windows-domain 1.2.0 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +6 -10
- data/Gemfile +1 -4
- data/README.md +12 -0
- data/development/Vagrantfile +2 -1
- data/lib/vagrant-windows-domain/config.rb +21 -3
- data/lib/vagrant-windows-domain/locales/en.yml +3 -1
- data/lib/vagrant-windows-domain/plugin.rb +4 -4
- data/lib/vagrant-windows-domain/provisioner.rb +6 -8
- data/lib/vagrant-windows-domain/templates/runner.ps1.erb +230 -21
- data/lib/vagrant-windows-domain/version.rb +1 -1
- data/spec/provisioner/config_spec.rb +1 -0
- data/spec/provisioner/provisioner_spec.rb +9 -22
- data/vagrant-windows-domain.gemspec +7 -7
- metadata +16 -55
- data/spec/provisioner/leave_domain_spec.rb +0 -131
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b03f283e47170d9b9a2db97da8a456a11ba260a851fc2f54f8a84d5513e258bd
|
4
|
+
data.tar.gz: 05f3530dd6fa06382d09515160c8a06f4c538d45f66ee15f80840e6d1276b059
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75ed7c28a93fe9a00a5cc7d30ed30f4631e1e4773f196fe5dcfb667265f30bcf514afcc74a4af08230dacbd39364eef6c5850494f0c29824bbe21a0f22f9ee15
|
7
|
+
data.tar.gz: 247b3cb63c12c8597a1fcceeca3799f4f30cd529fcd197e3d0d7eb198febeb11d977bc1eab66d989ba0efb2d56b8cca05d3e705a994b705ff409844d65835097
|
data/.travis.yml
CHANGED
@@ -1,20 +1,16 @@
|
|
1
1
|
language: ruby
|
2
2
|
before_install:
|
3
|
-
-
|
4
|
-
- gem
|
5
|
-
- gem install bundler --version 1.12.5
|
6
|
-
- gem install bundler --version 1.12.5
|
3
|
+
- gem update --system
|
4
|
+
- gem install bundler
|
7
5
|
rvm:
|
8
|
-
- 2.2.3
|
9
|
-
- 2.3.0
|
10
6
|
- ruby-head
|
7
|
+
- 2.5.1
|
8
|
+
- 2.4.4
|
11
9
|
matrix:
|
12
10
|
allow_failures:
|
13
11
|
- rvm: ruby-head
|
14
12
|
fast_finish: true
|
15
13
|
env:
|
16
14
|
matrix:
|
17
|
-
- VAGRANT_VERSION=
|
18
|
-
|
19
|
-
secure: bs4ezY+1Wksy8hH3nymPJ3AL99mpXULVc/AIh16JetEYw1850QkX7r4gQukMlcyByKUhxucjDLid0Y+KDH5kGMM16QjrVQGhAnUQzMoLD2qPbAaxDCUqpCJtFEEQKYxJvFvEK8a5SQzAsTVG4sgABQ/MllsIIH0FjkWgFtH6050=
|
20
|
-
script: bundle _1.12.5_ exec rake test:unit
|
15
|
+
- VAGRANT_VERSION=v2.1.5
|
16
|
+
script: bundle exec rake test:unit
|
data/Gemfile
CHANGED
@@ -4,9 +4,6 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
group :development do
|
7
|
-
gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
|
7
|
+
gem "vagrant", git: "https://github.com/mitchellh/vagrant.git", :tag => "v2.1.5"
|
8
8
|
end
|
9
9
|
|
10
|
-
group :plugins do
|
11
|
-
gem "vagrant-windows-domain", path: "."
|
12
|
-
end
|
data/README.md
CHANGED
@@ -47,6 +47,18 @@ config.vm.provision :windows_domain do |domain|
|
|
47
47
|
# If not supplied the plugin will prompt the user during provisioning to provide one.
|
48
48
|
domain.password = "iprobablyshouldntusethisfield"
|
49
49
|
|
50
|
+
# IP address of primary DNS server
|
51
|
+
#
|
52
|
+
# Specifies the IP address you want assigned as the primary DNS server for the primary nic.
|
53
|
+
# If not supplied, the nic's primary dns server will be assigned dynamically.
|
54
|
+
domain.primary_dns = "8.8.8.8"
|
55
|
+
|
56
|
+
#IP address of the secondary DNS server
|
57
|
+
#
|
58
|
+
# Specifies the IP address you want assigned as the secondary DNS server for the primary nic
|
59
|
+
# If not supplied, the nic's secondary dns server will be assigned dynamically.
|
60
|
+
domain.secondary_dns = "8.8.4.4"
|
61
|
+
|
50
62
|
# The set of Advanced options to pass when joining the Domain.
|
51
63
|
#
|
52
64
|
# See (https://technet.microsoft.com/en-us/library/hh849798.aspx) for detail, these are generally not required.
|
data/development/Vagrantfile
CHANGED
@@ -13,7 +13,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|
13
13
|
config.vm.box = "mfellows/windows2012r2"
|
14
14
|
config.vm.guest = :windows
|
15
15
|
config.vm.communicator = "winrm"
|
16
|
-
|
16
|
+
#ALlows for vagrant to successfully connect to destination machine with winrm
|
17
|
+
config.vm.network :forwarded_port, guest: 5985, host: 55985 #, id: "winrm", auto_correct: true
|
17
18
|
|
18
19
|
config.vm.provider "virtualbox" do |v|
|
19
20
|
v.gui = true
|
@@ -40,6 +40,16 @@ module VagrantPlugins
|
|
40
40
|
# The default value is the default OU for machine objects in the domain.
|
41
41
|
attr_accessor :ou_path
|
42
42
|
|
43
|
+
# IP address of primary DNS server
|
44
|
+
#
|
45
|
+
# Specifies the IP address you want assigned as the primary DNS server for the primary nic
|
46
|
+
attr_accessor :primary_dns
|
47
|
+
|
48
|
+
#IP address of the secondary DNS server
|
49
|
+
#
|
50
|
+
# Specifies the IP address you want assigned as the secondary DNS server for the primary nic
|
51
|
+
attr_accessor :secondary_dns
|
52
|
+
|
43
53
|
# Performs an unsecure join to the specified domain.
|
44
54
|
#
|
45
55
|
# When this option is used username/password are not required
|
@@ -56,6 +66,8 @@ module VagrantPlugins
|
|
56
66
|
@password = UNSET_VALUE
|
57
67
|
@join_options = {}
|
58
68
|
@ou_path = UNSET_VALUE
|
69
|
+
@primary_dns = UNSET_VALUE
|
70
|
+
@secondary_dns = UNSET_VALUE
|
59
71
|
@unsecure = UNSET_VALUE
|
60
72
|
@rename = UNSET_VALUE
|
61
73
|
@logger = Log4r::Logger.new("vagrant::vagrant_windows_domain")
|
@@ -63,7 +75,7 @@ module VagrantPlugins
|
|
63
75
|
|
64
76
|
# Final step of the Configuration lifecyle prior to
|
65
77
|
# validation.
|
66
|
-
#
|
78
|
+
#
|
67
79
|
# Ensures all attributes are set to defaults if not provided.
|
68
80
|
def finalize!
|
69
81
|
super
|
@@ -75,8 +87,10 @@ module VagrantPlugins
|
|
75
87
|
@password = nil if @password == UNSET_VALUE || @password == ""
|
76
88
|
@join_options = [] if @join_options == UNSET_VALUE
|
77
89
|
@ou_path = nil if @ou_path == UNSET_VALUE
|
90
|
+
@primary_dns = nil if @primary_dns == UNSET_VALUE || @primary_dns == ""
|
91
|
+
@secondary_dns = nil if @secondary_dns == UNSET_VALUE || @secondary_dns == ""
|
78
92
|
@unsecure = false if @unsecure == UNSET_VALUE
|
79
|
-
@rename =
|
93
|
+
@rename = false if @rename == UNSET_VALUE
|
80
94
|
end
|
81
95
|
|
82
96
|
# Validate configuration and return a hash of errors.
|
@@ -89,9 +103,13 @@ module VagrantPlugins
|
|
89
103
|
errors = _detected_errors
|
90
104
|
|
91
105
|
# Need to supply one of them!
|
92
|
-
if (
|
106
|
+
if (@username != nil && @password != nil) && @unsecure == true
|
93
107
|
errors << I18n.t("vagrant_windows_domain.errors.both_credentials_provided")
|
94
108
|
end
|
109
|
+
|
110
|
+
if @secondary_dns != nil && @primary_dns == nil
|
111
|
+
errors << I18n.t("vagrant_windows_domain.errors.invalid_dns_config")
|
112
|
+
end
|
95
113
|
|
96
114
|
{ "windows domain provisioner" => errors }
|
97
115
|
end
|
@@ -14,4 +14,6 @@ en:
|
|
14
14
|
binary_not_detected: |-
|
15
15
|
"The command '%{binary} required to join/remove the guest machine from the domain '%{domain}' was not found on the guest machine"
|
16
16
|
absolute_module_path: |-
|
17
|
-
"Absolute 'module_path' not allowed. Please provide a path relative to your Vagrantfile."
|
17
|
+
"Absolute 'module_path' not allowed. Please provide a path relative to your Vagrantfile."
|
18
|
+
invalid_dns_config: |-
|
19
|
+
"Primary dns must be set before configuring Secondary DNS."
|
@@ -24,10 +24,10 @@ module VagrantPlugins
|
|
24
24
|
Provisioner
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
# action_hook(:windows_domain, :machine_action_destroy) do |hook|
|
28
|
+
# require_relative 'action/leave_domain'
|
29
|
+
# hook.prepend(VagrantPlugins::WindowsDomain::LeaveDomain)
|
30
|
+
# end
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -107,7 +107,7 @@ module VagrantPlugins
|
|
107
107
|
restart_guest
|
108
108
|
|
109
109
|
@logger.debug("Need to reboot to join the domain correctly - 2nd reboot")
|
110
|
-
restart_guest
|
110
|
+
#restart_guest
|
111
111
|
end
|
112
112
|
end
|
113
113
|
end
|
@@ -150,14 +150,14 @@ module VagrantPlugins
|
|
150
150
|
# This is the method called when destroying a machine that allows
|
151
151
|
# for any state related to the machine created by the provisioner
|
152
152
|
# to be cleaned up.
|
153
|
-
def
|
153
|
+
def cleanup
|
154
154
|
if @config && @config.domain != nil
|
155
155
|
if is_joined_to_domain()
|
156
156
|
set_credentials
|
157
157
|
result = leave_domain
|
158
158
|
if result
|
159
159
|
@logger.debug("Need to reboot to leave the domain correctly")
|
160
|
-
restart_guest
|
160
|
+
#restart_guest
|
161
161
|
end
|
162
162
|
end
|
163
163
|
else
|
@@ -215,6 +215,8 @@ module VagrantPlugins
|
|
215
215
|
domain: @config.domain,
|
216
216
|
computer_name: @config.computer_name,
|
217
217
|
ou_path: @config.ou_path,
|
218
|
+
primary_dns: @config.primary_dns,
|
219
|
+
secondary_dns: @config.secondary_dns,
|
218
220
|
add_to_domain: add_to_domain,
|
219
221
|
unsecure: @config.unsecure,
|
220
222
|
rename: @config.rename,
|
@@ -246,10 +248,6 @@ module VagrantPlugins
|
|
246
248
|
params["-Credential $credentials"] = nil
|
247
249
|
end
|
248
250
|
|
249
|
-
if @config.computer_name != nil && @config.computer_name != @old_computer_name
|
250
|
-
params["-NewName"] = "'#{@config.computer_name}'"
|
251
|
-
end
|
252
|
-
|
253
251
|
if @config.ou_path
|
254
252
|
params["-OUPath"] = "'#{@config.ou_path}'"
|
255
253
|
end
|
@@ -314,7 +312,7 @@ module VagrantPlugins
|
|
314
312
|
last_type = nil
|
315
313
|
new_line = ""
|
316
314
|
error = false
|
317
|
-
machine.communicate.sudo("powershell -ExecutionPolicy Bypass -OutputFormat Text -file #{script_path}", opts) do |type, data|
|
315
|
+
exit_status = @machine.communicate.sudo("powershell -ExecutionPolicy Bypass -OutputFormat Text -file #{script_path}", opts) do |type, data|
|
318
316
|
if !data.chomp.empty?
|
319
317
|
error = true if type == :stderr
|
320
318
|
if [:stderr, :stdout].include?(type)
|
@@ -17,8 +17,192 @@ function Repair-OpenSSHPasswd(){
|
|
17
17
|
$passwd | Set-Content $passwdPath -Encoding Ascii
|
18
18
|
}
|
19
19
|
}
|
20
|
+
function New-ADSIPrincipalContext
|
21
|
+
{
|
22
|
+
[CmdletBinding(SupportsShouldProcess = $true)]
|
23
|
+
[OutputType('System.DirectoryServices.AccountManagement.PrincipalContext')]
|
24
|
+
PARAM
|
25
|
+
(
|
26
|
+
[Alias("RunAs")]
|
27
|
+
[System.Management.Automation.PSCredential]
|
28
|
+
[System.Management.Automation.Credential()]
|
29
|
+
$Credential = [System.Management.Automation.PSCredential]::Empty,
|
30
|
+
|
31
|
+
[Parameter(Mandatory = $true)]
|
32
|
+
[System.DirectoryServices.AccountManagement.ContextType]$ContextType,
|
33
|
+
|
34
|
+
$DomainName = [System.DirectoryServices.ActiveDirectory.Domain]::Getcurrentdomain(),
|
35
|
+
|
36
|
+
$Container,
|
37
|
+
|
38
|
+
[System.DirectoryServices.AccountManagement.ContextOptions[]]$ContextOptions
|
39
|
+
)
|
40
|
+
|
41
|
+
BEGIN
|
42
|
+
{
|
43
|
+
$ScriptName = (Get-Variable -name MyInvocation -Scope 0 -ValueOnly).MyCommand
|
44
|
+
Write-Verbose -Message "[$ScriptName] Add Type System.DirectoryServices.AccountManagement"
|
45
|
+
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
|
46
|
+
}
|
47
|
+
PROCESS
|
48
|
+
{
|
49
|
+
TRY
|
50
|
+
{
|
51
|
+
switch ($ContextType)
|
52
|
+
{
|
53
|
+
"Domain" { $ArgumentList = $ContextType, $DomainName }
|
54
|
+
"Machine" { $ArgumentList = $ContextType, $ComputerName }
|
55
|
+
"ApplicationDirectory" { $ArgumentList = $ContextType }
|
56
|
+
}
|
57
|
+
|
58
|
+
IF ($PSBoundParameters['Container'])
|
59
|
+
{
|
60
|
+
$ArgumentList += $Container
|
61
|
+
}
|
62
|
+
|
63
|
+
IF ($PSBoundParameters['ContextOptions'])
|
64
|
+
{
|
65
|
+
$ArgumentList += $($ContextOptions)
|
66
|
+
}
|
67
|
+
|
68
|
+
IF ($PSBoundParameters['Credential'])
|
69
|
+
{
|
70
|
+
# Query the specified domain or current if not entered, with the specified credentials
|
71
|
+
$ArgumentList += $($Credential.UserName), $($Credential.GetNetworkCredential().password)
|
72
|
+
}
|
73
|
+
|
74
|
+
IF ($PSCmdlet.ShouldProcess($DomainName, "Create Principal Context"))
|
75
|
+
{
|
76
|
+
# Query
|
77
|
+
New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList $ArgumentList
|
78
|
+
}
|
79
|
+
} #TRY
|
80
|
+
CATCH
|
81
|
+
{
|
82
|
+
$PSCmdlet.ThrowTerminatingError($_)
|
83
|
+
}
|
84
|
+
} #PROCESS
|
85
|
+
}
|
20
86
|
|
87
|
+
function Get-ADSIComputer
|
88
|
+
{
|
89
|
+
[CmdletBinding(DefaultParameterSetName="All")]
|
90
|
+
param ([Parameter(Mandatory=$true,ParameterSetName="Identity")]
|
91
|
+
[string]$Identity,
|
92
|
+
|
93
|
+
[Alias("RunAs")]
|
94
|
+
[System.Management.Automation.PSCredential]
|
95
|
+
[System.Management.Automation.Credential()]
|
96
|
+
$Credential = [System.Management.Automation.PSCredential]::Empty,
|
97
|
+
|
98
|
+
[String]$DomainName
|
99
|
+
)
|
100
|
+
BEGIN
|
101
|
+
{
|
102
|
+
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
|
103
|
+
|
104
|
+
# Create Context splatting
|
105
|
+
$ContextSplatting = @{ ContextType = "Domain" }
|
106
|
+
|
107
|
+
IF ($PSBoundParameters['Credential']) { $ContextSplatting.Credential = $Credential }
|
108
|
+
IF ($PSBoundParameters['DomainName']) { $ContextSplatting.DomainName = $DomainName }
|
109
|
+
|
110
|
+
$Context = New-ADSIPrincipalContext @ContextSplatting
|
111
|
+
|
112
|
+
}
|
113
|
+
PROCESS
|
114
|
+
{
|
115
|
+
TRY{
|
116
|
+
IF($Identity)
|
117
|
+
{
|
118
|
+
[System.DirectoryServices.AccountManagement.ComputerPrincipal]::FindByIdentity($Context, $Identity)
|
119
|
+
}
|
120
|
+
ELSE{
|
121
|
+
$ComputerPrincipal = New-object -TypeName System.DirectoryServices.AccountManagement.ComputerPrincipal -ArgumentList $Context
|
122
|
+
$Searcher = new-object System.DirectoryServices.AccountManagement.PrincipalSearcher
|
123
|
+
$Searcher.QueryFilter = $ComputerPrincipal
|
124
|
+
|
125
|
+
$Searcher.FindAll()
|
126
|
+
}
|
127
|
+
}
|
128
|
+
CATCH
|
129
|
+
{
|
130
|
+
$pscmdlet.ThrowTerminatingError($_)
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
function Remove-ADSIComputer
|
136
|
+
{
|
137
|
+
[CmdletBinding(SupportsShouldProcess = $true)]
|
138
|
+
PARAM (
|
139
|
+
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, ValueFromPipeline = $true)]
|
140
|
+
$Identity,
|
141
|
+
|
142
|
+
[Alias("RunAs")]
|
143
|
+
[System.Management.Automation.PSCredential]
|
144
|
+
[System.Management.Automation.Credential()]
|
145
|
+
$Credential = [System.Management.Automation.PSCredential]::Empty,
|
146
|
+
|
147
|
+
[String]$DomainName,
|
148
|
+
|
149
|
+
[Switch]$Recursive
|
150
|
+
)
|
151
|
+
|
152
|
+
BEGIN
|
153
|
+
{
|
154
|
+
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
|
155
|
+
|
156
|
+
# Create Context splatting
|
157
|
+
$ContextSplatting = @{ }
|
158
|
+
IF ($PSBoundParameters['Credential']) { $ContextSplatting.Credential = $Credential }
|
159
|
+
IF ($PSBoundParameters['DomainName']) { $ContextSplatting.DomainName = $DomainName }
|
160
|
+
|
161
|
+
}
|
162
|
+
PROCESS
|
163
|
+
{
|
164
|
+
TRY
|
165
|
+
{
|
166
|
+
# Not Recursive
|
167
|
+
if (-not $PSBoundParameters['Recursive'])
|
168
|
+
{
|
169
|
+
if ($pscmdlet.ShouldProcess("$Identity", "Remove Account"))
|
170
|
+
{
|
171
|
+
$Account = Get-ADSIComputer -Identity $Identity @ContextSplatting
|
172
|
+
$Account.delete()
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
# Recursive (if the computer is the parent of one leaf or more)
|
177
|
+
if ($PSBoundParameters['Recursive'])
|
178
|
+
{
|
179
|
+
if ($pscmdlet.ShouldProcess("$Identity", "Remove Account and any child objects"))
|
180
|
+
{
|
181
|
+
$Account = Get-ADSIComputer -Identity $Identity @ContextSplatting
|
182
|
+
$Account.GetUnderlyingObject().deletetree()
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
}
|
187
|
+
CATCH
|
188
|
+
{
|
189
|
+
$pscmdlet.ThrowTerminatingError($_)
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}
|
193
|
+
try
|
194
|
+
{
|
195
|
+
Get-NetConnectionProfile -ErrorAction Stop | Set-NetConnectionProfile -NetworkCategory private -ErrorAction Stop
|
196
|
+
}
|
197
|
+
catch
|
198
|
+
{
|
199
|
+
Write-host "Network adapters already set to private network type"
|
200
|
+
}
|
201
|
+
<% if options[:computer_name] != nil %>
|
21
202
|
$computerName='<%= options[:computer_name] %>'
|
203
|
+
<% else %>
|
204
|
+
$computerName = $env:COMPUTERNAME
|
205
|
+
<% end %>
|
22
206
|
<% if options[:username] != nil && options[:unsecure] != true %>
|
23
207
|
$domain='<%= options[:domain] %>'
|
24
208
|
$username='<%= options[:username] %>'
|
@@ -26,14 +210,41 @@ $password='<%= options[:password] %>'
|
|
26
210
|
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
|
27
211
|
$credentials = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
|
28
212
|
<% end %>
|
213
|
+
|
29
214
|
<% if options[:add_to_domain] === true %>
|
30
215
|
if (Test-PartOfDomain -computerName $computerName -domain $domain){
|
31
216
|
throw "$computerName already part of domain $domain"
|
32
217
|
} else {
|
33
|
-
|
34
|
-
|
218
|
+
#If a value is provided for the Primary_DNS and Secondary_DNS variable in the vagrantfile, powershell will determine if the string is a valid IP and will statically set the primary and secondary dns servers of the vm's nic if it is. If only Primary_DNS variable is provided, powershell will statically set the primary dns server of the vm's nic while leaving the secondary unset.
|
219
|
+
<% if options[:primary_dns] != nil %>
|
220
|
+
$wmi = Get-WmiObject -ComputerName $env:COMPUTERNAME -Namespace "root\CIMV2" -Class "Win32_NetworkAdapterconfiguration" -Filter 'IPENABLED=TRUE AND Index=2' -Impersonation Impersonate -ErrorAction Stop | Where-Object { $_.DefaultIPGateway }
|
221
|
+
# $currdns = $wmi.DNSServerSearchOrder
|
222
|
+
$prim = '<%= options[:primary_dns] %>'
|
223
|
+
# Modified the configuration so that the secondary dns can only be set if the primary dns server has also been set
|
224
|
+
<% if options[:secondary_dns] != nil %>
|
225
|
+
$sec = '<%= options[:secondary_dns] %>'
|
226
|
+
If (($prim -match "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$") -and ($sec -match "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"))
|
227
|
+
{
|
228
|
+
$wmi.SetDNSServerSearchOrder(@("$prim", "$sec"))
|
229
|
+
}
|
230
|
+
else
|
231
|
+
{
|
232
|
+
throw "Invalid value provided for dns server ip"
|
233
|
+
}
|
234
|
+
<% else %>
|
235
|
+
If ($prim -match "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
|
236
|
+
{
|
237
|
+
$wmi.SetDNSServerSearchOrder("$prim")
|
238
|
+
}
|
239
|
+
else
|
240
|
+
{
|
241
|
+
throw "Invalid IP address provided"
|
242
|
+
}
|
243
|
+
<% end %>
|
244
|
+
<% end %>
|
245
|
+
Add-Computer <%= options[:parameters] %> -Verbose -Force
|
35
246
|
# Rename computer separately: Fixes GH issue #11
|
36
|
-
<% if options[:
|
247
|
+
<% if options[:computer_name] != nil %>
|
37
248
|
$completed = $false
|
38
249
|
while ( -not $completed) {
|
39
250
|
try {
|
@@ -51,28 +262,26 @@ if (Test-PartOfDomain -computerName $computerName -domain $domain){
|
|
51
262
|
}
|
52
263
|
}
|
53
264
|
<% end %>
|
54
|
-
|
55
265
|
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
266
|
}
|
64
267
|
<% else %>
|
65
|
-
|
66
|
-
|
268
|
+
$compobj = Get-ADSIComputer -Identity $computerName -Credential $credentials -DomainName $domain
|
269
|
+
if (!(Test-JoinedToADomain) -or !($compobj)) {
|
270
|
+
# Throw "$computerName not part of any domain"
|
271
|
+
return
|
67
272
|
} else {
|
68
|
-
|
273
|
+
#When destroying the vagrant machine, the goal is not as much to have the virtual machine disjoin from the domain, but to remove the computer object associated with the
|
274
|
+
#machine so that future runs of vagrant up will succeed (especially when the vagrantfile explicitly defines a computer name. That being the case, the remove-computer
|
275
|
+
#command has been replaced with a custom function which is able to remove the computer object associated with the vagrant machine in active directory.
|
276
|
+
try
|
277
|
+
{
|
278
|
+
Remove-ADSIComputer -Identity $env:COMPUTERNAME -DomainName $domain -Credential $credentials -Verbose -ErrorAction Stop
|
69
279
|
Repair-OpenSSHPasswd
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
&shutdown /s /t 15 /c "Vagrant Halt" /f /d p:4:1
|
280
|
+
}
|
281
|
+
catch
|
282
|
+
{
|
283
|
+
Repair-OpenSSHPasswd
|
284
|
+
}
|
285
|
+
|
77
286
|
}
|
78
287
|
<% end %>
|
@@ -74,11 +74,11 @@ describe VagrantPlugins::WindowsDomain::Provisioner do
|
|
74
74
|
allow(communicator).to receive(:upload)
|
75
75
|
allow(ui).to receive(:info)
|
76
76
|
expect(communicator).to receive(:test)
|
77
|
-
expect(vm).to receive(:boot_timeout).
|
77
|
+
expect(vm).to receive(:boot_timeout).once
|
78
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})
|
79
79
|
expect(communicator).to receive(:sudo).with("del c:/tmp/vagrant-windows-domain-runner.ps1")
|
80
|
-
expect(machine).to receive(:action).with(:reload, {:provision_ignore_sentinel=>false, :lock=>false}).
|
81
|
-
expect(communicator).to receive(:ready?).and_return(true).
|
80
|
+
expect(machine).to receive(:action).with(:reload, {:provision_ignore_sentinel=>false, :lock=>false}).once
|
81
|
+
expect(communicator).to receive(:ready?).and_return(true).once
|
82
82
|
subject.restart_sleep_duration = 0
|
83
83
|
subject.provision
|
84
84
|
expect(subject.old_computer_name).to eq("myoldcomputername")
|
@@ -88,11 +88,11 @@ describe VagrantPlugins::WindowsDomain::Provisioner do
|
|
88
88
|
allow(communicator).to receive(:upload)
|
89
89
|
allow(ui).to receive(:info)
|
90
90
|
expect(communicator).to receive(:test)
|
91
|
-
expect(vm).to receive(:boot_timeout).
|
91
|
+
expect(vm).to receive(:boot_timeout).once
|
92
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})
|
93
93
|
expect(communicator).to receive(:sudo).with("del c:/tmp/vagrant-windows-domain-runner.ps1")
|
94
|
-
expect(machine).to receive(:action). with(:reload, {:provision_ignore_sentinel=>false, :lock=>false}).
|
95
|
-
expect(communicator).to receive(:ready?).and_return(true).
|
94
|
+
expect(machine).to receive(:action). with(:reload, {:provision_ignore_sentinel=>false, :lock=>false}).once
|
95
|
+
expect(communicator).to receive(:ready?).and_return(true).once
|
96
96
|
subject.restart_sleep_duration = 0
|
97
97
|
subject.provision
|
98
98
|
end
|
@@ -190,19 +190,12 @@ describe VagrantPlugins::WindowsDomain::Provisioner do
|
|
190
190
|
it "should leave domain when a `vagrant destroy` is issued" do
|
191
191
|
allow(machine).to receive(:communicate).and_return(communicator)
|
192
192
|
expect(communicator).to receive(:test).and_return(true)
|
193
|
-
expect(vm).to receive(:boot_timeout)
|
194
193
|
expect(communicator).to receive(:upload)
|
195
194
|
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")
|
196
195
|
expect(ui).to receive(:info).with("\"Running Windows Domain Provisioner\"")
|
197
196
|
expect(ui).to receive(:info).with("deleted", {:color=>:green, :new_line=>false, :prefix=>false})
|
198
|
-
expect(ui).to receive(:say).with(:info, "Restarting computer for updates to take effect.")
|
199
|
-
expect(machine).to receive(:action). with(:reload, {:provision_ignore_sentinel=>false, :lock=>false})
|
200
|
-
expect(ui).to_not receive(:say)
|
201
|
-
expect(ui).to_not receive(:ask)
|
202
|
-
expect(communicator).to receive(:ready?).and_return(true)
|
203
|
-
subject.restart_sleep_duration = 0
|
204
197
|
|
205
|
-
subject.
|
198
|
+
subject.cleanup
|
206
199
|
end
|
207
200
|
|
208
201
|
it "should not leave domain plugin not associated with current Vagrantfile" do
|
@@ -211,7 +204,7 @@ describe VagrantPlugins::WindowsDomain::Provisioner do
|
|
211
204
|
subject = described_class.new machine, double("env", :domain => nil)
|
212
205
|
|
213
206
|
expect(ui).to_not receive(:ask)
|
214
|
-
expect(subject.
|
207
|
+
expect(subject.cleanup).to eq(nil)
|
215
208
|
end
|
216
209
|
|
217
210
|
it "should ask for credentials when leaving domain when no credentials were provided" do
|
@@ -220,19 +213,13 @@ describe VagrantPlugins::WindowsDomain::Provisioner do
|
|
220
213
|
allow(machine).to receive(:communicate).and_return(communicator)
|
221
214
|
allow(machine).to receive(:env).and_return(env)
|
222
215
|
|
223
|
-
expect(vm).to receive(:boot_timeout)
|
224
216
|
expect(communicator).to receive(:test).and_return(true)
|
225
217
|
expect(communicator).to receive(:upload)
|
226
218
|
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")
|
227
219
|
expect(ui).to receive(:info).with(any_args).twice
|
228
220
|
expect(ui).to receive(:ask).with("Please enter your domain password (output will be hidden): ", {:echo=>false}).and_return("myusername")
|
229
221
|
expect(ui).to receive(:ask).with("Please enter your domain username: ")
|
230
|
-
|
231
|
-
expect(machine).to receive(:action). with(:reload, {:provision_ignore_sentinel=>false, :lock=>false})
|
232
|
-
expect(communicator).to receive(:ready?).and_return(true)
|
233
|
-
subject.restart_sleep_duration = 0
|
234
|
-
|
235
|
-
subject.destroy
|
222
|
+
subject.cleanup
|
236
223
|
end
|
237
224
|
|
238
225
|
end
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["matt.fellows@onegeek.com.au"]
|
11
11
|
spec.summary = "Windows Domain Provisioner for Vagrant"
|
12
12
|
spec.description = "Adds and Removes Windows Guests from a Windows Domain, as part of the standard machine lifecycle."
|
13
|
-
spec.homepage = "https://github.com/
|
13
|
+
spec.homepage = "https://github.com/mefellows/vagrant-windows-domain"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -19,10 +19,10 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "rake"
|
22
|
-
spec.add_development_dependency "bundler"
|
23
|
-
spec.add_development_dependency "coveralls"
|
24
|
-
spec.add_development_dependency "rspec-core"
|
25
|
-
spec.add_development_dependency "rspec-expectations"
|
26
|
-
spec.add_development_dependency "rspec-mocks"
|
27
|
-
spec.add_development_dependency "rspec-its"
|
22
|
+
spec.add_development_dependency "bundler"
|
23
|
+
spec.add_development_dependency "coveralls"
|
24
|
+
spec.add_development_dependency "rspec-core"
|
25
|
+
spec.add_development_dependency "rspec-expectations"
|
26
|
+
spec.add_development_dependency "rspec-mocks"
|
27
|
+
spec.add_development_dependency "rspec-its"
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-windows-domain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Fellows
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -30,120 +30,84 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
- - "<="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 1.12.5
|
33
|
+
version: '0'
|
37
34
|
type: :development
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
38
|
- - ">="
|
42
39
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
-
- - "<="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 1.12.5
|
40
|
+
version: '0'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: coveralls
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
50
44
|
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 0.8.10
|
54
45
|
- - ">="
|
55
46
|
- !ruby/object:Gem::Version
|
56
|
-
version: 0
|
47
|
+
version: '0'
|
57
48
|
type: :development
|
58
49
|
prerelease: false
|
59
50
|
version_requirements: !ruby/object:Gem::Requirement
|
60
51
|
requirements:
|
61
|
-
- - "~>"
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: 0.8.10
|
64
52
|
- - ">="
|
65
53
|
- !ruby/object:Gem::Version
|
66
|
-
version: 0
|
54
|
+
version: '0'
|
67
55
|
- !ruby/object:Gem::Dependency
|
68
56
|
name: rspec-core
|
69
57
|
requirement: !ruby/object:Gem::Requirement
|
70
58
|
requirements:
|
71
|
-
- - "~>"
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: 3.4.2
|
74
59
|
- - ">="
|
75
60
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
61
|
+
version: '0'
|
77
62
|
type: :development
|
78
63
|
prerelease: false
|
79
64
|
version_requirements: !ruby/object:Gem::Requirement
|
80
65
|
requirements:
|
81
|
-
- - "~>"
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: 3.4.2
|
84
66
|
- - ">="
|
85
67
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
68
|
+
version: '0'
|
87
69
|
- !ruby/object:Gem::Dependency
|
88
70
|
name: rspec-expectations
|
89
71
|
requirement: !ruby/object:Gem::Requirement
|
90
72
|
requirements:
|
91
|
-
- - "~>"
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: 3.4.0
|
94
73
|
- - ">="
|
95
74
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
75
|
+
version: '0'
|
97
76
|
type: :development
|
98
77
|
prerelease: false
|
99
78
|
version_requirements: !ruby/object:Gem::Requirement
|
100
79
|
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 3.4.0
|
104
80
|
- - ">="
|
105
81
|
- !ruby/object:Gem::Version
|
106
|
-
version:
|
82
|
+
version: '0'
|
107
83
|
- !ruby/object:Gem::Dependency
|
108
84
|
name: rspec-mocks
|
109
85
|
requirement: !ruby/object:Gem::Requirement
|
110
86
|
requirements:
|
111
|
-
- - "~>"
|
112
|
-
- !ruby/object:Gem::Version
|
113
|
-
version: 3.4.1
|
114
87
|
- - ">="
|
115
88
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
89
|
+
version: '0'
|
117
90
|
type: :development
|
118
91
|
prerelease: false
|
119
92
|
version_requirements: !ruby/object:Gem::Requirement
|
120
93
|
requirements:
|
121
|
-
- - "~>"
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version: 3.4.1
|
124
94
|
- - ">="
|
125
95
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
96
|
+
version: '0'
|
127
97
|
- !ruby/object:Gem::Dependency
|
128
98
|
name: rspec-its
|
129
99
|
requirement: !ruby/object:Gem::Requirement
|
130
100
|
requirements:
|
131
|
-
- - "~>"
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version: 1.2.0
|
134
101
|
- - ">="
|
135
102
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
103
|
+
version: '0'
|
137
104
|
type: :development
|
138
105
|
prerelease: false
|
139
106
|
version_requirements: !ruby/object:Gem::Requirement
|
140
107
|
requirements:
|
141
|
-
- - "~>"
|
142
|
-
- !ruby/object:Gem::Version
|
143
|
-
version: 1.2.0
|
144
108
|
- - ">="
|
145
109
|
- !ruby/object:Gem::Version
|
146
|
-
version:
|
110
|
+
version: '0'
|
147
111
|
description: Adds and Removes Windows Guests from a Windows Domain, as part of the
|
148
112
|
standard machine lifecycle.
|
149
113
|
email:
|
@@ -169,11 +133,10 @@ files:
|
|
169
133
|
- lib/vagrant-windows-domain/version.rb
|
170
134
|
- spec/base.rb
|
171
135
|
- spec/provisioner/config_spec.rb
|
172
|
-
- spec/provisioner/leave_domain_spec.rb
|
173
136
|
- spec/provisioner/provisioner_spec.rb
|
174
137
|
- spec/spec_helper.rb
|
175
138
|
- vagrant-windows-domain.gemspec
|
176
|
-
homepage: https://github.com/
|
139
|
+
homepage: https://github.com/mefellows/vagrant-windows-domain
|
177
140
|
licenses:
|
178
141
|
- MIT
|
179
142
|
metadata: {}
|
@@ -192,14 +155,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
155
|
- !ruby/object:Gem::Version
|
193
156
|
version: '0'
|
194
157
|
requirements: []
|
195
|
-
|
196
|
-
rubygems_version: 2.5.1
|
158
|
+
rubygems_version: 3.0.3
|
197
159
|
signing_key:
|
198
160
|
specification_version: 4
|
199
161
|
summary: Windows Domain Provisioner for Vagrant
|
200
162
|
test_files:
|
201
163
|
- spec/base.rb
|
202
164
|
- spec/provisioner/config_spec.rb
|
203
|
-
- spec/provisioner/leave_domain_spec.rb
|
204
165
|
- spec/provisioner/provisioner_spec.rb
|
205
166
|
- spec/spec_helper.rb
|
@@ -1,131 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'vagrant-windows-domain/provisioner'
|
3
|
-
require 'vagrant-windows-domain/action/leave_domain'
|
4
|
-
require 'vagrant-windows-domain/config'
|
5
|
-
require 'base'
|
6
|
-
|
7
|
-
describe VagrantPlugins::WindowsDomain::LeaveDomain do
|
8
|
-
|
9
|
-
include_context "unit"
|
10
|
-
let(:instance) { described_class.new }
|
11
|
-
|
12
|
-
let(:root_path) { (Pathname.new(Dir.mktmpdir)).to_s }
|
13
|
-
let(:domain) { "foo.com" }
|
14
|
-
let(:ui) { double("ui") }
|
15
|
-
let(:app) { double("app") }
|
16
|
-
let(:communicator) { double ("communicator") }
|
17
|
-
let(:shell) { double ("shell") }
|
18
|
-
let(:powershell) { double ("powershell") }
|
19
|
-
let(:guest) { double ("guest") }
|
20
|
-
let(:configuration_file) { "manifests/MyWebsite.ps1" }
|
21
|
-
let(:module_path) { ["foo/modules", "foo/modules2"] }
|
22
|
-
let(:config) { VagrantPlugins::WindowsDomain::Config.new }
|
23
|
-
let(:vm) { double("vm", provisioners: [double("prov", config: config)]) }
|
24
|
-
let(:root_config) { double("root_config", vm: vm) }
|
25
|
-
let(:env) { {:ui => ui, :machine => machine} }
|
26
|
-
let(:machine) { double("machine", ui: ui, id: "1234", config: root_config) }
|
27
|
-
let(:provisioner) { double("provisioner") }
|
28
|
-
subject { described_class.new app, env }
|
29
|
-
|
30
|
-
describe "call" do
|
31
|
-
|
32
|
-
before do
|
33
|
-
allow(machine).to receive(:communicate).and_return(communicator)
|
34
|
-
allow(env).to receive(:machine).and_return(machine)
|
35
|
-
allow(communicator).to receive(:shell).and_return(shell)
|
36
|
-
allow(shell).to receive(:powershell).and_yield(:stdout, "myoldcomputername")
|
37
|
-
config.domain = domain
|
38
|
-
allow(env).to receive(:machine).and_return(machine)
|
39
|
-
allow(machine).to receive(:env).and_return(env)
|
40
|
-
allow(env).to receive(:ui).and_return(ui)
|
41
|
-
subject.provisioner = provisioner
|
42
|
-
end
|
43
|
-
|
44
|
-
context "when no configuration exists for the machine" do
|
45
|
-
it "should pass control to the next middleware Action" do
|
46
|
-
config.domain = nil
|
47
|
-
expect(app).to receive(:call).with(env)
|
48
|
-
subject.call(env)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when machine is running" do
|
53
|
-
it "should prompt the user if they would like to destroy & d/c the machine" do
|
54
|
-
state = double("state", id: :running)
|
55
|
-
expect(provisioner).to receive(:destroy)
|
56
|
-
|
57
|
-
expect(app).to receive(:call).with(env)
|
58
|
-
expect(ui).to receive(:ask).with("Are you sure you want to destroy this machine and disconnect from #{domain}? (y/n)").and_return("y")
|
59
|
-
expect(machine).to receive(:state).and_return(state).twice
|
60
|
-
subject.call(env)
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should not continue if the user declines to destroy the machine" do
|
65
|
-
state = double("state", id: :running)
|
66
|
-
expect(provisioner).to_not receive(:destroy)
|
67
|
-
|
68
|
-
expect(ui).to receive(:ask).with("Are you sure you want to destroy this machine and disconnect from #{domain}? (y/n)").and_return("n")
|
69
|
-
expect(machine).to receive(:state).and_return(state).twice
|
70
|
-
expect(app).to_not receive(:call).with(env)
|
71
|
-
subject.call(env)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "when machine is :paused, :saved or :poweroff" do
|
76
|
-
it "should prompt the user if they would like to force destroy the machine" do
|
77
|
-
state = double("state", id: :poweroff)
|
78
|
-
provisioner = double("provisioner")
|
79
|
-
subject.provisioner = provisioner
|
80
|
-
|
81
|
-
expect(ui).to receive(:say).with(:warn, "Machine is currently not running. To properly leave the #{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")
|
82
|
-
expect(ui).to receive(:ask).with("Would you like to continue destroying this machine, leaving this machine orphaned in the '#{domain}' network? If so, type 'destroy'").and_return("destroy")
|
83
|
-
expect(ui).to receive(:say).with(:warn, "Force destroying this machine and not leaving the domain foo.com. May FSM have mercy on your soul.")
|
84
|
-
expect(machine).to receive(:state).and_return(state).twice
|
85
|
-
expect(app).to receive(:call).with(env)
|
86
|
-
# Can't call destroy on a non-running machine
|
87
|
-
expect(provisioner).to_not receive(:destroy)
|
88
|
-
|
89
|
-
subject.call(env)
|
90
|
-
|
91
|
-
expect(env[:force_confirm_destroy]).to be(true)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should not pass on to middleware if user declines force destroy" do
|
95
|
-
state = double("state", id: :poweroff)
|
96
|
-
provisioner = double("provisioner")
|
97
|
-
subject.provisioner = provisioner
|
98
|
-
|
99
|
-
expect(ui).to receive(:say).with(:warn, "Machine is currently not running. To properly leave the #{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")
|
100
|
-
expect(ui).to receive(:ask).with("Would you like to continue destroying this machine, leaving this machine orphaned in the '#{domain}' network? If so, type 'destroy'").and_return("n")
|
101
|
-
expect(machine).to receive(:state).and_return(state).twice
|
102
|
-
expect(app).to_not receive(:call).with(env)
|
103
|
-
expect(provisioner).to_not receive(:destroy)
|
104
|
-
expect(env[:force_confirm_destroy]).to be(nil)
|
105
|
-
|
106
|
-
subject.call(env)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context "when machine is :not_created" do
|
111
|
-
it "should pass control to the next middleware action" do
|
112
|
-
state = double("state", id: :not_created)
|
113
|
-
expect(machine).to receive(:state).and_return(state)
|
114
|
-
|
115
|
-
expect(app).to receive(:call).with(env)
|
116
|
-
subject.call(env)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
|
122
|
-
describe "initialize" do
|
123
|
-
|
124
|
-
its("env") { should eq(env) }
|
125
|
-
its("app") { should eq(app) }
|
126
|
-
its("config") { should eq(config) }
|
127
|
-
its("machine") { should eq(machine) }
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|