✨ Make max reboot retry duration configurable
Previously the maximum amount of time Vagrant would poll for whether a machine has successfully reboot was hard coded to 120 seconds. This change introduces the VAGRANT_MAX_REBOOT_RETRY_TIMEOUT environment variable to allow this attribute to be configurable. Add RSpec tests of the maximum retry logic. Since the maximum retries are configured as a constant, we'd need to reload the class and that's fairly ugly to do in RSpec. Fixes #11695
This commit is contained in:
parent
9dc7f442a8
commit
a2f5d615a0
@ -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")
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user