Skip to content

Commit

Permalink
Merge pull request #6229 from mitchellh/b-winrm-info-respect-timeout
Browse files Browse the repository at this point in the history
communicators/winrm: respect boot_timeout when fetching winrm_info
  • Loading branch information
mitchellh committed Oct 12, 2015
2 parents 8ee97d5 + 1e84cc4 commit 5e48d35
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
7 changes: 6 additions & 1 deletion plugins/communicators/winrm/communicator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ def wait_for_ready(timeout)
# Wait for winrm_info to be ready
winrm_info = nil
while true
winrm_info = Helper.winrm_info(@machine)
winrm_info = nil
begin
winrm_info = Helper.winrm_info(@machine)
rescue Errors::WinRMNotReady
@logger.debug("WinRM not ready yet; retrying until boot_timeout is reached.")
end
break if winrm_info
sleep 0.5
end
Expand Down
38 changes: 35 additions & 3 deletions test/unit/plugins/communicators/winrm/communicator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
describe VagrantPlugins::CommunicatorWinRM::Communicator do
include_context "unit"

let(:winrm) { double("winrm", timeout: 1) }
let(:winrm) { double("winrm", timeout: 1, host: nil, port: 5986, guest_port: 5986) }
let(:config) { double("config", winrm: winrm) }
let(:machine) { double("machine", config: config) }

let(:provider) { double("provider") }
let(:ui) { double("ui") }
let(:machine) { double("machine", config: config, provider: provider, ui: ui) }
let(:shell) { double("shell") }

subject do
Expand All @@ -22,6 +23,37 @@
allow(shell).to receive(:password).and_return('password')
end

describe ".wait_for_ready" do
context "with no winrm_info capability and no static config (default scenario)" do
before do
# No default providers support this capability
allow(provider).to receive(:capability?).with(:winrm_info).and_return(false)

# Get us through the detail prints
allow(ui).to receive(:detail)
allow(shell).to receive(:host)
allow(shell).to receive(:port)
allow(shell).to receive(:username)
allow(shell).to receive(:config) { double("config", transport: nil)}
end

context "when ssh_info requires a multiple tries before it is ready" do
before do
allow(machine).to receive(:ssh_info).and_return(nil, {
host: '10.1.2.3',
port: '22',
})
# Makes ready? return true
allow(shell).to receive(:powershell).with("hostname").and_return({ exitcode: 0 })
end

it "retries ssh_info until ready" do
expect(subject.wait_for_ready(2)).to eq(true)
end
end
end
end

describe ".ready?" do
it "returns true if hostname command executes without error" do
expect(shell).to receive(:powershell).with("hostname").and_return({ exitcode: 0 })
Expand Down

0 comments on commit 5e48d35

Please sign in to comment.