diff --git a/plugins/guests/linux/cap/reboot.rb b/plugins/guests/linux/cap/reboot.rb index 0ac7d302d..9c1cb3132 100644 --- a/plugins/guests/linux/cap/reboot.rb +++ b/plugins/guests/linux/cap/reboot.rb @@ -6,7 +6,7 @@ module VagrantPlugins module Cap class Reboot extend Vagrant::Util::GuestInspection::Linux - MAX_REBOOT_RETRY_DURATION = 120 + MAX_REBOOT_RETRY_DURATION = ENV.fetch('VAGRANT_MAX_REBOOT_RETRY_TIMEOUT', 120).to_i def self.reboot(machine) @logger = Log4r::Logger.new("vagrant::linux::reboot") diff --git a/plugins/guests/windows/cap/reboot.rb b/plugins/guests/windows/cap/reboot.rb index 70f10a41a..b0e92c02d 100644 --- a/plugins/guests/windows/cap/reboot.rb +++ b/plugins/guests/windows/cap/reboot.rb @@ -4,7 +4,7 @@ module VagrantPlugins module GuestWindows module Cap class Reboot - MAX_REBOOT_RETRY_DURATION = 120 + MAX_REBOOT_RETRY_DURATION = ENV.fetch('VAGRANT_MAX_REBOOT_RETRY_TIMEOUT', 120).to_i def self.reboot(machine) @logger = Log4r::Logger.new("vagrant::windows::reboot") diff --git a/test/unit/plugins/guests/linux/cap/reboot_test.rb b/test/unit/plugins/guests/linux/cap/reboot_test.rb index bffc8daf1..d5ae18388 100644 --- a/test/unit/plugins/guests/linux/cap/reboot_test.rb +++ b/test/unit/plugins/guests/linux/cap/reboot_test.rb @@ -75,5 +75,22 @@ describe "VagrantPlugins::GuestLinux::Cap::Reboot" do end end end + + context "reboot configuration" do + before do + allow(communicator).to receive(:execute) + expect(communicator).to receive(:execute).with(/reboot/, nil).and_return(0) + allow(described_class).to receive(:sleep) + allow(described_class).to receive(:wait_for_reboot).and_raise(Vagrant::Errors::MachineGuestNotReady) + end + + describe ".reboot default" do + it "allows setting a custom max reboot retry duration" do + max_retries = 26 # initial call + 25 retries since multiple of 5 + expect(described_class).to receive(:wait_for_reboot).exactly(max_retries).times + expect { described_class.reboot(machine) }.to raise_error(Vagrant::Errors::MachineGuestNotReady) + end + end + end end end diff --git a/test/unit/plugins/guests/windows/cap/reboot_test.rb b/test/unit/plugins/guests/windows/cap/reboot_test.rb index b7562cce2..114098758 100644 --- a/test/unit/plugins/guests/windows/cap/reboot_test.rb +++ b/test/unit/plugins/guests/windows/cap/reboot_test.rb @@ -112,4 +112,22 @@ describe "VagrantPlugins::GuestWindows::Cap::Reboot" do end end end + + context "reboot configuration" do + before do + allow(communicator).to receive(:execute) + expect(communicator).to receive(:test).with(/# Function/, { error_check: false, shell: :powershell }).and_return(0) + expect(communicator).to receive(:execute).with(/shutdown/, { shell: :powershell }).and_return(0) + allow(described_class).to receive(:sleep) + allow(described_class).to receive(:wait_for_reboot).and_raise(StandardError) + end + + describe ".reboot default" do + it "allows setting a custom max reboot retry duration" do + max_retries = 26 # initial call + 25 retries since multiple of 5 + expect(described_class).to receive(:wait_for_reboot).exactly(max_retries).times + expect { described_class.reboot(machine) }.to raise_error(Exception) + end + end + end end