diff --git a/plugins/communicators/winrm/shell.rb b/plugins/communicators/winrm/shell.rb index 3bdd869db..700408940 100644 --- a/plugins/communicators/winrm/shell.rb +++ b/plugins/communicators/winrm/shell.rb @@ -105,7 +105,7 @@ module VagrantPlugins endpoint: endpoint, message: exception.message when WinRM::WinRMHTTPTransportError - case exception.response_code + case exception.status_code # If the error is a 401, we can return a more specific error message when 401 raise Errors::AuthenticationFailed, @@ -137,7 +137,10 @@ module VagrantPlugins # This is raised if we can't work out how to route traffic. raise Errors::NoRoute else - raise + raise Errors::ExecutionError, + shell: shell, + command: command, + message: exception.message end end diff --git a/test/unit/plugins/communicators/winrm/communicator_test.rb b/test/unit/plugins/communicators/winrm/communicator_test.rb index c73106900..1afaffffe 100644 --- a/test/unit/plugins/communicators/winrm/communicator_test.rb +++ b/test/unit/plugins/communicators/winrm/communicator_test.rb @@ -28,11 +28,16 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do expect(subject.ready?).to be_true end - it "returns false if hostname command fails to execute without error" do - expect(shell).to receive(:powershell).with("hostname").and_raise(Vagrant::Errors::VagrantError) + it "returns false if hostname command fails with a transient error" do + expect(shell).to receive(:powershell).with("hostname").and_raise(VagrantPlugins::CommunicatorWinRM::Errors::TransientError) expect(subject.ready?).to be_false end + it "raises an error if hostname command fails with an unknown error" do + expect(shell).to receive(:powershell).with("hostname").and_raise(Vagrant::Errors::VagrantError) + expect { subject.ready? }.to raise_error(Vagrant::Errors::VagrantError) + end + it "raises timeout error when hostname command takes longer then winrm timeout" do expect(shell).to receive(:powershell).with("hostname") do sleep 2 # winrm.timeout = 1 diff --git a/test/unit/plugins/communicators/winrm/shell_test.rb b/test/unit/plugins/communicators/winrm/shell_test.rb index 05e8351b4..7a402e3cb 100644 --- a/test/unit/plugins/communicators/winrm/shell_test.rb +++ b/test/unit/plugins/communicators/winrm/shell_test.rb @@ -28,11 +28,12 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do expect(subject.powershell("dir")[:exitcode]).to eq(0) end - it "should raise auth error when exception message contains 401" do - expect(session).to receive(:powershell).with(/^dir.+/).and_raise( - StandardError.new("Oh no! a 401 SOAP error!")) + it "should raise auth error when WinRM exception has a response code of 401" do + # The default settings might an account lockout - 20 auth failures! + expect(session).to receive(:powershell).with(/^dir.+/).exactly(20).times.and_raise( + WinRM::WinRMHTTPTransportError.new("Oh no!!", 401)) expect { subject.powershell("dir") }.to raise_error( - VagrantPlugins::CommunicatorWinRM::Errors::AuthError) + VagrantPlugins::CommunicatorWinRM::Errors::AuthenticationFailed) end it "should raise an execution error when an exception occurs" do diff --git a/test/unit/plugins/kernel_v2/config/vm_test.rb b/test/unit/plugins/kernel_v2/config/vm_test.rb index 073e88e22..3028e2552 100644 --- a/test/unit/plugins/kernel_v2/config/vm_test.rb +++ b/test/unit/plugins/kernel_v2/config/vm_test.rb @@ -167,14 +167,15 @@ describe VagrantPlugins::Kernel_V2::VMConfig do subject.communicator = "winrm" subject.finalize! n = subject.networks - expect(n.length).to eq(1) + expect(n.length).to eq(2) # WinRM HTTP - expect(n[0][0]).to eq(:forwarded_port) - expect(n[0][1][:guest]).to eq(5985) - expect(n[0][1][:host]).to eq(55985) - expect(n[0][1][:host_ip]).to eq("127.0.0.1") - expect(n[0][1][:id]).to eq("winrm") + network = find_network("winrm") + # expect(n[0][0]).to eq(:forwarded_port) + expect(network[:guest]).to eq(5985) + expect(network[:host]).to eq(55985) + expect(network[:host_ip]).to eq("127.0.0.1") + expect(network[:id]).to eq("winrm") end it "allows overriding SSH" do