diff --git a/plugins/guests/windows/cap/change_host_name.rb b/plugins/guests/windows/cap/change_host_name.rb index fa48a3137..979627dc0 100644 --- a/plugins/guests/windows/cap/change_host_name.rb +++ b/plugins/guests/windows/cap/change_host_name.rb @@ -28,7 +28,12 @@ module VagrantPlugins error_key: :rename_computer_failed) # Don't continue until the machine has shutdown and rebooted - sleep(sleep_timeout) + if machine.guest.capability?(:wait_for_reboot) + machine.guest.capability(:wait_for_reboot) + else + # use graceful_halt_timeout only if guest cannot wait for reboot + sleep(sleep_timeout) + end end end end diff --git a/test/unit/plugins/guests/windows/cap/change_host_name_test.rb b/test/unit/plugins/guests/windows/cap/change_host_name_test.rb index 33bf261ba..a75412ae2 100644 --- a/test/unit/plugins/guests/windows/cap/change_host_name_test.rb +++ b/test/unit/plugins/guests/windows/cap/change_host_name_test.rb @@ -34,6 +34,9 @@ describe "VagrantPlugins::GuestWindows::Cap::ChangeHostName" do 'if (!([System.Net.Dns]::GetHostName() -eq \'newhostname\')) { exit 0 } exit 1', exit_code: 0) communicator.stub_command(rename_script, exit_code: 0) + allow(machine).to receive(:guest) + allow(machine.guest).to receive(:capability) + allow(machine.guest).to receive(:capability?) described_class.change_host_name_and_wait(machine, 'newhostname', 0) end