Skip to content

Commit 43f2503

Browse files
committed
Fixes #13491 - detect expected disconnections and don't fail on them
specific messages (such as 'restart host' on stdout) as last output of a command cause the disconnect issue to not cause the task to fail, as it's expected in that case.
1 parent 734b8b6 commit 43f2503

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

lib/smart_proxy_remote_execution_ssh/session.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module Proxy::RemoteExecution::Ssh
55
# Dynflow action. It runs just one (actor) thread for all the commands
66
# running in the system and updates the Dynflow actions periodically.
77
class Session < ::Dynflow::Actor
8+
EXPECTED_POWER_ACTION_MESSAGES = ["restart host", "shutdown host"]
9+
810
def initialize(options = {})
911
@clock = options[:clock] || Dynflow::Clock.spawn('proxy-dispatcher-clock')
1012
@logger = options[:logger] || Logger.new($stderr)
@@ -56,7 +58,12 @@ def refresh
5658
end
5759
end
5860
rescue Net::SSH::Disconnect => e
59-
@command_buffer.concat(CommandUpdate.encode_exception("Failed to refresh the connector", e, true))
61+
check_expecting_disconnect
62+
if @expecting_disconnect
63+
@command_buffer << CommandUpdate::StatusData.new(0)
64+
else
65+
@command_buffer.concat(CommandUpdate.encode_exception("Failed to refresh the connector", e, true))
66+
end
6067
refresh_command_buffer
6168
finish_command
6269
rescue => e
@@ -69,6 +76,7 @@ def refresh
6976
def refresh_command_buffer
7077
@logger.debug("command #{@command} got new output: #{@command_buffer.inspect}")
7178
command_update = CommandUpdate.new(@command_buffer)
79+
check_expecting_disconnect
7280
@command.suspended_action << command_update
7381
@command_buffer = []
7482
if command_update.exit_status
@@ -190,5 +198,16 @@ def plan_next_refresh
190198
@refresh_planned = true
191199
end
192200
end
201+
202+
# when a remote server disconnects, it's hard to tell if it was on purpose (when calling reboot)
203+
# or it's an error. When it's expected, we expect the script to produce 'restart host' as
204+
# its last command output
205+
def check_expecting_disconnect
206+
last_output = @command_buffer.reverse.find { |d| d.is_a? CommandUpdate::StdoutData }
207+
return unless last_output
208+
if EXPECTED_POWER_ACTION_MESSAGES.any? { |message| last_output.data =~ /^#{message}/ }
209+
@expecting_disconnect = true
210+
end
211+
end
193212
end
194213
end

0 commit comments

Comments
 (0)