Merge pull request #10532 from chrisroberts/e-reboot
Add reboot option to shell provisioner
This commit is contained in:
commit
1f959e03cb
|
@ -17,6 +17,7 @@ module VagrantPlugins
|
||||||
attr_accessor :sensitive
|
attr_accessor :sensitive
|
||||||
attr_accessor :powershell_args
|
attr_accessor :powershell_args
|
||||||
attr_accessor :powershell_elevated_interactive
|
attr_accessor :powershell_elevated_interactive
|
||||||
|
attr_accessor :reboot
|
||||||
attr_accessor :reset
|
attr_accessor :reset
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
|
@ -32,6 +33,7 @@ module VagrantPlugins
|
||||||
@keep_color = UNSET_VALUE
|
@keep_color = UNSET_VALUE
|
||||||
@name = UNSET_VALUE
|
@name = UNSET_VALUE
|
||||||
@sensitive = UNSET_VALUE
|
@sensitive = UNSET_VALUE
|
||||||
|
@reboot = UNSET_VALUE
|
||||||
@reset = UNSET_VALUE
|
@reset = UNSET_VALUE
|
||||||
@powershell_args = UNSET_VALUE
|
@powershell_args = UNSET_VALUE
|
||||||
@powershell_elevated_interactive = UNSET_VALUE
|
@powershell_elevated_interactive = UNSET_VALUE
|
||||||
|
@ -50,6 +52,7 @@ module VagrantPlugins
|
||||||
@keep_color = false if @keep_color == UNSET_VALUE
|
@keep_color = false if @keep_color == UNSET_VALUE
|
||||||
@name = nil if @name == UNSET_VALUE
|
@name = nil if @name == UNSET_VALUE
|
||||||
@sensitive = false if @sensitive == UNSET_VALUE
|
@sensitive = false if @sensitive == UNSET_VALUE
|
||||||
|
@reboot = false if @reboot == UNSET_VALUE
|
||||||
@reset = false if @reset == UNSET_VALUE
|
@reset = false if @reset == UNSET_VALUE
|
||||||
@powershell_args = "-ExecutionPolicy Bypass" if @powershell_args == UNSET_VALUE
|
@powershell_args = "-ExecutionPolicy Bypass" if @powershell_args == UNSET_VALUE
|
||||||
@powershell_elevated_interactive = false if @powershell_elevated_interactive == UNSET_VALUE
|
@powershell_elevated_interactive = false if @powershell_elevated_interactive == UNSET_VALUE
|
||||||
|
@ -71,7 +74,7 @@ module VagrantPlugins
|
||||||
# Validate that the parameters are properly set
|
# Validate that the parameters are properly set
|
||||||
if path && inline
|
if path && inline
|
||||||
errors << I18n.t("vagrant.provisioners.shell.path_and_inline_set")
|
errors << I18n.t("vagrant.provisioners.shell.path_and_inline_set")
|
||||||
elsif !path && !inline && !reset
|
elsif !path && !inline && !reset && !reboot
|
||||||
errors << I18n.t("vagrant.provisioners.shell.no_path_or_inline")
|
errors << I18n.t("vagrant.provisioners.shell.no_path_or_inline")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,12 @@ module VagrantPlugins
|
||||||
provision_ssh(args)
|
provision_ssh(args)
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
|
if config.reboot
|
||||||
|
@machine.guest.capability(:reboot)
|
||||||
|
else
|
||||||
@machine.communicate.reset! if config.reset
|
@machine.communicate.reset! if config.reset
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,14 @@ describe "VagrantPlugins::Shell::Config" do
|
||||||
result = subject.validate(machine)
|
result = subject.validate(machine)
|
||||||
expect(result["shell provisioner"]).to be_empty
|
expect(result["shell provisioner"]).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns no error when inline and path are unset but reboot is true" do
|
||||||
|
subject.reboot = true
|
||||||
|
subject.finalize!
|
||||||
|
|
||||||
|
result = subject.validate(machine)
|
||||||
|
expect(result["shell provisioner"]).to be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'finalize!' do
|
describe 'finalize!' do
|
||||||
|
|
|
@ -31,7 +31,8 @@ describe "Vagrant::Shell::Provisioner" do
|
||||||
:path => path,
|
:path => path,
|
||||||
:inline => inline,
|
:inline => inline,
|
||||||
:binary => false,
|
:binary => false,
|
||||||
:reset => true
|
:reset => true,
|
||||||
|
:reboot => false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +63,55 @@ describe "Vagrant::Shell::Provisioner" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when reboot is enabled" do
|
||||||
|
let(:path) { nil }
|
||||||
|
let(:inline) { "" }
|
||||||
|
let(:communicator) { double("communicator") }
|
||||||
|
let(:guest) { double("guest") }
|
||||||
|
|
||||||
|
let(:config) {
|
||||||
|
double(
|
||||||
|
:config,
|
||||||
|
:args => "doesn't matter",
|
||||||
|
:env => {},
|
||||||
|
:upload_path => "arbitrary",
|
||||||
|
:remote? => false,
|
||||||
|
:path => path,
|
||||||
|
:inline => inline,
|
||||||
|
:binary => false,
|
||||||
|
:reset => false,
|
||||||
|
:reboot => true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:vsp) {
|
||||||
|
VagrantPlugins::Shell::Provisioner.new(machine, config)
|
||||||
|
}
|
||||||
|
|
||||||
|
before {
|
||||||
|
allow(machine).to receive(:communicate).and_return(communicator)
|
||||||
|
allow(machine).to receive(:guest).and_return(guest)
|
||||||
|
allow(vsp).to receive(:provision_ssh)
|
||||||
|
}
|
||||||
|
|
||||||
|
it "should provision and then reboot the guest" do
|
||||||
|
expect(vsp).to receive(:provision_ssh)
|
||||||
|
expect(guest).to receive(:capability).with(:reboot)
|
||||||
|
vsp.provision
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when path and inline are not set" do
|
||||||
|
let(:path) { nil }
|
||||||
|
let(:inline) { nil }
|
||||||
|
|
||||||
|
it "should reboot the guest and not provision" do
|
||||||
|
expect(vsp).not_to receive(:provision_ssh)
|
||||||
|
expect(guest).to receive(:capability).with(:reboot)
|
||||||
|
vsp.provision
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "with a script that contains invalid us-ascii byte sequences" do
|
context "with a script that contains invalid us-ascii byte sequences" do
|
||||||
let(:config) {
|
let(:config) {
|
||||||
double(
|
double(
|
||||||
|
@ -73,7 +123,8 @@ describe "Vagrant::Shell::Provisioner" do
|
||||||
:path => nil,
|
:path => nil,
|
||||||
:inline => script_that_is_incorrectly_us_ascii_encoded,
|
:inline => script_that_is_incorrectly_us_ascii_encoded,
|
||||||
:binary => false,
|
:binary => false,
|
||||||
:reset => false
|
:reset => false,
|
||||||
|
:reboot => false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +157,8 @@ describe "Vagrant::Shell::Provisioner" do
|
||||||
:path => nil,
|
:path => nil,
|
||||||
:inline => script,
|
:inline => script,
|
||||||
:binary => false,
|
:binary => false,
|
||||||
:reset => false
|
:reset => false,
|
||||||
|
:reboot => false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +188,8 @@ describe "Vagrant::Shell::Provisioner" do
|
||||||
:binary => false,
|
:binary => false,
|
||||||
:md5 => nil,
|
:md5 => nil,
|
||||||
:sha1 => 'EXPECTED_VALUE',
|
:sha1 => 'EXPECTED_VALUE',
|
||||||
:reset => false
|
:reset => false,
|
||||||
|
:reboot => false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +220,8 @@ describe "Vagrant::Shell::Provisioner" do
|
||||||
:binary => false,
|
:binary => false,
|
||||||
:md5 => 'EXPECTED_VALUE',
|
:md5 => 'EXPECTED_VALUE',
|
||||||
:sha1 => nil,
|
:sha1 => nil,
|
||||||
:reset => false
|
:reset => false,
|
||||||
|
:reboot => false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,9 @@ The remainder of the available options are optional:
|
||||||
guests use a scheduled task to run as a true administrator without the
|
guests use a scheduled task to run as a true administrator without the
|
||||||
WinRM limitations.
|
WinRM limitations.
|
||||||
|
|
||||||
|
* `reboot` (boolean) - Reboot the guest. This requires the guest to have a
|
||||||
|
reboot capability implemented.
|
||||||
|
|
||||||
* `reset` (boolean) - Reset the communicator to the machine after completion. This
|
* `reset` (boolean) - Reset the communicator to the machine after completion. This
|
||||||
is useful when a shell may need to be reloaded.
|
is useful when a shell may need to be reloaded.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue