Merge pull request #10321 from chrisroberts/f-ssh-comm-output

Prevent overly verbose output from SSH communicator
This commit is contained in:
Chris Roberts 2018-10-19 15:59:01 -07:00 committed by GitHub
commit b0fc33e9b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 6 deletions

View File

@ -75,8 +75,7 @@ module VagrantPlugins
ssh_auth_type = "password" if ssh_info[:password]
@machine.ui.detail("SSH auth method: #{ssh_auth_type}")
last_message = nil
last_message_repeat_at = 0
previous_messages = {}
while true
message = nil
begin
@ -123,14 +122,13 @@ module VagrantPlugins
if message
message_at = Time.now.to_f
show_message = true
if last_message == message
show_message = (message_at - last_message_repeat_at) > 10.0
if previous_messages[message]
show_message = (message_at - previous_messages[message]) > 10.0
end
if show_message
@machine.ui.detail("Warning: #{message} Retrying...")
last_message = message
last_message_repeat_at = message_at
previous_messages[message] = message_at
end
end
end

View File

@ -116,6 +116,49 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
expect(communicator.wait_for_ready(0.6)).to eq(true)
end
end
context "when printing message to the user" do
before do
allow(machine).to receive(:ssh_info).
and_return(host: '10.1.2.3', port: 22).ordered
allow(communicator).to receive(:connect)
allow(communicator).to receive(:ready?).and_return(true)
end
it "should print message" do
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout)
expect(ui).to receive(:detail).with(/timeout/)
communicator.wait_for_ready(0.5)
end
it "should not print the same message twice" do
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout)
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout)
expect(ui).to receive(:detail).with(/timeout/)
expect(ui).not_to receive(:detail).with(/timeout/)
communicator.wait_for_ready(0.5)
end
it "should print different messages" do
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout)
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHDisconnected)
expect(ui).to receive(:detail).with(/timeout/)
expect(ui).to receive(:detail).with(/disconnect/)
communicator.wait_for_ready(0.5)
end
it "should not print different messages twice" do
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout)
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHDisconnected)
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHConnectionTimeout)
expect(communicator).to receive(:connect).and_raise(Vagrant::Errors::SSHDisconnected)
expect(ui).to receive(:detail).with(/timeout/)
expect(ui).to receive(:detail).with(/disconnect/)
expect(ui).not_to receive(:detail).with(/timeout/)
expect(ui).not_to receive(:detail).with(/disconnect/)
communicator.wait_for_ready(0.5)
end
end
end
end